client.cpp 396 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407
  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 "Chat/Chat.h"
  36. #include "SpellProcess.h"
  37. #include "Zone/ChestTrap.h"
  38. //#include "Quests.h"
  39. #ifdef WIN32
  40. #include <WinSock2.h>
  41. #include <windows.h>
  42. #define snprintf _snprintf
  43. #define vsnprintf _vsnprintf
  44. #define strncasecmp _strnicmp
  45. #define strcasecmp _stricmp
  46. #else
  47. #include <sys/socket.h>
  48. #ifdef FREEBSD
  49. #include <sys/types.h>
  50. #endif
  51. #include <netinet/in.h>
  52. #include <arpa/inet.h>
  53. #include <unistd.h>
  54. #endif
  55. #if defined(__GNUC__)
  56. #define _snprintf snprintf
  57. #endif
  58. #include "client.h"
  59. #include "../common/emu_opcodes.h"
  60. #include "../common/packet_dump.h"
  61. #include "WorldDatabase.h"
  62. #include "races.h"
  63. #include "classes.h"
  64. #include "LoginServer.h"
  65. #include "World.h"
  66. #include "../common/EQ2_Common_Structs.h"
  67. #include "net.h"
  68. #include "../common/MiscFunctions.h"
  69. #include "Skills.h"
  70. #include "LuaInterface.h"
  71. #include "Quests.h"
  72. #include "Collections/Collections.h"
  73. #include "Achievements/Achievements.h"
  74. #include "Traits/Traits.h"
  75. #include "Recipes/Recipe.h"
  76. #include "Tradeskills/Tradeskills.h"
  77. #include "AltAdvancement/AltAdvancement.h"
  78. #include "Bots/Bot.h"
  79. extern WorldDatabase database;
  80. extern const char* ZONE_NAME;
  81. extern LoginServer loginserver;
  82. extern sint32 numclients;
  83. extern NetConnection net;
  84. extern Commands commands;
  85. extern ClientList client_list;
  86. extern ZoneList zone_list;
  87. extern ZoneAuth zone_auth;
  88. extern MasterItemList master_item_list;
  89. extern MasterSkillList master_skill_list;
  90. extern MasterSpellList master_spell_list;
  91. extern MasterTraitList master_trait_list;
  92. extern MasterQuestList master_quest_list;
  93. extern MasterFactionList master_faction_list;
  94. extern MasterRecipeList master_recipe_list;
  95. extern volatile bool RunLoops;
  96. extern ConfigReader configReader;
  97. extern LuaInterface* lua_interface;
  98. extern World world;
  99. extern Variables variables;
  100. extern Classes classes;
  101. extern Races races;
  102. extern GuildList guild_list;
  103. extern MasterCollectionList master_collection_list;
  104. extern MasterAchievementList master_achievement_list;
  105. extern RuleManager rule_manager;
  106. extern Chat chat;
  107. extern MasterAAList master_aa_list;
  108. extern MasterAAList master_tree_nodes;
  109. extern ChestTrapList chest_trap_list;
  110. using namespace std;
  111. Client::Client(EQStream* ieqs) : underworld_cooldown_timer(5000), pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  112. eqs = ieqs;
  113. ip = eqs->GetrIP();
  114. port = ntohs(eqs->GetrPort());
  115. merchant_transaction = nullptr;
  116. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  117. ResetSendMail(false);
  118. timestamp_flag = 0;
  119. current_quest_id = 0;
  120. last_update_time = 0;
  121. quest_updates = false;
  122. //autobootup_timeout = new Timer(10000);
  123. //autobootup_timeout->Disable();
  124. CLE_keepalive_timer = new Timer(15000);
  125. connect = new Timer(1000);
  126. connect->Disable();
  127. zoneID = 0;
  128. account_name[0] = 0;
  129. character_id = 0;
  130. account_id = 0;
  131. pwaitingforbootup = 0;
  132. current_zone = 0;
  133. connected_to_zone = false;
  134. connected = false;
  135. camp_timer = 0;
  136. client_zoning = false;
  137. zoning_id = 0;
  138. zoning_x = 0;
  139. zoning_y = 0;
  140. zoning_z = 0;
  141. zoning_instance_id = 0;
  142. player_pos_changed = false;
  143. ++numclients;
  144. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  145. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  146. remove_from_list = false;
  147. new_client_login = false;
  148. UpdateWindowTitle(0);
  149. num_active_failures = 0;
  150. player = new Player();
  151. player->SetClient(this);
  152. combine_spawn = 0;
  153. lua_debug = false;
  154. ready_for_spawns = false;
  155. ready_for_updates = false;
  156. lua_debug_timer.Disable();
  157. transport_spawn = 0;
  158. MBuyBack.SetName("Client::MBuyBack");
  159. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  160. MDeletePlayer.SetName("Client::MDeletePlayer");
  161. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  162. search_items = 0;
  163. version = 0;
  164. next_conversation_id = 0;
  165. pending_guild_invite.guild = 0;
  166. pending_guild_invite.invited_by = 0;
  167. m_recipeListSent = false;
  168. m_resurrect.SetName("Client::m_resurrect");
  169. current_rez.expire_timer = 0;
  170. current_rez.should_delete = true;
  171. pending_last_name = 0;
  172. should_target = false;
  173. initial_spawns_sent = false;
  174. MQuestTimers.SetName("Client::quest_timers");
  175. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  176. on_auto_mount = false;
  177. should_load_spells = true;
  178. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  179. delayedLogin = false;
  180. delayedAccountID = 0;
  181. delayedAccessKey = 0;
  182. delayTimer.Disable();
  183. tempPlacementSpawn = nullptr;
  184. placement_unique_item_id = 0;
  185. SetHasOwnerOrEditAccess(false);
  186. temporary_transport_id = 0;
  187. rejoin_group_id = 0;
  188. lastRegionRemapTime = 0;
  189. regionDebugMessaging = false;
  190. client_reloading_zone = false;
  191. last_saved_timestamp = 0;
  192. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  193. MConversation.SetName("Client::MConversation");
  194. save_spell_state_timer.Disable();
  195. save_spell_state_time_bucket = 0;
  196. player_loading_complete = false;
  197. MItemDetails.SetName("Client::MItemDetails");
  198. MSpellDetails.SetName("Client::MSpellDetails");
  199. hasSentTempPlacementSpawn = false;
  200. spawn_removal_timer.Start();
  201. disable_save = false;
  202. SetZoningDestination(nullptr);
  203. underworld_cooldown_timer.Disable();
  204. player_pos_change_count = 0;
  205. pov_ghost_spawn_id = 0;
  206. }
  207. Client::~Client() {
  208. RemoveClientFromZone();
  209. //let the stream factory know were done with this stream
  210. if (eqs) {
  211. eqs->Close();
  212. try {
  213. eqs->ReleaseFromUse();
  214. }
  215. catch (...) {}
  216. }
  217. eqs = NULL;
  218. //safe_delete(autobootup_timeout);
  219. vector<QueuedQuest*>::iterator itr;
  220. QueuedQuest* queued_quest = 0;
  221. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  222. queued_quest = *itr;
  223. safe_delete(queued_quest);
  224. }
  225. quest_queue.clear();
  226. vector<QuestRewardData*>::iterator rwd_itr;
  227. QuestRewardData* quest_rwd_data = 0;
  228. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  229. quest_rwd_data = *rwd_itr;
  230. safe_delete(quest_rwd_data);
  231. }
  232. quest_pending_reward.clear();
  233. safe_delete(CLE_keepalive_timer);
  234. safe_delete(connect);
  235. --numclients;
  236. UpdateWindowTitle(0);
  237. }
  238. void Client::RemoveClientFromZone() {
  239. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  240. Spawn* tmp = GetTempPlacementSpawn();
  241. SetTempPlacementSpawn(nullptr);
  242. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  243. }
  244. if(player && player->GetZone())
  245. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  246. if (current_zone && player) {
  247. if (player->GetGroupMemberInfo())
  248. {
  249. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  250. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  251. else
  252. TempRemoveGroup();
  253. }
  254. world.GetGroupManager()->ClearPendingInvite(player);
  255. }
  256. if (lua_interface)
  257. lua_interface->RemoveDebugClients(this);
  258. if (player)
  259. zone_list.RemoveClientFromMap(player->GetName(), this);
  260. safe_delete(camp_timer);
  261. safe_delete(search_items);
  262. safe_delete(current_rez.expire_timer);
  263. safe_delete(pending_last_name);
  264. safe_delete_array(incoming_paperdoll.image_bytes);
  265. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  266. if (player && !player->GetPendingDeletion())
  267. safe_delete(player);
  268. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  269. deque<BuyBackItem*>::iterator itr;
  270. MBuyBack.writelock(__FUNCTION__, __LINE__);
  271. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  272. safe_delete(*itr);
  273. itr = buy_back_items.erase(itr);
  274. }
  275. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  276. }
  277. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  278. if (eqs) {
  279. if (!eqs->CheckActive()) {
  280. client_list.Remove(this);
  281. eqs = 0;
  282. }
  283. }
  284. if (app && eqs && version > 0)
  285. eqs->EQ2QueuePacket(app, attemptedCombine);
  286. else {
  287. safe_delete(app);
  288. }
  289. }
  290. void Client::PopulateSkillMap() {
  291. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  292. if (app)
  293. QueuePacket(app);
  294. else {
  295. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  296. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  297. }
  298. }
  299. void Client::SendLoginInfo() {
  300. if(GetPlayer()->IsReturningFromLD())
  301. firstlogin = true;
  302. if (firstlogin) {
  303. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  304. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  305. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  306. PopulateSkillMap();
  307. // 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!
  308. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  309. }
  310. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  311. database.ToggleCharacterOnline(this, 1);
  312. int32 count = 0;
  313. if(!GetPlayer()->IsReturningFromLD())
  314. {
  315. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  316. count = database.LoadCharacterSkills(GetCharacterID(), player);
  317. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  318. count = database.LoadCharacterSpells(GetCharacterID(), player);
  319. }
  320. else
  321. {
  322. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  323. }
  324. // get the latest character starting skills / spells, may have been updated after character creation
  325. world.SyncCharacterAbilities(this);
  326. if(!GetPlayer()->IsReturningFromLD())
  327. {
  328. count = database.LoadCharacterTitles(GetCharacterID(), player);
  329. if (count == 0) {
  330. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  331. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  332. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  333. }
  334. }
  335. if(!GetPlayer()->IsReturningFromLD())
  336. {
  337. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  338. if (count == 0)
  339. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  340. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  341. if (count == 0)
  342. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  343. }
  344. ClientPacketFunctions::SendLoginAccepted(this);
  345. ClientPacketFunctions::SendAbilities ( this );
  346. ClientPacketFunctions::SendCommandNamePacket(this);
  347. ClientPacketFunctions::SendQuickBarInit(this);
  348. // we only need to send the MOTD if it is the first time the person is logging in.
  349. if (firstlogin) {
  350. ClientPacketFunctions::SendMOTD(this);
  351. ClientPacketFunctions::SendCharacterMacros(this);
  352. zone_list.CheckFriendList(this);
  353. }
  354. if(!GetPlayer()->IsReturningFromLD())
  355. {
  356. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  357. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  358. {
  359. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  360. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  361. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  362. }
  363. database.LoadPlayerFactions(this);
  364. database.LoadCharacterQuests(this);
  365. database.LoadCharacterQuestRewards(this);
  366. database.LoadPlayerMail(this);
  367. }
  368. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  369. SendQuestJournal(true, 0, false);
  370. if (version > 546) // right version? possibly not!
  371. master_aa_list.DisplayAA(this, 0, 3);
  372. if (version > 283)
  373. SendCollectionList();
  374. SendBiography();
  375. map<int32, Quest*>::iterator itr;
  376. Quest* quest = 0;
  377. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  378. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  379. quest = itr->second;
  380. if (quest->IsTracked()) {
  381. quest->SetTracked(false);
  382. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  383. quest->SetTracked(true);
  384. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  385. }
  386. }
  387. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  388. // SendAchievementsList();
  389. /*Guild* guild = player->GetGuild();
  390. if (guild) {
  391. guild->UpdateGuildMemberInfo(GetPlayer());
  392. if (firstlogin)
  393. guild->SendGuildMOTD(this);
  394. guild->SendGuildUpdate(this);
  395. guild->SendGuildMember(GetPlayer(), firstlogin);
  396. guild->SendGuildEventList(this);
  397. guild->SendGuildBankEventList(this);
  398. guild->SendAllGuildEvents(this);
  399. guild->SendGuildMemberList(this);
  400. }*/
  401. if (version > 283) {
  402. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  403. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  404. if (outapp) {
  405. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  406. //DumpPacket(outapp);
  407. QueuePacket(outapp);
  408. }
  409. }
  410. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  411. ClientPacketFunctions::SendCommandList(this);
  412. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  413. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  414. ClientPacketFunctions::SendInstanceList(this);
  415. SendZoneInfo();
  416. /*Spell* spell = 0;
  417. vector<QuickBarItem*>::iterator itr;
  418. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  419. if((*itr)->type == 1){
  420. spell = master_spell_list.GetSpell((*itr)->id);
  421. if(spell)
  422. QueuePacket(spell->serialize(this, false, 0x20));
  423. }
  424. }*/
  425. }
  426. void Client::SendPlayerDeathWindow()
  427. {
  428. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  429. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  430. vector<RevivePoint*>::iterator itr;
  431. if (results && results->size() > 0)
  432. {
  433. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  434. if (packet)
  435. {
  436. packet->setArrayLengthByName("location_count", results->size());
  437. RevivePoint* point = 0;
  438. int32 i = 0;
  439. for (itr = results->begin(); itr != results->end(); itr++, i++)
  440. {
  441. point = *itr;
  442. if (point)
  443. {
  444. packet->setArrayDataByName("location_id", point->id, i);
  445. //zone_name = database.GetZoneName(point->zone_id);
  446. string zone_name = database.GetZoneDescription(point->zone_id);
  447. if (zone_name.length() > 0)
  448. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  449. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  450. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  451. }
  452. if (point->id == 0xFFFFFFFF)//tmp location
  453. safe_delete(point);
  454. }
  455. // done with the revive points so lets free up the pointer
  456. safe_delete(results);
  457. #if EQDEBUG >= 3
  458. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  459. packet->PrintPacket();
  460. #endif
  461. EQ2Packet* outapp = packet->serialize();
  462. QueuePacket(outapp);
  463. safe_delete(packet);
  464. }
  465. }
  466. }
  467. void Client::DisplayDeadWindow()
  468. {
  469. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  470. player->SetHP(0);
  471. player->SetPower(0);
  472. GetCurrentZone()->TriggerCharSheetTimer();
  473. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  474. if (packet)
  475. {
  476. packet->setDataByName("parameter1", 8);
  477. packet->setDataByName("value", 1);
  478. QueuePacket(packet->serialize());
  479. packet->setDataByName("parameter1", 16);
  480. QueuePacket(packet->serialize());
  481. safe_delete(packet);
  482. }
  483. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  484. if (packet)
  485. {
  486. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  487. QueuePacket(packet->serialize());
  488. safe_delete(packet);
  489. }
  490. SendPlayerDeathWindow();
  491. }
  492. void Client::HandlePlayerRevive(int32 point_id)
  493. {
  494. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  495. if (packet)
  496. {
  497. packet->setDataByName("parameter1", 8);
  498. QueuePacket(packet->serialize());
  499. packet->setDataByName("parameter1", 16);
  500. QueuePacket(packet->serialize());
  501. safe_delete(packet);
  502. }
  503. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  504. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  505. if (packet)
  506. {
  507. QueuePacket(packet->serialize());
  508. safe_delete(packet);
  509. }
  510. float origX, origY, origZ, origHeading = 0.0f;
  511. origX = player->GetX();
  512. origY = player->GetY();
  513. origZ = player->GetZ();
  514. origHeading = player->GetHeading();
  515. ZoneServer* originalZone = GetCurrentZone();
  516. int32 origGridID = GetPlayer()->appearance.pos.grid_id;
  517. float x, y, z, heading;
  518. RevivePoint* revive_point = 0;
  519. if (point_id != 0xFFFFFFFF)
  520. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  521. string zone_desc;
  522. const char* location_name = "Unknown";
  523. //revive at zone safe coords
  524. if (!revive_point)
  525. {
  526. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  527. x = GetCurrentZone()->GetSafeX();
  528. y = GetCurrentZone()->GetSafeY();
  529. z = GetCurrentZone()->GetSafeZ();
  530. heading = GetCurrentZone()->GetSafeHeading();
  531. zone_desc = GetCurrentZone()->GetZoneDescription();
  532. location_name = "Zone Safe Point";
  533. Zone(GetCurrentZone()->GetZoneName(), false);
  534. }
  535. else
  536. {
  537. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  538. x = revive_point->x;
  539. y = revive_point->y;
  540. z = revive_point->z;
  541. heading = revive_point->heading;
  542. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  543. location_name = revive_point->location_name.c_str();
  544. Zone(GetCurrentZone()->GetZoneName(), false);
  545. }
  546. player->SetResurrecting(true);
  547. player->SetX(x);
  548. player->SetY(y);
  549. player->SetZ(z);
  550. player->SetHeading(heading);
  551. player->SetHP(player->GetTotalHP());
  552. player->SetPower(player->GetTotalPower());
  553. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  554. zone_desc.c_str(),
  555. player->GetX(),
  556. player->GetY(),
  557. player->GetZ(),
  558. player->GetHeading(),
  559. player->GetHP(),
  560. player->GetPower(),
  561. location_name);
  562. //player->ClearEverything();
  563. Save();
  564. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  565. {
  566. string zone_name = database.GetZoneName(revive_point->zone_id);
  567. if (zone_name.length() == 0)
  568. {
  569. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  570. x = GetCurrentZone()->GetSafeX();
  571. y = GetCurrentZone()->GetSafeY();
  572. z = GetCurrentZone()->GetSafeZ();
  573. heading = GetCurrentZone()->GetSafeHeading();
  574. location_name = "Zone Safe Point";
  575. }
  576. else
  577. {
  578. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  579. location_name = revive_point->location_name.c_str();
  580. player->ClearEverything();
  581. Zone(zone_name.c_str(), false);
  582. }
  583. }
  584. zone_desc = GetCurrentZone()->GetZoneDescription();
  585. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  586. player->SetSpawnType(4);
  587. if (version > 283) {
  588. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  589. if (packet)
  590. {
  591. QueuePacket(packet->serialize());
  592. safe_delete(packet);
  593. }
  594. }
  595. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  596. if (packet)
  597. {
  598. packet->setDataByName("x", x);
  599. packet->setDataByName("y", y);
  600. packet->setDataByName("z", z);
  601. QueuePacket(packet->serialize());
  602. safe_delete(packet);
  603. }
  604. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  605. if (packet)
  606. {
  607. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  608. packet->setDataByName("speed", 32);
  609. packet->setDataByName("unknown2", 0);
  610. //DoF Merge: old value and speed wasn't included
  611. //packet->setDataByName("unknown2", 255);
  612. QueuePacket(packet->serialize());
  613. safe_delete(packet);
  614. }
  615. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  616. if (packet)
  617. {
  618. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  619. QueuePacket(packet->serialize());
  620. safe_delete(packet);
  621. }
  622. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  623. {
  624. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  625. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  626. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  627. originalZone->RemoveSpawn(player, false, true, true, true, true);
  628. originalZone->AddSpawn(shard);
  629. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  630. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  631. }
  632. m_resurrect.writelock(__FUNCTION__, __LINE__);
  633. if (current_rez.active)
  634. current_rez.should_delete = true;
  635. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  636. }
  637. void Client::SendCharInfo() {
  638. EQ2Packet* app;
  639. player->SetEquippedItemAppearances();
  640. ClientPacketFunctions::SendCharacterData(this);
  641. SendCharPOVGhost();
  642. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  643. if (packet) {
  644. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  645. packet->setDataByName("size", .56);
  646. packet->setDataByName("unknown2", 255);
  647. packet->setDataByName("speed", player->GetSpeed());
  648. packet->setDataByName("air_speed", player->GetAirSpeed());
  649. EQ2Packet* app = packet->serialize();
  650. QueuePacket(app);
  651. safe_delete(packet);
  652. }
  653. if (version <= 283) {
  654. //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
  655. Sleep(2000);
  656. }
  657. //sending bad spawn packet?
  658. //SendAchievementsList();
  659. ClientPacketFunctions::SendCharacterSheet(this);
  660. ClientPacketFunctions::SendTraitList(this);// moved from below
  661. ClientPacketFunctions::SendAbilities(this);
  662. ClientPacketFunctions::SendSkillBook(this);
  663. if (!IsReloadingZone() && !player->IsResurrecting()) {
  664. if(GetVersion() > 546) //we will send this later on for 546 and below
  665. ClientPacketFunctions::SendUpdateSpellBook(this);
  666. }
  667. else {
  668. player->SetResurrecting(false);
  669. }
  670. GetCurrentZone()->AddSpawn(player);
  671. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  672. GetPlayer()->SetX(zoning_x);
  673. GetPlayer()->SetY(zoning_y);
  674. GetPlayer()->SetZ(zoning_z);
  675. GetPlayer()->SetHeading(zoning_h);
  676. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  677. QueuePacket(packet);
  678. }
  679. //SendCollectionList();
  680. Guild* guild = player->GetGuild();
  681. if (guild)
  682. guild->GuildMemberLogin(this, firstlogin);
  683. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  684. if (app) {
  685. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  686. //DumpPacket(app);
  687. QueuePacket(app);
  688. }
  689. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  690. if (app) {
  691. QueuePacket(app);
  692. }
  693. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  694. if (app) {
  695. QueuePacket(app);
  696. }
  697. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  698. if (items && items->size() > 0) {
  699. for (int32 i = 0; i < items->size(); i++) {
  700. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  701. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  702. //DumpPacket(outapp);
  703. QueuePacket(outapp);
  704. }
  705. }
  706. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  707. QueuePacket(app);
  708. safe_delete(items);
  709. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  710. if (items && items->size() > 0) {
  711. for (int32 i = 0; i < items->size(); i++)
  712. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  713. }
  714. safe_delete(items);
  715. if (version > 283) {
  716. SendTitleUpdate();
  717. }
  718. GetPlayer()->ChangePrimaryWeapon();
  719. GetPlayer()->ChangeSecondaryWeapon();
  720. GetPlayer()->ChangeRangedWeapon();
  721. if(!GetPlayer()->IsReturningFromLD()) {
  722. database.LoadBuyBacks(this);
  723. }
  724. if (version > 546)
  725. master_aa_list.DisplayAA(this, 0, 0);
  726. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  727. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  728. string zone_motd_send = "Zone MOTD: " + zone_motd;
  729. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  730. }
  731. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  732. if (zone_script && lua_interface)
  733. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  734. this->client_zoning = false;
  735. this->zoning_id = 0;
  736. this->zoning_instance_id = 0;
  737. SetZoningDestination(nullptr);
  738. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  739. GetCurrentZone()->AddDamagedSpawn(player);
  740. if (firstlogin)
  741. firstlogin = false;
  742. player->ClearProcs();
  743. items = player->GetEquippedItemList();
  744. if (items && items->size() > 0) {
  745. for (int32 i = 0; i < items->size(); i++) {
  746. Item* item = items->at(i);
  747. if (item && item->GetItemScript() && lua_interface)
  748. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  749. }
  750. }
  751. //Allow this player to change their last name if they meet the level requirement
  752. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  753. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  754. safe_delete(items);
  755. if (!player->Alive())
  756. DisplayDeadWindow();
  757. ClientPacketFunctions::SendLocalizedTextMessage(this);
  758. if (GetCurrentZone()->GetInstanceID())
  759. {
  760. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  761. if (ph) {
  762. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  763. string name = string(GetPlayer()->GetName());
  764. if (name.compare(ph->player_name) == 0)
  765. SetHasOwnerOrEditAccess(true);
  766. }
  767. }
  768. if (version > 546)
  769. ClientPacketFunctions::SendHousingList(this);
  770. bool groupMentor = false;
  771. GetPlayer()->group_id = rejoin_group_id;
  772. if(!world.RejoinGroup(this, rejoin_group_id))
  773. GetPlayer()->group_id = 0;
  774. else
  775. {
  776. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  777. if(ent && ent->IsPlayer())
  778. {
  779. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  780. groupMentor = true;
  781. }
  782. }
  783. if(!groupMentor)
  784. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  785. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  786. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  787. GetPlayer()->SetSaveSpellEffects(false);
  788. GetPlayer()->SetCharSheetChanged(true);
  789. GetPlayer()->SetReturningFromLD(false);
  790. }
  791. void Client::SendZoneSpawns() {
  792. //Allows us to place spawns almost anywhere
  793. if (version > 283) {
  794. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  795. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  796. QueuePacket(app);
  797. }
  798. ClientPacketFunctions::SendSkillSlotMappings(this);
  799. ClientPacketFunctions::SendGameWorldTime(this);
  800. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  801. }
  802. void Client::SendCharPOVGhost() {
  803. bool use_ghost_pov = false;
  804. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  805. int32 ghost_id = 0;
  806. if (set_pov) {
  807. if(pov_ghost_spawn_id) {
  808. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  809. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  810. if(spawn) {
  811. use_ghost_pov = true;
  812. }
  813. }
  814. if(use_ghost_pov) {
  815. set_pov->setDataByName("spawn_id", ghost_id);
  816. }
  817. else {
  818. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  819. }
  820. EQ2Packet* app_pov = set_pov->serialize();
  821. QueuePacket(app_pov);
  822. safe_delete(set_pov);
  823. }
  824. }
  825. void Client::SendZoneInfo() {
  826. ZoneServer* zone = GetCurrentZone();
  827. if (zone) {
  828. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  829. QueuePacket(packet);
  830. if (version > 283) {
  831. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  832. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  833. #if EQDEBUG >= 9
  834. fog_packet->PrintPacket();
  835. #endif
  836. if (fog_packet) {
  837. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  838. QueuePacket(fog_packet->serialize());
  839. safe_delete(fog_packet);
  840. }
  841. zone->SendFlightPathsPackets(this);
  842. }
  843. }
  844. /*
  845. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  848. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  849. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  865. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  866. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  867. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  871. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  875. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  876. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  877. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  878. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  879. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  880. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  881. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  882. QueuePacket(appA);
  883. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  884. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  885. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  886. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  887. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  888. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  889. QueuePacket(appB);
  890. */
  891. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  892. SendFriendList();
  893. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  894. SendIgnoreList();
  895. }
  896. void Client::SendDefaultGroupOptions() {
  897. /*
  898. 0 - loot method
  899. 1 - loot items rarity
  900. 2 - Auto split coin
  901. 4 - default yell method
  902. 6 - group autolock
  903. 7 - solo autolock
  904. */
  905. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  906. if (default_options) {
  907. default_options->setDataByName("loot_method", 1);
  908. default_options->setDataByName("loot_items_rarity", 1);
  909. default_options->setDataByName("auto_split_coin", 1);
  910. default_options->setDataByName("default_yell_method", 1);
  911. EQ2Packet* app7 = default_options->serialize();
  912. QueuePacket(app7);
  913. safe_delete(default_options);
  914. }
  915. }
  916. bool Client::HandlePacket(EQApplicationPacket* app) {
  917. bool ret = true;
  918. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  919. //DumpPacket(app);
  920. #if EQDEBUG >= 9
  921. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  922. DumpPacket(app, true);
  923. #endif
  924. EmuOpcode opcode = app->GetOpcode();
  925. #if EQDEBUG >= 9
  926. const char* name = app->GetOpcodeName();
  927. if (name)
  928. cout << name;
  929. else
  930. cout << "Unknown";
  931. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  932. DumpPacket(app);
  933. #endif
  934. //if (opcode != OP_UpdatePositionMsg) {
  935. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  936. //}
  937. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  938. {
  939. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  940. }
  941. switch (opcode) {
  942. case _maxEmuOpcode:
  943. break;
  944. case OP_LoginByNumRequestMsg: {
  945. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  946. PacketStruct* request;
  947. request = configReader.getStruct("LoginByNumRequest", 1);
  948. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  949. // test the original location of Version for clients older than 1212
  950. version = request->getType_int16_ByName("version");
  951. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  952. // must be new client data version method, re-fetch the packet
  953. safe_delete(request);
  954. request = configReader.getStruct("LoginByNumRequest", 1208);
  955. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  956. // Xinux suggests using an INT16 here. Our first new version = 57000
  957. version = request->getType_int16_ByName("version");
  958. }
  959. else {
  960. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  961. break;
  962. }
  963. }
  964. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  965. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  966. ClientPacketFunctions::SendLoginDenied(this);
  967. return false;
  968. }
  969. int32 account_id = request->getType_int32_ByName("account_id");
  970. int32 access_code = request->getType_int32_ByName("access_code");
  971. if (!HandleNewLogin(account_id, access_code))
  972. return false;
  973. }
  974. safe_delete(request);
  975. break;
  976. }
  977. case OP_MapRequest: {
  978. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  979. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  980. if (packet && app->size > 2 && GetCurrentZone()) {
  981. packet->LoadPacketData(app->pBuffer, app->size);
  982. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  983. if (fog_packet) {
  984. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  985. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  986. fog_packet->setDataByName("unknown1", 1);
  987. fog_packet->setDataByName("unknown3", 1);
  988. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  989. //fog_packet->PrintPacket();
  990. QueuePacket(fog_packet->serialize());
  991. safe_delete(fog_packet);
  992. }
  993. safe_delete(packet);
  994. }
  995. break;
  996. }
  997. case OP_RequestCampMsg: {
  998. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  999. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1000. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1001. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1002. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1003. request->getType_int8_ByName("quit"),
  1004. request->getType_int8_ByName("camp_desktop"),
  1005. request->getType_int16_ByName("camp_char_select"),
  1006. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1007. //DumpPacket(app->pBuffer, app->size);
  1008. //request->PrintPacket();
  1009. if (!camp_timer) {
  1010. int16 camp_time = 20; // default if rule cannot be found
  1011. if (GetAdminStatus() >= 100)
  1012. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1013. else
  1014. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1015. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1016. if (response) {
  1017. bool disconnect = false;
  1018. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1019. // Command: /camp desktop
  1020. // Command: /quit
  1021. response->setDataByName("camp_desktop", 1);
  1022. disconnect = true;
  1023. }
  1024. else {
  1025. // Command: /camp
  1026. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1027. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1028. response->setDataByName("seconds", camp_time);
  1029. }
  1030. camp_timer = new Timer(camp_time * 1000);
  1031. camp_timer->Enable();
  1032. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1033. // /camp {char_name}
  1034. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1035. }
  1036. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1037. // /camp (go back to char selection screen)
  1038. response->setDataByName("char_name", " ");
  1039. response->setDataByName("camp_char_select", 1);
  1040. }
  1041. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1042. response->getType_int8_ByName("seconds"),
  1043. response->getType_int8_ByName("camp_desktop"),
  1044. response->getType_int8_ByName("camp_char_select"),
  1045. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1046. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1047. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1048. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1049. //response->PrintPacket();
  1050. QueuePacket(response->serialize());
  1051. safe_delete(response);
  1052. if (disconnect)
  1053. Disconnect();
  1054. }
  1055. }
  1056. }
  1057. safe_delete(request);
  1058. break;
  1059. }
  1060. case OP_StoodMsg: {
  1061. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1062. if (camp_timer)
  1063. {
  1064. // JA: clear camping flag
  1065. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1066. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1067. safe_delete(camp_timer);
  1068. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1069. QueuePacket(outapp);
  1070. }
  1071. player->SetTempVisualState(0);
  1072. break;
  1073. }
  1074. case OP_StandMsg: {
  1075. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1076. if (camp_timer)
  1077. {
  1078. // JA: clear camping flag
  1079. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1080. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1081. safe_delete(camp_timer);
  1082. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1083. QueuePacket(outapp);
  1084. }
  1085. player->SetTempVisualState(539);
  1086. break;
  1087. }
  1088. case OP_SitMsg: {
  1089. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1090. player->SetTempVisualState(538);
  1091. break;
  1092. }
  1093. case OP_SatMsg: {
  1094. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1095. player->SetTempVisualState(540);
  1096. break;
  1097. }
  1098. case OP_QuestJournalOpenMsg:
  1099. case OP_QuestJournalInspectMsg: {
  1100. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1101. if (app->size < sizeof(int32))
  1102. break;
  1103. int32 quest_id = 0;
  1104. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1105. Quest* quest = GetActiveQuest(quest_id);
  1106. if (quest)
  1107. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1108. else {
  1109. quest = player->GetCompletedQuest(quest_id);
  1110. if (quest)
  1111. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1112. }
  1113. break;
  1114. }
  1115. case OP_QuestJournalSetVisibleMsg: {
  1116. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1117. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1118. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1119. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1120. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1121. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1122. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1123. if (player_quests) {
  1124. if (player_quests->count(quest_id) > 0)
  1125. player_quests->at(quest_id)->SetHidden(hidden);
  1126. else
  1127. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1128. }
  1129. else
  1130. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1131. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1132. safe_delete(packet);
  1133. }
  1134. break;
  1135. }
  1136. case OP_MacroUpdateMsg: {
  1137. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1138. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1139. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1140. vector<string>* update = new vector<string>;
  1141. int8 number = macro_update->getType_int8_ByName("number");
  1142. int16 icon = macro_update->getType_int16_ByName("icon");
  1143. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1144. int8 count = macro_update->getType_int8_ByName("macro_count");
  1145. if (GetVersion() <= 283) {
  1146. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1147. }
  1148. else {
  1149. for (int8 i = 0; i < count; i++) {
  1150. char tmp_command[15] = { 0 };
  1151. sprintf(tmp_command, "command_%i", i);
  1152. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1153. }
  1154. }
  1155. if (name.length() == 0)
  1156. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1157. else
  1158. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1159. safe_delete(update);
  1160. safe_delete(macro_update);
  1161. }
  1162. break;
  1163. }
  1164. case OP_DialogSelectMsg: {
  1165. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1166. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1167. if (packet) {
  1168. packet->LoadPacketData(app->pBuffer, app->size);
  1169. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1170. int32 response_index = packet->getType_int32_ByName("response");
  1171. if (GetCurrentZone()) {
  1172. MConversation.readlock();
  1173. int32 spawn_id = conversation_spawns[conversation_id];
  1174. Spawn* spawn = nullptr;
  1175. if(spawn_id) {
  1176. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  1177. }
  1178. Item* item = conversation_items[conversation_id];
  1179. MConversation.releasereadlock();
  1180. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1181. if (spawn)
  1182. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1183. else if (item && lua_interface && item->GetItemScript())
  1184. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1185. else
  1186. CloseDialog(conversation_id);
  1187. }
  1188. else
  1189. CloseDialog(conversation_id);
  1190. }
  1191. safe_delete(packet);
  1192. }
  1193. break;
  1194. }
  1195. case OP_CancelMoveObjectModeMsg: {
  1196. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1197. if (GetTempPlacementSpawn())
  1198. {
  1199. Spawn* tmp = GetTempPlacementSpawn();
  1200. SetTempPlacementSpawn(nullptr);
  1201. SetPlacementUniqueItemID(0);
  1202. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1203. break; // break out early if we are tied to a temp spawn
  1204. }
  1205. // if we are moving some other object? other use-cases not covered
  1206. break;
  1207. }
  1208. case OP_PositionMoveableObject: {
  1209. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1210. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1211. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1212. Spawn* spawn = 0;
  1213. if (GetTempPlacementSpawn())
  1214. spawn = GetTempPlacementSpawn();
  1215. else
  1216. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1217. if (!spawn) {
  1218. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1219. break;
  1220. }
  1221. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1222. {
  1223. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1224. break;
  1225. }
  1226. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1227. if(uniqueID) {
  1228. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1229. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1230. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1231. break;
  1232. }
  1233. }
  1234. // handles instantiation logic + adding to zone of a new house object
  1235. PopulateHouseSpawn(place_object);
  1236. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1237. char query[256];
  1238. switch (GetSpawnPlacementMode())
  1239. {
  1240. case ServerSpawnPlacementMode::OPEN_HEADING:
  1241. {
  1242. if (spawn && spawn->IsWidget())
  1243. {
  1244. Widget* widget = (Widget*)spawn;
  1245. widget->SetOpenHeading(newHeading);
  1246. widget->SetIncludeHeading(true);
  1247. spawn->position_changed = true;
  1248. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1249. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1250. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1251. }
  1252. else
  1253. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1254. break;
  1255. }
  1256. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1257. {
  1258. if (spawn && spawn->IsWidget())
  1259. {
  1260. Widget* widget = (Widget*)spawn;
  1261. widget->SetClosedHeading(newHeading);
  1262. widget->SetIncludeHeading(true);
  1263. spawn->position_changed = true;
  1264. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1265. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1266. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1267. if (spawn->GetSpawnLocationID())
  1268. {
  1269. Query query;
  1270. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1271. }
  1272. }
  1273. else
  1274. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1275. break;
  1276. }
  1277. default:
  1278. {
  1279. spawn->SetX(place_object->getType_float_ByName("x"));
  1280. spawn->SetY(place_object->getType_float_ByName("y"));
  1281. spawn->SetZ(place_object->getType_float_ByName("z"));
  1282. spawn->SetHeading(newHeading);
  1283. spawn->SetSpawnOrigX(spawn->GetX());
  1284. spawn->SetSpawnOrigY(spawn->GetY());
  1285. spawn->SetSpawnOrigZ(spawn->GetZ());
  1286. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1287. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1288. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1289. else if (spawn->GetSpawnLocationID() > 0)
  1290. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1291. }
  1292. }
  1293. PopulateHouseSpawnFinalize();
  1294. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1295. safe_delete(place_object);
  1296. }
  1297. break;
  1298. }
  1299. case OP_CampAbortedMsg: {
  1300. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1301. if (camp_timer)
  1302. {
  1303. // JA: clear camping flag
  1304. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1305. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1306. safe_delete(camp_timer);
  1307. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1308. QueuePacket(outapp);
  1309. }
  1310. break;
  1311. }
  1312. case OP_DoneLoadingUIResourcesMsg: {
  1313. ClientPacketFunctions::SendUpdateSpellBook(this);
  1314. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1315. QueuePacket(app);
  1316. if(!player_loading_complete)
  1317. {
  1318. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1319. if (zone_script && lua_interface)
  1320. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1321. player_loading_complete = true;
  1322. }
  1323. break;
  1324. }
  1325. case OP_DoneLoadingZoneResourcesMsg: {
  1326. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1327. SendZoneSpawns();
  1328. break;
  1329. }
  1330. case OP_DefaultGroupOptionsRequestMsg: {
  1331. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1332. SendDefaultGroupOptions();
  1333. break;
  1334. }
  1335. case OP_DoneLoadingEntityResourcesMsg: {
  1336. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1337. if (!IsReadyForSpawns())
  1338. SetReadyForSpawns(true);
  1339. SendCharInfo();
  1340. pos_update.Start();
  1341. quest_pos_timer.Start();
  1342. break;
  1343. }
  1344. case OP_LootItemsRequestMsg: {
  1345. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1346. HandleLoot(app);
  1347. break;
  1348. }
  1349. case OP_WaypointSelectMsg: {
  1350. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1351. if (packet) {
  1352. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1353. int32 selection = packet->getType_int32_ByName("selection");
  1354. if (selection > 0) {
  1355. SelectWaypoint(selection);
  1356. }
  1357. }
  1358. }
  1359. break;
  1360. }
  1361. case OP_KnowledgeWindowSlotMappingMsg: {
  1362. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1363. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1364. if (packet) {
  1365. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1366. int num_updates = packet->getType_int16_ByName("spell_count");
  1367. int32 spell_id = 0;
  1368. int16 slot_id = 0;
  1369. char tmp_spell_id[15];
  1370. char tmp_slot[15];
  1371. for (int i = 0; i < num_updates; i++) {
  1372. memset(tmp_spell_id, 0, 15);
  1373. memset(tmp_slot, 0, 15);
  1374. sprintf(tmp_spell_id, "spell_id_%i", i);
  1375. sprintf(tmp_slot, "slot_id_%i", i);
  1376. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1377. if (spell_id > 0) {
  1378. slot_id = packet->getType_int16_ByName(tmp_slot);
  1379. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1380. if (spell && spell->slot != slot_id) {
  1381. spell->slot = slot_id;
  1382. spell->save_needed = true;
  1383. }
  1384. }
  1385. }
  1386. }
  1387. safe_delete(packet);
  1388. }
  1389. //SendKnowledgeWindowSlot();
  1390. break;
  1391. }
  1392. case OP_ReadyToZoneMsg: {
  1393. if (!IsReadyForSpawns())
  1394. {
  1395. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1396. }
  1397. else
  1398. {
  1399. if(zoning_destination)
  1400. SetCurrentZone(zoning_destination);
  1401. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1402. bool succeed_override_zone = true;
  1403. if(!GetCurrentZone()) {
  1404. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1405. if(zoning_instance_id) {
  1406. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1407. if(!zone) {
  1408. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
  1409. succeed_override_zone = false;
  1410. }
  1411. else {
  1412. SetCurrentZone(zone);
  1413. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1414. }
  1415. }
  1416. else if(zoning_id) {
  1417. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1418. if(!zone) {
  1419. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1420. succeed_override_zone = false;
  1421. }
  1422. else {
  1423. SetCurrentZone(zone);
  1424. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1425. }
  1426. }
  1427. }
  1428. if (client_zoning)
  1429. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1430. else
  1431. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1432. Disconnect();
  1433. }
  1434. break;
  1435. }
  1436. case OP_ClientFellMsg: {
  1437. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1438. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1439. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1440. float height = request->getType_float_ByName("height");
  1441. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1442. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1443. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1444. break;
  1445. }*/
  1446. float safe_height = 13.0f;
  1447. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1448. GetPlayer()->MStats.lock();
  1449. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1450. GetPlayer()->MStats.unlock();
  1451. if (skill)
  1452. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1453. if (height > safe_height) {
  1454. int16 damage = (int16)ceil((height - safe_height) * 125);
  1455. if (height >= 80)
  1456. damage = 30000;
  1457. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1458. if (damage > 0) {
  1459. GetPlayer()->TakeDamage(damage);
  1460. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1461. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1462. if (!GetPlayer()->GetInvulnerable())
  1463. GetPlayer()->SetCharSheetChanged(true);
  1464. 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);
  1465. if (GetPlayer()->GetHP() == 0) {
  1466. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1467. }
  1468. }
  1469. }
  1470. safe_delete(request);
  1471. }
  1472. break;
  1473. }
  1474. case OP_MapFogDataUpdateMsg: {
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1476. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1477. break;
  1478. }
  1479. case OP_SelectZoneTeleporterDestinatio: {
  1480. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1481. ProcessTeleportLocation(app);
  1482. break;
  1483. }
  1484. case OP_SendLatestRequestMsg: {
  1485. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1486. uchar blah25[] = { 0x01 };
  1487. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1488. QueuePacket(app25);
  1489. break;
  1490. }
  1491. case OP_ShowCreateFromRecipeUIMsg: {
  1492. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1493. break;
  1494. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1495. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1496. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1497. QueuePacket(app);
  1498. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1499. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1500. QueuePacket(app);
  1501. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1502. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1503. ,0xff,0xff,0xff};
  1504. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1505. QueuePacket(app);
  1506. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1507. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1508. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1509. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1510. QueuePacket(app);
  1511. uchar blah5[] ={0x00,0x00};
  1512. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1513. QueuePacket(app);
  1514. break;*/
  1515. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1516. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1517. //QueuePacket(app);
  1518. }
  1519. case OP_BeginItemCreationMsg: {
  1520. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1521. //DumpPacket(app->pBuffer, app->size);
  1522. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1523. if (packet) {
  1524. packet->LoadPacketData(app->pBuffer, app->size);
  1525. int32 item = 0;
  1526. vector<int32> items;
  1527. char tmp_item_id[20];
  1528. item = packet->getType_int32_ByName("primary_component_id");
  1529. if (item > 0)
  1530. items.push_back(item);
  1531. item = 0;
  1532. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1533. for (int8 i = 0; i < build_components; i++) {
  1534. memset(tmp_item_id, 0, 20);
  1535. sprintf(tmp_item_id, "component_id_%i", i);
  1536. item = packet->getType_int32_ByName(tmp_item_id);
  1537. if (item > 0)
  1538. items.push_back(item);
  1539. item = 0;
  1540. }
  1541. item = packet->getType_int32_ByName("fuel_id");
  1542. if (item > 0)
  1543. items.push_back(item);
  1544. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1545. safe_delete(packet);
  1546. }
  1547. break;
  1548. }
  1549. case OP_StopItemCreationMsg: {
  1550. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1551. //DumpPacket(app->pBuffer, app->size);
  1552. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1553. break;
  1554. }
  1555. case OP_SysClient:
  1556. case OP_SignalMsg: {
  1557. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1558. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1559. if (packet) {
  1560. packet->LoadPacketData(app->pBuffer, app->size);
  1561. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1562. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1563. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1564. SetReloadingZone(false);
  1565. if(GetPlayer()->IsDeletedSpawn()) {
  1566. GetPlayer()->SetDeletedSpawn(false);
  1567. }
  1568. ResetZoningCoords();
  1569. SetReadyForUpdates();
  1570. GetPlayer()->SendSpawnChanges(true);
  1571. ProcessStateCommands();
  1572. GetPlayer()->changed = true;
  1573. GetPlayer()->info_changed = true;
  1574. GetPlayer()->vis_changed = true;
  1575. player_pos_changed = true;
  1576. GetPlayer()->AddChangedZoneSpawn();
  1577. }
  1578. else {
  1579. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1580. }
  1581. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1582. if (zone_script && lua_interface)
  1583. {
  1584. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1585. }
  1586. }
  1587. break;
  1588. }
  1589. case OP_EntityVerbsRequestMsg: {
  1590. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1591. HandleVerbRequest(app);
  1592. break;
  1593. }
  1594. case OP_EntityVerbsVerbMsg: {
  1595. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1596. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1597. if (packet) {
  1598. packet->LoadPacketData(app->pBuffer, app->size);
  1599. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1600. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1601. Spawn* spawn = player->GetTarget();
  1602. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1603. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1604. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1605. {
  1606. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1607. if (spawn->IsGroundSpawn())
  1608. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1609. else if (spawn->IsObject())
  1610. ((Object*)spawn)->HandleUse(this, command);
  1611. else if (spawn->IsWidget())
  1612. ((Widget*)spawn)->HandleUse(this, command);
  1613. else if (spawn->IsSign())
  1614. ((Sign*)spawn)->HandleUse(this, command);
  1615. }
  1616. }
  1617. }
  1618. else {
  1619. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1620. if (command.size > 0) {
  1621. string command_name = command.data;
  1622. if (command_name.find(" ") < 0xFFFFFFFF) {
  1623. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1624. string::size_type pos = command_name.find(" ");
  1625. while(pos != string::npos){
  1626. command_name.replace(pos, 1, "_");
  1627. pos = command_name.find(" ");
  1628. }
  1629. }
  1630. else
  1631. command_name = command_name.substr(0, command_name.find(" "));
  1632. }
  1633. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1634. if (handler != 0xFFFFFFFF) {
  1635. if (command.data == command_name) {
  1636. command.data = "";
  1637. command.size = 0;
  1638. }
  1639. else {
  1640. command.data = command.data.substr(command.data.find(" ") + 1);
  1641. command.size = command.data.length();
  1642. }
  1643. commands.Process(handler, &command, this);
  1644. }
  1645. else {
  1646. if (spawn && spawn->IsNPC()) {
  1647. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1648. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1649. command_name = command.data;
  1650. string::size_type pos = command_name.find(" ");
  1651. while (pos != string::npos) {
  1652. command_name.replace(pos, 1, "_");
  1653. pos = command_name.find(" ");
  1654. }
  1655. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1656. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1657. }
  1658. }
  1659. }
  1660. }
  1661. else
  1662. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1663. }
  1664. }
  1665. }
  1666. safe_delete(packet);
  1667. }
  1668. break;
  1669. }
  1670. case OP_SkillInfoRequest: {
  1671. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1672. HandleSkillInfoRequest(app);
  1673. break;
  1674. }
  1675. case OP_UpdateTargetMsg: {
  1676. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1677. int16 index = 0;
  1678. memcpy(&index, app->pBuffer, sizeof(int16));
  1679. if (index == 0xFFFF)
  1680. GetPlayer()->SetTarget(0);
  1681. else {
  1682. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1683. if(spawn)
  1684. GetPlayer()->SetTarget(spawn);
  1685. else {
  1686. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1687. }
  1688. }
  1689. if (GetPlayer()->GetTarget())
  1690. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1691. //player->SetTarget((int16*)app->pBuffer);
  1692. break;
  1693. }
  1694. case OP_ExamineInfoRequestMsg: {
  1695. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1696. HandleExamineInfoRequest(app);
  1697. break;
  1698. }
  1699. case OP_QuickbarUpdateMsg:
  1700. //case OP_QuickbarAddMsg:
  1701. {
  1702. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1703. HandleQuickbarUpdateRequest(app);
  1704. break;
  1705. }
  1706. case OP_PredictionUpdateMsg: {
  1707. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1708. if (version <= 546) {
  1709. int8 offset = 9;
  1710. if (app->pBuffer[0] == 0xFF)
  1711. offset += 2;
  1712. if (app->size > offset) {
  1713. if (player->IsCasting()) {
  1714. float distance = 0;
  1715. float x = player->GetX();
  1716. float y = player->GetY();
  1717. float z = player->GetZ();
  1718. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1719. distance = player->GetDistance(x, y, z, false);
  1720. if (distance > .5)
  1721. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1722. }
  1723. else
  1724. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1725. player_pos_changed = true;
  1726. //DumpPacket(app);
  1727. }
  1728. }
  1729. else {
  1730. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1731. QueuePacket(app);
  1732. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1733. }
  1734. break;
  1735. }
  1736. case OP_RemoteCmdMsg: {
  1737. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1738. if (app->size > 0) {
  1739. EQ2_CommandString remote(app->pBuffer, app->size);
  1740. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1741. #if EQDEBUG >= 9
  1742. DumpPacket(app);
  1743. #endif
  1744. commands.Process(remote.handler, &remote.command, this);
  1745. }
  1746. else //bad client, disconnect
  1747. Disconnect();
  1748. break;
  1749. }
  1750. case OP_CancelSpellCast: {
  1751. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1752. current_zone->Interrupted(player, 0, 0, true);
  1753. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1754. break;
  1755. }
  1756. case OP_UpdatePositionMsg: {
  1757. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1758. int8 offset = 13;
  1759. if (app->pBuffer[0] == 0xFF)
  1760. offset += 2;
  1761. if (app->size > offset) {
  1762. if (player->IsCasting()) {
  1763. float distance = 0;
  1764. float x = player->GetX();
  1765. float y = player->GetY();
  1766. float z = player->GetZ();
  1767. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1768. distance = player->GetDistance(x, y, z, false);
  1769. if (distance > .5)
  1770. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1771. }
  1772. else
  1773. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1774. player_pos_changed = true;
  1775. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1776. //DumpPacket(app);
  1777. }
  1778. break;
  1779. }
  1780. case OP_MailSendMessageMsg: {
  1781. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1782. HandleSentMail(app);
  1783. break;
  1784. }
  1785. case OP_StopTrackingMsg: {
  1786. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1787. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1788. break;
  1789. }
  1790. case OP_BeginTrackingMsg: {
  1791. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1792. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1793. if (packet) {
  1794. packet->LoadPacketData(app->pBuffer, app->size);
  1795. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1796. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1797. if (spawn) {
  1798. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1799. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1800. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1801. }
  1802. safe_delete(packet);
  1803. }
  1804. break;
  1805. }
  1806. case OP_BioUpdateMsg: {
  1807. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1808. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1809. if (packet) {
  1810. packet->LoadPacketData(app->pBuffer, app->size);
  1811. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1812. safe_delete(packet);
  1813. }
  1814. break;
  1815. }
  1816. case OP_RewardPackMsg: {
  1817. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1818. /* 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
  1819. when we come across it (scatman) */
  1820. const char* name = app->GetOpcodeName();
  1821. if (name)
  1822. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1823. else
  1824. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1825. //DumpPacket(app);
  1826. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1827. if (packet) {
  1828. packet->LoadPacketData(app->pBuffer, app->size);
  1829. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1830. /* Player has contacted a guild recruiter */
  1831. if (recruiter_name.length() > 0) {
  1832. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1833. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1834. if (recruiter && guild) {
  1835. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1836. 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()));
  1837. recruiter->PlaySound("ui_guild_page");
  1838. }
  1839. }
  1840. /* New picture taken for guild recruiting */
  1841. else {
  1842. //DumpPacket(app->pBuffer, app->size);
  1843. int32 guild_id = 0;
  1844. int16 picture_data_size = 0;
  1845. unsigned char* recruiter_picture_data = 0;
  1846. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1847. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1848. Guild* guild = guild_list.GetGuild(guild_id);
  1849. if (guild) {
  1850. GuildMember* gm = guild->GetGuildMember(player);
  1851. if (gm) {
  1852. safe_delete_array(gm->recruiter_picture_data);
  1853. recruiter_picture_data = new unsigned char[picture_data_size];
  1854. for (int16 i = 0; i < picture_data_size; i++)
  1855. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1856. gm->recruiter_picture_data = recruiter_picture_data;
  1857. gm->recruiter_picture_data_size = picture_data_size;
  1858. guild->SetMemberSaveNeeded(true);
  1859. }
  1860. }
  1861. }
  1862. safe_delete(packet);
  1863. }
  1864. break;
  1865. }
  1866. case OP_PetOptions: {
  1867. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1868. Spawn* target = player->GetTarget();
  1869. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1870. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1871. bool change = false;
  1872. packet->LoadPacketData(app->pBuffer, app->size);
  1873. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1874. if (strlen(name.c_str()) != 0) {
  1875. target->SetName(name.c_str());
  1876. player->GetInfoStruct()->set_pet_name(name);
  1877. GetCurrentZone()->SendUpdateTitles(target);
  1878. change = true;
  1879. }
  1880. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1881. // Check protect self setting and update if needed
  1882. if (packet->getType_int8_ByName("protect_self") == 1) {
  1883. if ((pet_behavior & 2) == 0) {
  1884. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1885. change = true;
  1886. }
  1887. }
  1888. else {
  1889. if ((pet_behavior & 2) != 0) {
  1890. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1891. change = true;
  1892. }
  1893. }
  1894. // Check protect master setting and update if needed
  1895. if (packet->getType_int8_ByName("protect_master") == 1) {
  1896. if ((pet_behavior & 1) == 0) {
  1897. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1898. change = true;
  1899. }
  1900. }
  1901. else {
  1902. if ((pet_behavior & 1) != 0) {
  1903. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1904. change = true;
  1905. }
  1906. }
  1907. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1908. // Check stay/follow setting and update if needed
  1909. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1910. if (pet_movement != 2) {
  1911. player->GetInfoStruct()->set_pet_movement(2);
  1912. change = true;
  1913. }
  1914. }
  1915. else {
  1916. if (pet_movement != 1) {
  1917. player->GetInfoStruct()->set_pet_movement(1);
  1918. change = true;
  1919. }
  1920. }
  1921. // Ranged/Melee settings are not implemented yet
  1922. if (change)
  1923. player->SetCharSheetChanged(true);
  1924. safe_delete(packet);
  1925. }
  1926. break;
  1927. }
  1928. case OP_RecipeBook: {
  1929. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1930. SendRecipeList();
  1931. break;
  1932. }
  1933. case OP_BuyPlayerHouseMsg: {
  1934. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1935. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1936. if (packet) {
  1937. packet->LoadPacketData(app->pBuffer, app->size);
  1938. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1939. if (hz) {
  1940. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1941. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1942. if (houses.size() > 24)
  1943. {
  1944. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1945. safe_delete(packet);
  1946. break;
  1947. }
  1948. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1949. {
  1950. std::string req = "You must be of ";
  1951. if (hz->alignment == 1)
  1952. req.append("Good");
  1953. else
  1954. req.append("Evil");
  1955. req.append(" alignment to purchase this house");
  1956. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1957. safe_delete(packet);
  1958. break;
  1959. }
  1960. int32 status_req = hz->upkeep_status + hz->cost_status;
  1961. int32 available_status = player->GetInfoStruct()->get_status_points();
  1962. if (status_req <= available_status &&
  1963. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1964. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1965. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1966. {
  1967. player->GetInfoStruct()->subtract_status_points(status_req);
  1968. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1969. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1970. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1971. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1972. //ClientPacketFunctions::SendHousingList(this);
  1973. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1974. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1975. PlaySound("coin_cha_ching");
  1976. }
  1977. else
  1978. {
  1979. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1980. PlaySound("buy_failed");
  1981. }
  1982. }
  1983. }
  1984. safe_delete(packet);
  1985. break;
  1986. }
  1987. case OP_EnterHouseMsg: {
  1988. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1989. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1990. if (packet) {
  1991. packet->LoadPacketData(app->pBuffer, app->size);
  1992. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1993. if (ph) {
  1994. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1995. if (hz) {
  1996. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1997. if (house) {
  1998. Zone(house, true);
  1999. }
  2000. }
  2001. }
  2002. }
  2003. safe_delete(packet);
  2004. break;
  2005. }
  2006. case OP_PayHouseUpkeepMsg: {
  2007. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2008. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2009. if (packet) {
  2010. packet->LoadPacketData(app->pBuffer, app->size);
  2011. int64 houseID = packet->getType_int64_ByName("house_id");
  2012. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  2013. if (ph)
  2014. {
  2015. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2016. if (!hz)
  2017. {
  2018. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2019. safe_delete(packet);
  2020. break;
  2021. }
  2022. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2023. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2024. {
  2025. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2026. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2027. {
  2028. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2029. PlaySound("buy_failed");
  2030. safe_delete(packet);
  2031. break;
  2032. }
  2033. }
  2034. bool escrowChange = false;
  2035. int64 statusReq = hz->upkeep_status;
  2036. int64 tmpRecoverStatus = 0;
  2037. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2038. {
  2039. escrowChange = true;
  2040. tmpRecoverStatus = ph->escrow_status;
  2041. statusReq -= ph->escrow_status;
  2042. ph->escrow_status = 0;
  2043. }
  2044. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2045. {
  2046. escrowChange = true;
  2047. ph->escrow_status -= statusReq;
  2048. tmpRecoverStatus = statusReq;
  2049. statusReq = 0;
  2050. }
  2051. int64 coinReq = hz->upkeep_coin;
  2052. int64 tmpRecoverCoins = 0;
  2053. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2054. {
  2055. escrowChange = true;
  2056. tmpRecoverCoins = ph->escrow_coins;
  2057. coinReq -= ph->escrow_coins;
  2058. ph->escrow_coins = 0;
  2059. }
  2060. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2061. {
  2062. escrowChange = true;
  2063. // more than enough in escrow, subtract and make our cost 0!
  2064. ph->escrow_coins -= coinReq;
  2065. tmpRecoverCoins = coinReq;
  2066. coinReq = 0;
  2067. }
  2068. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2069. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2070. {
  2071. if(coinReq && player->RemoveCoins(coinReq))
  2072. coinReq = 0;
  2073. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2074. statusReq = 0;
  2075. }
  2076. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2077. {
  2078. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2079. if (escrowChange)
  2080. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2081. ph->upkeep_due = upkeep_due;
  2082. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2083. //ClientPacketFunctions::SendHousingList(this);
  2084. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  2085. PlaySound("coin_cha_ching");
  2086. }
  2087. else
  2088. {
  2089. // recover the escrow we were going to use but could not spend due to lack of funds
  2090. if (tmpRecoverCoins)
  2091. ph->escrow_coins += tmpRecoverCoins;
  2092. if(tmpRecoverStatus)
  2093. ph->escrow_status += tmpRecoverStatus;
  2094. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2095. PlaySound("buy_failed");
  2096. }
  2097. }
  2098. else
  2099. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2100. }
  2101. safe_delete(packet);
  2102. break;
  2103. }
  2104. case OP_ExitHouseMsg: {
  2105. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2106. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2107. if (instance_id > 0) {
  2108. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2109. if (ph) {
  2110. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2111. if (hz) {
  2112. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2113. // determine if this is an instanced zone that already exists
  2114. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2115. if (instance_zone || new_zone) {
  2116. GetPlayer()->SetX(hz->exit_x);
  2117. GetPlayer()->SetY(hz->exit_y);
  2118. GetPlayer()->SetZ(hz->exit_z);
  2119. GetPlayer()->SetHeading(hz->exit_heading);
  2120. if (instance_zone)
  2121. Zone(instance_zone->GetInstanceID(), false, true);
  2122. else
  2123. Zone(new_zone, false);
  2124. }
  2125. }
  2126. }
  2127. }
  2128. break;
  2129. }
  2130. case OP_QuestJournalWaypointMsg: {
  2131. //DumpPacket(app);
  2132. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2133. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2134. if (packet) {
  2135. packet->LoadPacketData(app->pBuffer, app->size);
  2136. int32 quests = packet->getType_int32_ByName("num_quests");
  2137. if (quests > 100) // just picking a number higher than max allowed
  2138. {
  2139. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2140. break;
  2141. }
  2142. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2143. for (int32 i = 0; i < quests; i++) {
  2144. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2145. if (id == 0)
  2146. continue;
  2147. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2148. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2149. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2150. if (player->player_quests.count(id) > 0) {
  2151. player->player_quests[id]->SetTracked(tracked);
  2152. player->player_quests[id]->SetSaveNeeded(true);
  2153. }
  2154. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2155. }
  2156. safe_delete(packet);
  2157. }
  2158. break;
  2159. }
  2160. case OP_PaperdollImage: {
  2161. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2162. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2163. //First check if this is a new image... delete an existing partial image if one exists
  2164. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2165. if (packet_index == 0) {
  2166. safe_delete_array(incoming_paperdoll.image_bytes);
  2167. incoming_paperdoll.last_received_packet_index = 0;
  2168. incoming_paperdoll.current_size_bytes = 0;
  2169. }
  2170. //return if this packet is not the one we are expecting...
  2171. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2172. safe_delete(packet);
  2173. break;
  2174. }
  2175. //Check how many packets we're supposed to be receiving for this/these images
  2176. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2177. //Check the image type, if this is a new type in the same series of packets we have a new image
  2178. int8 img_type = packet->getType_int8_ByName("image_type");
  2179. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2180. //We have a new image. Save the old data and clear before continuing
  2181. SavePlayerImages();
  2182. }
  2183. incoming_paperdoll.image_type = img_type;
  2184. //Get the size of the image data in this packet
  2185. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2186. if (image_size <= 0 || image_size > 1048576) {
  2187. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2188. safe_delete(packet);
  2189. break;
  2190. }
  2191. //Create a new array
  2192. int32 new_image_size = image_size;
  2193. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2194. if (incoming_paperdoll.image_bytes) {
  2195. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2196. safe_delete_array(incoming_paperdoll.image_bytes);
  2197. }
  2198. //variable i should be the index in the packet of the first PNG file byte
  2199. vector<DataStruct*>* d_structs = packet->getStructs();
  2200. vector<DataStruct*>::iterator itr;
  2201. int32 i = 0;
  2202. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2203. DataStruct* ds = (*itr);
  2204. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2205. i += ds->GetDataSizeInBytes();
  2206. else
  2207. break;
  2208. }
  2209. //Return if this packet is bad and we would read out of bounds
  2210. if (app->size - i < new_image_size) {
  2211. safe_delete(packet);
  2212. safe_delete_array(new_image);
  2213. break;
  2214. }
  2215. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2216. memcpy(tmp, app->pBuffer + i, new_image_size);
  2217. incoming_paperdoll.current_size_bytes += new_image_size;
  2218. incoming_paperdoll.image_bytes = new_image;
  2219. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2220. if (incoming_paperdoll.image_num_packets == 1 ||
  2221. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2222. SavePlayerImages();
  2223. }
  2224. incoming_paperdoll.last_received_packet_index = packet_index;
  2225. }
  2226. safe_delete(packet);
  2227. */
  2228. break;
  2229. }
  2230. case OP_ReadyForTakeOffMsg:
  2231. {
  2232. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2233. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2234. if (GetPendingFlightPath() > 0) {
  2235. if (index != -1) {
  2236. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2237. if (packet) {
  2238. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2239. packet->setDataByName("path_id", index);
  2240. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2241. QueuePacket(packet->serialize());
  2242. safe_delete(packet);
  2243. on_auto_mount = true;
  2244. }
  2245. }
  2246. else {
  2247. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2248. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2249. EndAutoMount();
  2250. }
  2251. SetPendingFlightPath(0);
  2252. }
  2253. else
  2254. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2255. break;
  2256. }
  2257. case OP_EarlyLandingRequestMsg:
  2258. {
  2259. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2260. EndAutoMount();
  2261. break;
  2262. }
  2263. case OP_SubmitCharCust:
  2264. {
  2265. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2266. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2267. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2268. int8 type = packet->getType_int8_ByName("type");
  2269. if (type == 0) {
  2270. if (player->custNPC) {
  2271. player->custNPCTarget->CustomizeAppearance(packet);
  2272. current_zone->SendSpawnChanges(player->custNPCTarget);
  2273. }
  2274. else {
  2275. player->CustomizeAppearance(packet);
  2276. current_zone->SendSpawnChanges(player);
  2277. }
  2278. }
  2279. }
  2280. if (player->custNPC) {
  2281. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2282. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2283. if (player->custNPCTarget->IsBot())
  2284. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2285. player->custNPC = false;
  2286. player->custNPCTarget = 0;
  2287. player->changed = true;
  2288. player->info_changed = true;
  2289. current_zone->SendSpawnChanges(player, this);
  2290. }
  2291. break;
  2292. }
  2293. default: {
  2294. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2295. const char* name = app->GetOpcodeName();
  2296. if (name)
  2297. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2298. else
  2299. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2300. //DumpPacket(app);
  2301. }
  2302. }
  2303. if (!eqs || !eqs->CheckActive()) {
  2304. return false;
  2305. }
  2306. return ret;
  2307. }
  2308. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2309. if (!item) {
  2310. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2311. return false;
  2312. }
  2313. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2314. int16 lore_stack_count = 0;
  2315. if(((conflictItemList = player->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2316. (conflictequipmentList = player->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2317. (conflictAppearanceEquipmentList = player->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2318. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2319. return false;
  2320. }
  2321. else if(conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2322. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2323. return false;
  2324. }
  2325. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2326. if (player->item_list.AssignItemToFreeSlot(item)) {
  2327. if(item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2328. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  2329. if (gmi && gmi->group_id)
  2330. {
  2331. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2332. if (group)
  2333. {
  2334. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2335. deque<GroupMemberInfo*>* members = group->GetMembers();
  2336. if(members) {
  2337. for (int8 i = 0; i < members->size(); i++) {
  2338. Entity* member = members->at(i)->member;
  2339. if(!member)
  2340. continue;
  2341. if ((member->GetZone() != this->GetPlayer()->GetZone()))
  2342. continue;
  2343. if(member->IsPlayer()) {
  2344. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2345. item->save_needed = true;
  2346. }
  2347. }
  2348. }
  2349. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2350. }
  2351. }
  2352. }
  2353. int8 type = CHANNEL_LOOT;
  2354. if (entity) {
  2355. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2356. }
  2357. else {
  2358. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2359. }
  2360. Guild* guild = player->GetGuild();
  2361. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2362. char adjective[32];
  2363. int8 type;
  2364. memset(adjective, 0, sizeof(adjective));
  2365. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2366. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2367. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2368. }
  2369. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2370. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2371. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2372. }
  2373. else {
  2374. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2375. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2376. }
  2377. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2378. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2379. }
  2380. if (item->GetItemScript() && lua_interface)
  2381. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2382. CheckPlayerQuestsItemUpdate(item);
  2383. return true;
  2384. }
  2385. else
  2386. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2387. }
  2388. else
  2389. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2390. return false;
  2391. }
  2392. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2393. if (!entity) {
  2394. return false;
  2395. }
  2396. Item* item = entity->LootItem(item_id);
  2397. bool success = false;
  2398. success = HandleLootItem(entity, item);
  2399. if(!success)
  2400. entity->AddLootItem(item);
  2401. return success;
  2402. }
  2403. void Client::HandleLoot(EQApplicationPacket* app) {
  2404. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2405. if (packet) {
  2406. packet->LoadPacketData(app->pBuffer, app->size);
  2407. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2408. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2409. safe_delete(packet);
  2410. int32 item_id = 0;
  2411. Item* item = 0;
  2412. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2413. if (player->HasPendingLootItems(loot_id)) {
  2414. Item* master_item = 0;
  2415. if (loot_all) {
  2416. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2417. if (items) {
  2418. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2419. master_item = items->at(i);
  2420. if (master_item) {
  2421. item = new Item(master_item);
  2422. if (item) {
  2423. loot_all = HandleLootItem(0, item);
  2424. if (loot_all)
  2425. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2426. }
  2427. }
  2428. }
  2429. safe_delete(items);
  2430. }
  2431. }
  2432. else {
  2433. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2434. if (packet) {
  2435. packet->LoadPacketData(app->pBuffer, app->size);
  2436. item_id = packet->getType_int32_ByName("item_id");
  2437. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2438. if (items) {
  2439. for (int32 i = 0; i < items->size(); i++) {
  2440. master_item = items->at(i);
  2441. if (master_item && master_item->details.item_id == item_id) {
  2442. item = new Item(master_item);
  2443. if (item && HandleLootItem(0, item))
  2444. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2445. break;
  2446. }
  2447. }
  2448. safe_delete(items);
  2449. }
  2450. safe_delete(packet);
  2451. }
  2452. }
  2453. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2454. if (outapp)
  2455. QueuePacket(outapp);
  2456. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2457. }
  2458. else {
  2459. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2460. if (loot_all) {
  2461. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2462. loot_all = HandleLootItem(spawn, item_id);
  2463. }
  2464. }
  2465. else {
  2466. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2467. if (packet) {
  2468. packet->LoadPacketData(app->pBuffer, app->size);
  2469. item_id = packet->getType_int32_ByName("item_id");
  2470. HandleLootItem(spawn, item_id);
  2471. safe_delete(packet);
  2472. }
  2473. }
  2474. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2475. if (outapp)
  2476. QueuePacket(outapp);
  2477. Loot(spawn);
  2478. if (!spawn->HasLoot()) {
  2479. CloseLoot(loot_id);
  2480. if (spawn->IsNPC())
  2481. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2482. }
  2483. }
  2484. else {
  2485. if (!spawn) {
  2486. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2487. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2488. }
  2489. else
  2490. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2491. }
  2492. }
  2493. }
  2494. }
  2495. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2496. PacketStruct* request = 0;
  2497. // cout << "Request: \n";
  2498. // DumpPacket(app);
  2499. switch (app->pBuffer[0]) {
  2500. case 0: { //items
  2501. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2502. if (request) {
  2503. request->LoadPacketData(app->pBuffer, app->size);
  2504. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2505. if (!item)
  2506. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2507. if (item) {
  2508. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2509. if (response) {
  2510. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2511. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2512. response->setSmallStringByName("name", item->name.c_str());
  2513. EQ2Packet* app2 = response->serialize();
  2514. //DumpPacket(app2);
  2515. QueuePacket(app2);
  2516. safe_delete(response);
  2517. }
  2518. }
  2519. }
  2520. break;
  2521. }
  2522. case 2: {//spells
  2523. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2524. if (request) {
  2525. request->LoadPacketData(app->pBuffer, app->size);
  2526. int32 id = request->getType_int32_ByName("id");
  2527. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2528. Spell* spell = master_spell_list.GetSpell(id, tier);
  2529. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2530. if (response) {
  2531. response->setDataByName("request_type", 2);
  2532. response->setDataByName("unique_id", tier);
  2533. response->setDataByName("id", id);
  2534. if (spell)
  2535. response->setSmallStringByName("name", spell->GetName());
  2536. else
  2537. response->setSmallStringByName("name", "Unknown Spell");
  2538. EQ2Packet* app2 = response->serialize();
  2539. // DumpPacket(app2);
  2540. QueuePacket(app2);
  2541. safe_delete(response);
  2542. }
  2543. }
  2544. break;
  2545. }
  2546. default: {
  2547. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2548. }
  2549. }
  2550. safe_delete(request);
  2551. }
  2552. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2553. PacketStruct* request = 0;
  2554. if (!app || app->size == 0)
  2555. return;
  2556. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2557. //DumpPacket(app);
  2558. int8 type = app->pBuffer[0];
  2559. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2560. if (version <= 283) {
  2561. if (type == 1)
  2562. type = 4;
  2563. else if (type == 2)
  2564. type = 5;
  2565. }
  2566. if (type == 3) {
  2567. Spell* spell = 0;
  2568. bool trait_display;
  2569. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2570. if (!request) {
  2571. return;
  2572. }
  2573. request->LoadPacketData(app->pBuffer, app->size);
  2574. int32 id = request->getType_int32_ByName("id");
  2575. int32 tier = request->getType_int32_ByName("tier");
  2576. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2577. bool display = true;
  2578. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2579. display = false;
  2580. else if (version <= 546)
  2581. display = request->getType_int8_ByName("display");
  2582. else if (version > 546)
  2583. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2584. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2585. if (trait_tier != 0xFFFFFFFF) {
  2586. spell = master_spell_list.GetSpell(id, trait_tier);
  2587. if (!spell) {
  2588. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2589. }
  2590. trait_display = true;
  2591. }
  2592. else {
  2593. spell = master_spell_list.GetSpell(id, tier);
  2594. trait_display = false;
  2595. }
  2596. // if we can't find it on the master spell list, see if it is a custom spell
  2597. if (!spell)
  2598. {
  2599. lua_interface->FindCustomSpellLock();
  2600. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2601. if (tmpSpell)
  2602. spell = tmpSpell->spell;
  2603. lua_interface->FindCustomSpellUnlock();
  2604. }
  2605. if (spell && !CountSentSpell(id, tier)) {
  2606. if (!spell->IsCopiedSpell())
  2607. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2608. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2609. //DumpPacket(app);
  2610. QueuePacket(app);
  2611. }
  2612. }
  2613. else if (type == 0) {
  2614. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2615. if (!request) {
  2616. return;
  2617. }
  2618. request->LoadPacketData(app->pBuffer, app->size);
  2619. int32 id = request->getType_int32_ByName("id");
  2620. Item* item = 0;
  2621. // translate from unique id to spawn id for houses
  2622. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2623. bool wasSpawn = false;
  2624. if (spawn)
  2625. {
  2626. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2627. if (item)
  2628. {
  2629. wasSpawn = true;
  2630. item = new Item(item);
  2631. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2632. }
  2633. }
  2634. if (!item)
  2635. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2636. if (!item)
  2637. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2638. if (!item)
  2639. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2640. if (!item)
  2641. item = master_item_list.GetItem(id);
  2642. if (item) {// && sent_item_details.count(id) == 0){
  2643. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2644. sent_item_details[id] = true;
  2645. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2646. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2647. //DumpPacket(app);
  2648. QueuePacket(app);
  2649. if (wasSpawn)
  2650. delete item;
  2651. }
  2652. else {
  2653. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2654. DumpPacket(app);
  2655. }
  2656. }
  2657. else if (type == 1) {
  2658. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2659. if (!request) {
  2660. return;
  2661. }
  2662. request->LoadPacketData(app->pBuffer, app->size);
  2663. int32 id = request->getType_int32_ByName("id");
  2664. int32 unique_id = request->getType_int32_ByName("unique_id");
  2665. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2666. if (!item)
  2667. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2668. if (!item)
  2669. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2670. if (!item)
  2671. item = master_item_list.GetItem(id);
  2672. if (item) {
  2673. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2674. sent_item_details[id] = true;
  2675. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2676. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2677. //DumpPacket(app);
  2678. QueuePacket(app);
  2679. }
  2680. else {
  2681. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2682. DumpPacket(app);
  2683. }
  2684. }
  2685. else if (type == 2) {
  2686. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2687. if (!request) {
  2688. return;
  2689. }
  2690. request->LoadPacketData(app->pBuffer, app->size);
  2691. int32 id = request->getType_int32_ByName("item_id");
  2692. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2693. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2694. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2695. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2696. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2697. //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);
  2698. Item* item = master_item_list.GetItem(id);
  2699. if (item) {
  2700. //only display popup for non merchant links
  2701. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2702. //DumpPacket(app);
  2703. QueuePacket(app);
  2704. }
  2705. else {
  2706. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2707. DumpPacket(app);
  2708. }
  2709. }
  2710. else if (type == 4) { //spell effect
  2711. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2712. if (!request) {
  2713. return;
  2714. }
  2715. request->LoadPacketData(app->pBuffer, app->size);
  2716. int32 id = request->getType_int32_ByName("id");
  2717. int16 display = request->getType_int8_ByName("partial_info");
  2718. SpellEffects* effect = player->GetSpellEffect(id);
  2719. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2720. if (effect) {
  2721. int8 tier = effect->tier;
  2722. Spell* spell = master_spell_list.GetSpell(id, tier);
  2723. // if we can't find it on the master spell list, see if it is a custom spell
  2724. if (!spell)
  2725. {
  2726. lua_interface->FindCustomSpellLock();
  2727. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2728. EQ2Packet* pack = 0;
  2729. if (tmpSpell)
  2730. spell = tmpSpell->spell;
  2731. lua_interface->FindCustomSpellUnlock();
  2732. }
  2733. if (spell && !CountSentSpell(id, tier)) {
  2734. if (!spell->IsCopiedSpell())
  2735. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2736. int8 type = 0;
  2737. if (version <= 283)
  2738. type = 1;
  2739. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2740. //DumpPacket(app);
  2741. QueuePacket(app);
  2742. }
  2743. }
  2744. }
  2745. else if (type == 5) { // recipe info
  2746. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2747. if (!request)
  2748. return;
  2749. request->LoadPacketData(app->pBuffer, app->size);
  2750. int32 id = request->getType_int32_ByName("unknown_id");
  2751. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2752. if (recipe) {
  2753. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2754. //DumpPacket(app);
  2755. QueuePacket(app);
  2756. }
  2757. }
  2758. else if (type == 6) { // AA spell info
  2759. Spell* spell = 0;
  2760. //Spell* spell2 = 0;
  2761. //AltAdvanceData* data = 0;
  2762. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2763. if (!request)
  2764. return;
  2765. request->LoadPacketData(app->pBuffer, app->size);
  2766. int32 id = request->getType_int32_ByName("id");
  2767. int32 tier = GetPlayer()->GetSpellTier(id);
  2768. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2769. //data = master_aa_list.GetAltAdvancement(id);
  2770. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2771. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2772. spell = master_spell_list.GetSpell(id, tier);
  2773. if (!spell)
  2774. spell = master_spell_list.GetSpell(id, 1);
  2775. if (!spell)
  2776. {
  2777. lua_interface->FindCustomSpellLock();
  2778. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2779. if (tmpSpell)
  2780. spell = tmpSpell->spell;
  2781. lua_interface->FindCustomSpellUnlock();
  2782. }
  2783. if (!spell)
  2784. {
  2785. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2786. return;
  2787. }
  2788. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2789. if (!spell->IsCopiedSpell())
  2790. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2791. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2792. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2793. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2794. //DumpPacket(app);
  2795. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2796. QueuePacket(app);
  2797. //}
  2798. }
  2799. else {
  2800. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2801. DumpPacket(app);
  2802. }
  2803. safe_delete(request);
  2804. }
  2805. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2806. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2807. if (request) {
  2808. request->LoadPacketData(app->pBuffer, app->size);
  2809. int32 id = request->getType_int32_ByName("id");
  2810. int32 bar = request->getType_int32_ByName("hotbar_number");
  2811. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2812. int32 type = request->getType_int32_ByName("type");
  2813. int8 tier = request->getType_int32_ByName("unique_id");
  2814. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2815. Spell* spell = 0;
  2816. if (type == 0xFFFFFFFF)
  2817. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2818. else {
  2819. if (type == QUICKBAR_NORMAL)
  2820. spell = master_spell_list.GetSpell(id, tier);
  2821. if (spell)
  2822. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2823. else
  2824. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2825. }
  2826. safe_delete(request);
  2827. }
  2828. }
  2829. bool Client::Process(bool zone_process) {
  2830. if (!eqs) {
  2831. return false;
  2832. }
  2833. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2834. return true;
  2835. }
  2836. if (new_client_login) {
  2837. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2838. SendLoginInfo();
  2839. new_client_login = false;
  2840. }
  2841. bool ret = true;
  2842. sockaddr_in to;
  2843. memset((char*)&to, 0, sizeof(to));
  2844. to.sin_family = AF_INET;
  2845. to.sin_port = port;
  2846. to.sin_addr.s_addr = ip;
  2847. /************ Get all packets from packet manager out queue and process them ************/
  2848. EQApplicationPacket* app = 0;
  2849. if (eqs && !eqs->CheckActive()) {
  2850. num_active_failures++;
  2851. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2852. if (num_active_failures > 100) {
  2853. return false;
  2854. }
  2855. return true;
  2856. }
  2857. while (ret && eqs && (app = eqs->PopPacket())) {
  2858. ret = HandlePacket(app);
  2859. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2860. delete app;
  2861. }
  2862. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2863. player->ApplyPassiveSpells();
  2864. //database.LoadCharacterActiveSpells(player);
  2865. player->UnlockAllSpells(true);
  2866. should_load_spells = false;
  2867. }
  2868. if(spawn_removal_timer.Check() && GetPlayer()) {
  2869. GetPlayer()->CheckSpawnStateQueue();
  2870. }
  2871. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2872. {
  2873. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2874. return false;
  2875. }
  2876. if (quest_updates) {
  2877. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2878. ProcessQuestUpdates();
  2879. }
  2880. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2881. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2882. CheckQuestQueue();
  2883. }
  2884. MSaveSpellStateMutex.lock();
  2885. if(save_spell_state_timer.Check())
  2886. {
  2887. save_spell_state_timer.Disable();
  2888. GetPlayer()->SaveSpellEffects();
  2889. }
  2890. MSaveSpellStateMutex.unlock();
  2891. if (temp_placement_timer.Check()) {
  2892. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2893. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2894. hasSentTempPlacementSpawn = true;
  2895. temp_placement_timer.Disable();
  2896. }
  2897. }
  2898. if (pos_update.Check())
  2899. {
  2900. ProcessStateCommands();
  2901. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2902. if(GetPlayer()->GetRegionMap())
  2903. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2904. if(player_pos_changed && IsReadyForUpdates()) {
  2905. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  2906. bool underworld = false;
  2907. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  2908. if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  2909. underworld = true;
  2910. }
  2911. }
  2912. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  2913. underworld = true;
  2914. }
  2915. if(underworld) {
  2916. player->SetX(GetCurrentZone()->GetSafeX());
  2917. player->SetY(GetCurrentZone()->GetSafeY());
  2918. player->SetZ(GetCurrentZone()->GetSafeZ());
  2919. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  2920. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  2921. if(app){
  2922. QueuePacket(app);
  2923. }
  2924. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  2925. }
  2926. underworld_cooldown_timer.Start();
  2927. }
  2928. //GetPlayer()->CalculateLocation();
  2929. client_list.CheckPlayersInvisStatus(this);
  2930. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2931. player_pos_changed = false;
  2932. GetCurrentZone()->CheckTransporters(this);
  2933. if(GetPlayer()->GetRegionMap())
  2934. {
  2935. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2936. }
  2937. }
  2938. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  2939. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2940. }
  2941. }
  2942. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2943. lua_interface->UpdateDebugClients(this);
  2944. if (quest_pos_timer.Check())
  2945. CheckPlayerQuestsLocationUpdate();
  2946. if (player->GetSkills()->HasSkillUpdates()) {
  2947. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2948. if (skills) {
  2949. Skill* skill = 0;
  2950. vector<Skill*>::iterator itr;
  2951. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2952. skill = *itr;
  2953. SkillChanged(skill, skill->previous_val, skill->current_val);
  2954. }
  2955. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2956. if (app) QueuePacket(app);
  2957. safe_delete(skills);
  2958. }
  2959. }
  2960. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2961. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2962. safe_delete(current_rez.expire_timer);
  2963. current_rez.expire_timer = 0;
  2964. current_rez.active = false;
  2965. current_rez.caster = 0;
  2966. current_rez.crit = false;
  2967. current_rez.crit_mod = 0;
  2968. current_rez.expire_timer = 0;
  2969. current_rez.heal_name = "";
  2970. current_rez.hp_perc = 0;
  2971. current_rez.mp_perc = 0;
  2972. current_rez.no_calcs = false;
  2973. current_rez.range = 0;
  2974. current_rez.should_delete = false;
  2975. current_rez.spell_name = "";
  2976. current_rez.spell_visual = 0;
  2977. current_rez.subspell = 0;
  2978. }
  2979. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2980. // Quest timers
  2981. Quest* failed_step = 0;
  2982. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2983. if (quest_timers.size() > 0) {
  2984. vector<int32>::iterator itr;
  2985. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2986. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2987. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2988. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2989. Quest* quest = player_quests->at(*itr);
  2990. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2991. failed_step = quest;
  2992. break;
  2993. }
  2994. }
  2995. else {
  2996. itr = quest_timers.erase(itr);
  2997. break;
  2998. }
  2999. }
  3000. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3001. }
  3002. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3003. if (failed_step)
  3004. failed_step->StepFailed(failed_step->GetTimerStep());
  3005. if (player->ControlFlagsChanged())
  3006. player->SendControlFlagUpdates(this);
  3007. if (camp_timer && camp_timer->Check()) {
  3008. ResetSendMail();
  3009. if(getConnection())
  3010. getConnection()->SendDisconnect(false);
  3011. safe_delete(camp_timer);
  3012. ret = false;
  3013. }
  3014. if (!eqs || (eqs && !eqs->CheckActive()))
  3015. ret = false;
  3016. // redundant to client disconnect
  3017. // if(!ret)
  3018. // Save();
  3019. return ret;
  3020. }
  3021. ClientList::ClientList() {
  3022. MClients.SetName("ClientList::MClients");
  3023. }
  3024. ClientList::~ClientList() {
  3025. }
  3026. void ClientList::ReloadQuests() {
  3027. list<Client*>::iterator client_iter;
  3028. Client* client = 0;
  3029. MClients.readlock(__FUNCTION__, __LINE__);
  3030. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3031. client = *client_iter;
  3032. if (client)
  3033. client->ReloadQuests();
  3034. }
  3035. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3036. }
  3037. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3038. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3039. return;
  3040. list<Client*>::iterator client_iter;
  3041. Client* client = 0;
  3042. MClients.readlock(__FUNCTION__, __LINE__);
  3043. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3044. client = *client_iter;
  3045. if (client == owner || client->GetPlayer() == NULL)
  3046. continue;
  3047. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3048. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3049. }
  3050. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3051. }
  3052. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3053. list<Client*>::iterator client_iter;
  3054. Client* client = 0;
  3055. MClients.readlock(__FUNCTION__, __LINE__);
  3056. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3057. client = *client_iter;
  3058. if (!client->GetPlayer())
  3059. continue;
  3060. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3061. }
  3062. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3063. }
  3064. int32 ClientList::Count() {
  3065. return client_list.size();
  3066. }
  3067. void ClientList::Add(Client* client) {
  3068. MClients.writelock(__FUNCTION__, __LINE__);
  3069. client_list.push_back(client);
  3070. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3071. }
  3072. Client* ClientList::FindByAccountID(int32 account_id) {
  3073. list<Client*>::iterator client_iter;
  3074. Client* client = 0;
  3075. Client* ret = 0;
  3076. MClients.readlock(__FUNCTION__, __LINE__);
  3077. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3078. client = *client_iter;
  3079. if (client->GetAccountID() == account_id) {
  3080. ret = client;
  3081. break;
  3082. }
  3083. }
  3084. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3085. return ret;
  3086. }
  3087. Client* ClientList::FindByName(char* charName) {
  3088. list<Client*>::iterator client_iter;
  3089. Client* client = 0;
  3090. Client* ret = 0;
  3091. MClients.readlock(__FUNCTION__, __LINE__);
  3092. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3093. client = *client_iter;
  3094. if (!client || !client->GetPlayer())
  3095. continue;
  3096. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3097. ret = client;
  3098. break;
  3099. }
  3100. }
  3101. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3102. return ret;
  3103. }
  3104. Client* ClientList::Get(int32 ip, int16 port) {
  3105. list<Client*>::iterator client_iter;
  3106. Client* client = 0;
  3107. Client* ret = 0;
  3108. MClients.readlock(__FUNCTION__, __LINE__);
  3109. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3110. client = *client_iter;
  3111. if (client->GetIP() == ip && client->GetPort() == port) {
  3112. ret = client;
  3113. break;
  3114. }
  3115. }
  3116. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3117. return ret;
  3118. }
  3119. void ClientList::Process() {
  3120. list<Client*>::iterator client_iter;
  3121. list<Client*>::iterator erase_iter;
  3122. Client* client = 0;
  3123. MClients.readlock(__FUNCTION__, __LINE__);
  3124. erase_iter = client_list.end();
  3125. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3126. client = *client_iter;
  3127. // have a sanity check because the client list can sometimes obtain null client pointers
  3128. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3129. erase_iter = client_iter;
  3130. break;
  3131. }
  3132. }
  3133. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3134. if (erase_iter != client_list.end()) {
  3135. client = *erase_iter;
  3136. MClients.writelock(__FUNCTION__, __LINE__);
  3137. client_list.erase(erase_iter);
  3138. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3139. if (client && !client->remove_from_list) {
  3140. struct in_addr in;
  3141. in.s_addr = client->GetIP();
  3142. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3143. safe_delete(client);
  3144. }
  3145. }
  3146. }
  3147. void ClientList::RemoveConnection(EQStream* eqs) {
  3148. Client* client;
  3149. if (eqs) {
  3150. list<Client*>::iterator client_iter;
  3151. MClients.readlock(__FUNCTION__, __LINE__);
  3152. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3153. client = *client_iter;
  3154. if (client->getConnection() == eqs)
  3155. client->Disconnect(true);
  3156. }
  3157. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3158. }
  3159. }
  3160. bool ClientList::ContainsStream(EQStream* eqs) {
  3161. if (!eqs) {
  3162. return false;
  3163. }
  3164. list<Client*>::iterator client_iter;
  3165. bool ret = false;
  3166. MClients.readlock(__FUNCTION__, __LINE__);
  3167. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3168. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3169. ret = true;
  3170. break;
  3171. }
  3172. }
  3173. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3174. return ret;
  3175. }
  3176. void ClientList::Remove(Client* client, bool remove_data) {
  3177. client->remove_from_list = true;
  3178. if (remove_data) {
  3179. safe_delete(client);
  3180. }
  3181. }
  3182. void Client::SetCurrentZone(int32 id) {
  3183. if (current_zone) {
  3184. //current_zone->GetCombat()->RemoveHate(player);
  3185. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3186. }
  3187. SetCurrentZone(zone_list.Get(id));
  3188. }
  3189. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3190. if (current_zone) {
  3191. //current_zone->GetCombat()->RemoveHate(player);
  3192. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3193. }
  3194. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3195. }
  3196. ZoneServer* Client::GetCurrentZone() {
  3197. return current_zone;
  3198. }
  3199. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3200. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3201. if (channel_type == CHANNEL_LOOT)
  3202. return CHANNEL_COLOR_NEW_LOOT;
  3203. }
  3204. else if (GetVersion() >= 973) {
  3205. if (channel_type == CHANNEL_LOOT)
  3206. return CHANNEL_COLOR_NEWEST_LOOT;
  3207. }
  3208. if (GetVersion() <= 283) {
  3209. if (channel_type <=12)
  3210. return channel_type;
  3211. switch (channel_type) {
  3212. case CHANNEL_GROUP_CHAT:
  3213. case CHANNEL_GROUP_SAY:
  3214. case CHANNEL_RAID_SAY:
  3215. case CHANNEL_GUILD_CHAT:
  3216. case CHANNEL_GUILD_SAY:
  3217. case CHANNEL_OFFICER_SAY:
  3218. case CHANNEL_GUILD_MOTD:
  3219. return channel_type - 1;
  3220. case CHANNEL_PRIVATE_CHAT:
  3221. case CHANNEL_NONPLAYER_TELL:
  3222. return channel_type - 5;
  3223. case CHANNEL_PRIVATE_TELL:
  3224. case CHANNEL_TELL_FROM_CS:
  3225. return channel_type - 6;
  3226. case CHANNEL_CHAT_CHANNEL_TEXT:
  3227. case CHANNEL_OUT_OF_CHARACTER:
  3228. case CHANNEL_AUCTION:
  3229. case CHANNEL_CUSTOM_CHANNEL:
  3230. case CHANNEL_CHARACTER_TEXT:
  3231. case CHANNEL_REWARD:
  3232. case CHANNEL_DEATH:
  3233. case CHANNEL_PET_CHAT:
  3234. case CHANNEL_SKILL:
  3235. return channel_type - 7;
  3236. case CHANNEL_SPELLS:
  3237. case CHANNEL_YOU_CAST:
  3238. case CHANNEL_YOU_FAIL:
  3239. return channel_type - 8;
  3240. case CHANNEL_FRIENDLY_CAST:
  3241. case CHANNEL_FRIENDLY_FAIL:
  3242. case CHANNEL_OTHER_CAST:
  3243. case CHANNEL_OTHER_FAIL:
  3244. case CHANNEL_HOSTILE_CAST:
  3245. case CHANNEL_HOSTILE_FAIL:
  3246. case CHANNEL_WORN_OFF:
  3247. case CHANNEL_SPELLS_OTHER:
  3248. return channel_type - 9;
  3249. case CHANNEL_COMBAT:
  3250. return channel_type - 15;
  3251. case CHANNEL_HEROIC_OPPORTUNITY:
  3252. case CHANNEL_NON_MELEE_DAMAGE:
  3253. case CHANNEL_DAMAGE_SHIELD:
  3254. return channel_type - 16;
  3255. case CHANNEL_MELEE_COMBAT:
  3256. case CHANNEL_WARNINGS:
  3257. case CHANNEL_YOU_HIT:
  3258. case CHANNEL_YOU_MISS:
  3259. case CHANNEL_ATTACKER_HITS:
  3260. case CHANNEL_ATTACKER_MISSES:
  3261. return channel_type - 18;
  3262. case CHANNEL_OTHER_HIT:
  3263. case CHANNEL_OTHER_MISSES:
  3264. case CHANNEL_CRITICAL_HIT:
  3265. return channel_type - 22;
  3266. case CHANNEL_OTHER:
  3267. case CHANNEL_MONEY_SPLIT:
  3268. case CHANNEL_LOOT:
  3269. return channel_type - 30;
  3270. case CHANNEL_COMMAND_TEXT:
  3271. case CHANNEL_BROADCAST:
  3272. case CHANNEL_WHO:
  3273. case CHANNEL_COMMANDS:
  3274. case CHANNEL_MERCHANT:
  3275. case CHANNEL_MERCHANT_BUY_SELL:
  3276. case CHANNEL_CONSIDER_MESSAGE:
  3277. case CHANNEL_CON_MINUS_2:
  3278. case CHANNEL_CON_MINUS_1:
  3279. case CHANNEL_CON_0:
  3280. case CHANNEL_CON_1:
  3281. case CHANNEL_CON_2:
  3282. return channel_type - 31;
  3283. default: {
  3284. return CHANNEL_DEFAULT;
  3285. }
  3286. }
  3287. }
  3288. else if (GetVersion() <= 546) {
  3289. if (channel_type < 20)
  3290. return channel_type;
  3291. switch (channel_type) {
  3292. case CHANNEL_GUILD_MOTD:
  3293. case CHANNEL_GUILD_MEMBER_ONLINE:
  3294. case CHANNEL_GUILD_EVENT:
  3295. return channel_type + 1;
  3296. case CHANNEL_PRIVATE_CHAT:
  3297. case CHANNEL_NONPLAYER_TELL:
  3298. return channel_type - 1;
  3299. case CHANNEL_PRIVATE_TELL:
  3300. case CHANNEL_TELL_FROM_CS:
  3301. case CHANNEL_ARENA:
  3302. case CHANNEL_CHAT_CHANNEL_TEXT:
  3303. case CHANNEL_OUT_OF_CHARACTER:
  3304. case CHANNEL_AUCTION:
  3305. case CHANNEL_CUSTOM_CHANNEL:
  3306. case CHANNEL_CHARACTER_TEXT:
  3307. case CHANNEL_REWARD:
  3308. case CHANNEL_DEATH:
  3309. case CHANNEL_PET_CHAT:
  3310. case CHANNEL_SKILL:
  3311. case CHANNEL_FACTION:
  3312. case CHANNEL_SPELLS:
  3313. case CHANNEL_YOU_CAST:
  3314. case CHANNEL_YOU_FAIL:
  3315. return channel_type - 2;
  3316. case CHANNEL_FRIENDLY_CAST:
  3317. case CHANNEL_FRIENDLY_FAIL:
  3318. case CHANNEL_OTHER_CAST:
  3319. case CHANNEL_OTHER_FAIL:
  3320. case CHANNEL_HOSTILE_CAST:
  3321. case CHANNEL_HOSTILE_FAIL:
  3322. case CHANNEL_WORN_OFF:
  3323. case CHANNEL_SPELLS_OTHER:
  3324. case CHANNEL_HEAL_SPELLS:
  3325. case CHANNEL_HEALS:
  3326. case CHANNEL_FRIENDLY_HEALS:
  3327. case CHANNEL_OTHER_HEALS:
  3328. case CHANNEL_HOSTILE_HEALS:
  3329. return channel_type - 3;
  3330. case CHANNEL_COMBAT:
  3331. case CHANNEL_GENERAL_COMBAT:
  3332. case CHANNEL_HEROIC_OPPORTUNITY:
  3333. case CHANNEL_NON_MELEE_DAMAGE:
  3334. case CHANNEL_DAMAGE_SHIELD:
  3335. case CHANNEL_WARD:
  3336. return channel_type - 4;
  3337. case CHANNEL_MELEE_COMBAT:
  3338. case CHANNEL_WARNINGS:
  3339. case CHANNEL_YOU_HIT:
  3340. case CHANNEL_YOU_MISS:
  3341. case CHANNEL_ATTACKER_HITS:
  3342. case CHANNEL_ATTACKER_MISSES:
  3343. case CHANNEL_YOUR_PET_HITS:
  3344. case CHANNEL_YOUR_PET_MISSES:
  3345. case CHANNEL_ATTACKER_HITS_PET:
  3346. case CHANNEL_ATTACKER_MISSES_PET:
  3347. case CHANNEL_OTHER_HIT:
  3348. case CHANNEL_OTHER_MISSES:
  3349. return channel_type - 5;
  3350. case CHANNEL_OTHER:
  3351. case CHANNEL_MONEY_SPLIT:
  3352. case CHANNEL_LOOT:
  3353. return channel_type - 14;
  3354. case CHANNEL_COMMAND_TEXT:
  3355. case CHANNEL_BROADCAST:
  3356. case CHANNEL_WHO:
  3357. case CHANNEL_COMMANDS:
  3358. case CHANNEL_MERCHANT:
  3359. case CHANNEL_MERCHANT_BUY_SELL:
  3360. case CHANNEL_CONSIDER_MESSAGE:
  3361. case CHANNEL_CON_MINUS_2:
  3362. case CHANNEL_CON_MINUS_1:
  3363. case CHANNEL_CON_0:
  3364. case CHANNEL_CON_1:
  3365. case CHANNEL_CON_2:
  3366. case CHANNEL_TRADESKILLS:
  3367. case CHANNEL_HARVESTING:
  3368. case CHANNEL_HARVESTING_WARNINGS:
  3369. return channel_type - 15;
  3370. default: {
  3371. return CHANNEL_DEFAULT;
  3372. }
  3373. }
  3374. }
  3375. else {
  3376. switch (channel_type) {
  3377. default: {
  3378. return channel_type;
  3379. }
  3380. }
  3381. }
  3382. return channel_type;
  3383. }
  3384. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3385. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3386. return;
  3387. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3388. if (packet) {
  3389. packet->setDataByName("from", from->GetPlayer()->GetName());
  3390. packet->setDataByName("to", to);
  3391. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3392. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3393. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3394. packet->setDataByName("unknown2", 1, 1);
  3395. packet->setDataByName("show_bubble", 1);
  3396. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3397. packet->setDataByName("understood", 1);
  3398. }
  3399. packet->setDataByName("time", 2);
  3400. packet->setDataByName("language", current_language_id);
  3401. packet->setMediumStringByName("message", message);
  3402. EQ2Packet* outpacket = packet->serialize();
  3403. QueuePacket(outpacket);
  3404. safe_delete(packet);
  3405. }
  3406. }
  3407. void Client::SimpleMessage(int8 color, const char* message) {
  3408. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3409. if (command_packet) {
  3410. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3411. command_packet->setMediumStringByName("text", message);
  3412. command_packet->setDataByName("unknown02", 0x00ff);
  3413. EQ2Packet* outapp = command_packet->serialize();
  3414. QueuePacket(outapp);
  3415. safe_delete(command_packet);
  3416. }
  3417. }
  3418. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3419. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3420. if (packet) {
  3421. int8 xxx = spell->GetSpellData()->is_aa;
  3422. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3423. packet->setDataByName("spell_id", spell->GetSpellID());
  3424. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3425. packet->setDataByName("spell_name", spell->GetName());
  3426. if(add_silently)
  3427. packet->setDataByName("add_silently", 1);
  3428. if(add_to_hotbar)
  3429. packet->setDataByName("add_to_hotbar", 1);
  3430. packet->setDataByName("unknown", xxx);
  3431. packet->setDataByName("display_spell_tier", 1);
  3432. packet->setDataByName("unknown3", 1);
  3433. packet->setDataByName("tier", spell->GetSpellTier());
  3434. packet->setDataByName("icon", spell->GetSpellIcon());
  3435. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3436. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3437. //packet->PrintPacket();
  3438. EQ2Packet* outapp = packet->serialize();
  3439. //DumpPacket(outapp);
  3440. QueuePacket(outapp);
  3441. safe_delete(packet);
  3442. }
  3443. }
  3444. void Client::Message(int8 type, const char* message, ...) {
  3445. va_list argptr;
  3446. char buffer[4096];
  3447. va_start(argptr, message);
  3448. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3449. va_end(argptr);
  3450. SimpleMessage(type, buffer);
  3451. }
  3452. void Client::Disconnect(bool send_disconnect)
  3453. {
  3454. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3455. this->Save();
  3456. this->GetPlayer()->WritePlayerStatistics();
  3457. SetConnected(false);
  3458. if (send_disconnect && getConnection())
  3459. getConnection()->SendDisconnect(true);
  3460. eqs = 0;
  3461. }
  3462. bool Client::Summon(const char* search_name) {
  3463. Spawn* target = 0;
  3464. if (search_name || GetPlayer()->GetTarget()) {
  3465. Client* search_client = 0;
  3466. if (search_name) {
  3467. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3468. if (target && target->IsPlayer())
  3469. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3470. if (!target) {
  3471. search_client = zone_list.GetClientByCharName(string(search_name));
  3472. if (search_client)
  3473. target = search_client->GetPlayer();
  3474. }
  3475. }
  3476. else
  3477. target = GetPlayer()->GetTarget();
  3478. if (target && target != GetPlayer()) {
  3479. target->SetX(GetPlayer()->GetX());
  3480. target->SetY(GetPlayer()->GetY());
  3481. target->SetZ(GetPlayer()->GetZ());
  3482. target->SetHeading(GetPlayer()->GetHeading());
  3483. if (!target->IsPlayer()) {
  3484. target->SetSpawnOrigX(target->GetX());
  3485. target->SetSpawnOrigY(target->GetY());
  3486. target->SetSpawnOrigZ(target->GetZ());
  3487. target->SetSpawnOrigHeading(target->GetHeading());
  3488. }
  3489. target->SetLocation(GetPlayer()->GetLocation());
  3490. }
  3491. else if (target)
  3492. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3493. if (search_client && search_client != this) {
  3494. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3495. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3496. if (search_client->GetCurrentZone() != GetCurrentZone())
  3497. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3498. else {
  3499. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3500. if (app)
  3501. search_client->QueuePacket(app);
  3502. }
  3503. }
  3504. }
  3505. if (!target)
  3506. return false;
  3507. else
  3508. return true;
  3509. }
  3510. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3511. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3512. if(instanceType < 1)
  3513. return std::string("");
  3514. ZoneServer* instance_zone = nullptr;
  3515. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3516. if (data) {
  3517. // If lockout instances check to see if we are locked out
  3518. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3519. int32 time = 0;
  3520. // Check success timer
  3521. if (data->last_success_timestamp > 0) {
  3522. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3523. // Timer has not expired yet can't re enter
  3524. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3525. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3526. }
  3527. }
  3528. // Check failure timer
  3529. if (data->last_failure_timestamp > 0) {
  3530. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3531. // Timer has not expired yet
  3532. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3533. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3534. }
  3535. }
  3536. // Time > 0 then we are locked out, make the message and send it and return true
  3537. if (time > 0) {
  3538. string time_msg = "";
  3539. int16 hour;
  3540. int8 min;
  3541. int8 sec;
  3542. hour = time / 3600;
  3543. time = time % 3600;
  3544. min = time / 60;
  3545. time = time % 60;
  3546. sec = time;
  3547. if (hour > 0) {
  3548. char temp[10];
  3549. snprintf(temp, 9," %i", hour);
  3550. time_msg.append(temp);
  3551. time_msg.append(" hour");
  3552. time_msg.append((hour > 1) ? "s" : "");
  3553. }
  3554. if (min > 0) {
  3555. char temp[5];
  3556. snprintf(temp, 4," %i", min);
  3557. time_msg.append(temp);
  3558. time_msg.append(" minute");
  3559. time_msg.append((min > 1) ? "s" : "");
  3560. }
  3561. // Only add seconds if minutes and hours are 0
  3562. if (hour == 0 && min == 0 && sec > 0) {
  3563. char temp[5];
  3564. snprintf(temp, 4," %i", sec);
  3565. time_msg.append(temp);
  3566. time_msg.append(" second");
  3567. time_msg.append((sec > 1) ? "s" : "");
  3568. }
  3569. if(displayClient)
  3570. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3571. return time_msg;
  3572. }
  3573. }
  3574. }
  3575. return std::string("");
  3576. }
  3577. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3578. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3579. if(instanceType < 1)
  3580. return nullptr;
  3581. ZoneServer* instance_zone = nullptr;
  3582. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3583. if (data) {
  3584. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3585. // If lockout instances check to see if we are locked out
  3586. if (lockoutTime.length() > 0) {
  3587. return nullptr;
  3588. }
  3589. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3590. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3591. // 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
  3592. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3593. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3594. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3595. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3596. }
  3597. else
  3598. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3599. data->instance_id = instance_zone->GetInstanceID();
  3600. }
  3601. }
  3602. return instance_zone;
  3603. }
  3604. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3605. ZoneServer* instance_zone = NULL;
  3606. int8 instanceType = 0;
  3607. // determine if this is a group instanced zone that already exists
  3608. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3609. if (instance_zone != NULL)
  3610. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3611. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3612. {
  3613. // best to check if we already have our own instance!
  3614. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3615. {
  3616. switch (instanceType)
  3617. {
  3618. case SOLO_LOCKOUT_INSTANCE:
  3619. case GROUP_LOCKOUT_INSTANCE:
  3620. case RAID_LOCKOUT_INSTANCE:
  3621. {
  3622. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3623. if (instance_zone) {
  3624. // 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
  3625. // so delete `instances` entry for the zone when it shuts down.
  3626. 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());
  3627. if (db_id > 0)
  3628. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3629. }
  3630. break;
  3631. }
  3632. case SOLO_PERSIST_INSTANCE:
  3633. case GROUP_PERSIST_INSTANCE:
  3634. case RAID_PERSIST_INSTANCE:
  3635. {
  3636. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3637. if (instance_zone) {
  3638. 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());
  3639. if (db_id > 0)
  3640. 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()));
  3641. }
  3642. break;
  3643. }
  3644. case PUBLIC_INSTANCE:
  3645. case TRADESKILL_INSTANCE:
  3646. {
  3647. // if its public/tradeskill, look for a public already setup
  3648. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3649. if (instance_zone) {
  3650. // Check the current population against the max population, if greater or equal start a new version
  3651. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3652. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3653. }
  3654. else
  3655. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3656. break;
  3657. }
  3658. case PERSONAL_HOUSE_INSTANCE:
  3659. case GUILD_HOUSE_INSTANCE:
  3660. {
  3661. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3662. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3663. // with the OP_EnterHouseMsg opcode
  3664. break;
  3665. }
  3666. case QUEST_INSTANCE:
  3667. {
  3668. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3669. break;
  3670. /*
  3671. 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`;
  3672. */
  3673. }
  3674. default:
  3675. {
  3676. // NONE
  3677. }
  3678. }
  3679. }
  3680. if (instance_zone != NULL)
  3681. Zone(instance_zone, zone_coords_valid);
  3682. }
  3683. if (instance_zone != NULL)
  3684. return true;
  3685. else
  3686. return false;
  3687. }
  3688. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3689. Spawn* target = 0;
  3690. if (search_name || GetPlayer()->GetTarget()) {
  3691. Client* search_client = 0;
  3692. if (search_name) {
  3693. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3694. if (!target) {
  3695. search_client = zone_list.GetClientByCharName(search_name);
  3696. if (search_client)
  3697. target = search_client->GetPlayer();
  3698. }
  3699. if (target)
  3700. GetPlayer()->SetTarget(target);
  3701. }
  3702. else
  3703. target = GetPlayer()->GetTarget();
  3704. if (target && target != GetPlayer()) {
  3705. GetPlayer()->SetX(target->GetX());
  3706. GetPlayer()->SetY(target->GetY());
  3707. GetPlayer()->SetZ(target->GetZ());
  3708. GetPlayer()->SetHeading(target->GetHeading());
  3709. GetPlayer()->SetLocation(target->GetLocation());
  3710. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3711. }
  3712. else if (target)
  3713. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3714. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3715. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3716. else if (target) {
  3717. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3718. if (app)
  3719. QueuePacket(app);
  3720. }
  3721. }
  3722. if (!target)
  3723. return false;
  3724. else
  3725. return true;
  3726. }
  3727. bool Client::CheckZoneAccess(const char* zoneName) {
  3728. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3729. ZoneServer* zone = zone_list.Get(zoneName, false);
  3730. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3731. if (zone && zone->GetZoneLockState())
  3732. {
  3733. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3734. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3735. return false;
  3736. }
  3737. sint16 zoneMinStatus = 0;
  3738. int16 zoneMinLevel = 0;
  3739. int16 zoneMaxLevel = 0;
  3740. int16 zoneMinVersion = 0;
  3741. if (!zone)
  3742. {
  3743. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3744. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3745. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3746. return true;
  3747. }
  3748. }
  3749. else
  3750. {
  3751. zoneMinStatus = zone->GetMinimumStatus();
  3752. zoneMinLevel = zone->GetMinimumLevel();
  3753. zoneMaxLevel = zone->GetMaximumLevel();
  3754. zoneMinVersion = zone->GetMinimumVersion();
  3755. }
  3756. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3757. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3758. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3759. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3760. {
  3761. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3762. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3763. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3764. return false;
  3765. }
  3766. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3767. {
  3768. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3769. {
  3770. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3771. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3772. return false;
  3773. }
  3774. }
  3775. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3776. {
  3777. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3778. {
  3779. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3780. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3781. return false;
  3782. }
  3783. }
  3784. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3785. {
  3786. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3787. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3788. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3789. {
  3790. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3791. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3792. return false;
  3793. }
  3794. }
  3795. return true;
  3796. }
  3797. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3798. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3799. }
  3800. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3801. if (!new_zone) {
  3802. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3803. return;
  3804. }
  3805. client_zoning = true;
  3806. zoning_id = new_zone->GetZoneID();
  3807. zoning_instance_id = new_zone->GetInstanceID();
  3808. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3809. player->SetResurrecting(true);
  3810. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3811. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3812. MSaveSpellStateMutex.lock();
  3813. player->SaveSpellEffects();
  3814. player->SetSaveSpellEffects(true);
  3815. MSaveSpellStateMutex.unlock();
  3816. ResetSendMail();
  3817. // Remove players pet from zone if there is one
  3818. ((Entity*)player)->DismissAllPets();
  3819. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3820. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3821. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3822. SetZoningDestination(new_zone);
  3823. SetCurrentZone(new_zone);
  3824. if (player->GetGroupMemberInfo())
  3825. {
  3826. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3827. player->UpdateGroupMemberInfo();
  3828. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3829. }
  3830. // block out the member info for the group
  3831. TempRemoveGroup();
  3832. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3833. if (set_coords)
  3834. {
  3835. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3836. __FUNCTION__,
  3837. GetCurrentZone()->GetSafeX(),
  3838. GetCurrentZone()->GetSafeY(),
  3839. GetCurrentZone()->GetSafeZ(),
  3840. GetCurrentZone()->GetSafeHeading(),
  3841. new_zone->GetZoneName()
  3842. );
  3843. player->SetX(GetCurrentZone()->GetSafeX());
  3844. player->SetY(GetCurrentZone()->GetSafeY());
  3845. player->SetZ(GetCurrentZone()->GetSafeZ());
  3846. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3847. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  3848. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  3849. }
  3850. else {
  3851. ResetZoningCoords();
  3852. }
  3853. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3854. Save();
  3855. char* new_zone_ip = 0;
  3856. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3857. new_zone_ip = net.GetInternalWorldAddress();
  3858. else
  3859. new_zone_ip = net.GetWorldAddress();
  3860. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3861. int32 key = Timer::GetUnixTimeStamp();
  3862. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3863. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3864. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3865. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3866. if (version > 283) {
  3867. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3868. if (packet)
  3869. {
  3870. QueuePacket(packet->serialize());
  3871. safe_delete(packet);
  3872. }
  3873. }
  3874. }
  3875. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3876. {
  3877. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3878. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3879. }
  3880. float Client::DistanceFrom(Client* client) {
  3881. float ret = 0;
  3882. if (client && client != this) {
  3883. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3884. ret = sqrt(ret);
  3885. }
  3886. return ret;
  3887. }
  3888. void Client::DetermineCharacterUpdates() {
  3889. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3890. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3891. cdu->account_id = GetAccountID();
  3892. cdu->char_id = GetCharacterID();
  3893. int32 timestamp = Timer::GetUnixTimeStamp();
  3894. int8 flag = GetTimeStampFlag();
  3895. if (flag & LEVEL_UPDATE_FLAG)
  3896. {
  3897. cdu->update_field = LEVEL_UPDATE_FLAG;
  3898. cdu->update_data = player->GetLevel();
  3899. loginserver.SendPacket(outpack);
  3900. }
  3901. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3902. if (flag & CLASS_UPDATE_FLAG)
  3903. {
  3904. cdu->update_field = CLASS_UPDATE_FLAG;
  3905. cdu->update_data = player->GetAdventureClass();
  3906. loginserver.SendPacket(outpack);
  3907. }
  3908. if (flag & GENDER_UPDATE_FLAG)
  3909. {
  3910. cdu->update_field = GENDER_UPDATE_FLAG;
  3911. cdu->update_data = player->GetGender();
  3912. loginserver.SendPacket(outpack);
  3913. }
  3914. if (flag & DELETE_UPDATE_FLAG) {
  3915. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3916. }
  3917. safe_delete(outpack); // Zone, armor and name use a different structure
  3918. if (flag & RACE_UPDATE_FLAG)
  3919. {
  3920. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3921. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3922. ru->account_id = GetAccountID();
  3923. ru->char_id = GetCharacterID();
  3924. ru->race = player->GetRace();
  3925. ru->model_type = player->GetModelType();
  3926. loginserver.SendPacket(outpack);
  3927. safe_delete(outpack);
  3928. }
  3929. if (flag & ZONE_UPDATE_FLAG) {
  3930. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3931. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3932. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3933. czu->account_id = GetAccountID();
  3934. czu->char_id = GetCharacterID();
  3935. czu->zone_id = GetCurrentZone()->GetZoneID();
  3936. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3937. czu->zone_length = strlen(zone_file);
  3938. if (czu->zone_length > 64)
  3939. czu->zone_length = 64;
  3940. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3941. loginserver.SendPacket(outpack);
  3942. safe_delete(outpack);
  3943. }
  3944. if (flag & ARMOR_UPDATE_FLAG) {
  3945. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3946. }
  3947. if (flag & NAME_UPDATE_FLAG) {
  3948. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3949. }
  3950. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3951. }
  3952. void Client::Save() {
  3953. if (GetCharacterID() == 0)
  3954. return;
  3955. if (current_zone) {
  3956. DetermineCharacterUpdates();
  3957. UpdateCharacterInstances();
  3958. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3959. database.Save(this);
  3960. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3961. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3962. GetPlayer()->ResetQuickbarNeeded();
  3963. }
  3964. database.SaveItems(this);
  3965. database.SaveBuyBacks(this);
  3966. GetPlayer()->SaveHistory();
  3967. GetPlayer()->SaveLUAHistory();
  3968. MSaveSpellStateMutex.lock();
  3969. GetPlayer()->SaveSpellEffects();
  3970. MSaveSpellStateMutex.unlock();
  3971. }
  3972. }
  3973. void Client::UpdateCharacterInstances() {
  3974. if (GetPlayer() != NULL)
  3975. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3976. /*if ( GetPlayer() != NULL )
  3977. {
  3978. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3979. // to use for applying the update to each instances timer
  3980. int32 lastSaveTS = GetLastSavedTimeStamp();
  3981. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3982. int32 diffTS = newSaveTS - lastSaveTS;
  3983. // update instance timers
  3984. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3985. // update with the new timestamp and save the db
  3986. this->SetLastSavedTimeStamp(newSaveTS);
  3987. }*/
  3988. }
  3989. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3990. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3991. if (packet) {
  3992. packet->LoadPacketData(app->pBuffer, app->size);
  3993. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3994. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3995. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3996. vector<EntityCommand*> commands;
  3997. vector<EntityCommand*> delete_commands;
  3998. if (out && spawn) {
  3999. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4000. {
  4001. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4002. if (!spawn->primary_command_list[i]->default_allow_list)
  4003. {
  4004. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4005. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4006. continue;
  4007. }
  4008. else
  4009. {
  4010. // default is allow list, only deny if added to the list as deny (false itr second)
  4011. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4012. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4013. continue;
  4014. }
  4015. commands.push_back(spawn->primary_command_list[i]);
  4016. }
  4017. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4018. commands.push_back(spawn->secondary_command_list[i]);
  4019. if (spawn->IsPlayer()) {
  4020. if (player->IsFriend(spawn->GetName()))
  4021. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4022. else
  4023. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4024. if (player->IsIgnored(spawn->GetName()))
  4025. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4026. else
  4027. {
  4028. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4029. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4030. }
  4031. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4032. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4033. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4034. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4035. }
  4036. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4037. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4038. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4039. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4040. }
  4041. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4042. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4043. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4044. }
  4045. out->setDataByName("spawn_id", spawn_id);
  4046. out->setArrayLengthByName("num_verbs", commands.size());
  4047. for (int32 i = 0; i < commands.size(); i++) {
  4048. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4049. out->setArrayDataByName("distance", commands[i]->distance, i);
  4050. if (commands[i]->error_text.length() == 0)
  4051. out->setArrayAddToPacketByName("error", false, i);
  4052. else {
  4053. out->setArrayDataByName("display_error", 1, i);
  4054. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4055. }
  4056. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4057. }
  4058. EQ2Packet* outapp = out->serialize();
  4059. //DumpPacket(outapp);
  4060. QueuePacket(outapp);
  4061. safe_delete(out);
  4062. for (int32 i = 0; i < delete_commands.size(); i++) {
  4063. safe_delete(delete_commands[i]);
  4064. }
  4065. }
  4066. safe_delete(packet);
  4067. }
  4068. }
  4069. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4070. if (previous_value != new_value) {
  4071. 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);
  4072. char tmp[200] = { 0 };
  4073. 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);
  4074. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4075. }
  4076. }
  4077. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4078. {
  4079. /* JA notes on the unknown:
  4080. 2 = ding glimmer
  4081. 16 = Achievement Unlocked
  4082. 6 no longer does anything
  4083. */
  4084. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4085. if (packet) {
  4086. packet->setDataByName("unknown", unknown);
  4087. packet->setMediumStringByName("text", text);
  4088. if (type && strlen(type) > 0)
  4089. packet->setMediumStringByName("message_type", type);
  4090. packet->setDataByName("size", size);
  4091. packet->setDataByName("red", red);
  4092. packet->setDataByName("green", green);
  4093. packet->setDataByName("blue", blue);
  4094. QueuePacket(packet->serialize());
  4095. safe_delete(packet);
  4096. }
  4097. }
  4098. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4099. if (new_level < 1) {
  4100. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4101. return;
  4102. }
  4103. if (player->GetLevel() != new_level) {
  4104. player->SetLevel(new_level);
  4105. if (player->GetGroupMemberInfo()) {
  4106. player->UpdateGroupMemberInfo();
  4107. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4108. }
  4109. }
  4110. if (new_level > old_level) {
  4111. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4112. }
  4113. if (player->GetPet()) {
  4114. NPC* pet = (NPC*)player->GetPet();
  4115. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4116. pet->SetLevel(new_level);
  4117. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4118. if (command_packet) {
  4119. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4120. command_packet->setDataByName("anim_type", 1753);
  4121. QueuePacket(command_packet->serialize());
  4122. safe_delete(command_packet);
  4123. }
  4124. }
  4125. }
  4126. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4127. if (level_update) {
  4128. level_update->setDataByName("old_level", old_level);
  4129. level_update->setDataByName("new_level", new_level);
  4130. QueuePacket(level_update->serialize());
  4131. safe_delete(level_update);
  4132. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4133. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4134. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4135. }
  4136. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4137. if (command_packet) {
  4138. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4139. command_packet->setDataByName("anim_type", 1753);
  4140. QueuePacket(command_packet->serialize());
  4141. safe_delete(command_packet);
  4142. }
  4143. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4144. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4145. SendNewSpells(player->GetAdventureClass());
  4146. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4147. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4148. GetPlayer()->ChangePrimaryWeapon();
  4149. GetPlayer()->ChangeSecondaryWeapon();
  4150. GetPlayer()->ChangeRangedWeapon();
  4151. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4152. // GetPlayer()->SetLevel(new_level);
  4153. 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__);
  4154. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4155. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4156. GetPlayer()->CalculateBonuses();
  4157. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4158. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4159. /*InfoStruct* info = player->GetInfoStruct();
  4160. info->set_agi_base(new_level * 2 + 15);
  4161. info->set_intel_base(new_level * 2 + 15);
  4162. info->set_wis_base(new_level * 2 + 15);
  4163. info->set_str_base(new_level * 2 + 15);
  4164. info->set_sta_base(new_level * 2 + 15);
  4165. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4166. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4167. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4168. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4169. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4170. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4171. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4172. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4173. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4174. GetPlayer()->SetCharSheetChanged(true);
  4175. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4176. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4177. int16 new_skill_cap = 5 * new_level;
  4178. PlayerSkillList* player_skills = player->GetSkills();
  4179. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4180. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4181. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4182. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4183. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4184. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4185. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4186. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4187. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4188. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4189. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4190. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4191. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4192. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4193. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4194. if (new_level > player->GetTSLevel())
  4195. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4196. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4197. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4198. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4199. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4200. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4201. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4202. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4203. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4204. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4205. Guild* guild = GetPlayer()->GetGuild();
  4206. if (guild) {
  4207. int8 event_type = 0;
  4208. if (new_level < 10)
  4209. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4210. else if (new_level == 10)
  4211. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4212. else if (new_level >= 11 && new_level < 20)
  4213. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4214. else if (new_level == 20)
  4215. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4216. else if (new_level >= 21 && new_level < 30)
  4217. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4218. else if (new_level == 30)
  4219. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4220. else if (new_level >= 31 && new_level < 40)
  4221. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4222. else if (new_level == 40)
  4223. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4224. else if (new_level >= 41 && new_level < 50)
  4225. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4226. else if (new_level == 50)
  4227. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4228. else if (new_level >= 51 && new_level < 60)
  4229. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4230. else if (new_level == 60)
  4231. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4232. else if (new_level >= 61 && new_level < 70)
  4233. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4234. else if (new_level == 70)
  4235. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4236. else if (new_level >= 71 && new_level < 80)
  4237. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4238. else if (new_level == 80)
  4239. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4240. 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());
  4241. 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());
  4242. guild->UpdateGuildMemberInfo(GetPlayer());
  4243. guild->SendGuildMember(GetPlayer());
  4244. guild->SendGuildMemberList();
  4245. }
  4246. // Need to send the trait list every time the players level changes
  4247. // Also need to force the char sheet update or else there can be a large delay from when you level
  4248. // to when you are actually able to select traits.
  4249. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4250. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4251. if (version > 546)
  4252. master_aa_list.DisplayAA(this, 0, 0);
  4253. if (GetPlayer()->SpawnedBots.size() > 0) {
  4254. map<int32, int32>::iterator itr;
  4255. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4256. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4257. if (bot && bot->IsBot())
  4258. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4259. }
  4260. }
  4261. }
  4262. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4263. if (new_level < 1) {
  4264. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4265. return;
  4266. }
  4267. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4268. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4269. return;
  4270. }
  4271. if (new_level > old_level)
  4272. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4273. if (player->GetTSLevel() != new_level) {
  4274. player->SetTSLevel(new_level);
  4275. if (player->GetGroupMemberInfo()) {
  4276. player->UpdateGroupMemberInfo();
  4277. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4278. }
  4279. }
  4280. // Only tradeskill skills should increace, and then only those related to your class
  4281. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4282. if (level_update) {
  4283. level_update->setDataByName("old_level", old_level);
  4284. level_update->setDataByName("new_level", new_level);
  4285. level_update->setDataByName("type", 1);
  4286. QueuePacket(level_update->serialize());
  4287. safe_delete(level_update);
  4288. }
  4289. // Need to make tradeskill versions of the following
  4290. //SendNewSpells(player->GetAdventureClass());
  4291. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4292. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4293. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4294. if (command_packet) {
  4295. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4296. command_packet->setDataByName("anim_type", 1753);
  4297. QueuePacket(command_packet->serialize());
  4298. safe_delete(command_packet);
  4299. }
  4300. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4301. GetPlayer()->SetTSLevel(new_level);
  4302. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4303. GetPlayer()->SetCharSheetChanged(true);
  4304. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4305. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4306. PlayerSkillList* player_skills = player->GetSkills();
  4307. int16 specialize_skill_cap = new_level * 5;
  4308. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4309. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4310. int8 ts_class = player->GetTradeskillClass();
  4311. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4312. int32 skill_id_1, skill_id_2, skill_id_3;
  4313. switch (base_ts_class) {
  4314. case ARTISAN:
  4315. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4316. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4317. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4318. break;
  4319. case OUTFITTER:
  4320. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4321. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4322. skill_id_1 = SKILL_ID_TAILORING;
  4323. skill_id_2 = SKILL_ID_METALSHAPING;
  4324. skill_id_3 = SKILL_ID_METALWORKING;
  4325. if (ts_class == TAILOR) {
  4326. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4327. skill_id_1 = 0;
  4328. }
  4329. else if (ts_class == ARMORER) {
  4330. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4331. skill_id_2 = 0;
  4332. }
  4333. else if (ts_class == WEAPONSMITH) {
  4334. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4335. skill_id_3 = 0;
  4336. }
  4337. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4338. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4339. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4340. break;
  4341. case SCHOLAR:
  4342. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4343. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4344. skill_id_1 = SKILL_ID_SCRIBING;
  4345. skill_id_2 = SKILL_ID_CHEMISTRY;
  4346. skill_id_3 = SKILL_ID_ARTIFICING;
  4347. if (ts_class == SAGE) {
  4348. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4349. skill_id_1 = 0;
  4350. }
  4351. else if (ts_class == ALCHEMIST) {
  4352. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4353. skill_id_2 = 0;
  4354. }
  4355. else if (ts_class == JEWELER) {
  4356. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4357. skill_id_3 = 0;
  4358. }
  4359. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4360. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4361. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4362. break;
  4363. case CRAFTSMAN:
  4364. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4365. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4366. skill_id_1 = SKILL_ID_ARTISTRY;
  4367. skill_id_2 = SKILL_ID_FLETCHING;
  4368. skill_id_3 = SKILL_ID_SCULPTING;
  4369. if (ts_class == PROVISIONER) {
  4370. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4371. skill_id_1 = 0;
  4372. }
  4373. else if (ts_class == WOODWORKER) {
  4374. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4375. skill_id_2 = 0;
  4376. }
  4377. else if (ts_class == CARPENTER) {
  4378. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4379. skill_id_3 = 0;
  4380. }
  4381. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4382. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4383. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4384. break;
  4385. default:
  4386. break;
  4387. }
  4388. if (new_level > player->GetAdventureClass())
  4389. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4390. Guild* guild = GetPlayer()->GetGuild();
  4391. if (guild) {
  4392. int8 event_type = 0;
  4393. if (new_level < 10)
  4394. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4395. else if (new_level == 10)
  4396. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4397. else if (new_level >= 11 && new_level < 20)
  4398. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4399. else if (new_level == 20)
  4400. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4401. else if (new_level >= 21 && new_level < 30)
  4402. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4403. else if (new_level == 30)
  4404. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4405. else if (new_level >= 31 && new_level < 40)
  4406. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4407. else if (new_level == 40)
  4408. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4409. else if (new_level >= 41 && new_level < 50)
  4410. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4411. else if (new_level == 50)
  4412. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4413. else if (new_level >= 51 && new_level < 60)
  4414. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4415. else if (new_level == 60)
  4416. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4417. else if (new_level >= 61 && new_level < 70)
  4418. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4419. else if (new_level == 70)
  4420. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4421. else if (new_level >= 71 && new_level < 80)
  4422. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4423. else if (new_level == 80)
  4424. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4425. 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());
  4426. 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());
  4427. guild->UpdateGuildMemberInfo(GetPlayer());
  4428. guild->SendGuildMember(GetPlayer());
  4429. guild->SendGuildMemberList();
  4430. }
  4431. // Need to send the trait list every time the players level changes
  4432. // Also need to force the char sheet update or else there can be a large delay from when you level
  4433. // to when you are actually able to select traits.
  4434. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4435. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4436. }
  4437. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4438. if (entity)
  4439. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4440. }
  4441. void Client::CloseLoot(int32 spawn_id) {
  4442. if (GetVersion() > 546) {
  4443. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4444. if (packet) {
  4445. packet->setDataByName("window_id", 4);
  4446. EQ2Packet* outapp = packet->serialize();
  4447. if (outapp) {
  4448. //DumpPacket(outapp);
  4449. QueuePacket(outapp);
  4450. }
  4451. safe_delete(packet);
  4452. }
  4453. }
  4454. else if(spawn_id > 0){
  4455. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4456. if (packet) {
  4457. packet->setDataByName("spawn_id", spawn_id);
  4458. EQ2Packet* outapp = packet->serialize();
  4459. if (outapp)
  4460. QueuePacket(outapp);
  4461. safe_delete(packet);
  4462. }
  4463. }
  4464. }
  4465. string Client::GetCoinMessage(int32 total_coins) {
  4466. if (total_coins == 0) {
  4467. return " 0 Copper";
  4468. }
  4469. char tmp[64] = { 0 };
  4470. string message = "";
  4471. int32 val = 0;
  4472. if (total_coins >= 1000000) {
  4473. val = total_coins / 1000000;
  4474. total_coins -= 1000000 * val;
  4475. sprintf(tmp, " %u Platinum", val);
  4476. message.append(tmp);
  4477. memset(tmp, 0, 64);
  4478. }
  4479. if (total_coins >= 10000) {
  4480. val = total_coins / 10000;
  4481. total_coins -= 10000 * val;
  4482. sprintf(tmp, " %u Gold", val);
  4483. message.append(tmp);
  4484. memset(tmp, 0, 64);
  4485. }
  4486. if (total_coins >= 100) {
  4487. val = total_coins / 100;
  4488. total_coins -= 100 * val;
  4489. sprintf(tmp, " %u Silver", val);
  4490. message.append(tmp);
  4491. memset(tmp, 0, 64);
  4492. }
  4493. if (total_coins > 0) {
  4494. sprintf(tmp, " %u Copper", (int32)total_coins);
  4495. message.append(tmp);
  4496. }
  4497. return message;
  4498. }
  4499. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4500. if (!entity) {
  4501. CloseLoot(0);
  4502. return;
  4503. }
  4504. if (total_coins > 0) {
  4505. player->AddCoins(total_coins);
  4506. //PlaySound("coin_cha_ching");
  4507. string message = "";
  4508. if (entity->GetHP() == 0) {
  4509. message = "You loot ";
  4510. entity->SetLootCoins(0);
  4511. }
  4512. else
  4513. message = "You receive ";
  4514. message.append(GetCoinMessage(total_coins));
  4515. if (entity->GetHP() == 0)
  4516. message.append(" from the corpse of ").append(entity->GetName());
  4517. int8 type = CHANNEL_LOOT;
  4518. SimpleMessage(type, message.c_str());
  4519. }
  4520. if (!items || items->size() == 0)
  4521. CloseLoot(entity->GetID());
  4522. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4523. if (packet) {
  4524. vector<Item*>::iterator itr;
  4525. int32 packet_size = 0;
  4526. EQ2Packet* outapp = 0;
  4527. uchar* data = 0;
  4528. if (GetVersion() >= 284) {
  4529. if (GetVersion() > 546) {
  4530. if (items && items->size() > 0) {
  4531. packet->setDataByName("loot_count", items->size());
  4532. packet->setDataByName("display", 1);
  4533. }
  4534. packet->setDataByName("loot_type", 1);
  4535. if (version >= 1096)
  4536. packet->setDataByName("lotto_timeout", 0x78);
  4537. else
  4538. packet->setDataByName("lotto_timeout", 0x3C);
  4539. packet->setDataByName("loot_id", entity->GetID());
  4540. EQ2Packet* tmpPacket = packet->serialize();
  4541. packet_size += tmpPacket->size;
  4542. if (items && items->size() > 0) {
  4543. data = new uchar[items->size() * 1000 + packet_size];
  4544. memset(data, 0, items->size() * 1000 + packet_size);
  4545. }
  4546. else {
  4547. data = new uchar[packet_size];
  4548. memset(data, 0, packet_size);
  4549. }
  4550. uchar* ptr = data;
  4551. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4552. ptr += tmpPacket->size;
  4553. safe_delete(tmpPacket);
  4554. Item* item = 0;
  4555. if (items && items->size() > 0) {
  4556. for (itr = items->begin(); itr != items->end(); itr++) {
  4557. item = *itr;
  4558. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4559. ptr += sizeof(int32);
  4560. packet_size += sizeof(int32);
  4561. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4562. int8 offset = 0;
  4563. if (GetVersion() >= 1188) {
  4564. offset = 13;
  4565. }
  4566. else if (GetVersion() >= 860) {
  4567. offset = 11;
  4568. }
  4569. else if (GetVersion() <= 546) {
  4570. offset = 19;
  4571. }
  4572. else {
  4573. offset = 10;
  4574. }
  4575. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4576. ptr += tmpPacket->size - offset;
  4577. packet_size += tmpPacket->size - offset;
  4578. safe_delete(tmpPacket);
  4579. }
  4580. }
  4581. packet_size -= sizeof(int32);
  4582. memcpy(data, &packet_size, sizeof(int32));
  4583. packet_size += sizeof(int32);
  4584. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4585. }
  4586. else {
  4587. if (items && items->size() > 0) {
  4588. packet->setArrayLengthByName("loot_count", items->size());
  4589. Item* item = 0;
  4590. if (items && items->size() > 0) {
  4591. int i = 0;
  4592. for (itr = items->begin(); itr != items->end(); itr++) {
  4593. item = *itr;
  4594. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4595. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4596. i++;
  4597. }
  4598. }
  4599. packet->setDataByName("display", 1);
  4600. }
  4601. packet->setDataByName("loot_type", 1); // normal
  4602. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4603. packet->setDataByName("spawn_id", entity->GetID());
  4604. outapp = packet->serialize();
  4605. }
  4606. }
  4607. else {
  4608. if (items && items->size() > 0) {
  4609. packet->setArrayLengthByName("loot_count", items->size());
  4610. for (int i = 0; i < items->size(); i++) {
  4611. Item* item = (*items)[i];
  4612. packet->setArrayDataByName("name", item->name.c_str(), i);
  4613. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4614. packet->setArrayDataByName("count", item->details.count, i);
  4615. packet->setArrayDataByName("icon", item->details.icon, i);
  4616. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4617. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4618. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4619. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4620. else
  4621. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4622. }
  4623. }
  4624. packet->setDataByName("object_id", entity->GetID());
  4625. packet->setDataByName("unknown3", 1);
  4626. packet->setDataByName("unknown4", 1);
  4627. packet->setDataByName("unknown5", 60);
  4628. outapp = packet->serialize();
  4629. }
  4630. if (outapp) {
  4631. QueuePacket(outapp);
  4632. }
  4633. safe_delete_array(data);
  4634. safe_delete(packet);
  4635. }
  4636. }
  4637. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4638. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4639. int32 total_coins = entity->GetLootCoins();
  4640. entity->LockLoot();
  4641. Loot(total_coins, entity->GetLootItems(), entity);
  4642. entity->UnlockLoot();
  4643. OpenChest(entity, attemptDisarm);
  4644. }
  4645. else
  4646. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4647. }
  4648. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4649. {
  4650. if (!entity)
  4651. return;
  4652. int8 chest_difficulty = 0;
  4653. int32 state = 0;
  4654. // Check for the chest and set the action state
  4655. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4656. string modelName;
  4657. if (entity->GetModelType() == 4034) {
  4658. // small chest, open with copper coins
  4659. // does not include traps, however can be disarmed
  4660. chest_difficulty = 1;
  4661. state = 11899;
  4662. modelName.append("Small Chest");
  4663. }
  4664. else if (entity->GetModelType() == 5864) {
  4665. // treasure chest, open with silver coins
  4666. chest_difficulty = 2;
  4667. state = 11901;
  4668. modelName.append("Treasure Chest");
  4669. }
  4670. else if (entity->GetModelType() == 5865) {
  4671. // ornate chest, open with gold coins
  4672. chest_difficulty = 3;
  4673. state = 11900;
  4674. modelName.append("Ornate Chest");
  4675. }
  4676. else if (entity->GetModelType() == 4015) {
  4677. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4678. chest_difficulty = 5;
  4679. state = 11898;
  4680. modelName.append("Exquisite Chest");
  4681. }
  4682. bool firstChestOpen = false;
  4683. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4684. {
  4685. ChestTrap::ChestTrapInfo nextTrap;
  4686. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4687. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4688. firstChestOpen = true;
  4689. entity->SetTrapTriggered(true, state);
  4690. if (ret)
  4691. {
  4692. if (disarmSkill && attemptDisarm)
  4693. {
  4694. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4695. {
  4696. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4697. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4698. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4699. }
  4700. else
  4701. {
  4702. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4703. }
  4704. // despite fail/succeed we should always try to increase skill if disarm is available
  4705. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4706. }
  4707. else // no disarm skill, always fail
  4708. {
  4709. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4710. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4711. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4712. }
  4713. }
  4714. }
  4715. else if (!entity->HasTrapTriggered())
  4716. {
  4717. firstChestOpen = true;
  4718. entity->SetTrapTriggered(true, state);
  4719. }
  4720. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4721. // for those in range the SendStateCommand will cause it to animate open.
  4722. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4723. if (firstChestOpen)
  4724. GetCurrentZone()->SendStateCommand(entity, state);
  4725. }
  4726. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4727. {
  4728. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4729. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4730. if (source == NULL)
  4731. source = (Entity*)GetPlayer();
  4732. if (spell)
  4733. {
  4734. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4735. if (gmi && gmi->group_id)
  4736. {
  4737. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4738. if (group)
  4739. {
  4740. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4741. deque<GroupMemberInfo*>* members = group->GetMembers();
  4742. for (int8 i = 0; i < members->size(); i++) {
  4743. Entity* member = members->at(i)->member;
  4744. if(!member)
  4745. continue;
  4746. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4747. continue;
  4748. // if we have a radius provided then check if the group member is outside the radius or not
  4749. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4750. continue;
  4751. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4752. }
  4753. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4754. }
  4755. }
  4756. else
  4757. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4758. }
  4759. }
  4760. Spawn* Client::GetBanker() {
  4761. return banker;
  4762. }
  4763. void Client::SetBanker(Spawn* in_banker) {
  4764. banker = in_banker;
  4765. }
  4766. void Client::Bank(Spawn* banker, bool cancel) {
  4767. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4768. if (!cancel)
  4769. SetBanker(banker);
  4770. else
  4771. SetBanker(0);
  4772. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4773. if (packet) {
  4774. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4775. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4776. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4777. int32 coins1, coins2;
  4778. coins1 = ((int32*)&coins)[0];
  4779. coins2 = ((int32*)&coins)[1];
  4780. packet->setDataByName("bank_coins", coins1);
  4781. packet->setDataByName("bank_coins2", coins2);
  4782. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4783. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4784. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4785. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4786. if (!cancel)
  4787. packet->setDataByName("display", 1);
  4788. QueuePacket(packet->serialize());
  4789. safe_delete(packet);
  4790. }
  4791. }
  4792. }
  4793. void Client::BankWithdrawal(int64 amount) {
  4794. bool cheater = false;
  4795. if (GetBanker() && amount > 0) {
  4796. string withdrawal = "";
  4797. char withdrawal_data[512] = { 0 };
  4798. int32 tmp = 0;
  4799. if (amount >= 1000000) {
  4800. tmp = amount / 1000000;
  4801. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4802. if (tmp > bank_coins_plat)
  4803. cheater = true;
  4804. else {
  4805. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4806. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4807. amount -= (int64)tmp * 1000000;
  4808. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4809. withdrawal.append(withdrawal_data);
  4810. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4811. }
  4812. }
  4813. if (!cheater && amount >= 10000) {
  4814. tmp = amount / 10000;
  4815. if (tmp > GetPlayer()->GetBankCoinsGold())
  4816. cheater = true;
  4817. else {
  4818. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4819. bank_coins_gold -= tmp;
  4820. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4821. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4822. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4823. }
  4824. else
  4825. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4826. amount -= tmp * 10000;
  4827. sprintf(withdrawal_data, "%u Gold ", tmp);
  4828. withdrawal.append(withdrawal_data);
  4829. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4830. }
  4831. }
  4832. if (!cheater && amount >= 100) {
  4833. tmp = amount / 100;
  4834. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4835. if (tmp > bank_coins_silver)
  4836. cheater = true;
  4837. else {
  4838. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4839. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4840. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4841. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4842. }
  4843. else
  4844. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4845. amount -= tmp * 100;
  4846. sprintf(withdrawal_data, "%u Silver ", tmp);
  4847. withdrawal.append(withdrawal_data);
  4848. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4849. }
  4850. }
  4851. if (!cheater) {
  4852. if (amount > 0) {
  4853. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4854. withdrawal.append(withdrawal_data);
  4855. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4856. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4857. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4858. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4859. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4860. }
  4861. else
  4862. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4863. }
  4864. if (withdrawal.length() > 0) {
  4865. withdrawal.append("withdrawn ");
  4866. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4867. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4868. withdrawal.append(withdrawal_data);
  4869. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4870. }
  4871. }
  4872. else
  4873. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4874. player->SetCharSheetChanged(true);
  4875. Bank(banker);
  4876. }
  4877. }
  4878. void Client::BankDeposit(int64 amount) {
  4879. bool cheater = false;
  4880. if (GetBanker() && amount > 0) {
  4881. int32 tmp = 0;
  4882. char deposit_data[512] = { 0 };
  4883. string deposit = "";
  4884. if (amount >= 1000000) {
  4885. tmp = amount / 1000000;
  4886. if (tmp > GetPlayer()->GetCoinsPlat())
  4887. cheater = true;
  4888. else {
  4889. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4890. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4891. amount -= (int64)tmp * 1000000;
  4892. sprintf(deposit_data, "%u Platinum ", tmp);
  4893. deposit.append(deposit_data);
  4894. memset(deposit_data, 0, sizeof(deposit_data));
  4895. }
  4896. }
  4897. if (!cheater && amount >= 10000) {
  4898. tmp = amount / 10000;
  4899. if (tmp > GetPlayer()->GetCoinsGold())
  4900. cheater = true;
  4901. else {
  4902. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4903. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4904. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4905. }
  4906. else
  4907. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4908. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4909. amount -= tmp * 10000;
  4910. sprintf(deposit_data, "%u Gold ", tmp);
  4911. deposit.append(deposit_data);
  4912. memset(deposit_data, 0, sizeof(deposit_data));
  4913. }
  4914. }
  4915. if (!cheater && amount >= 100) {
  4916. tmp = amount / 100;
  4917. if (tmp > GetPlayer()->GetCoinsSilver())
  4918. cheater = true;
  4919. else {
  4920. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4921. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4922. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4923. }
  4924. else
  4925. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4926. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4927. amount -= tmp * 100;
  4928. sprintf(deposit_data, "%u Silver ", tmp);
  4929. deposit.append(deposit_data);
  4930. memset(deposit_data, 0, sizeof(deposit_data));
  4931. }
  4932. }
  4933. if (!cheater) {
  4934. if (amount > 0) {
  4935. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4936. deposit.append(deposit_data);
  4937. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4938. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4939. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4940. }
  4941. else
  4942. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4943. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4944. }
  4945. if (deposit.length() > 0) {
  4946. deposit.append("deposited ");
  4947. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4948. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4949. deposit.append(deposit_data);
  4950. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4951. }
  4952. }
  4953. else
  4954. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4955. player->SetCharSheetChanged(true);
  4956. Bank(banker);
  4957. }
  4958. }
  4959. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4960. {
  4961. MPendingQuestAccept.lock();
  4962. pending_quest_accept.push_back(quest->GetQuestID());
  4963. MPendingQuestAccept.unlock();
  4964. }
  4965. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  4966. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  4967. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  4968. quest_updates = update;
  4969. if(quest_updates) {
  4970. SaveQuestRewardData(true);
  4971. }
  4972. }
  4973. void Client::QueueQuestReward(int32 quest_id, bool is_temporary, bool is_collection, bool has_displayed, int64 tmp_coin, int32 tmp_status, std::string description, bool db_saved, int32 index) {
  4974. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  4975. return;
  4976. QuestRewardData* data = new QuestRewardData;
  4977. data->quest_id = quest_id;
  4978. data->is_temporary = is_temporary;
  4979. data->is_collection = is_collection;
  4980. data->has_displayed = has_displayed;
  4981. data->tmp_coin = tmp_coin;
  4982. data->tmp_status = tmp_status;
  4983. data->description = std::string(description);
  4984. data->db_saved = db_saved;
  4985. data->db_index = index;
  4986. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4987. quest_pending_reward.push_back(data);
  4988. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4989. }
  4990. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  4991. bool success = false;
  4992. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  4993. if (quest_pending_reward.size() > 0) {
  4994. vector<QuestRewardData*>::iterator itr;
  4995. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  4996. int32 questID = (*itr)->quest_id;
  4997. bool temporary = (*itr)->is_temporary;
  4998. bool collection = (*itr)->is_collection;
  4999. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5000. success = true;
  5001. break;
  5002. }
  5003. }
  5004. }
  5005. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5006. return success;
  5007. }
  5008. void Client::RemoveQueuedQuestReward() {
  5009. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5010. if(quest_pending_reward.size() > 0) {
  5011. QuestRewardData* data = quest_pending_reward.at(0);
  5012. if(data->db_saved) {
  5013. Query query;
  5014. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5015. if(data->is_temporary && data->quest_id) {
  5016. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5017. }
  5018. }
  5019. quest_pending_reward.erase(quest_pending_reward.begin());
  5020. }
  5021. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5022. SaveQuestRewardData(true);
  5023. }
  5024. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5025. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5026. quest_pending_updates[quest_id][step_id] = progress;
  5027. quest_updates = true;
  5028. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5029. }
  5030. void Client::ProcessQuestUpdates() {
  5031. if(!GetPlayer()->IsFullyLoggedIn())
  5032. return;
  5033. if (quest_pending_updates.size() > 0) {
  5034. map<int32, map<int32, int32> > tmp_quest_updates;
  5035. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5036. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5037. quest_pending_updates.clear();
  5038. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5039. map<int32, map<int32, int32> >::iterator quest_itr;
  5040. map<int32, int32>::iterator step_itr;
  5041. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5042. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5043. if (step_itr->second == 0xFFFFFFFF) {
  5044. SetStepComplete(quest_itr->first, step_itr->first);
  5045. player->SendQuestRequiredSpawns(quest_itr->first);
  5046. }
  5047. else
  5048. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5049. }
  5050. }
  5051. }
  5052. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5053. if (quest_pending_reward.size() > 0) {
  5054. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5055. // only able to display one reward at a time
  5056. if(GetPlayer()->IsActiveReward())
  5057. return;
  5058. Query query;
  5059. vector<QuestRewardData*>::iterator itr;
  5060. vector<QuestRewardData*> tmp_quest_rewards;
  5061. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5062. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5063. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5064. bool delete_first = false;
  5065. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5066. int32 questID = (*itr)->quest_id;
  5067. Quest* quest = 0;
  5068. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5069. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5070. GetPlayer()->SetActiveReward(true);
  5071. (*itr)->has_displayed = true;
  5072. UpdateCharacterRewardData((*itr));
  5073. break;
  5074. }
  5075. else if(questID > 0 && (quest = GetPlayer()->GetAnyQuest(questID))) {
  5076. quest->SetQuestTemporaryState((*itr)->is_temporary, (*itr)->description);
  5077. if((*itr)->is_temporary) {
  5078. quest->SetStatusTmpReward((*itr)->tmp_status);
  5079. quest->SetCoinTmpReward((*itr)->tmp_coin);
  5080. }
  5081. GiveQuestReward(quest, (*itr)->has_displayed);
  5082. GetPlayer()->SetActiveReward(true);
  5083. (*itr)->has_displayed = true;
  5084. UpdateCharacterRewardData((*itr));
  5085. // only able to display one reward at a time
  5086. break;
  5087. } else {
  5088. delete_first = true;
  5089. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5090. break;
  5091. }
  5092. }
  5093. if(delete_first) {
  5094. RemoveQueuedQuestReward();
  5095. }
  5096. } else {
  5097. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5098. }
  5099. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5100. if (quest_pending_reward.size() > 0) {
  5101. quest_updates = true;
  5102. }
  5103. else {
  5104. quest_updates = false;
  5105. }
  5106. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5107. }
  5108. void Client::CheckQuestQueue() {
  5109. MQuestQueue.writelock();
  5110. last_update_time = 0;
  5111. vector<QueuedQuest*>::iterator itr;
  5112. QueuedQuest* queued_quest = 0;
  5113. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5114. queued_quest = *itr;
  5115. Quest* quest = GetPlayer()->GetAnyQuest(queued_quest->quest_id);
  5116. if(quest) {
  5117. SendQuestUpdateStepImmediately(quest, queued_quest->step, queued_quest->display_quest_helper);
  5118. if(quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  5119. SendQuestJournal();
  5120. }
  5121. else {
  5122. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", queued_quest->quest_id, GetPlayer()->GetName());
  5123. }
  5124. safe_delete(queued_quest);
  5125. }
  5126. quest_queue.clear();
  5127. MQuestQueue.releasewritelock();
  5128. }
  5129. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5130. Quest* quest = player->SetStepComplete(quest_id, step);
  5131. if (quest) {
  5132. SendQuestUpdate(quest);
  5133. GetCurrentZone()->SendQuestUpdates(this);
  5134. }
  5135. }
  5136. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5137. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5138. if (quest) {
  5139. SendQuestUpdate(quest);
  5140. GetCurrentZone()->SendQuestUpdates(this);
  5141. }
  5142. }
  5143. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5144. bool hadUpdates = false;
  5145. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5146. if (quest_updates) {
  5147. for (int32 i = 0; i < quest_updates->size(); i++)
  5148. {
  5149. SendQuestUpdate(quest_updates->at(i));
  5150. hadUpdates = true;
  5151. }
  5152. }
  5153. safe_delete(quest_updates);
  5154. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5155. if (quest_failures) {
  5156. for (int32 i = 0; i < quest_failures->size(); i++)
  5157. {
  5158. SendQuestFailure(quest_failures->at(i));
  5159. hadUpdates = true;
  5160. }
  5161. }
  5162. safe_delete(quest_failures);
  5163. if (hadUpdates)
  5164. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5165. }
  5166. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5167. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5168. if (quest_updates) {
  5169. for (int32 i = 0; i < quest_updates->size(); i++)
  5170. SendQuestUpdate(quest_updates->at(i));
  5171. GetCurrentZone()->SendQuestUpdates(this);
  5172. }
  5173. safe_delete(quest_updates);
  5174. }
  5175. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5176. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5177. if (quest_updates) {
  5178. for (int32 i = 0; i < quest_updates->size(); i++)
  5179. SendQuestUpdate(quest_updates->at(i));
  5180. }
  5181. safe_delete(quest_updates);
  5182. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5183. if (quest_failures) {
  5184. for (int32 i = 0; i < quest_failures->size(); i++)
  5185. SendQuestFailure(quest_failures->at(i));
  5186. }
  5187. safe_delete(quest_failures);
  5188. }
  5189. void Client::CheckPlayerQuestsLocationUpdate() {
  5190. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5191. if (quest_updates) {
  5192. for (int32 i = 0; i < quest_updates->size(); i++)
  5193. SendQuestUpdate(quest_updates->at(i));
  5194. }
  5195. safe_delete(quest_updates);
  5196. }
  5197. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5198. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5199. if (quest_updates) {
  5200. for (int32 i = 0; i < quest_updates->size(); i++)
  5201. SendQuestUpdate(quest_updates->at(i));
  5202. }
  5203. safe_delete(quest_updates);
  5204. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5205. if (quest_failures) {
  5206. for (int32 i = 0; i < quest_failures->size(); i++)
  5207. SendQuestFailure(quest_failures->at(i));
  5208. }
  5209. safe_delete(quest_failures);
  5210. }
  5211. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5212. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5213. player->pending_quests[quest->GetQuestID()] = quest;
  5214. AcceptQuest(quest->GetQuestID());
  5215. }
  5216. else {
  5217. player->pending_quests[quest->GetQuestID()] = quest;
  5218. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5219. //DumpPacket(outapp);
  5220. QueuePacket(outapp);
  5221. }
  5222. }
  5223. Quest* Client::GetActiveQuest(int32 quest_id) {
  5224. Quest* quest = 0;
  5225. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  5226. if (player->player_quests.count(quest_id) > 0) {
  5227. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  5228. quest = player->player_quests[quest_id];
  5229. }
  5230. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  5231. return quest;
  5232. }
  5233. void Client::AcceptQuest(int32 id) {
  5234. Quest* quest = GetPendingQuest(id);
  5235. if (quest) {
  5236. RemovePendingQuest(quest);
  5237. AddPlayerQuest(quest);
  5238. GetCurrentZone()->SendQuestUpdates(this);
  5239. // If character has already completed this quest once update the given date in the database
  5240. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  5241. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  5242. if (quest2)
  5243. quest->SetCompleteCount(quest2->GetCompleteCount());
  5244. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  5245. }
  5246. }
  5247. }
  5248. Quest* Client::GetPendingQuest(int32 id) {
  5249. if (player->pending_quests.count(id) > 0) {
  5250. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  5251. return player->pending_quests[id];
  5252. }
  5253. return 0;
  5254. }
  5255. void Client::RemovePendingQuest(Quest* quest) {
  5256. player->pending_quests.erase(quest->GetQuestID());
  5257. }
  5258. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5259. if (!quest || !progress) {
  5260. return;
  5261. }
  5262. map<int32, int32>::iterator itr;
  5263. QuestStep* step = 0;
  5264. player->SetZone(GetCurrentZone(), GetVersion());
  5265. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5266. step = quest->GetQuestStep(itr->first);
  5267. if (step && itr->second > 0) {
  5268. step->SetStepProgress(itr->second);
  5269. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5270. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5271. }
  5272. }
  5273. if (lua_interface && step)
  5274. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5275. else if(!step) {
  5276. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5277. }
  5278. }
  5279. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5280. bool lockCleared = false;
  5281. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5282. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5283. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5284. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5285. int32 questID = quest->GetQuestID();
  5286. lockCleared = true;
  5287. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5288. RemovePlayerQuest(questID, false, false);
  5289. }
  5290. player->player_quests[quest->GetQuestID()] = quest;
  5291. if(!lockCleared)
  5292. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5293. quest->SetPlayer(player);
  5294. current_quest_id = quest->GetQuestID();
  5295. if (send_packets && quest->GetQuestGiver() > 0)
  5296. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5297. if (lua_interface && call_accepted)
  5298. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5299. if (send_packets) {
  5300. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5301. //SendQuestJournal();
  5302. SendQuestJournalUpdate(quest);
  5303. // sent twice to match live
  5304. quest->SetTracked(false);
  5305. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5306. quest->SetTracked(true);
  5307. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5308. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5309. }
  5310. //This isn't during a load screen, so update spawns with required quests
  5311. if (call_accepted)
  5312. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5313. }
  5314. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5315. if (current_quest_id == id)
  5316. current_quest_id = 0;
  5317. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5318. if (player->player_quests.count(id) > 0) {
  5319. if (delete_quest) {
  5320. player->player_quests[id]->SetDeleted(true);
  5321. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5322. }
  5323. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5324. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5325. if (send_update && quest_giver > 0)
  5326. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5327. if (send_update) {
  5328. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5329. SendQuestJournal(false, 0, true);
  5330. }
  5331. player->RemoveQuest(id, delete_quest);
  5332. if (send_update) {
  5333. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5334. SendQuestJournal(false, 0, true);
  5335. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5336. }
  5337. }
  5338. else {
  5339. // if we don't have any quests to count then release the write lock
  5340. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5341. }
  5342. }
  5343. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5344. if (quest) {
  5345. QuestStep* quest_step = quest->GetQuestStep(step);
  5346. if (quest_step) {
  5347. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5348. quest_step->WasUpdated(false);
  5349. }
  5350. }
  5351. }
  5352. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5353. QueuedQuest* item = new QueuedQuest;
  5354. item->quest_id = quest->GetQuestID();
  5355. item->step = step;
  5356. item->display_quest_helper = display_quest_helper;
  5357. MQuestQueue.writelock();
  5358. quest_queue.push_back(item);
  5359. last_update_time = Timer::GetCurrentTime2();
  5360. MQuestQueue.releasewritelock();
  5361. }
  5362. void Client::SendQuestFailure(Quest* quest) {
  5363. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5364. if (failures) {
  5365. QuestStep* step = 0;
  5366. for (int32 i = 0; i < failures->size(); i++) {
  5367. step = failures->at(i);
  5368. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5369. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5370. SendQuestJournal(false, 0, true);
  5371. }
  5372. failures->clear();
  5373. }
  5374. }
  5375. void Client::SendQuestUpdate(Quest* quest) {
  5376. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5377. if (updates) {
  5378. QuestStep* step = 0;
  5379. bool updated = false;
  5380. for (int32 i = 0; i < updates->size(); i++) {
  5381. step = updates->at(i);
  5382. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5383. {
  5384. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5385. SendQuestUpdateStep(quest, step->GetStepID());
  5386. updated = true;
  5387. }
  5388. if (step->WasUpdated()) {
  5389. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5390. SendQuestJournal(false, 0, true);
  5391. if(!updated)
  5392. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5393. updated = true;
  5394. }
  5395. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5396. }
  5397. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5398. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5399. SendQuestJournalUpdate(quest, true);
  5400. }
  5401. if (quest->GetCompleted()) {
  5402. if (quest->GetQuestReturnNPC() > 0)
  5403. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5404. if (quest->GetCompletedFlag())
  5405. quest->SetCompletedFlag(false);
  5406. }
  5407. updates->clear();
  5408. }
  5409. }
  5410. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5411. if (!client)
  5412. client = this;
  5413. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5414. if (packet) {
  5415. EQ2Packet* outapp = packet->serialize();
  5416. //DumpPacket(outapp);
  5417. client->QueuePacket(outapp);
  5418. safe_delete(packet);
  5419. }
  5420. }
  5421. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5422. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5423. if (packet) {
  5424. QueuePacket(packet->serialize());
  5425. safe_delete(packet);
  5426. }
  5427. }
  5428. void Client::ReloadQuests() {
  5429. vector<int32> ids = player->GetQuestIDs();
  5430. Quest* quest = 0;
  5431. for (int32 i = 0; i < ids.size(); i++) {
  5432. quest = master_quest_list.GetQuest(ids[i]);
  5433. if (quest)
  5434. AddPlayerQuest(quest, false);
  5435. else
  5436. RemovePlayerQuest(ids[i]);
  5437. }
  5438. }
  5439. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5440. bool found_quest = false;
  5441. vector<int32>::iterator itr;
  5442. vector<Item*>* items = 0;
  5443. int32 questID = 0;
  5444. Quest* quest = 0;
  5445. MPendingQuestAccept.lock();
  5446. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  5447. questID = *itr;
  5448. quest = GetPlayer()->GetAnyQuest(questID);
  5449. if(!quest) {
  5450. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  5451. itr = pending_quest_accept.erase(itr);
  5452. continue;
  5453. }
  5454. if(quest->GetQuestTemporaryState())
  5455. items = quest->GetTmpRewardItems();
  5456. else
  5457. items = quest->GetRewardItems();
  5458. if (item_id == 0) {
  5459. found_quest = true;
  5460. }
  5461. else {
  5462. items = quest->GetSelectableRewardItems();
  5463. if (items && items->size() > 0) {
  5464. for (int32 i = 0; i < items->size(); i++) {
  5465. if (items->at(i)->details.item_id == item_id) {
  5466. found_quest = true;
  5467. break;
  5468. }
  5469. }
  5470. }
  5471. }
  5472. if (found_quest) {
  5473. pending_quest_accept.erase(itr);
  5474. break;
  5475. }
  5476. itr++;
  5477. }
  5478. MPendingQuestAccept.unlock();
  5479. if (found_quest)
  5480. return quest;
  5481. return 0;
  5482. }
  5483. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5484. int8 num_slots_needed = 0;
  5485. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5486. Item* master_item = 0;
  5487. if (item_id > 0) {
  5488. num_slots_needed++;
  5489. master_item = master_item_list.GetItem(item_id);
  5490. }
  5491. int32 totalItems = 0;
  5492. vector<Item*>* items = 0;
  5493. vector<Item*>* tmpItems = 0;
  5494. bool isTempState = quest->GetQuestTemporaryState();
  5495. if(isTempState)
  5496. {
  5497. tmpItems = quest->GetTmpRewardItems();
  5498. if (tmpItems && tmpItems->size() > 0)
  5499. {
  5500. num_slots_needed += tmpItems->size();
  5501. totalItems += tmpItems->size();
  5502. }
  5503. }
  5504. else
  5505. {
  5506. items = quest->GetRewardItems();
  5507. if (items && items->size() > 0)
  5508. {
  5509. num_slots_needed += items->size();
  5510. totalItems += items->size();
  5511. }
  5512. }
  5513. RemoveQueuedQuestReward();
  5514. GetPlayer()->SetActiveReward(false);
  5515. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5516. if (master_item)
  5517. AddItem(item_id);
  5518. if (tmpItems && tmpItems->size() > 0) {
  5519. for (int32 i = 0; i < tmpItems->size(); i++)
  5520. AddItem(new Item(tmpItems->at(i)));
  5521. }
  5522. if (items && items->size() > 0) {
  5523. for (int32 i = 0; i < items->size(); i++)
  5524. AddItem(new Item(items->at(i)));
  5525. }
  5526. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5527. if (outapp)
  5528. QueuePacket(outapp);
  5529. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5530. map<int32, sint32>::iterator itr;
  5531. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5532. int32 faction_id = itr->first;
  5533. sint32 amount = itr->second;
  5534. if (amount > 0)
  5535. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5536. else
  5537. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5538. }
  5539. if(quest->GetQuestTemporaryState())
  5540. {
  5541. int64 total_coins = quest->GetCoinTmpReward();
  5542. if (total_coins > 0)
  5543. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5544. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5545. }
  5546. else {
  5547. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5548. }
  5549. quest->SetQuestTemporaryState(false);
  5550. player->SetCharSheetChanged(true);
  5551. }
  5552. else {
  5553. GetPlayer()->SetActiveReward(true);
  5554. AddPendingQuestAcceptReward(quest);
  5555. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5556. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5557. }
  5558. }
  5559. 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, bool was_displayed) {
  5560. 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))) {
  5561. /*if (quest)
  5562. text = quest->GetName();
  5563. else*/
  5564. return;//nothing to give
  5565. }
  5566. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  5567. GetPlayer()->ClearPendingItemRewards();
  5568. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5569. if (packet2) {
  5570. int32 source_id = 0;
  5571. if (quest)
  5572. source_id = quest->GetQuestID();
  5573. int64 rewarded_coin = 0;
  5574. if (quest) {
  5575. if (quest->GetCoinsReward() > 0) {
  5576. if (quest->GetCoinsRewardMax() > 0)
  5577. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5578. else
  5579. rewarded_coin = quest->GetCoinsReward();
  5580. }
  5581. quest->SetGeneratedCoin(rewarded_coin);
  5582. }
  5583. if (rewarded_coin > coin)
  5584. coin = rewarded_coin;
  5585. if (!quest && !was_displayed) { //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
  5586. if (coin > 0) {
  5587. player->AddCoins(coin);
  5588. PlaySound("coin_cha_ching");
  5589. }
  5590. }
  5591. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5592. packet2->setSubstructDataByName("reward_data", "reward", header);
  5593. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5594. if (player->GetGuild() && !was_displayed) {
  5595. 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
  5596. player->GetInfoStruct()->add_status_points(status_points);
  5597. player->SetCharSheetChanged(true);
  5598. }
  5599. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5600. }
  5601. if(text)
  5602. packet2->setSubstructDataByName("reward_data", "text", text);
  5603. if(rewards){
  5604. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5605. for (int i = 0; i < rewards->size(); i++) {
  5606. Item* item = rewards->at(i);
  5607. if (item) {
  5608. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5609. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5610. }
  5611. 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
  5612. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5613. }
  5614. }
  5615. if (selectable_rewards) {
  5616. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5617. for (int i = 0; i < selectable_rewards->size(); i++) {
  5618. Item* item = selectable_rewards->at(i);
  5619. if (item) {
  5620. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5621. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5622. 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
  5623. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5624. }
  5625. }
  5626. }
  5627. if (factions) {
  5628. map<int32, sint32>::iterator itr;
  5629. map<Faction*, signed int> factions_map;
  5630. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5631. Faction* faction = master_faction_list.GetFaction(itr->first);
  5632. if (faction)
  5633. factions_map[faction] = itr->second;
  5634. }
  5635. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5636. map<Faction*, signed int>::iterator faction_itr;
  5637. int8 i = 0;
  5638. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5639. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5640. sint32 amount = faction_itr->second;
  5641. packet2->setArrayDataByName("amount", amount, i);
  5642. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5643. if (amount > 0)
  5644. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5645. else
  5646. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5647. }
  5648. i++;
  5649. }
  5650. }
  5651. QueuePacket(packet2->serialize());
  5652. safe_delete(packet2);
  5653. }
  5654. }
  5655. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  5656. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  5657. if(!items || !packet)
  5658. return;
  5659. if (items) {
  5660. int32 total_item_count = 0;
  5661. for(int s=0;s<items->size();s++) {
  5662. Item* tmpItem = items->at(s);
  5663. if(tmpItem) {
  5664. if(tmpItem->details.count > 1) {
  5665. total_item_count += tmpItem->details.count;
  5666. }
  5667. else {
  5668. total_item_count += 1;
  5669. }
  5670. }
  5671. }
  5672. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  5673. int16 count = 0;
  5674. int16 pos = 0;
  5675. for (int32 i = 0; i < items->size();) {
  5676. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  5677. if (version < 860)
  5678. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, -1);
  5679. else if (version < 1193)
  5680. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  5681. else
  5682. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  5683. pos++;
  5684. if(count >= items->at(i)->details.count-1) {
  5685. count = 0;
  5686. }
  5687. else if(items->at(i)->details.count > 1) {
  5688. count++;
  5689. continue;
  5690. }
  5691. i++;
  5692. }
  5693. }
  5694. }
  5695. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  5696. if (!quest)
  5697. return;
  5698. if (GetVersion() <= 546) {
  5699. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), customDescription.c_str(), was_displayed);
  5700. return;
  5701. }
  5702. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5703. if (packet) {
  5704. packet->setDataByName("title", "Quest Reward!");
  5705. packet->setDataByName("name", quest->GetName());
  5706. if(tempReward)
  5707. {
  5708. packet->setDataByName("description", customDescription.c_str());
  5709. }
  5710. else
  5711. packet->setDataByName("description", quest->GetCompletedDescription());
  5712. packet->setDataByName("level", quest->GetLevel());
  5713. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5714. int8 difficulty = 0;
  5715. if ((string)quest->GetType() == "Tradeskill")
  5716. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5717. else
  5718. difficulty = player->GetArrowColor(quest->GetLevel());
  5719. packet->setDataByName("difficulty", difficulty);
  5720. if(tempReward)
  5721. {
  5722. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5723. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5724. packet->setDataByName("status_points", quest->GetStatusPoints());
  5725. }
  5726. else
  5727. {
  5728. int64 rewarded_coin = 0;
  5729. if (quest->GetCoinsReward() > 0) {
  5730. if (quest->GetCoinsRewardMax() > 0)
  5731. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5732. else
  5733. rewarded_coin = quest->GetCoinsReward();
  5734. }
  5735. quest->SetGeneratedCoin(rewarded_coin);
  5736. packet->setDataByName("max_coin", rewarded_coin);
  5737. packet->setDataByName("min_coin", rewarded_coin);
  5738. packet->setDataByName("status_points", quest->GetStatusPoints());
  5739. }
  5740. if(tempReward) {
  5741. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  5742. }
  5743. else
  5744. {
  5745. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5746. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  5747. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  5748. std::string("select_reward_id"), std::string("select_item"));
  5749. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5750. if (reward_factions && reward_factions->size() > 0) {
  5751. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5752. map<int32, sint32>::iterator itr;
  5753. int16 index = 0;
  5754. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5755. int32 faction_id = itr->first;
  5756. sint32 amount = itr->second;
  5757. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5758. if (faction_name) {
  5759. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5760. packet->setArrayDataByName("amount", amount, index);
  5761. }
  5762. index++;
  5763. }
  5764. }
  5765. }
  5766. EQ2Packet* outapp = packet->serialize();
  5767. // DumpPacket(outapp);
  5768. QueuePacket(outapp);
  5769. safe_delete(packet);
  5770. }
  5771. }
  5772. void Client::DisplayRandomizeFeatures(int32 flags) {
  5773. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5774. if (flags > 0) {
  5775. if (flags & RANDOMIZE_GENDER)
  5776. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5777. if (flags & RANDOMIZE_RACE)
  5778. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5779. if (flags & RANDOMIZE_MODEL_TYPE)
  5780. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5781. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5782. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5783. if (flags & RANDOMIZE_HAIR_TYPE)
  5784. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5785. if (flags & RANDOMIZE_WING_TYPE)
  5786. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5787. if (flags & RANDOMIZE_CHEEK_TYPE)
  5788. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5789. if (flags & RANDOMIZE_CHIN_TYPE)
  5790. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5791. if (flags & RANDOMIZE_EAR_TYPE)
  5792. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5793. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5794. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5795. if (flags & RANDOMIZE_EYE_TYPE)
  5796. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5797. if (flags & RANDOMIZE_LIP_TYPE)
  5798. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5799. if (flags & RANDOMIZE_NOSE_TYPE)
  5800. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5801. if (flags & RANDOMIZE_EYE_COLOR)
  5802. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5803. if (flags & RANDOMIZE_HAIR_COLOR1)
  5804. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5805. if (flags & RANDOMIZE_HAIR_COLOR2)
  5806. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5807. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5808. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5809. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5810. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5811. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5812. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5813. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5814. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5815. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5816. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5817. if (flags & RANDOMIZE_SKIN_COLOR)
  5818. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5819. if (flags & RANDOMIZE_WING_COLOR1)
  5820. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5821. if (flags & RANDOMIZE_WING_COLOR2)
  5822. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5823. }
  5824. else
  5825. {
  5826. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5827. }
  5828. }
  5829. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  5830. current_quest_id = 0;
  5831. if(!quest->GetQuestTemporaryState() && !has_displayed)
  5832. {
  5833. quest->IncrementCompleteCount();
  5834. player->AddCompletedQuest(quest);
  5835. }
  5836. AddPendingQuestAcceptReward(quest);
  5837. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5838. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5839. SendQuestJournal();
  5840. if(quest->GetQuestTemporaryState()) {
  5841. return;
  5842. }
  5843. if(!has_displayed) {
  5844. if (quest->GetExpReward() > 0) {
  5845. int32 xp = quest->GetExpReward();
  5846. player->AddXP(xp);
  5847. }
  5848. if (quest->GetTSExpReward() > 0) {
  5849. int8 ts_level = player->GetTSLevel();
  5850. int32 xp = quest->GetTSExpReward();
  5851. if (player->AddTSXP(xp)) {
  5852. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5853. if (player->GetTSLevel() != ts_level)
  5854. ChangeTSLevel(ts_level, player->GetTSLevel());
  5855. player->SetCharSheetChanged(true);
  5856. }
  5857. }
  5858. int64 total_coins = quest->GetGeneratedCoin();
  5859. if (total_coins > 0)
  5860. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5861. player->RemoveQuest(quest->GetQuestID(), false);
  5862. }
  5863. if (quest->GetQuestGiver() > 0)
  5864. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5865. if(!has_displayed) {
  5866. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5867. }
  5868. }
  5869. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  5870. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5871. if (packet) {
  5872. packet->setDataByName("conversation_id", conversation_id);
  5873. packet->setDataByName("text", text);
  5874. packet->setDataByName("language", language); // default 0
  5875. packet->setDataByName("can_close", can_close); // default 1
  5876. conversation_map[conversation_id].clear();
  5877. if (conversations) {
  5878. packet->setArrayLengthByName("num_responses", conversations->size());
  5879. for (int32 i = 0; i < conversations->size(); i++) {
  5880. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5881. if (conversations->at(i).function.length() > 0)
  5882. conversation_map[conversation_id][i] = conversations->at(i).function;
  5883. }
  5884. }
  5885. packet->setDataByName("spawn_id", spawn_id);
  5886. if (mp3) {
  5887. packet->setDataByName("voice", mp3);
  5888. packet->setDataByName("key1", key1);
  5889. packet->setDataByName("key2", key2);
  5890. }
  5891. QueuePacket(packet->serialize());
  5892. safe_delete(packet);
  5893. }
  5894. }
  5895. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  5896. if (!item || !text || !conversations || conversations->size() == 0) {
  5897. return;
  5898. }
  5899. int32 conversation_id = GetConversationID(0, item);
  5900. if (conversation_id == 0) {
  5901. next_conversation_id++;
  5902. conversation_id = next_conversation_id;
  5903. }
  5904. MConversation.writelock();
  5905. conversation_items[conversation_id] = item;
  5906. MConversation.releasewritelock();
  5907. if (type == 4)
  5908. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5909. else
  5910. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5911. }
  5912. void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  5913. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5914. return;
  5915. }
  5916. int32 conversation_id = GetConversationID(src, 0);
  5917. if (conversation_id == 0) {
  5918. next_conversation_id++;
  5919. conversation_id = next_conversation_id;
  5920. }
  5921. MConversation.writelock();
  5922. conversation_spawns[conversation_id] = src->GetID();
  5923. MConversation.releasewritelock();
  5924. /* Spawns can start two different types of conversations.
  5925. * Type 1: The chat type with bubbles.
  5926. * Type 2: The dialog type with the blue box. */
  5927. if (type == 1)
  5928. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  5929. else if (type == 2)
  5930. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5931. else //if (type == 3)
  5932. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5933. }
  5934. void Client::CloseDialog(int32 conversation_id) {
  5935. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5936. if (packet) {
  5937. packet->setDataByName("conversation_id", conversation_id);
  5938. QueuePacket(packet->serialize());
  5939. safe_delete(packet);
  5940. }
  5941. MConversation.writelock();
  5942. std::map<int32, Item*>::iterator itr;
  5943. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5944. {
  5945. conversation_items.erase(itr);
  5946. }
  5947. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  5948. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5949. {
  5950. conversation_spawns.erase(itr2);
  5951. }
  5952. MConversation.releasewritelock();
  5953. }
  5954. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5955. int32 conversation_id = 0;
  5956. MConversation.readlock();
  5957. if (spawn) {
  5958. map<int32, int32>::iterator itr;
  5959. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5960. if (itr->second == spawn->GetID()) {
  5961. conversation_id = itr->first;
  5962. break;
  5963. }
  5964. }
  5965. }
  5966. else if (item) {
  5967. map<int32, Item*>::iterator itr;
  5968. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5969. if (itr->second == item) {
  5970. conversation_id = itr->first;
  5971. break;
  5972. }
  5973. }
  5974. }
  5975. MConversation.releasereadlock();
  5976. return conversation_id;
  5977. }
  5978. Spawn* Client::GetCombineSpawn() {
  5979. return combine_spawn;
  5980. }
  5981. bool Client::ShouldTarget() {
  5982. return should_target;
  5983. }
  5984. void Client::TargetSpawn(Spawn* spawn) {
  5985. should_target = false;
  5986. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5987. if (packet) {
  5988. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5989. QueuePacket(packet->serialize());
  5990. safe_delete(packet);
  5991. }
  5992. }
  5993. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5994. combine_spawn = spawn;
  5995. spawn->RemoveSpawnFromGroup(true);
  5996. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5997. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5998. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5999. should_target = true;
  6000. }
  6001. void Client::AddCombineSpawn(Spawn* spawn) {
  6002. if (combine_spawn && combine_spawn != spawn && spawn) {
  6003. combine_spawn->AddSpawnToGroup(spawn);
  6004. spawn->AddSpawnToGroup(combine_spawn);
  6005. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6006. }
  6007. else if (spawn)
  6008. combine_spawn = spawn;
  6009. should_target = true;
  6010. }
  6011. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6012. if (combine_spawn && spawn)
  6013. spawn->RemoveSpawnFromGroup();
  6014. if (combine_spawn == spawn)
  6015. combine_spawn->RemoveSpawnFromGroup(true);
  6016. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6017. if (combine_spawn == spawn)
  6018. combine_spawn = 0;
  6019. }
  6020. void Client::SaveCombineSpawns(const char* name) {
  6021. if (!combine_spawn) {
  6022. return;
  6023. }
  6024. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6025. if (!spawns) {
  6026. return;
  6027. }
  6028. int32 count = spawns->size();
  6029. int32 spawnLocationID = 0;
  6030. if (count == 1)
  6031. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6032. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6033. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6034. // we remove the spawn inside SaveCombinedSpawnLocation
  6035. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6036. }
  6037. else
  6038. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6039. safe_delete(spawns);
  6040. combine_spawn = 0;
  6041. }
  6042. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6043. Item* master_item = master_item_list.GetItem(item_id);
  6044. Item* item = 0;
  6045. if (master_item)
  6046. item = new Item(master_item);
  6047. if (item) {
  6048. if (quantity > 0)
  6049. item->details.count = quantity;
  6050. return AddItem(item, nullptr, type);
  6051. }
  6052. else
  6053. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6054. return false;
  6055. }
  6056. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6057. if (!item) {
  6058. return false;
  6059. }
  6060. if (item->IsBag()) {
  6061. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  6062. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  6063. }
  6064. if (player->AddItem(item, type)) {
  6065. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6066. if (outapp) {
  6067. //DumpPacket(outapp);
  6068. QueuePacket(outapp);
  6069. //resend bag desc with new item name added
  6070. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6071. if (outapp) {
  6072. //DumpPacket(outapp);
  6073. QueuePacket(outapp);
  6074. }
  6075. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6076. DumpPacket(app);
  6077. client->QueuePacket(app);
  6078. */
  6079. }
  6080. CheckPlayerQuestsItemUpdate(item);
  6081. if (item->GetItemScript() && lua_interface)
  6082. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6083. }
  6084. else {
  6085. // likely lore conflict
  6086. safe_delete(item);
  6087. if(item_deleted)
  6088. *item_deleted = true;
  6089. return false;
  6090. }
  6091. return true;
  6092. }
  6093. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6094. Item* master_item = master_item_list.GetItem(item_id);
  6095. Item* item = 0;
  6096. if (master_item)
  6097. item = new Item(master_item);
  6098. if (item) {
  6099. if (quantity > 0)
  6100. item->details.count = quantity;
  6101. return AddItemToBank(item);
  6102. }
  6103. else
  6104. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6105. return false;
  6106. }
  6107. bool Client::AddItemToBank(Item* item) {
  6108. if (!item) {
  6109. return false;
  6110. }
  6111. if (player->AddItemToBank(item)) {
  6112. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6113. if (outapp) {
  6114. QueuePacket(outapp);
  6115. //resend bag desc with new item name added
  6116. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6117. if (outapp)
  6118. QueuePacket(outapp);
  6119. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6120. DumpPacket(app);
  6121. client->QueuePacket(app);
  6122. */
  6123. }
  6124. CheckPlayerQuestsItemUpdate(item);
  6125. if (item->GetItemScript() && lua_interface)
  6126. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6127. }
  6128. else {
  6129. // likely lore conflict
  6130. safe_delete(item);
  6131. return false;
  6132. }
  6133. return true;
  6134. }
  6135. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6136. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6137. EQ2Packet* outapp = 0;
  6138. for(int32 i=0;i<packets.size();i++)
  6139. {
  6140. outapp = packets[i];
  6141. if(outapp)
  6142. QueuePacket(outapp);
  6143. }
  6144. GetPlayer()->ChangePrimaryWeapon();
  6145. GetPlayer()->ChangeSecondaryWeapon();
  6146. GetPlayer()->ChangeRangedWeapon();
  6147. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6148. QueuePacket(characterSheetPackets);
  6149. }
  6150. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6151. EQ2Packet* outapp;
  6152. bool delete_item = false;
  6153. assert(item);
  6154. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6155. item->details.count -= quantity;
  6156. item->save_needed = true;
  6157. }
  6158. else {
  6159. database.DeleteItem(character_id, item, 0);
  6160. player->GetPlayerItemList()->RemoveItem(item, false);
  6161. delete_item = true;
  6162. }
  6163. if(force_override_no_delete)
  6164. delete_item = false;
  6165. if ((outapp = player->SendInventoryUpdate(version))) {
  6166. QueuePacket(outapp);
  6167. if (item->GetItemScript() && lua_interface)
  6168. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6169. if (delete_item)
  6170. {
  6171. PurgeItem(item);
  6172. safe_delete(item);
  6173. }
  6174. return true;
  6175. }
  6176. return false;
  6177. }
  6178. void Client::SetLuaDebugClient(bool val) {
  6179. if (val)
  6180. lua_debug_timer.Start();
  6181. lua_debug = val;
  6182. if (lua_interface && !val) {
  6183. lua_interface->RemoveDebugClients(this);
  6184. lua_debug_timer.Disable();
  6185. }
  6186. }
  6187. void Client::SetMerchantTransaction(Spawn* spawn) {
  6188. merchant_transaction = spawn;
  6189. }
  6190. Spawn* Client::GetMerchantTransaction() {
  6191. return merchant_transaction;
  6192. }
  6193. void Client::SetMailTransaction(Spawn* spawn) {
  6194. ResetSendMail(spawn ? false : true);
  6195. MMailWindowMutex.lock();
  6196. mail_transaction = spawn;
  6197. MMailWindowMutex.unlock();
  6198. }
  6199. Spawn* Client::GetMailTransaction() {
  6200. return mail_transaction;
  6201. }
  6202. void Client::PlaySound(const char* name) {
  6203. if (name) {
  6204. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6205. if (packet) {
  6206. packet->setMediumStringByName("name", name);
  6207. QueuePacket(packet->serialize());
  6208. safe_delete(packet);
  6209. }
  6210. }
  6211. }
  6212. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6213. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6214. if(multiplier){
  6215. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6216. float diff_low = faction_val - multiplier->faction_min;
  6217. if(diff_low < 0)
  6218. diff_low*=-1;
  6219. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6220. if(total_diff < 0)
  6221. total_diff*=-1;
  6222. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6223. float total1 = (diff_low/total_diff);
  6224. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6225. return final_buy_multiplier;
  6226. }*/
  6227. return 1;
  6228. }
  6229. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6230. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6231. if(multiplier){
  6232. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6233. float diff_low = faction_val - multiplier->faction_min;
  6234. if(diff_low < 0)
  6235. diff_low*=-1;
  6236. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6237. if(total_diff < 0)
  6238. total_diff*=-1;
  6239. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6240. float total1 = (diff_low/total_diff);
  6241. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6242. return final_sell_multiplier;
  6243. }*/
  6244. return 1;
  6245. }
  6246. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6247. Spawn* spawn = GetMerchantTransaction();
  6248. Guild* guild = GetPlayer()->GetGuild();
  6249. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6250. spawn->IsClientInMerchantLevelRange(this)) {
  6251. int32 total_sell_price = 0;
  6252. int32 total_status_sell_price = 0; //for status
  6253. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6254. int32 sell_price = 0;
  6255. int32 status_sell_price = 0; //for status
  6256. Item* master_item = master_item_list.GetItem(item_id);
  6257. Item* item = 0;
  6258. if (unique_id == 0)
  6259. item = player->item_list.GetItemFromID(item_id, quantity);
  6260. else
  6261. item = player->item_list.GetItemFromUniqueID(unique_id);
  6262. if (!item)
  6263. item = player->item_list.GetItemFromID(item_id);
  6264. if (item && master_item) {
  6265. if(item->details.item_locked)
  6266. {
  6267. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6268. return;
  6269. }
  6270. else if(item->CheckFlag(NO_VALUE))
  6271. {
  6272. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6273. return;
  6274. }
  6275. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6276. if (sell_price > item->sell_price)
  6277. sell_price = item->sell_price;
  6278. if (quantity > item->details.count)
  6279. quantity = item->details.count;
  6280. total_sell_price = sell_price * quantity;
  6281. //------------------------------For Selling Status Items
  6282. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6283. if (status_sell_price > item->sell_status)
  6284. status_sell_price = item->sell_status;
  6285. if (quantity > item->details.count)
  6286. quantity = item->details.count;
  6287. total_status_sell_price = status_sell_price * quantity;
  6288. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6289. total_status_sell_price = 0;
  6290. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6291. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6292. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6293. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6294. guild->SendGuildMemberList();
  6295. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6296. }
  6297. if (quantity > 1)
  6298. {
  6299. if(total_status_sell_price)
  6300. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s and %u Status Points.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6301. else
  6302. 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());
  6303. }
  6304. else
  6305. {
  6306. if(total_status_sell_price)
  6307. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s and %u Status Points.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6308. else
  6309. 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());
  6310. }
  6311. player->AddCoins(total_sell_price);
  6312. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6313. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6314. if (quantity >= item->details.count) {
  6315. database.DeleteItem(GetCharacterID(), item, 0);
  6316. player->item_list.DestroyItem(item->details.index);
  6317. }
  6318. else {
  6319. item->details.count -= quantity;
  6320. item->save_needed = true;
  6321. }
  6322. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6323. if (outapp)
  6324. QueuePacket(outapp);
  6325. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6326. SendBuyBackList();
  6327. }
  6328. }
  6329. }
  6330. void Client::BuyBack(int32 item_id, int16 quantity) {
  6331. Spawn* spawn = GetMerchantTransaction();
  6332. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6333. spawn->IsClientInMerchantLevelRange(this)) {
  6334. deque<BuyBackItem*>::iterator itr;
  6335. BuyBackItem* buyback = 0;
  6336. BuyBackItem* closest = 0;
  6337. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6338. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6339. buyback = *itr;
  6340. if (buyback->unique_id == item_id) {
  6341. closest = buyback;
  6342. quantity = buyback->quantity;
  6343. break;
  6344. }
  6345. }
  6346. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6347. if (closest) {
  6348. Item* item = 0;
  6349. Item* master_item = master_item_list.GetItem(closest->item_id);
  6350. if (master_item) {
  6351. item = new Item(master_item);
  6352. if (closest->quantity >= quantity)
  6353. item->details.count = quantity;
  6354. else
  6355. item->details.count = closest->quantity;
  6356. }
  6357. bool itemDeleted = false;
  6358. bool itemAdded = false;
  6359. sint64 dispFlags = 0;
  6360. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6361. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6362. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6363. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6364. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6365. bool removed = false;
  6366. if (closest->quantity == quantity) {
  6367. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6368. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6369. if (*itr == closest) {
  6370. buy_back_items.erase(itr);
  6371. removed = true;
  6372. break;
  6373. }
  6374. }
  6375. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6376. }
  6377. else {
  6378. closest->quantity -= quantity;
  6379. closest->save_needed = true;
  6380. }
  6381. itemAdded = AddItem(item, &itemDeleted);
  6382. if (removed) {
  6383. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6384. safe_delete(closest);
  6385. }
  6386. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6387. SendBuyBackList();
  6388. }
  6389. else
  6390. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6391. if(!itemAdded && !itemDeleted)
  6392. safe_delete(item);
  6393. }
  6394. }
  6395. }
  6396. void Client::BuyItem(int32 item_id, int16 quantity) {
  6397. // Get the merchant we are buying from
  6398. Spawn* spawn = GetMerchantTransaction();
  6399. // Make sure the spawn has a merchant list
  6400. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6401. int32 total_buy_price = 0;
  6402. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6403. int32 sell_price = 0;
  6404. Item* master_item = master_item_list.GetItem(item_id);
  6405. Item* item = 0;
  6406. int16 total_available = 0;
  6407. vector<MerchantItemInfo>* temp;
  6408. vector<MerchantItemInfo>::iterator itr;
  6409. MerchantItemInfo* ItemInfo = 0;
  6410. temp = world.GetMerchantList(spawn->GetMerchantID());
  6411. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6412. if ((*itr).item_id == item_id) {
  6413. ItemInfo = &(*itr);
  6414. break;
  6415. }
  6416. }
  6417. if (master_item && ItemInfo) {
  6418. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6419. quantity = 1;
  6420. total_available = 0xFFFF;
  6421. sell_price = master_item->sell_price;
  6422. }
  6423. else {
  6424. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6425. sell_price = (int32)(master_item->sell_price * multiplier);
  6426. if (quantity > total_available)
  6427. quantity = total_available;
  6428. }
  6429. sint64 dispFlags = 0;
  6430. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6431. {
  6432. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6433. return;
  6434. }
  6435. if(quantity < 1)
  6436. {
  6437. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6438. return;
  6439. }
  6440. total_buy_price = sell_price * quantity;
  6441. item = new Item(master_item);
  6442. item->details.count = quantity;
  6443. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6444. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6445. safe_delete(item);
  6446. }
  6447. else {
  6448. // Price not set in the merchant_inventory table, use the old method
  6449. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6450. if (player->RemoveCoins(total_buy_price)) {
  6451. item->SetMaxSellValue(sell_price);
  6452. if (quantity > 1)
  6453. 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());
  6454. else
  6455. 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());
  6456. bool itemDeleted = false;
  6457. AddItem(item, &itemDeleted);
  6458. if(!itemDeleted) {
  6459. CheckPlayerQuestsItemUpdate(item);
  6460. if (item && total_available < 0xFF) {
  6461. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6462. SendBuyMerchantList();
  6463. }
  6464. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6465. PlayLotto(total_buy_price, item->details.item_id);
  6466. }
  6467. }
  6468. else {
  6469. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6470. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6471. PlaySound("buy_failed");
  6472. }
  6473. }
  6474. else {
  6475. // Price set in merchant_inventory table
  6476. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6477. // TODO: need to add support for station cash
  6478. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6479. // Check items
  6480. int16 item_quantity = 0;
  6481. // Default these to true in case price_item_id or price_item2_id was never set
  6482. bool hasItem1 = true;
  6483. bool hasItem2 = true;
  6484. Item* tempItem1 = 0;
  6485. Item* tempItem2 = 0;
  6486. if (ItemInfo->price_item_id != 0) {
  6487. // Same item for whatever reason lets add the quantities together
  6488. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6489. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6490. else
  6491. item_quantity = ItemInfo->price_item_qty;
  6492. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6493. if (tempItem1) {
  6494. if (tempItem1->details.count < item_quantity)
  6495. hasItem1 = false;
  6496. }
  6497. else {
  6498. hasItem1 = false;
  6499. }
  6500. }
  6501. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6502. // as item1 and we already checked for it so we can skip this check
  6503. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6504. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6505. if (tempItem2) {
  6506. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6507. hasItem2 = false;
  6508. }
  6509. else {
  6510. hasItem2 = false;
  6511. }
  6512. }
  6513. // if we have every thing then remove the price and give the item
  6514. if (hasItem1 && hasItem2) {
  6515. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6516. // TODO: station cash
  6517. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6518. // so there is no need to send it more then that one time
  6519. if (tempItem1) {
  6520. if (tempItem1->details.count > item_quantity) {
  6521. tempItem1->details.count -= item_quantity;
  6522. tempItem1->save_needed = true;
  6523. }
  6524. else {
  6525. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6526. player->item_list.DestroyItem(tempItem1->details.index);
  6527. }
  6528. }
  6529. if (tempItem2) {
  6530. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6531. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6532. tempItem2->save_needed = true;
  6533. }
  6534. else {
  6535. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6536. player->item_list.DestroyItem(tempItem2->details.index);
  6537. }
  6538. }
  6539. // 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
  6540. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6541. item->SetMaxSellValue(sell_price);
  6542. if (quantity > 1)
  6543. 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());
  6544. else
  6545. 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());
  6546. bool itemDeleted = false;
  6547. AddItem(item, &itemDeleted);
  6548. if(!itemDeleted) {
  6549. CheckPlayerQuestsItemUpdate(item);
  6550. if (item && total_available < 0xFF) {
  6551. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6552. SendBuyMerchantList();
  6553. }
  6554. SendSellMerchantList();
  6555. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6556. PlayLotto(total_buy_price, item->details.item_id);
  6557. }
  6558. }
  6559. else {
  6560. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6561. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6562. PlaySound("buy_failed");
  6563. }
  6564. }
  6565. else {
  6566. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6567. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6568. PlaySound("buy_failed");
  6569. }
  6570. }
  6571. }
  6572. }
  6573. }
  6574. }
  6575. void Client::RepairItem(int32 item_id) {
  6576. Spawn* spawn = GetMerchantTransaction();
  6577. if (spawn) {
  6578. Item* item = player->item_list.GetItemFromID(item_id);
  6579. if (!item)
  6580. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6581. if (item) {
  6582. if(item->CheckFlag(NO_REPAIR)) {
  6583. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  6584. PlaySound("buy_failed");
  6585. }
  6586. else {
  6587. int32 repair_cost = item->CalculateRepairCost();
  6588. if (player->RemoveCoins((int32)repair_cost)) {
  6589. item->generic_info.condition = 100;
  6590. item->save_needed = true;
  6591. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6592. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6593. QueuePacket(item->serialize(version, false, player));
  6594. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6595. PlaySound("coin_cha_ching");
  6596. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6597. SendRepairList();
  6598. }
  6599. else {
  6600. string popup_text = "You do not have enough coin to repair ";
  6601. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  6602. popup_text.append(popup_item);
  6603. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6604. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6605. PlaySound("buy_failed");
  6606. }
  6607. }
  6608. }
  6609. }
  6610. }
  6611. void Client::RepairAllItems() {
  6612. Spawn* spawn = GetMerchantTransaction();
  6613. if (spawn) {
  6614. vector<Item*>* repairable_items = GetRepairableItems();
  6615. if (repairable_items && repairable_items->size() > 0) {
  6616. vector<Item*>::iterator itr;
  6617. int64 total_cost = 0;
  6618. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6619. total_cost += (*itr)->CalculateRepairCost();
  6620. if (player->RemoveCoins((int32)total_cost)) {
  6621. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6622. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6623. Item* item = *itr;
  6624. if (item) {
  6625. item->generic_info.condition = 100;
  6626. item->save_needed = true;
  6627. QueuePacket(item->serialize(version, false, player));
  6628. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6629. }
  6630. }
  6631. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6632. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6633. PlaySound("coin_cha_ching");
  6634. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6635. SendRepairList();
  6636. }
  6637. else {
  6638. string popup_text = "You do not have enough coin to repair all of your items. ";
  6639. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6640. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6641. PlaySound("buy_failed");
  6642. }
  6643. }
  6644. safe_delete(repairable_items);
  6645. }
  6646. }
  6647. void Client::SendAchievementsList()
  6648. {
  6649. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6650. map<int32, Achievement *>::iterator itr;
  6651. Achievement *achievement;
  6652. vector<AchievementRequirements *> *requirements = 0;
  6653. vector<AchievementRequirements *>::iterator itr2;
  6654. AchievementRequirements *requirement;
  6655. vector<AchievementRewards *> *rewards = 0;
  6656. vector<AchievementRewards *>::iterator itr3;
  6657. AchievementRewards *reward;
  6658. PacketStruct *packet;
  6659. int16 i = 0;
  6660. int16 j = 0;
  6661. int16 k = 0;
  6662. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6663. return;
  6664. }
  6665. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6666. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6667. achievement = itr->second;
  6668. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6669. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6670. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6671. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6672. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6673. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6674. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6675. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6676. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6677. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6678. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6679. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6680. requirements = achievement->GetRequirements();
  6681. rewards = achievement->GetRewards();
  6682. j = 0;
  6683. k = 0;
  6684. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6685. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6686. requirement = *itr2;
  6687. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6688. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6689. j++;
  6690. }
  6691. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6692. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6693. reward = *itr3;
  6694. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6695. k++;
  6696. }
  6697. i++;
  6698. }
  6699. //packet->PrintPacket();
  6700. EQ2Packet* data = packet->serialize();
  6701. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6702. safe_delete(packet);
  6703. safe_delete(data);
  6704. //DumpPacket(app);
  6705. QueuePacket(app);*/
  6706. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6707. SendAchievementUpdate(true);
  6708. }
  6709. void Client::SendAchievementUpdate(bool first_login) {
  6710. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6711. map<int32, AchievementUpdate*>::iterator itr;
  6712. AchievementUpdate* update;
  6713. vector<AchievementUpdateItems*>* update_items = 0;
  6714. vector<AchievementUpdateItems*>::iterator itr2;
  6715. AchievementUpdateItems* update_item;
  6716. int16 i = 0;
  6717. int16 j = 0;
  6718. PacketStruct* packet;
  6719. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6720. return;
  6721. }
  6722. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6723. packet->setArrayLengthByName("num_achievements", updates->size());
  6724. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6725. update = itr->second;
  6726. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6727. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6728. update_items = update->GetUpdateItems();
  6729. j = 0;
  6730. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6731. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6732. update_item = *itr2;
  6733. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6734. j++;
  6735. }
  6736. i++;
  6737. }
  6738. //packet->PrintPacket();
  6739. EQ2Packet* data = packet->serialize();
  6740. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6741. safe_delete(packet);
  6742. safe_delete(data);
  6743. //DumpPacket(app);
  6744. QueuePacket(app);
  6745. }
  6746. void Client::SendBuyMerchantList(bool sell) {
  6747. Spawn* spawn = GetMerchantTransaction();
  6748. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6749. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6750. if (items) {
  6751. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6752. if (packet) {
  6753. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6754. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6755. packet->setArrayLengthByName("num_items", items->size());
  6756. vector<MerchantItemInfo>::iterator itr;
  6757. sint8 item_difficulty = 0;
  6758. int32 sell_price = 0;
  6759. int i = 0;
  6760. int tmp_level = 0;
  6761. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6762. MerchantItemInfo ItemInfo = *itr;
  6763. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6764. if (!item)
  6765. continue;
  6766. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6767. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6768. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6769. packet->setArrayDataByName("icon", item->details.icon, i);
  6770. if (item->generic_info.adventure_default_level > 0)
  6771. tmp_level = item->generic_info.adventure_default_level;
  6772. else
  6773. tmp_level = item->generic_info.tradeskill_default_level;
  6774. packet->setArrayDataByName("level", tmp_level, i);
  6775. packet->setArrayDataByName("tier", item->details.tier, i);
  6776. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6777. item_difficulty = player->GetArrowColor(tmp_level);
  6778. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6779. item_difficulty = ARROW_COLOR_WHITE;
  6780. sint64 overrideValue = 0;
  6781. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6782. item_difficulty = (sint8)overrideValue;
  6783. item_difficulty -= 6;
  6784. if (item_difficulty < 0)
  6785. item_difficulty *= -1;
  6786. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6787. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6788. packet->setArrayDataByName("unknown5", 255, i);
  6789. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6790. sint64 dispFlags = 0;
  6791. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  6792. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6793. std::string overrideValueStr;
  6794. // classic client isn't properly tracking this field, DoF we don't have it identified yet, but no field to cause any issues (can add later if identified)
  6795. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6796. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6797. // If no price set in the merchant_inventory table then use the old method
  6798. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6799. sell_price = (int32)(item->sell_price * multiplier);
  6800. packet->setArrayDataByName("price", sell_price, i);
  6801. }
  6802. else {
  6803. int8 count = 0;
  6804. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6805. count++;
  6806. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6807. count++;
  6808. if (count != 0) {
  6809. packet->setSubArrayLengthByName("num_tokens", count, i);
  6810. int8 index = 0;
  6811. Item* token = 0;
  6812. if (ItemInfo.price_item_id != 0) {
  6813. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6814. if (item) {
  6815. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6816. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6817. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6818. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6819. }
  6820. token = 0;
  6821. index++;
  6822. }
  6823. if (ItemInfo.price_item2_id != 0) {
  6824. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6825. if (item) {
  6826. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6827. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6828. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6829. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6830. }
  6831. }
  6832. }
  6833. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6834. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6835. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6836. }
  6837. }
  6838. if (GetVersion() <= 546) {
  6839. //buy is 0 so dont need to set it
  6840. if (sell)
  6841. packet->setDataByName("type", 1);
  6842. }
  6843. else {
  6844. if (sell)
  6845. packet->setDataByName("type", 130);
  6846. else
  6847. packet->setDataByName("type", 2);
  6848. }
  6849. EQ2Packet* outapp = packet->serialize();
  6850. // DumpPacket(outapp);
  6851. QueuePacket(outapp);
  6852. safe_delete(packet);
  6853. }
  6854. safe_delete(items);
  6855. }
  6856. else {
  6857. // Need to send an empty packet in the event there is no item list, otherwise the
  6858. // last item list sent to the player will show for this merchant
  6859. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6860. if (packet) {
  6861. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6862. if (GetVersion() <= 546) {
  6863. //buy is 0 so dont need to set it
  6864. if (sell)
  6865. packet->setDataByName("type", 1);
  6866. }
  6867. else {
  6868. if (sell)
  6869. packet->setDataByName("type", 130);
  6870. else
  6871. packet->setDataByName("type", 2);
  6872. }
  6873. EQ2Packet* outapp = packet->serialize();
  6874. QueuePacket(outapp);
  6875. safe_delete(packet);
  6876. }
  6877. }
  6878. }
  6879. }
  6880. void Client::SendSellMerchantList(bool sell) {
  6881. Spawn* spawn = GetMerchantTransaction();
  6882. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6883. return;
  6884. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6885. map<int32, Item*>* items = player->GetItemList();
  6886. if (items) {
  6887. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6888. if (packet) {
  6889. vector<Item*> sellable_items;
  6890. map<int32, Item*>::iterator test_itr;
  6891. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6892. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6893. sellable_items.push_back(test_itr->second);
  6894. }
  6895. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6896. packet->setArrayLengthByName("num_items", sellable_items.size());
  6897. vector<Item*>::iterator itr;
  6898. Item* item = 0;
  6899. sint8 item_difficulty = 0;
  6900. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6901. int32 sell_price = 0;
  6902. Item* master_item = 0;
  6903. int i = 0;
  6904. int tmp_level = 0;
  6905. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6906. item = *itr;
  6907. master_item = master_item_list.GetItem(item->details.item_id);
  6908. if (master_item)
  6909. sell_price = (int32)(master_item->sell_price * multiplier);
  6910. else
  6911. sell_price = 0;
  6912. if (sell_price > item->sell_price)
  6913. sell_price = item->sell_price;
  6914. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6915. string thename = item->name;
  6916. packet->setArrayDataByName("price", sell_price, i);
  6917. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6918. int8 dispFlags = 0;
  6919. // only city merchants allow selling for status
  6920. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6921. {
  6922. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6923. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6924. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6925. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6926. }
  6927. }
  6928. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6929. {
  6930. if(GetVersion() < 1188)
  6931. dispFlags += DISPLAY_FLAG_RED_TEXT; // for older clients it isn't "no buy back", you can either have 1 for red text or 255 for 'not for sale' to be checked
  6932. else
  6933. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6934. }
  6935. if(item->no_sale)
  6936. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6937. packet->setArrayDataByName("display_flags", dispFlags, i);
  6938. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6939. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6940. packet->setArrayDataByName("stack_size", item->details.count, i);
  6941. packet->setArrayDataByName("icon", item->details.icon, i);
  6942. if (item->generic_info.adventure_default_level > 0)
  6943. tmp_level = item->generic_info.adventure_default_level;
  6944. else
  6945. tmp_level = item->generic_info.tradeskill_default_level;
  6946. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6947. packet->setArrayDataByName("tier", item->details.tier, i);
  6948. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6949. item_difficulty = player->GetArrowColor(tmp_level);
  6950. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6951. item_difficulty = ARROW_COLOR_WHITE;
  6952. sint64 overrideValue = 0;
  6953. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6954. item_difficulty = (sint8)overrideValue;
  6955. item_difficulty -= 6;
  6956. if (item_difficulty < 0)
  6957. item_difficulty *= -1;
  6958. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6959. if (item->details.count == 1)
  6960. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6961. else
  6962. packet->setArrayDataByName("quantity", item->details.count, i);
  6963. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6964. if (GetVersion() <= 1096)
  6965. packet->setArrayDataByName("description", item->description.c_str(), i);
  6966. }
  6967. if (GetVersion() <= 546) {
  6968. packet->setDataByName("type", 1);
  6969. }
  6970. else {
  6971. if (sell)
  6972. packet->setDataByName("type", 129);
  6973. else
  6974. packet->setDataByName("type", 1);
  6975. }
  6976. packet->setDataByName("unknown8a", 16256, 6);
  6977. packet->setDataByName("unknown8a", 16256, 10);
  6978. //packet->PrintPacket();
  6979. EQ2Packet* outapp = packet->serialize();
  6980. //DumpPacket(outapp);
  6981. QueuePacket(outapp);
  6982. safe_delete(packet);
  6983. }
  6984. safe_delete(items);
  6985. }
  6986. }
  6987. }
  6988. void Client::SendBuyBackList(bool sell) {
  6989. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6990. return;
  6991. Spawn* spawn = GetMerchantTransaction();
  6992. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6993. deque<BuyBackItem*>::iterator itr;
  6994. int i = 0;
  6995. Item* master_item = 0;
  6996. BuyBackItem* buyback = 0;
  6997. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6998. if (packet) {
  6999. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7000. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7001. sint8 item_difficulty = 0;
  7002. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7003. int tmp_level = 0;
  7004. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7005. buyback = *itr;
  7006. master_item = master_item_list.GetItem(buyback->item_id);
  7007. if (master_item) {
  7008. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7009. packet->setArrayDataByName("price", buyback->price, i);
  7010. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7011. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7012. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7013. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7014. if (master_item->generic_info.adventure_default_level > 0)
  7015. tmp_level = master_item->generic_info.adventure_default_level;
  7016. else
  7017. tmp_level = master_item->generic_info.tradeskill_default_level;
  7018. packet->setArrayDataByName("level", tmp_level, i);
  7019. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7020. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7021. item_difficulty = player->GetArrowColor(tmp_level);
  7022. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7023. item_difficulty = ARROW_COLOR_WHITE;
  7024. sint64 overrideValue = 0;
  7025. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7026. item_difficulty = (sint8)overrideValue;
  7027. item_difficulty -= 6;
  7028. if (item_difficulty < 0)
  7029. item_difficulty *= -1;
  7030. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7031. sint64 dispFlags = 0;
  7032. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7033. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7034. if (buyback->quantity == 1)
  7035. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7036. else
  7037. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7038. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7039. if (GetVersion() <= 1096)
  7040. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7041. }
  7042. }
  7043. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7044. if (sell)
  7045. packet->setDataByName("type", 640);
  7046. else
  7047. packet->setDataByName("type", 512);
  7048. EQ2Packet* outapp = packet->serialize();
  7049. // DumpPacket(outapp);
  7050. QueuePacket(outapp);
  7051. safe_delete(packet);
  7052. }
  7053. }
  7054. }
  7055. void Client::SendRepairList() {
  7056. Spawn* spawn = GetMerchantTransaction();
  7057. if (spawn) {
  7058. vector<Item*>* repairable_items = GetRepairableItems();
  7059. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7060. if (packet) {
  7061. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7062. packet->setArrayLengthByName("num_items", repairable_items->size());
  7063. Item* item = 0;
  7064. sint8 item_difficulty = 0;
  7065. int32 i = 0;
  7066. vector<Item*>::iterator itr;
  7067. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7068. item = *itr;
  7069. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7070. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7071. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7072. packet->setArrayDataByName("stack_size", item->details.count, i);
  7073. packet->setArrayDataByName("icon", item->details.icon, i);
  7074. /*if (item->generic_info.adventure_default_level > 0)
  7075. tmp_level = item->generic_info.adventure_default_level;
  7076. else
  7077. tmp_level = item->generic_info.tradeskill_default_level;
  7078. packet->setArrayDataByName("level", tmp_level, i);*/
  7079. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7080. packet->setArrayDataByName("tier", item->details.tier, i);
  7081. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7082. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7083. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7084. item_difficulty = ARROW_COLOR_WHITE;
  7085. item_difficulty -= 6;
  7086. if (item_difficulty < 0)
  7087. item_difficulty *= -1;
  7088. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7089. if (item->details.count == 1)
  7090. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7091. else
  7092. packet->setArrayDataByName("quantity", item->details.count, i);
  7093. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7094. if (GetVersion() <= 1096)
  7095. packet->setArrayDataByName("description", item->description.c_str(), i);
  7096. }
  7097. if (GetVersion() <= 546) {
  7098. packet->setDataByName("type", 16);
  7099. }
  7100. else {
  7101. packet->setDataByName("type", 96);
  7102. }
  7103. EQ2Packet* outapp = packet->serialize();
  7104. QueuePacket(outapp);
  7105. safe_delete(packet);
  7106. }
  7107. safe_delete(repairable_items);
  7108. }
  7109. }
  7110. void Client::ShowLottoWindow() {
  7111. Spawn* spawn = GetMerchantTransaction();
  7112. if (spawn) {
  7113. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7114. if (!item_id)
  7115. {
  7116. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7117. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7118. return;
  7119. }
  7120. else if (item_id == 0)
  7121. {
  7122. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7123. return;
  7124. }
  7125. Item* item = master_item_list.GetItem(item_id);
  7126. if (!item) {
  7127. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7128. return;
  7129. }
  7130. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7131. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7132. if (packet) {
  7133. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7134. packet->setArrayLengthByName("num_items", 1);
  7135. packet->setArrayDataByName("item_name", item->name.c_str());
  7136. packet->setArrayDataByName("price", item->sell_price);
  7137. packet->setArrayDataByName("item_id", item->details.item_id);
  7138. packet->setArrayDataByName("stack_size", item->details.count);
  7139. packet->setArrayDataByName("icon", item->details.icon);
  7140. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7141. packet->setArrayDataByName("tier", item->details.tier);
  7142. packet->setArrayDataByName("item_id2", item->details.item_id);
  7143. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7144. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7145. item_difficulty = ARROW_COLOR_WHITE;
  7146. item_difficulty -= 6;
  7147. if (item_difficulty < 0)
  7148. item_difficulty *= -1;
  7149. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7150. //if(item->details.count == 1)
  7151. packet->setArrayDataByName("quantity", 0xFFFF);
  7152. //else
  7153. // packet->setArrayDataByName("quantity", item->details.count);
  7154. packet->setArrayDataByName("stack_size2", item->details.count);
  7155. packet->setArrayDataByName("description", item->description.c_str());
  7156. if (GetVersion() <= 546) {
  7157. packet->setDataByName("type", 128);
  7158. }
  7159. else {
  7160. packet->setDataByName("type", 0x00000102);
  7161. }
  7162. QueuePacket(packet->serialize());
  7163. safe_delete(packet);
  7164. }
  7165. }
  7166. }
  7167. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7168. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7169. if (packet) {
  7170. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7171. int32 rolls[6] = { 0 };
  7172. int32 lottery_digits[6] = { 0 };
  7173. int8 num_matches = 0;
  7174. int64 jackpot = 0;
  7175. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7176. if (!item) {
  7177. return;
  7178. }
  7179. database.DeleteItem(GetCharacterID(), item, 0);
  7180. GetPlayer()->item_list.RemoveItem(item, true);
  7181. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7182. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7183. if (!winning_numbers) {
  7184. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7185. variables.AddVariable(winning_numbers);
  7186. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7187. }
  7188. if (strlen(winning_numbers->GetValue()) != 12) {
  7189. winning_numbers->SetValue("231205182236");
  7190. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7191. }
  7192. try {
  7193. for (int32 i = 0; i < 12; i += 2) {
  7194. char num[4];
  7195. strncpy(num, winning_numbers->GetValue() + i, 2);
  7196. lottery_digits[i / 2] = atoi(num);
  7197. }
  7198. }
  7199. catch (...) {
  7200. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7201. return;
  7202. }
  7203. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7204. if (!jackpot_var) {
  7205. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7206. variables.AddVariable(jackpot_var);
  7207. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7208. }
  7209. try {
  7210. jackpot = atoul(jackpot_var->GetValue());
  7211. if (jackpot < 10000)
  7212. jackpot = 10000;
  7213. }
  7214. catch (...) {
  7215. jackpot = 10000;
  7216. }
  7217. char new_jackpot[128] = { 0 };
  7218. sprintf(new_jackpot, "%llu", jackpot + price);
  7219. jackpot_var->SetValue(new_jackpot);
  7220. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7221. world.PickRandomLottoDigits(rolls);
  7222. packet->setDataByName("roll_digit1", rolls[0]);
  7223. packet->setDataByName("roll_digit2", rolls[1]);
  7224. packet->setDataByName("roll_digit3", rolls[2]);
  7225. packet->setDataByName("roll_digit4", rolls[3]);
  7226. packet->setDataByName("roll_digit5", rolls[4]);
  7227. packet->setDataByName("roll_digit6", rolls[5]);
  7228. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7229. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7230. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7231. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7232. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7233. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7234. QueuePacket(packet->serialize());
  7235. safe_delete(packet);
  7236. for (int32 i = 0; i < 6; i++) {
  7237. for (int32 j = 0; j < 6; j++) {
  7238. if (rolls[i] == lottery_digits[j]) {
  7239. num_matches++;
  7240. break;
  7241. }
  7242. }
  7243. }
  7244. char new_jackpot_str[16];
  7245. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7246. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7247. if (num_matches == 6) {
  7248. world.PickRandomLottoDigits(lottery_digits);
  7249. for (int32 i = 0; i < 12; i += 2)
  7250. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7251. winning_numbers->SetValue(new_jackpot_str);
  7252. jackpot_var->SetValue("10000");
  7253. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7254. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7255. }
  7256. }
  7257. }
  7258. void Client::SendGuildCreateWindow() {
  7259. if (GetVersion() <= 546) {
  7260. SimpleMessage(0, "Not implemented on this client...yet?");
  7261. }
  7262. else {
  7263. Spawn* spawn = GetPlayer()->GetTarget();
  7264. if (spawn) {
  7265. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7266. if (packet) {
  7267. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7268. packet->setArrayLengthByName("num_items", 0);
  7269. packet->setDataByName("type", 0x00008000);
  7270. QueuePacket(packet->serialize());
  7271. safe_delete(packet);
  7272. }
  7273. }
  7274. }
  7275. }
  7276. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7277. BuyBackItem* item = new BuyBackItem;
  7278. item->item_id = item_id;
  7279. item->unique_id = unique_id;
  7280. item->price = price;
  7281. item->quantity = quantity;
  7282. item->save_needed = save_needed;
  7283. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7284. buy_back_items.push_back(item);
  7285. if (buy_back_items.size() > 10) {
  7286. safe_delete(buy_back_items.front());
  7287. buy_back_items.pop_front();
  7288. }
  7289. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7290. }
  7291. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7292. return &buy_back_items;
  7293. }
  7294. vector<Item*>* Client::GetRepairableItems() {
  7295. vector<Item*>* repairable_items = new vector<Item*>;
  7296. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7297. map<int32, Item*>* items = player->GetItemList();
  7298. if (equipped_items && equipped_items->size() > 0) {
  7299. for (int32 i = 0; i < equipped_items->size(); i++) {
  7300. Item* item = equipped_items->at(i);
  7301. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7302. repairable_items->push_back(item);
  7303. }
  7304. }
  7305. if (items && items->size() > 0) {
  7306. map<int32, Item*>::iterator itr;
  7307. for (itr = items->begin(); itr != items->end(); itr++) {
  7308. Item* item = itr->second;
  7309. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7310. repairable_items->push_back(item);
  7311. }
  7312. }
  7313. safe_delete(equipped_items);
  7314. safe_delete(items);
  7315. return repairable_items;
  7316. }
  7317. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  7318. if(type == NO_EFFECT_TYPE)
  7319. return nullptr;
  7320. vector<Item*>* return_items = new vector<Item*>;
  7321. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7322. map<int32, Item*>* items = player->GetItemList();
  7323. if (equipped_items && equipped_items->size() > 0) {
  7324. for (int32 i = 0; i < equipped_items->size(); i++) {
  7325. Item* item = equipped_items->at(i);
  7326. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7327. return_items->push_back(item);
  7328. }
  7329. }
  7330. if (items && items->size() > 0) {
  7331. map<int32, Item*>::iterator itr;
  7332. for (itr = items->begin(); itr != items->end(); itr++) {
  7333. Item* item = itr->second;
  7334. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7335. return_items->push_back(item);
  7336. }
  7337. }
  7338. safe_delete(equipped_items);
  7339. safe_delete(items);
  7340. return return_items;
  7341. }
  7342. void Client::SendMailList() {
  7343. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7344. if (kiosk_id > 0) {
  7345. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7346. if (p) {
  7347. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7348. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7349. int32 i = 0;
  7350. p->setDataByName("kiosk_id", kiosk_id);
  7351. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7352. while (itr.Next()) {
  7353. Mail* mail = itr->second;
  7354. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7355. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7356. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7357. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7358. p->setArrayDataByName("unknown1", 0x0000, i);
  7359. p->setArrayDataByName("already_read", mail->already_read, i);
  7360. if(mail->expire_time)
  7361. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7362. else
  7363. p->setArrayDataByName("mail_deletion", 0, i);
  7364. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7365. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7366. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7367. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7368. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7369. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7370. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7371. //p->setArrayDataByName("unknown2", 0, i);
  7372. bool successItemAdd = false;
  7373. if(mail->stack || mail->char_item_id)
  7374. {
  7375. Item* item = master_item_list.GetItem(mail->char_item_id);
  7376. if(item)
  7377. {
  7378. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7379. if (version < 860)
  7380. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7381. else if (version < 1193)
  7382. p->setItemArrayDataByName("item", item, player, i);
  7383. else
  7384. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7385. successItemAdd = true;
  7386. }
  7387. }
  7388. if(!successItemAdd)
  7389. {
  7390. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7391. p->setArrayDataByName("end_tag3", 0xFF, i);
  7392. }
  7393. i++;
  7394. }
  7395. // GMs send mail for free!
  7396. if (GetAdminStatus() > 0)
  7397. {
  7398. p->setDataByName("postage_cost", 0);
  7399. p->setDataByName("attachment_cost", 0);
  7400. }
  7401. else
  7402. {
  7403. p->setDataByName("postage_cost", 10);
  7404. p->setDataByName("attachment_cost", 50);
  7405. }
  7406. p->setDataByName("unknown3", 0x01F4);
  7407. p->setDataByName("unknown4", 0x01000000);
  7408. EQ2Packet* pack = p->serialize();
  7409. QueuePacket(pack);
  7410. safe_delete(p);
  7411. }
  7412. }
  7413. else
  7414. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7415. }
  7416. void Client::DisplayMailMessage(int32 mail_id) {
  7417. Mail* mail = player->GetMail(mail_id);
  7418. if (mail) {
  7419. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7420. if (kiosk_id > 0) {
  7421. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7422. if (update) {
  7423. update->setDataByName("action", 0x03);
  7424. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7425. update->setDataByName("packetsubtype", 0xFF);
  7426. QueuePacket(update->serialize());
  7427. safe_delete(update);
  7428. }
  7429. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7430. if (packet) {
  7431. packet->setDataByName("kiosk_id", kiosk_id);
  7432. packet->setDataByName("mail_id", mail->mail_id);
  7433. packet->setDataByName("player_to_id", mail->player_to_id);
  7434. packet->setDataByName("player_from", mail->player_from.c_str());
  7435. packet->setDataByName("subject", mail->subject.c_str());
  7436. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7437. packet->setDataByName("unknown1", 1);
  7438. packet->setDataByName("unknown2", 0);
  7439. packet->setDataByName("lock_report_button", 1);
  7440. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7441. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7442. packet->setDataByName("coin_copper", mail->coin_copper);
  7443. packet->setDataByName("coin_silver", mail->coin_silver);
  7444. packet->setDataByName("coin_gold", mail->coin_gold);
  7445. packet->setDataByName("coin_plat", mail->coin_plat);
  7446. if(mail->stack || mail->char_item_id)
  7447. {
  7448. Item* item = master_item_list.GetItem(mail->char_item_id);
  7449. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7450. if (version < 860)
  7451. packet->setItemByName("item", item, player, 0, -1);
  7452. else if (version < 1193)
  7453. packet->setItemByName("item", item, player, 0, 0);
  7454. else
  7455. packet->setItemByName("item", item, player, 0, 2);
  7456. }
  7457. else
  7458. {
  7459. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7460. packet->setDataByName("end_tag3", 0xFF);
  7461. }
  7462. mail->already_read = true;
  7463. mail->save_needed = true;
  7464. EQ2Packet* pack = packet->serialize();
  7465. QueuePacket(pack);
  7466. safe_delete(packet);
  7467. // trying to update this causes the window not to open
  7468. //SendMailList();
  7469. }
  7470. }
  7471. else
  7472. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7473. }
  7474. }
  7475. /* 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
  7476. packet back to the client before the mail actually sent. */
  7477. void Client::HandleSentMail(EQApplicationPacket* app) {
  7478. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7479. if (packet) {
  7480. packet->LoadPacketData(app->pBuffer, app->size);
  7481. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7482. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7483. vector<int32>* ids = 0;
  7484. MMailWindowMutex.lock();
  7485. if (reply_packet) {
  7486. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7487. if (player_to.length() == 0)
  7488. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7489. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7490. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7491. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7492. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7493. else {
  7494. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7495. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7496. ids = database.GetAllPlayerIDs();
  7497. else
  7498. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7499. }
  7500. else {
  7501. ids = new vector<int32>;
  7502. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7503. }
  7504. if (ids) {
  7505. for (int32 i = 0; i < ids->size(); i++) {
  7506. int32 player_to_id = ids->at(i);
  7507. if (player_to_id > 0) {
  7508. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7509. Mail* mail = new Mail;
  7510. mail->mail_id = 0;
  7511. mail->player_to_id = player_to_id;
  7512. mail->player_from = string(GetPlayer()->GetName());
  7513. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7514. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7515. mail->already_read = 0;
  7516. mail->mail_type = MAIL_TYPE_REGULAR;
  7517. mail->coin_copper = mail_window.coin_copper;
  7518. mail->coin_silver = mail_window.coin_silver;
  7519. mail->coin_gold = mail_window.coin_gold;
  7520. mail->coin_plat = mail_window.coin_plat;
  7521. mail->char_item_id = mail_window.char_item_id;
  7522. mail->stack = mail_window.stack;
  7523. // GM's send mail for free!
  7524. if (GetAdminStatus() > 0)
  7525. {
  7526. mail->postage_cost = 0;
  7527. mail->attachment_cost = 0;
  7528. }
  7529. else
  7530. {
  7531. mail->postage_cost = 10;
  7532. mail->attachment_cost = 50;
  7533. }
  7534. mail->time_sent = Timer::GetUnixTimeStamp();
  7535. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7536. mail->save_needed = false;
  7537. database.SavePlayerMail(mail);
  7538. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7539. if (to_client) {
  7540. to_client->GetPlayer()->AddMail(mail);
  7541. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  7542. string popup_text = "You have unread mail!";
  7543. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7544. }
  7545. else {
  7546. // don't need the pointer the client doesn't exist currently
  7547. safe_delete(mail);
  7548. }
  7549. ResetSendMail(false, false);
  7550. }
  7551. else
  7552. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  7553. }
  7554. }
  7555. }
  7556. string players_to = "";
  7557. if (ids) {
  7558. for (int32 i = 0; i < ids->size(); i++) {
  7559. if (ids->at(i) != 0)
  7560. players_to.append(database.GetCharacterName(ids->at(i)));
  7561. if (i < (ids->size() - 1))
  7562. players_to.append(", ");
  7563. }
  7564. }
  7565. reply_packet->setDataByName("player_to", players_to.c_str());
  7566. reply_packet->setDataByName("reply_type", reply_type);
  7567. QueuePacket(reply_packet->serialize());
  7568. safe_delete(reply_packet);
  7569. safe_delete(ids);
  7570. }
  7571. safe_delete(packet);
  7572. MMailWindowMutex.unlock();
  7573. }
  7574. }
  7575. void Client::DeleteMail(int32 mail_id, bool from_database) {
  7576. player->DeleteMail(mail_id, from_database);
  7577. }
  7578. bool Client::AddMailItem(Item* item)
  7579. {
  7580. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  7581. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  7582. return false;
  7583. }
  7584. bool ret = false;
  7585. if (GetMailTransaction()) {
  7586. MMailWindowMutex.lock();
  7587. if(mail_window.char_item_id == 0)
  7588. {
  7589. mail_window.item = item;
  7590. mail_window.char_item_id = item->details.item_id;
  7591. mail_window.stack = item->details.count;
  7592. ret = true;
  7593. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7594. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7595. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7596. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7597. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7598. if(item)
  7599. {
  7600. packet->setDataByName("stack", mail_window.stack);
  7601. item->stack_count = mail_window.stack;
  7602. if (version < 860)
  7603. packet->setItemByName("item", item, player, 0, -1);
  7604. else if (version < 1193)
  7605. packet->setItemByName("item", item, player, 0, 0);
  7606. else
  7607. packet->setItemByName("item", item, player, 0, 2);
  7608. }
  7609. else
  7610. {
  7611. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7612. packet->setDataByName("end_tag3", 0xFF);
  7613. }
  7614. QueuePacket(packet->serialize());
  7615. }
  7616. MMailWindowMutex.unlock();
  7617. }
  7618. return ret;
  7619. }
  7620. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7621. bool ret = false;
  7622. if (GetMailTransaction()) {
  7623. MMailWindowMutex.lock();
  7624. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7625. if (packet) {
  7626. if (copper > 0) {
  7627. if (player->RemoveCoins(copper)) {
  7628. mail_window.coin_copper += copper;
  7629. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7630. ret = true;
  7631. }
  7632. }
  7633. else if (silver > 0) {
  7634. if (player->RemoveCoins(silver * 100)) {
  7635. mail_window.coin_silver += silver;
  7636. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7637. ret = true;
  7638. }
  7639. }
  7640. else if (gold > 0) {
  7641. if (player->RemoveCoins(gold * 10000)) {
  7642. mail_window.coin_gold += gold;
  7643. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7644. ret = true;
  7645. }
  7646. }
  7647. else if (plat > 0) {
  7648. if (player->RemoveCoins(plat * 1000000)) {
  7649. mail_window.coin_plat += plat;
  7650. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7651. ret = true;
  7652. }
  7653. }
  7654. if (ret) {
  7655. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7656. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7657. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7658. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7659. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7660. if(item)
  7661. {
  7662. packet->setDataByName("stack", mail_window.stack);
  7663. item->stack_count = mail_window.stack;
  7664. if (version < 860)
  7665. packet->setItemByName("item", item, player, 0, -1);
  7666. else if (version < 1193)
  7667. packet->setItemByName("item", item, player, 0, 0);
  7668. else
  7669. packet->setItemByName("item", item, player, 0, 2);
  7670. }
  7671. else
  7672. {
  7673. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7674. packet->setDataByName("end_tag3", 0xFF);
  7675. }
  7676. //packet->PrintPacket();
  7677. QueuePacket(packet->serialize());
  7678. }
  7679. else
  7680. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7681. safe_delete(packet);
  7682. }
  7683. MMailWindowMutex.unlock();
  7684. }
  7685. else
  7686. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7687. return ret;
  7688. }
  7689. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7690. bool ret = false;
  7691. if (GetMailTransaction()) {
  7692. MMailWindowMutex.lock();
  7693. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7694. if (packet) {
  7695. if (copper > 0) {
  7696. player->AddCoins(copper);
  7697. mail_window.coin_copper -= copper;
  7698. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7699. ret = true;
  7700. }
  7701. else if (silver > 0) {
  7702. player->AddCoins(silver * 100);
  7703. mail_window.coin_silver -= silver;
  7704. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7705. ret = true;
  7706. }
  7707. else if (gold > 0) {
  7708. player->AddCoins(gold * 10000);
  7709. mail_window.coin_gold -= gold;
  7710. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7711. ret = true;
  7712. }
  7713. else if (plat > 0) {
  7714. player->AddCoins(plat * 1000000);
  7715. mail_window.coin_plat -= plat;
  7716. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7717. ret = true;
  7718. }
  7719. if (ret) {
  7720. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7721. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7722. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7723. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7724. packet->setDataByName("stack", 0);
  7725. packet->setDataByName("packettype", 0x2BFE);
  7726. packet->setDataByName("packetsubtype", 0xFF);
  7727. packet->setDataByName("unknown2", 0);
  7728. QueuePacket(packet->serialize());
  7729. }
  7730. safe_delete(packet);
  7731. }
  7732. MMailWindowMutex.unlock();
  7733. }
  7734. else
  7735. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7736. return ret;
  7737. }
  7738. void Client::TakeMailAttachments(int32 mail_id) {
  7739. if (GetMailTransaction()) {
  7740. Mail* mail = player->GetMail(mail_id);
  7741. if (mail) {
  7742. int64 amount = 0;
  7743. if (mail->coin_copper > 0) {
  7744. amount += mail->coin_copper;
  7745. mail->coin_copper = 0;
  7746. }
  7747. if (mail->coin_silver > 0) {
  7748. amount += mail->coin_silver * 100;
  7749. mail->coin_silver = 0;
  7750. }
  7751. if (mail->coin_gold > 0) {
  7752. amount += mail->coin_gold * 10000;
  7753. mail->coin_gold = 0;
  7754. }
  7755. if (mail->coin_plat > 0) {
  7756. amount += mail->coin_plat * 1000000;
  7757. mail->coin_plat = 0;
  7758. }
  7759. if (mail->char_item_id > 0) {
  7760. AddItem(mail->char_item_id, mail->stack);
  7761. mail->char_item_id = 0;
  7762. mail->stack = 0;
  7763. }
  7764. /* 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
  7765. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7766. find it in any packet logs.*/
  7767. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7768. if (packet) {
  7769. packet->setDataByName("unknown", 0x03);
  7770. packet->setDataByName("coin_copper", mail->coin_copper);
  7771. packet->setDataByName("coin_silver", mail->coin_silver);
  7772. packet->setDataByName("coin_gold", mail->coin_gold);
  7773. packet->setDataByName("coin_plat", mail->coin_plat);
  7774. packet->setDataByName("stack", 0);
  7775. packet->setDataByName("packettype", 0x2BFE);
  7776. packet->setDataByName("packetsubtype", 0xFF);
  7777. packet->setDataByName("unknown2", 0);
  7778. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7779. DumpPacket(packet->serialize());
  7780. QueuePacket(packet->serialize());
  7781. safe_delete(packet);
  7782. }*/
  7783. database.SavePlayerMail(mail);
  7784. if (amount > 0)
  7785. player->AddCoins(amount);
  7786. SendMailList();
  7787. }
  7788. }
  7789. else
  7790. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7791. }
  7792. void Client::ResetSendMail(bool cancel, bool needslock) {
  7793. if(cancel && mail_transaction)
  7794. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7795. if(needslock)
  7796. MMailWindowMutex.lock();
  7797. if(cancel)
  7798. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7799. if(!cancel)
  7800. mail_transaction = 0;
  7801. mail_window.coin_copper = 0;
  7802. mail_window.coin_silver = 0;
  7803. mail_window.coin_gold = 0;
  7804. mail_window.coin_plat = 0;
  7805. mail_window.char_item_id = 0;
  7806. mail_window.stack = 0;
  7807. if(mail_window.item){
  7808. if(cancel)
  7809. AddItem(mail_window.item);
  7810. else
  7811. safe_delete(mail_window.item);
  7812. }
  7813. mail_window.item = nullptr;
  7814. if(needslock)
  7815. MMailWindowMutex.unlock();
  7816. }
  7817. bool Client::GateAllowed() {
  7818. ZoneServer* zone = GetCurrentZone();
  7819. if (zone){
  7820. bool cangate = zone->GetCanGate();
  7821. return cangate;
  7822. }
  7823. return false;
  7824. }
  7825. bool Client::BindAllowed() {
  7826. ZoneServer* zone = GetCurrentZone();
  7827. if (zone){
  7828. bool canbind = zone->GetCanBind();
  7829. return canbind;
  7830. }
  7831. return false;
  7832. }
  7833. bool Client::Bind() {
  7834. int canbind = BindAllowed();
  7835. if(canbind == 0) {
  7836. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  7837. return false;
  7838. }
  7839. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7840. player->GetPlayerInfo()->SetBindX(player->GetX());
  7841. player->GetPlayerInfo()->SetBindY(player->GetY());
  7842. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7843. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7844. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  7845. return true;
  7846. }
  7847. bool Client::Gate(bool is_spell) {
  7848. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  7849. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  7850. return false;
  7851. }
  7852. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7853. if (zone) {
  7854. int cangate = GateAllowed();
  7855. if(cangate == 0) {
  7856. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  7857. return false;
  7858. }
  7859. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7860. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7861. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7862. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7863. Zone(zone, false, is_spell);
  7864. return true;
  7865. }
  7866. return false;
  7867. }
  7868. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7869. if (!destinations || !spawn) {
  7870. return;
  7871. }
  7872. bool has_map = false;
  7873. if (transport_id > 0)
  7874. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7875. transport_spawn = spawn;
  7876. vector<TransportDestination*> transport_list;
  7877. vector<TransportDestination*>::iterator itr;
  7878. TransportDestination* destination = 0;
  7879. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7880. destination = *itr;
  7881. 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)))
  7882. transport_list.push_back(destination);
  7883. }
  7884. if (transport_list.size() == 0 && destination) {
  7885. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7886. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7887. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7888. else
  7889. {
  7890. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7891. if (app)
  7892. QueuePacket(app);
  7893. }
  7894. }
  7895. else {
  7896. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7897. // determine if this is an instanced zone that already exists
  7898. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7899. if (instance_zone || new_zone) {
  7900. GetPlayer()->SetX(destination->destination_x);
  7901. GetPlayer()->SetY(destination->destination_y);
  7902. GetPlayer()->SetZ(destination->destination_z);
  7903. GetPlayer()->SetHeading(destination->destination_heading);
  7904. if (instance_zone)
  7905. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7906. else
  7907. Zone(new_zone, false, is_spell);
  7908. }
  7909. }
  7910. if (destination->message.length() > 0)
  7911. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7912. }
  7913. else if (transport_list.size() > 0) {
  7914. if (!spawn->IsSoundsDisabled())
  7915. PlaySound("mariner_bell");
  7916. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7917. if (packet) {
  7918. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7919. // Put all the destinations the player can go in a new vector
  7920. vector<TransportDestination*> destinations;
  7921. for (int32 i = 0; i < transport_list.size(); i++) {
  7922. destination = transport_list.at(i);
  7923. // Check min level
  7924. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7925. continue;
  7926. // Check max level
  7927. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7928. continue;
  7929. // Check quest complete
  7930. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7931. continue;
  7932. // Check req quest and step
  7933. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7934. continue;
  7935. // 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
  7936. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7937. packet->setDataByName("current_zone", destination->display_name.c_str());
  7938. packet->setDataByName("current_map_x", destination->map_x);
  7939. packet->setDataByName("current_map_y", destination->map_y);
  7940. }
  7941. else {
  7942. destinations.push_back(destination);
  7943. }
  7944. }
  7945. // Use the new vector to create the packet
  7946. destination = 0;
  7947. packet->setArrayLengthByName("num_destinations", destinations.size());
  7948. for (int32 i = 0; i < destinations.size(); i++) {
  7949. destination = destinations.at(i);
  7950. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7951. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7952. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7953. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7954. packet->setArrayDataByName("cost", destination->cost, i);
  7955. if (has_map) {
  7956. packet->setArrayDataByName("map_x", destination->map_x, i);
  7957. packet->setArrayDataByName("map_y", destination->map_y, i);
  7958. }
  7959. }
  7960. if (has_map)
  7961. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7962. EQ2Packet* app = packet->serialize();
  7963. //DumpPacket(app);
  7964. if (destinations.size() > 0)
  7965. QueuePacket(app);
  7966. safe_delete(packet);
  7967. }
  7968. }
  7969. }
  7970. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7971. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7972. if (packet) {
  7973. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7974. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7975. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7976. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7977. int32 cost = packet->getType_int32_ByName("cost");
  7978. vector<TransportDestination*> destinations;
  7979. TransportDestination* destination = 0;
  7980. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7981. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7982. vector<TransportDestination*>::iterator itr;
  7983. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7984. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7985. destination = *itr;
  7986. break;
  7987. }
  7988. }
  7989. SetTemporaryTransportID(0);
  7990. if (!destination)
  7991. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7992. else {
  7993. if (cost == 0 || player->RemoveCoins(cost)) {
  7994. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7995. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7996. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7997. else
  7998. {
  7999. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8000. if (outapp)
  8001. QueuePacket(outapp);
  8002. }
  8003. }
  8004. else {
  8005. GetPlayer()->SetX(destination->destination_x);
  8006. GetPlayer()->SetY(destination->destination_y);
  8007. GetPlayer()->SetZ(destination->destination_z);
  8008. GetPlayer()->SetHeading(destination->destination_heading);
  8009. // Test if where we're going is an Instanced zone
  8010. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8011. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8012. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8013. Zone(new_zone, false);
  8014. }
  8015. }
  8016. if (destination->message.length() > 0)
  8017. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8018. }
  8019. else
  8020. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8021. }
  8022. }
  8023. safe_delete(packet);
  8024. }
  8025. }
  8026. void Client::SendNewSpells(int8 class_id) {
  8027. if (class_id > 0) {
  8028. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8029. vector<Spell*>::iterator itr;
  8030. Spell* spell = 0;
  8031. bool send_updates = false;
  8032. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8033. spell = *itr;
  8034. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8035. send_updates = true;
  8036. SendSpellUpdate(spell);
  8037. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8038. player->UnlockSpell(spell);
  8039. }
  8040. }
  8041. if (send_updates) {
  8042. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8043. if (outapp)
  8044. QueuePacket(outapp);
  8045. }
  8046. safe_delete(spells);
  8047. }
  8048. }
  8049. void Client::SetItemSearch(vector<Item*>* items) {
  8050. if (items) {
  8051. safe_delete(search_items);
  8052. search_items = items;
  8053. }
  8054. }
  8055. vector<Item*>* Client::GetSearchItems() {
  8056. return search_items;
  8057. }
  8058. void Client::SearchStore(int32 page) {
  8059. if (search_items) {
  8060. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8061. if (packet) {
  8062. int32 x = page * 8;
  8063. if (search_items->size() > 8) {
  8064. if ((search_items->size() - x) > 8)
  8065. packet->setArrayLengthByName("num_items", 8);
  8066. else
  8067. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8068. }
  8069. else
  8070. packet->setArrayLengthByName("num_items", search_items->size());
  8071. if (search_items->size() > 0) {
  8072. packet->setArrayLengthByName("num_sellers", 1);
  8073. packet->setArrayDataByName("seller_seller_id", 1);
  8074. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  8075. packet->setDataByName("per_page", 8);
  8076. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8077. packet->setDataByName("page", page);
  8078. Item* item = 0;
  8079. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8080. for (int32 i = 0; i < limit; i++, x++) {
  8081. if (x >= search_items->size())
  8082. break;
  8083. item = search_items->at(x);
  8084. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8085. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8086. packet->setArrayDataByName("icon", item->details.icon, i);
  8087. //packet->setArrayDataByName("unknown2b", i, i);
  8088. packet->setArrayDataByName("item_seller_id", 1, i);
  8089. if (item->stack_count == 0)
  8090. packet->setArrayDataByName("quantity", 1, i);
  8091. else
  8092. packet->setArrayDataByName("quantity", item->stack_count, i);
  8093. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8094. std::string tmpStr("");
  8095. tmpStr.append(item->name.c_str());
  8096. tmpStr.append(" (");
  8097. tmpStr.append(std::to_string(item->details.item_id));
  8098. tmpStr.append(")");
  8099. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8100. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8101. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8102. }
  8103. }
  8104. /*EQ2Packet* outapp = packet->serialize();
  8105. DumpPacket(outapp);
  8106. QueuePacket(outapp);*/
  8107. QueuePacket(packet->serialize());
  8108. safe_delete(packet);
  8109. }
  8110. }
  8111. }
  8112. void Client::SetReadyForUpdates() {
  8113. GetPlayer()->SetFullyLoggedIn(true);
  8114. if (!ready_for_updates)
  8115. database.loadCharacterProperties(this);
  8116. ready_for_updates = true;
  8117. }
  8118. void Client::SetReadyForSpawns(bool val) {
  8119. ready_for_spawns = val;
  8120. if (GetPlayer()->GetActivityStatus() > 0) {
  8121. GetPlayer()->SetActivityStatus(0);
  8122. if (GetPlayer()->GetGroupMemberInfo()) {
  8123. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8124. }
  8125. }
  8126. GetPlayer()->SetActiveReward(false);
  8127. zone_list.CheckFriendZoned(this);
  8128. }
  8129. void Client::SendChatRelationship(int8 type, const char* name) {
  8130. if (!name) {
  8131. return;
  8132. }
  8133. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8134. if (packet) {
  8135. packet->setDataByName("account_id", GetAccountID());
  8136. packet->setDataByName("type", type);
  8137. packet->setArrayLengthByName("num_names", 1);
  8138. packet->setArrayDataByName("name", name);
  8139. if (type == 0) {
  8140. Client* client = zone_list.GetClientByCharName(name);
  8141. if (client) {
  8142. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8143. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8144. }
  8145. }
  8146. QueuePacket(packet->serialize());
  8147. safe_delete(packet);
  8148. }
  8149. }
  8150. void Client::SendFriendList() {
  8151. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8152. if (packet) {
  8153. packet->setDataByName("account_id", GetAccountID());
  8154. map<string, int8>::iterator itr;
  8155. map<string, int8>* friends = player->GetFriends();
  8156. if (friends && friends->size() > 0) {
  8157. Client* client = 0;
  8158. vector<string> names;
  8159. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8160. if (itr->second == 2)
  8161. continue;
  8162. names.push_back(itr->first);
  8163. }
  8164. packet->setArrayLengthByName("num_names", names.size());
  8165. for (int32 i = 0; i < names.size(); i++) {
  8166. client = zone_list.GetClientByCharName(names[i]);
  8167. packet->setArrayDataByName("name", names[i].c_str(), i);
  8168. if (client) {
  8169. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8170. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8171. }
  8172. }
  8173. }
  8174. QueuePacket(packet->serialize());
  8175. safe_delete(packet);
  8176. }
  8177. }
  8178. void Client::SendIgnoreList() {
  8179. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8180. if (packet) {
  8181. packet->setDataByName("account_id", GetAccountID());
  8182. packet->setDataByName("type", 2);
  8183. map<string, int8>::iterator itr;
  8184. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8185. if (ignored && ignored->size() > 0) {
  8186. vector<string> names;
  8187. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8188. if (itr->second == 2)
  8189. continue;
  8190. names.push_back(itr->first);
  8191. }
  8192. packet->setArrayLengthByName("num_names", names.size());
  8193. for (int32 i = 0; i < names.size(); i++)
  8194. packet->setArrayDataByName("name", names[i].c_str(), i);
  8195. }
  8196. QueuePacket(packet->serialize());
  8197. safe_delete(packet);
  8198. }
  8199. }
  8200. void Client::AddWaypoint(string name, int8 type) {
  8201. waypoint_id++;
  8202. WaypointInfo info;
  8203. info.id = waypoint_id;
  8204. info.type = type;
  8205. waypoints[name] = info;
  8206. }
  8207. void Client::SendWaypoints() {
  8208. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8209. if (packet) {
  8210. packet->setArrayLengthByName("num_updates", waypoints.size());
  8211. map<string, WaypointInfo>::iterator itr;
  8212. int16 i = 0;
  8213. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8214. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8215. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8216. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8217. i++;
  8218. }
  8219. packet->setDataByName("unknown", 0xFFFFFFFF);
  8220. QueuePacket(packet->serialize());
  8221. safe_delete(packet);
  8222. }
  8223. }
  8224. void Client::SelectWaypoint(int32 id) {
  8225. string found_name = "";
  8226. map<string, WaypointInfo>::iterator itr;
  8227. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8228. if (itr->second.id == id) {
  8229. found_name = itr->first;
  8230. break;
  8231. }
  8232. }
  8233. if (found_name.length() > 0) {
  8234. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8235. ShowPathToTarget(spawn);
  8236. }
  8237. }
  8238. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8239. if (waypoint_name) {
  8240. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8241. if (packet) {
  8242. packet->setArrayLengthByName("num_updates", 1);
  8243. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8244. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8245. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8246. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8247. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8248. packet->setDataByName("unknown", 0xFFFFFFFF);
  8249. QueuePacket(packet->serialize());
  8250. safe_delete(packet);
  8251. }
  8252. }
  8253. }
  8254. void Client::ClearWaypoint() {
  8255. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8256. if (packet) {
  8257. QueuePacket(packet->serialize());
  8258. safe_delete(packet);
  8259. }
  8260. }
  8261. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8262. if (current_zone->pathing) {
  8263. if (GetPlayer()->GetMap()) {
  8264. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8265. return false;
  8266. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8267. return false;
  8268. auto loc = glm::vec3(x, z, y);
  8269. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  8270. if (new_z != BEST_Z_INVALID) //this is actually y
  8271. y = new_z;
  8272. }
  8273. bool partial = false;
  8274. bool stuck = false;
  8275. PathfinderOptions opts;
  8276. opts.smooth_path = true;
  8277. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8278. opts.offset = y_offset + 1.0f;
  8279. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8280. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8281. if (packet) {
  8282. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8283. packet->setArrayLengthByName("num_points", path.size());
  8284. int i = 0;
  8285. for (auto& node : path)
  8286. {
  8287. packet->setArrayDataByName("x", node.pos.x, i);
  8288. packet->setArrayDataByName("y", node.pos.z, i);
  8289. packet->setArrayDataByName("z", node.pos.y, i);
  8290. packet->setDataByName("waypoint_x", x);
  8291. packet->setDataByName("waypoint_y", y);
  8292. packet->setDataByName("waypoint_z", z);
  8293. i++;
  8294. }
  8295. if (i > 0)
  8296. QueuePacket(packet->serialize());
  8297. safe_delete(packet);
  8298. return (i > 0);
  8299. }
  8300. }
  8301. return false;
  8302. }
  8303. bool Client::ShowPathToTarget(Spawn* spawn) {
  8304. if (spawn) {
  8305. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  8306. }
  8307. return false;
  8308. }
  8309. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  8310. if (waypoint_name) {
  8311. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8312. if (packet) {
  8313. packet->setArrayLengthByName("num_points", 1);
  8314. packet->setArrayDataByName("x", x, 0);
  8315. packet->setArrayDataByName("y", y, 0);
  8316. packet->setArrayDataByName("z", z, 0);
  8317. packet->setDataByName("waypoint_x", x);
  8318. packet->setDataByName("waypoint_y", y);
  8319. packet->setDataByName("waypoint_z", z);
  8320. packet->setDataByName("waypoint_name", waypoint_name);
  8321. packet->setDataByName("unknown", 0);
  8322. QueuePacket(packet->serialize());
  8323. safe_delete(packet);
  8324. }
  8325. }
  8326. }
  8327. void Client::InspectPlayer(Player* player_to_inspect) {
  8328. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  8329. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  8330. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8331. if(pvp_allowed == true){
  8332. if(source_pvp_alignment != target_pvp_alignment){
  8333. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  8334. return;
  8335. }
  8336. }
  8337. if (player_to_inspect) {
  8338. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  8339. if (packet) {
  8340. packet->setDataByName("unknown", 0);
  8341. packet->setSmallStringByName("name", player_to_inspect->GetName());
  8342. packet->setDataByName("race", player_to_inspect->GetRace());
  8343. packet->setDataByName("gender", player_to_inspect->GetGender());
  8344. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  8345. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  8346. packet->setDataByName("adventure_level_effective", effective_level);
  8347. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  8348. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  8349. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  8350. packet->setDataByName("health", player_to_inspect->GetHP());
  8351. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  8352. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  8353. packet->setDataByName("power", player_to_inspect->GetPower());
  8354. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  8355. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  8356. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  8357. packet->setDataByName("unknown1", 0);
  8358. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  8359. packet->setDataByName("unknown2", 0);
  8360. packet->setDataByName("mitigation_percentage", 0);
  8361. packet->setDataByName("strength", player_to_inspect->GetStr());
  8362. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  8363. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8364. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8365. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8366. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8367. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8368. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8369. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8370. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8371. packet->setDataByName("unknown4", 0);
  8372. packet->setDataByName("unknown5", 0);
  8373. packet->setDataByName("unknown6", 0);
  8374. packet->setDataByName("unknown7", 0);
  8375. packet->setDataByName("unknown8", 0);
  8376. packet->setDataByName("unknown9", 0);
  8377. packet->setDataByName("unknown10", 0);
  8378. packet->setDataByName("unknown11", 0);
  8379. packet->setDataByName("unknown12", 0);
  8380. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8381. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8382. packet->setDataByName("heat_resist_percentage", 0);
  8383. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8384. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8385. packet->setDataByName("cold_resist_percentage", 0);
  8386. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8387. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8388. packet->setDataByName("magic_resist_percentage", 0);
  8389. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8390. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8391. packet->setDataByName("mental_resist_percentage", 0);
  8392. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8393. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8394. packet->setDataByName("divine_resist_percentage", 0);
  8395. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8396. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8397. packet->setDataByName("disease_resist_percentage", 0);
  8398. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8399. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8400. packet->setDataByName("poison_resist_percentage", 0);
  8401. packet->setArrayLengthByName("num_chars", 0x01FF);
  8402. string biography = player_to_inspect->GetBiography();
  8403. for (size_t i = 0; i < biography.length(); i++)
  8404. packet->setArrayDataByName("biography_char", biography[i], i);
  8405. for(int32 s=0;s<NUM_SLOTS;s++) {
  8406. int32 slot = s*2;
  8407. char item_slot_name[64], item_slot_name_appearance[64];
  8408. _snprintf(item_slot_name,64,"slot_%u",slot);
  8409. int32 slot_appearance = (s*2)+1;
  8410. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  8411. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(s);
  8412. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13);
  8413. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  8414. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  8415. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13);
  8416. }
  8417. else {
  8418. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13);
  8419. }
  8420. }
  8421. QueuePacket(packet->serialize());
  8422. safe_delete(packet);
  8423. }
  8424. }
  8425. }
  8426. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8427. pending_guild_invite.guild = guild;
  8428. pending_guild_invite.invited_by = invited_by;
  8429. }
  8430. void Client::ShowClaimWindow() {
  8431. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8432. if (packet) {
  8433. map<int32, Item*>* items = &master_item_list.items;
  8434. map<int32, Item*>::iterator itr;
  8435. int32 i = 0;
  8436. if (items->size() > 10)
  8437. packet->setArrayLengthByName("num_claim_items", 10);
  8438. else
  8439. packet->setArrayLengthByName("num_claim_items", items->size());
  8440. for (itr = items->begin(); itr != items->end(); itr++) {
  8441. if (i == 10)
  8442. break;
  8443. Item* item = itr->second;
  8444. packet->setArrayDataByName("id", i, i);
  8445. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8446. packet->setArrayDataByName("num_remaining", 5, i);
  8447. packet->setArrayDataByName("one_per_character", 1, i);
  8448. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8449. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8450. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8451. packet->setArrayDataByName("category", "Scott's Shit", i);
  8452. packet->setArrayDataByName("icon", item->details.icon, i);
  8453. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8454. i++;
  8455. }
  8456. packet->setDataByName("unknown3", 1);
  8457. QueuePacket(packet->serialize());
  8458. safe_delete(packet);
  8459. }
  8460. }
  8461. void Client::ShowGuildSearchWindow() {
  8462. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8463. if (packet) {
  8464. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8465. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8466. packet->setArrayLengthByName("num_guilds", guilds->size());
  8467. int32 i = 0;
  8468. while (itr.Next()) {
  8469. Guild* guild = itr.second;
  8470. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8471. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8472. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8473. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8474. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8475. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8476. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8477. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8478. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8479. packet->setArrayDataByName("unknown7", 0x02, i);
  8480. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8481. i++;
  8482. }
  8483. QueuePacket(packet->serialize());
  8484. safe_delete(packet);
  8485. }
  8486. }
  8487. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8488. PacketStruct* packet;
  8489. vector<int8>* slot_data;
  8490. vector<int8>::iterator itr;
  8491. int32 slots = 0;
  8492. assert(item);
  8493. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8494. return;
  8495. }
  8496. slot_data = &item->slot_data;
  8497. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8498. if (version >= 1188)
  8499. slots = *itr;
  8500. else
  8501. slots += (int8)pow(2.0, *itr);
  8502. }
  8503. packet->setDataByName("slot", slots);
  8504. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8505. if (slots == 2) {
  8506. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8507. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8508. }
  8509. else {
  8510. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8511. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8512. }
  8513. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8514. if (slots == 4) {
  8515. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8516. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8517. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8518. }
  8519. else if (slots == 7) {
  8520. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8521. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8522. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8523. }
  8524. else {
  8525. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8526. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8527. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8528. }
  8529. packet->setDataByName("icon", item->details.icon);
  8530. packet->setDataByName("item_id", item->details.item_id);
  8531. packet->setDataByName("item_crc", crc);
  8532. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8533. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8534. packet->setDataByName("unknown5", 0xFF, 9);
  8535. packet->setDataByName("unknown5", 0xFF, 10);
  8536. QueuePacket(packet->serialize());
  8537. safe_delete(packet);
  8538. }
  8539. void Client::SendCollectionList() {
  8540. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8541. map<int32, Collection*>::iterator itr;
  8542. vector<struct CollectionItem*>* collection_items;
  8543. Collection* collection;
  8544. struct CollectionItem* collection_item;
  8545. PacketStruct* packet = 0;
  8546. int16 i = 0, j;
  8547. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8548. return;
  8549. packet->setArrayLengthByName("num_collections", collections->size());
  8550. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8551. collection = itr->second;
  8552. collection_items = collection->GetCollectionItems();
  8553. packet->setArrayDataByName("unknown", 1, i);
  8554. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8555. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8556. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8557. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8558. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8559. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8560. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8561. for (j = 0; j < collection_items->size(); j++) {
  8562. collection_item = collection_items->at(j);
  8563. Item* item = master_item_list.GetItem(collection_item->item);
  8564. if (item) {
  8565. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8566. if (version < 955)
  8567. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8568. else
  8569. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8570. }
  8571. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8572. }
  8573. i++;
  8574. }
  8575. packet->setDataByName("new_collection_flag", 1);
  8576. QueuePacket(packet->serialize());
  8577. safe_delete(packet);
  8578. }
  8579. bool Client::SendCollectionsForItem(Item* item) {
  8580. map<int32, Collection*> collections_to_send;
  8581. map<int32, Collection*>* collections;
  8582. map<int32, Collection*>::iterator itr;
  8583. vector<struct CollectionItem*>* collection_items;
  8584. Collection* collection;
  8585. struct CollectionItem* collection_item;
  8586. PacketStruct* packet;
  8587. int16 i;
  8588. assert(item);
  8589. /* get any collections required by this item that the player already has */
  8590. collections = player->GetCollectionList()->GetCollections();
  8591. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8592. collection = itr->second;
  8593. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8594. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8595. collections_to_send[collection->GetID()] = collection;
  8596. }
  8597. }
  8598. /* get any collections required by this item that the player does not have and send it to the client */
  8599. collections = master_collection_list.GetCollections();
  8600. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8601. collection = itr->second;
  8602. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8603. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8604. return false;
  8605. }
  8606. packet->setArrayLengthByName("num_collections", 1);
  8607. packet->setArrayDataByName("unknown", 1, 0);
  8608. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8609. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8610. packet->setArrayDataByName("completed", 0, 0);
  8611. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8612. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8613. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8614. packet->setArrayDataByName("unknown3", 0x28, 0);
  8615. collection_items = collection->GetCollectionItems();
  8616. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8617. for (i = 0; i < collection_items->size(); i++) {
  8618. collection_item = collection_items->at(i);
  8619. Item* item2 = master_item_list.GetItem(collection_item->item);
  8620. if (item2) {
  8621. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8622. if (version < 955)
  8623. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8624. else
  8625. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8626. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8627. }
  8628. }
  8629. packet->setDataByName("new_collection_flag", 0);
  8630. QueuePacket(packet->serialize());
  8631. safe_delete(packet);
  8632. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8633. collections_to_send[collection->GetID()] = collection;
  8634. }
  8635. }
  8636. /* send the client a list of collections that should be filtered for this item */
  8637. if (collections_to_send.size() > 0) {
  8638. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8639. return false;
  8640. }
  8641. i = 0;
  8642. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8643. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8644. collection = itr->second;
  8645. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8646. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8647. i++;
  8648. }
  8649. packet->setDataByName("item_icon", item->details.icon);
  8650. packet->setDataByName("item_name", item->name.c_str());
  8651. packet->setDataByName("item_id", item->details.item_id);
  8652. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8653. QueuePacket(packet->serialize());
  8654. safe_delete(packet);
  8655. }
  8656. return collections_to_send.size() > 0;
  8657. }
  8658. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8659. Collection* collection;
  8660. struct CollectionItem* collection_item;
  8661. PacketStruct* packet;
  8662. char tmp[200] = { 0 };
  8663. assert(item);
  8664. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8665. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8666. /* get the item struct that represents the item for this collection */
  8667. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8668. SendCollectionList();
  8669. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8670. return;
  8671. }
  8672. /* sanity check */
  8673. if (collection_item->found) {
  8674. SendCollectionList();
  8675. 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());
  8676. return;
  8677. }
  8678. }
  8679. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8680. collection = new Collection(collection);
  8681. /* get the item struct that represents the item for this collection */
  8682. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8683. SendCollectionList();
  8684. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8685. safe_delete(collection);
  8686. return;
  8687. }
  8688. /* add the new collection to the player's collection list */
  8689. if (!player->GetCollectionList()->AddCollection(collection)) {
  8690. SendCollectionList();
  8691. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8692. safe_delete(collection);
  8693. return;
  8694. }
  8695. }
  8696. else {
  8697. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8698. return;
  8699. }
  8700. collection_item->found = 1;
  8701. collection->SetSaveNeeded(true);
  8702. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8703. SendCollectionList();
  8704. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8705. return;
  8706. }
  8707. packet->setDataByName("collection_id", collection_id);
  8708. packet->setDataByName("collection_item_num", collection_item->index);
  8709. packet->setDataByName("add", 1);
  8710. QueuePacket(packet->serialize());
  8711. Item* item2 = master_item_list.GetItem(collection_item->item);
  8712. if (item2) {
  8713. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8714. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8715. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8716. }
  8717. safe_delete(packet);
  8718. RemoveItem(item, 1);
  8719. SendCollectionList();
  8720. }
  8721. void Client::DisplayCollectionComplete(Collection* collection) {
  8722. vector<struct CollectionRewardItem*>* reward_items;
  8723. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8724. struct CollectionRewardItem* reward_item;
  8725. PacketStruct* packet;
  8726. int32 i;
  8727. assert(collection);
  8728. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8729. return;
  8730. }
  8731. reward_items = collection->GetRewardItems();
  8732. selectable_reward_items = collection->GetSelectableRewardItems();
  8733. packet->setDataByName("title", "Quest Reward!");
  8734. packet->setDataByName("name", collection->GetName());
  8735. packet->setDataByName("description", collection->GetCategory());
  8736. packet->setDataByName("level", collection->GetLevel());
  8737. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8738. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8739. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8740. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8741. for (i = 0; i < reward_items->size(); i++) {
  8742. reward_item = reward_items->at(i);
  8743. if(!reward_item->item)
  8744. {
  8745. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8746. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8747. continue;
  8748. }
  8749. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8750. if (version < 860)
  8751. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8752. else if (version < 1193)
  8753. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8754. else
  8755. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8756. }
  8757. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8758. for (i = 0; i < selectable_reward_items->size(); i++) {
  8759. reward_item = selectable_reward_items->at(i);
  8760. if(!reward_item->item)
  8761. {
  8762. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8763. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8764. continue;
  8765. }
  8766. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8767. if (version < 860)
  8768. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8769. else if (version < 1193)
  8770. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8771. else
  8772. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8773. }
  8774. QueuePacket(packet->serialize());
  8775. safe_delete(packet);
  8776. }
  8777. void Client::HandInCollections() {
  8778. map<int32, Collection*>* collections;
  8779. map<int32, Collection*>::iterator itr;
  8780. Collection* collection;
  8781. /* only show 1 collection reward dialog at a time */
  8782. if (player->GetPendingCollectionReward()) {
  8783. return;
  8784. }
  8785. collections = player->GetCollectionList()->GetCollections();
  8786. /* 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
  8787. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8788. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8789. collection = itr->second;
  8790. if (collection->GetIsReadyToTurnIn()) {
  8791. player->SetPendingCollectionReward(collection);
  8792. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  8793. QuestRewardData* data = new QuestRewardData;
  8794. data->quest_id = 0;
  8795. data->is_temporary = false;
  8796. data->description = std::string("");
  8797. data->is_collection = true;
  8798. data->has_displayed = false;
  8799. data->tmp_coin = 0;
  8800. data->tmp_status = 0;
  8801. data->db_saved = false;
  8802. data->db_index = 0;
  8803. quest_pending_reward.push_back(data);
  8804. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  8805. quest_updates = true;
  8806. break;
  8807. }
  8808. }
  8809. if(quest_updates) {
  8810. SaveQuestRewardData(true);
  8811. }
  8812. }
  8813. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8814. vector<struct CollectionRewardItem*>* reward_items;
  8815. vector<struct CollectionRewardItem*>::iterator itr;
  8816. struct CollectionRewardItem* reward_item;
  8817. int16 num_slots_needed;
  8818. int16 num_slots;
  8819. assert(collection);
  8820. reward_items = collection->GetRewardItems();
  8821. num_slots_needed = (int16)reward_items->size();
  8822. if (selectable_item_id > 0)
  8823. num_slots_needed++;
  8824. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8825. if (num_slots < num_slots_needed) {
  8826. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8827. DisplayCollectionComplete(collection);
  8828. return;
  8829. }
  8830. /* add manditory items */
  8831. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8832. reward_item = *itr;
  8833. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8834. }
  8835. /* find and add the selectable item if there's one */
  8836. if (selectable_item_id > 0) {
  8837. reward_items = collection->GetSelectableRewardItems();
  8838. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8839. reward_item = *itr;
  8840. if (reward_item->item->details.item_id == selectable_item_id) {
  8841. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8842. break;
  8843. }
  8844. }
  8845. }
  8846. if (collection->GetRewardXP() > 0) {
  8847. player->AddXP((int32)collection->GetRewardXP());
  8848. }
  8849. if (collection->GetRewardCoin() > 0) {
  8850. player->AddCoins(collection->GetRewardCoin());
  8851. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8852. }
  8853. collection->SetCompleted(true);
  8854. //update achievements for completeing collection here
  8855. collection->SetSaveNeeded(true);
  8856. SendCollectionList();
  8857. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8858. player->SetPendingCollectionReward(0);
  8859. RemoveQueuedQuestReward();
  8860. GetPlayer()->SetActiveReward(false);
  8861. HandInCollections();
  8862. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  8863. }
  8864. void Client::SendRecipeList() {
  8865. PacketStruct* packet = 0;
  8866. if (GetRecipeListSent()) {
  8867. return;
  8868. }
  8869. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8870. return;
  8871. }
  8872. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8873. map<int32, Recipe*>::iterator itr;
  8874. Recipe* recipe;
  8875. int16 i = 0;
  8876. int index = 0;
  8877. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8878. recipe = itr->second;
  8879. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  8880. if (res != devices.end())
  8881. index = res - devices.begin();
  8882. else
  8883. devices.push_back(recipe->GetDevice());
  8884. }
  8885. packet->setArrayLengthByName("num_recipes", recipes->size());
  8886. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8887. recipe = itr->second;
  8888. packet->setArrayDataByName("id", recipe->GetID(), i);
  8889. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8890. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8891. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8892. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8893. //packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8894. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8895. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8896. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  8897. if (recipe_device != devices.end())
  8898. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  8899. else
  8900. {//TODO error should never get here
  8901. }
  8902. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  8903. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8904. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8905. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8906. i++;
  8907. }
  8908. //packet->PrintPacket();
  8909. //DumpPacket(packet->serialize());
  8910. QueuePacket(packet->serialize());
  8911. safe_delete(packet);
  8912. SetRecipeListSent(true);
  8913. }
  8914. void Client::ShowRecipeBook() {
  8915. PacketStruct* packet = 0;
  8916. Spawn* target = 0;
  8917. int index = 0;
  8918. if (!(target = player->GetTarget())) {
  8919. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8920. return;
  8921. }
  8922. if (!target->IsObject()) {
  8923. return;
  8924. }
  8925. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8926. return;
  8927. }
  8928. packet->setDataByName("device", target->GetName());
  8929. packet->setDataByName("unknown1", 1);
  8930. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  8931. if (res != devices.end()){
  8932. index = res - devices.begin();
  8933. int32 deviceID = 0;
  8934. deviceID |= 1UL << index;
  8935. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8936. packet->setDataByName("unknown2", devices.size());
  8937. packet->setDataByName("unknown3", deviceID);
  8938. }
  8939. else
  8940. packet->setDataByName("unknown2", devices.size());
  8941. QueuePacket(packet->serialize());
  8942. safe_delete(packet);
  8943. }
  8944. void Client::SendTitleUpdate() {
  8945. // must call release read lock before leaving function on GetPlayerTitles
  8946. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8947. vector<Title*>::iterator itr;
  8948. Title* title;
  8949. sint32 i = 0;
  8950. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8951. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8952. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8953. if (packet) {
  8954. packet->setArrayLengthByName("num_titles", titles->size());
  8955. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8956. title = *itr;
  8957. packet->setArrayDataByName("title", title->GetName(), i);
  8958. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8959. i++;
  8960. }
  8961. packet->setDataByName("current_prefix", prefix_index);
  8962. packet->setDataByName("current_suffix", suffix_index);
  8963. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8964. #if EQDEBUG >= 9
  8965. packet->PrintPacket();
  8966. #endif
  8967. QueuePacket(packet->serialize());
  8968. safe_delete(packet);
  8969. SendUpdateTitles(prefix_index, suffix_index);
  8970. }
  8971. player->GetPlayerTitles()->ReleaseReadLock();
  8972. }
  8973. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8974. Title* suffix_title = 0;
  8975. Title* prefix_title = 0;
  8976. if (suffix != -1) {
  8977. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8978. if(suffix_title)
  8979. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8980. }
  8981. else
  8982. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8983. if (prefix != -1) {
  8984. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8985. if(prefix_title)
  8986. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8987. }
  8988. else
  8989. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8990. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8991. }
  8992. void Client::SendLanguagesUpdate(int32 id) {
  8993. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8994. list<Language*>::iterator itr;
  8995. Language* language;
  8996. int32 i = 0;
  8997. GetPlayer()->SetCurrentLanguage(id);
  8998. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8999. if (packet) {
  9000. packet->setArrayLengthByName("num_languages", languages->size());
  9001. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9002. language = *itr;
  9003. packet->setArrayDataByName("language_id", language->GetID(), i);
  9004. i++;
  9005. }
  9006. packet->setDataByName("current_language", id);
  9007. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9008. #if EQDEBUG >= 9
  9009. packet->PrintPacket();
  9010. #endif
  9011. QueuePacket(packet->serialize());
  9012. safe_delete(packet);
  9013. }
  9014. }
  9015. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  9016. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  9017. if (packet) {
  9018. if (pet_name)
  9019. packet->setDataByName("pet_name", pet_name);
  9020. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  9021. packet->setDataByName("protect_master", 1);
  9022. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  9023. packet->setDataByName("protect_self", 1);
  9024. if (player->GetInfoStruct()->get_pet_movement() == 2)
  9025. packet->setDataByName("stay_follow_toggle", 1);
  9026. packet->setDataByName("pet_type", type);
  9027. QueuePacket(packet->serialize());
  9028. }
  9029. safe_delete(packet);
  9030. }
  9031. bool Client::IsCrafting() {
  9032. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  9033. }
  9034. void Client::SendBiography() {
  9035. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  9036. if (packet) {
  9037. char biography[512];
  9038. if(player->GetInfoStruct()->get_biography().size() < 1)
  9039. {
  9040. safe_delete(packet);
  9041. return;
  9042. }
  9043. else
  9044. {
  9045. int16 size = player->GetInfoStruct()->get_biography().size();
  9046. if(size>511)
  9047. size = 511;
  9048. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  9049. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  9050. }
  9051. packet->setDataByName("biography", biography);
  9052. QueuePacket(packet->serialize());
  9053. }
  9054. safe_delete(packet);
  9055. }
  9056. PendingResurrection* Client::GetCurrentRez() {
  9057. return &current_rez;
  9058. }
  9059. Mutex* Client::GetResurrectMutex() {
  9060. return &m_resurrect;
  9061. }
  9062. void Client::SendResurrectionWindow() {
  9063. Spawn* caster = current_rez.caster;
  9064. if (!caster || !player)
  9065. return;
  9066. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9067. if (!packet)
  9068. return;
  9069. char* tmp = new char[512];
  9070. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  9071. packet->setMediumStringByName("text", tmp);
  9072. packet->setMediumStringByName("accept_text", "Yes");
  9073. packet->setMediumStringByName("cancel_text", "No");
  9074. sprintf(tmp, "accept_resurrection %u", player->GetID());
  9075. packet->setMediumStringByName("accept_command", tmp);
  9076. sprintf(tmp, "decline_resurrection %u", player->GetID());
  9077. packet->setMediumStringByName("cancel_command", tmp);
  9078. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  9079. QueuePacket(packet->serialize());
  9080. safe_delete(packet);
  9081. safe_delete_array(tmp);
  9082. }
  9083. void Client::AcceptResurrection() {
  9084. Spawn* caster = current_rez.caster;
  9085. if (!player || !caster)
  9086. return;
  9087. if (player->Alive())
  9088. return;
  9089. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9090. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9091. SendResurrectionWindow();
  9092. return;
  9093. }
  9094. player->GetZone()->ResurrectSpawn(player, this);
  9095. current_rez.should_delete = true;
  9096. }
  9097. void Client::SetPendingLastName(string last_name) {
  9098. pending_last_name = new string;
  9099. pending_last_name->assign(last_name);
  9100. }
  9101. string* Client::GetPendingLastName() {
  9102. return pending_last_name;
  9103. }
  9104. void Client::RemovePendingLastName() {
  9105. safe_delete(pending_last_name);
  9106. }
  9107. void Client::SendLastNameConfirmation() {
  9108. if (!pending_last_name)
  9109. return;
  9110. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9111. if (packet) {
  9112. char* text = new char[128];
  9113. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9114. packet->setDataByName("text", text);
  9115. packet->setDataByName("accept_text", "Yes");
  9116. packet->setDataByName("accept_command", "confirmedlastname");
  9117. packet->setDataByName("cancel_text", "No");
  9118. packet->setDataByName("max_length", 50);
  9119. packet->setDataByName("unknown4", 1);
  9120. packet->setDataByName("unknown5", 1);
  9121. QueuePacket(packet->serialize());
  9122. safe_delete(packet);
  9123. safe_delete_array(text);
  9124. }
  9125. }
  9126. void Client::AddQuestTimer(int32 quest_id) {
  9127. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9128. quest_timers.push_back(quest_id);
  9129. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9130. }
  9131. void Client::RemoveQuestTimer(int32 quest_id) {
  9132. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9133. vector<int32>::iterator itr;
  9134. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9135. if ((*itr) == quest_id) {
  9136. quest_timers.erase(itr);
  9137. break;
  9138. }
  9139. }
  9140. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9141. }
  9142. void Client::SavePlayerImages() {
  9143. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9144. // Save the paperdoll image if the server allows it
  9145. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9146. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9147. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9148. // Save the head shot if the server allows it
  9149. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9150. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9151. // Send the head shot to the login server
  9152. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9153. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9154. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9155. memset(packet->pBuffer, 0, size);
  9156. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9157. pic->account_id = GetAccountID();
  9158. pic->char_id = GetCharacterID();
  9159. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9160. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9161. loginserver.SendPacket(packet);
  9162. safe_delete(packet);
  9163. }
  9164. }
  9165. safe_delete_array(incoming_paperdoll.image_bytes);
  9166. incoming_paperdoll.current_size_bytes = 0;
  9167. }
  9168. void Client::EndAutoMount() {
  9169. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9170. if (packet) {
  9171. packet->setDataByName("parameter1", 128);
  9172. packet->setDataByName("parameter2", 64);
  9173. packet->setDataByName("value", 1);
  9174. QueuePacket(packet->serialize());
  9175. safe_delete(packet);
  9176. }
  9177. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9178. if (packet) {
  9179. packet->setDataByName("parameter3", 4);
  9180. packet->setDataByName("parameter5", 2);
  9181. packet->setDataByName("value", 0);
  9182. QueuePacket(packet->serialize());
  9183. safe_delete(packet);
  9184. }
  9185. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9186. if (packet) {
  9187. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  9188. QueuePacket(packet->serialize());
  9189. safe_delete(packet);
  9190. }
  9191. on_auto_mount = false;
  9192. player->SetMount(((Player*)player)->GetTempMount());
  9193. EQ2_Color mount_color = player->GetTempMountColor();
  9194. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  9195. player->SetMountColor(&mount_color);
  9196. player->SetMountSaddleColor(&saddle_color);
  9197. player->SetTempMount(0);
  9198. }
  9199. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  9200. const char* spawn_script = spawn->GetSpawnScript();
  9201. bool should_use_spawn = true;
  9202. if (spawn_script) {
  9203. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  9204. if (state) {
  9205. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  9206. if (state_mutex)
  9207. state_mutex->writelock(__FUNCTION__, __LINE__);
  9208. lua_getglobal(state, "can_use_command");
  9209. if (lua_isfunction(state, -1)) {
  9210. lua_interface->SetSpawnValue(state, spawn);
  9211. lua_interface->SetSpawnValue(state, GetPlayer());
  9212. lua_interface->SetStringValue(state, command ? command : "");
  9213. if (lua_pcall(state, 3, 1, 0) == 0) {
  9214. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  9215. }
  9216. }
  9217. lua_interface->ResetFunctionStack(state);
  9218. if (state_mutex)
  9219. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  9220. }
  9221. }
  9222. return should_use_spawn;
  9223. }
  9224. bool Client::IsCurrentTransmuteID(int32 req_id) {
  9225. return req_id == transmuteID;
  9226. }
  9227. void Client::SetTransmuteID(int32 trans_id) {
  9228. transmuteID = trans_id;
  9229. }
  9230. int32 Client::GetTransmuteID() {
  9231. return transmuteID;
  9232. }
  9233. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  9234. {
  9235. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  9236. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  9237. if (zar)
  9238. {
  9239. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  9240. if (database.IsActiveQuery(charID))
  9241. {
  9242. delayedLogin = true;
  9243. delayedAccountID = account_id;
  9244. delayedAccessKey = access_code;
  9245. delayTimer.Start(500);
  9246. 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);
  9247. return true;
  9248. }
  9249. delayedLogin = false;
  9250. delayTimer.Disable();
  9251. firstlogin = zar->isFirstLogin();
  9252. 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);
  9253. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  9254. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  9255. GetPlayer()->vis_changed = false;
  9256. GetPlayer()->info_changed = false;
  9257. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9258. if (pvp_allowed)
  9259. this->GetPlayer()->SetAttackable(1);
  9260. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  9261. Client* client = zone_list.GetClientByCharName(player->GetName());
  9262. if (client) {
  9263. if (client->getConnection())
  9264. client->getConnection()->SendDisconnect(true);
  9265. if (client->GetCurrentZone() && !client->IsZoning()) {
  9266. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  9267. if (client->GetVersion() == version) {
  9268. client->DisableSave();
  9269. client->ReplaceGroupClient(this);
  9270. Player* current_player = GetPlayer();
  9271. SetPlayer(client->GetPlayer());
  9272. GetPlayer()->SetClient(this);
  9273. GetPlayer()->SetReturningFromLD(true);
  9274. SetCurrentZone(GetPlayer()->GetZone());
  9275. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  9276. client->SetPlayer(current_player);
  9277. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  9278. GetPlayer()->ResetSavedSpawns();
  9279. }
  9280. ZoneServer* tmpZone = client->GetCurrentZone();
  9281. tmpZone->RemoveClientImmediately(client);
  9282. }
  9283. }
  9284. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  9285. if (!GetCurrentZone()) {
  9286. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  9287. ClientPacketFunctions::SendLoginDenied(this);
  9288. }
  9289. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  9290. getConnection()->SetClientVersion(version);
  9291. GetCurrentZone()->SetSpawnStructs(this);
  9292. connected_to_zone = true;
  9293. client_list.Remove(this); //remove from master client list
  9294. GetCurrentZone()->AddClient(this); //add to zones client list
  9295. zone_list.AddClientToMap(player->GetName(), this);
  9296. // this initiates additional DB loading and client offloading within the Zone the player resides, need the client already added in zone and to the map above.
  9297. new_client_login = true;
  9298. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  9299. if (zone_script && lua_interface)
  9300. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  9301. }
  9302. else {
  9303. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  9304. ClientPacketFunctions::SendLoginDenied(this);
  9305. return false;
  9306. }
  9307. }
  9308. else {
  9309. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  9310. ClientPacketFunctions::SendLoginDenied(this);
  9311. }
  9312. zone_auth.RemoveAuth(zar);
  9313. }
  9314. else
  9315. {
  9316. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  9317. Disconnect();
  9318. }
  9319. return true;
  9320. }
  9321. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  9322. if (!IsReadyForUpdates())
  9323. return;
  9324. map<int32, SpawnData> info_changes;
  9325. map<int32, SpawnData> pos_changes;
  9326. map<int32, SpawnData> vis_changes;
  9327. map<int32, SpawnData> empty_changes;
  9328. int32 info_size = 0;
  9329. int32 pos_size = 0;
  9330. int32 vis_size = 0;
  9331. int count = 0;
  9332. for (const auto& spawn : spawns) {
  9333. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  9334. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  9335. continue;
  9336. if (spawn->vis_changed)
  9337. {
  9338. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9339. if (vis_change) {
  9340. SpawnData data;
  9341. data.spawn = spawn;
  9342. data.data = vis_change;
  9343. data.size = spawn->vis_packet_size;
  9344. map<int32, SpawnData> tmp_vis_changes;
  9345. tmp_vis_changes[index] = data;
  9346. map<int32, SpawnData> tmp_info_changes;
  9347. map<int32, SpawnData> tmp_pos_changes;
  9348. int32 tmp_info_size = 0;
  9349. int32 tmp_pos_size = 0;
  9350. if (spawn->info_changed) {
  9351. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9352. if (info_change) {
  9353. SpawnData data;
  9354. data.spawn = spawn;
  9355. data.data = info_change;
  9356. data.size = spawn->info_packet_size;
  9357. tmp_info_size = data.size;
  9358. tmp_info_changes[index] = data;
  9359. }
  9360. }
  9361. if (spawn->position_changed) {
  9362. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9363. if (pos_change) {
  9364. SpawnData data;
  9365. data.spawn = spawn;
  9366. data.data = pos_change;
  9367. data.size = spawn->pos_packet_size;
  9368. tmp_pos_size = data.size;
  9369. tmp_pos_changes[index] = data;
  9370. }
  9371. }
  9372. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  9373. for (auto& kv : tmp_info_changes) {
  9374. safe_delete_array(kv.second.data);
  9375. }
  9376. for (auto& kv : tmp_pos_changes) {
  9377. safe_delete_array(kv.second.data);
  9378. }
  9379. for (auto& kv : tmp_vis_changes) {
  9380. safe_delete_array(kv.second.data);
  9381. }
  9382. continue;
  9383. }
  9384. }
  9385. if (spawn->info_changed) {
  9386. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9387. if (info_change) {
  9388. SpawnData data;
  9389. data.spawn = spawn;
  9390. data.data = info_change;
  9391. data.size = spawn->info_packet_size;
  9392. info_size += spawn->info_packet_size;
  9393. info_changes[index] = data;
  9394. }
  9395. count++;
  9396. }
  9397. if (spawn->position_changed) {
  9398. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9399. if (pos_change) {
  9400. SpawnData data;
  9401. data.spawn = spawn;
  9402. data.data = pos_change;
  9403. data.size = spawn->pos_packet_size;
  9404. pos_size += spawn->pos_packet_size;
  9405. pos_changes[index] = data;
  9406. }
  9407. count++;
  9408. }
  9409. if (spawn->vis_changed) {
  9410. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9411. if (vis_change) {
  9412. SpawnData data;
  9413. data.spawn = spawn;
  9414. data.data = vis_change;
  9415. data.size = spawn->vis_packet_size;
  9416. vis_size += spawn->vis_packet_size;
  9417. vis_changes[index] = data;
  9418. }
  9419. count++;
  9420. }
  9421. }
  9422. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9423. return;
  9424. }
  9425. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9426. for (auto& kv : info_changes) {
  9427. safe_delete_array(kv.second.data);
  9428. }
  9429. for (auto& kv : pos_changes) {
  9430. safe_delete_array(kv.second.data);
  9431. }
  9432. for (auto& kv : vis_changes) {
  9433. safe_delete_array(kv.second.data);
  9434. }
  9435. }
  9436. 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)
  9437. {
  9438. static const int8 oversized = 255;
  9439. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9440. int32 size = info_size + pos_size + vis_size + 8;
  9441. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9442. size += 3;
  9443. size += CheckOverLoadSize(info_size);
  9444. size += CheckOverLoadSize(pos_size);
  9445. size += CheckOverLoadSize(vis_size);
  9446. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9447. size += 2;
  9448. }
  9449. uchar* tmp = new uchar[size];
  9450. uchar* ptr = tmp;
  9451. memset(tmp, 0, size);
  9452. if (version <= 283) {
  9453. if (size >= 255) {
  9454. size -= 3;
  9455. memcpy(ptr, &oversized, sizeof(int8));
  9456. ptr += sizeof(int8);
  9457. memcpy(ptr, &size, sizeof(int16));
  9458. ptr += sizeof(int16);
  9459. size += 3;
  9460. }
  9461. else {
  9462. size -= 1;
  9463. memcpy(ptr, &size, sizeof(int8));
  9464. ptr += sizeof(int8);
  9465. size += 1;
  9466. }
  9467. }
  9468. else {
  9469. size -= 4;
  9470. memcpy(ptr, &size, sizeof(int32));
  9471. ptr += sizeof(int32);
  9472. size += 4;
  9473. }
  9474. memcpy(ptr, &oversized, sizeof(int8));
  9475. ptr += sizeof(int8);
  9476. memcpy(ptr, &opcode_val, sizeof(int16));
  9477. ptr += sizeof(int16);
  9478. int32 current_time = Timer::GetCurrentTime2();
  9479. memcpy(ptr, &current_time, sizeof(int32));
  9480. ptr += sizeof(int32);
  9481. ptr += DoOverLoad(info_size, ptr);
  9482. for (const auto& kv : info_changes) {
  9483. auto info = kv.second;
  9484. memcpy(ptr, info.data, info.size);
  9485. ptr += info.size;
  9486. }
  9487. ptr += DoOverLoad(pos_size, ptr);
  9488. for (const auto& kv : pos_changes) {
  9489. auto pos = kv.second;
  9490. memcpy(ptr, pos.data, pos.size);
  9491. ptr += pos.size;
  9492. }
  9493. ptr += DoOverLoad(vis_size, ptr);
  9494. for (const auto& kv : vis_changes) {
  9495. auto vis = kv.second;
  9496. memcpy(ptr, vis.data, vis.size);
  9497. ptr += vis.size;
  9498. }
  9499. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9500. if (packet) {
  9501. /*char blah[64];
  9502. snprintf(blah, 64, "Sending %i", current_time);
  9503. SimpleMessage(4, blah);*/
  9504. QueuePacket(packet);
  9505. }
  9506. delete[] tmp;
  9507. }
  9508. void Client::SendHailCommand(Spawn* spawn)
  9509. {
  9510. // hardcoded 'hail' entity commands
  9511. switch (spawn->secondary_command_list_id)
  9512. {
  9513. case 9:
  9514. case 1262:
  9515. case 1265:
  9516. case 1267:
  9517. {
  9518. EQ2_16BitString* command = new EQ2_16BitString();
  9519. command->data = "";
  9520. command->size = 0;
  9521. commands.Process(COMMAND_HAIL, command, this, spawn);
  9522. safe_delete(command);
  9523. break;
  9524. }
  9525. }
  9526. }
  9527. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9528. {
  9529. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9530. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9531. if (packet) {
  9532. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9533. packet->setMediumStringByName("command_name", command);
  9534. packet->setDataByName("distance", distance);
  9535. QueuePacket(packet->serialize());
  9536. safe_delete(packet);
  9537. }
  9538. }
  9539. }
  9540. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9541. {
  9542. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9543. return false;
  9544. if (command == "house_spawn_examine")
  9545. {
  9546. uint32 itemID = spawn->GetPickupItemID();
  9547. if (itemID)
  9548. {
  9549. Item* item = master_item_list.GetItem(itemID);
  9550. if (item)
  9551. {
  9552. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9553. //DumpPacket(app);
  9554. QueuePacket(app);
  9555. }
  9556. }
  9557. return true;
  9558. }
  9559. return false;
  9560. }
  9561. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9562. {
  9563. if (GetTempPlacementSpawn())
  9564. {
  9565. Spawn* tmp = GetTempPlacementSpawn();
  9566. int32 spawn_group_id = database.GetNextSpawnLocation();
  9567. tmp->SetSpawnLocationID(spawn_group_id);
  9568. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9569. int32 spawnDBID = 0;
  9570. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9571. {
  9572. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9573. tmp->SetDatabaseID(spawnDBID);
  9574. }
  9575. else
  9576. {
  9577. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9578. if (spawnDBID)
  9579. {
  9580. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9581. tmp->SetDatabaseID(spawnDBID);
  9582. }
  9583. }
  9584. tmp->SetX(place_object->getType_float_ByName("x"));
  9585. tmp->SetY(place_object->getType_float_ByName("y"));
  9586. tmp->SetZ(place_object->getType_float_ByName("z"));
  9587. tmp->SetHeading(newHeading);
  9588. tmp->SetSpawnOrigX(tmp->GetX());
  9589. tmp->SetSpawnOrigY(tmp->GetY());
  9590. tmp->SetSpawnOrigZ(tmp->GetZ());
  9591. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9592. database.SaveSpawnInfo(tmp);
  9593. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9594. if (!spawnDBID)
  9595. {
  9596. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9597. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  9598. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  9599. }
  9600. return true;
  9601. }
  9602. return false;
  9603. }
  9604. bool Client::PopulateHouseSpawnFinalize()
  9605. {
  9606. if (GetTempPlacementSpawn())
  9607. {
  9608. Spawn* tmp = GetTempPlacementSpawn();
  9609. GetCurrentZone()->AddSpawn(tmp);
  9610. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9611. SetTempPlacementSpawn(nullptr);
  9612. int32 uniqueID = GetPlacementUniqueItemID();
  9613. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9614. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9615. tmp->SetPickupUniqueItemID(uniqueID);
  9616. if (uniqueItem)
  9617. {
  9618. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9619. {
  9620. Query query;
  9621. 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);
  9622. }
  9623. if(uniqueItem->GetItemScript() &&
  9624. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  9625. {
  9626. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9627. }
  9628. if(uniqueItem) {
  9629. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9630. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9631. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9632. }
  9633. SetPlacementUniqueItemID(0);
  9634. }
  9635. return true;
  9636. }
  9637. return false;
  9638. }
  9639. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9640. {
  9641. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9642. packet->setDataByName("placement_mode", placementMode);
  9643. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9644. packet->setDataByName("model_type", spawn->GetModelType());
  9645. packet->setDataByName("unknown", 1); //size
  9646. packet->setDataByName("unknown2", 1); //size 2
  9647. packet->setDataByName("unknown2", .5, 1); //size 3
  9648. packet->setDataByName("unknown2", 3, 2);
  9649. packet->setDataByName("unknown2", unknown2_3, 3);
  9650. packet->setDataByName("max_distance", 500);
  9651. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9652. QueuePacket(packet->serialize());
  9653. safe_delete(packet);
  9654. }
  9655. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9656. {
  9657. SetPendingFlightPath(path_id);
  9658. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9659. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9660. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9661. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9662. if (packet) {
  9663. QueuePacket(packet->serialize());
  9664. safe_delete(packet);
  9665. }
  9666. if (mount_id)
  9667. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9668. }
  9669. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  9670. {
  9671. if (!sender)
  9672. {
  9673. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9674. return;
  9675. }
  9676. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9677. if (!packet) {
  9678. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9679. return;
  9680. }
  9681. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9682. packet->setDataByName("book_title", title.c_str());
  9683. packet->setDataByName("book_type", "simple");
  9684. packet->setDataByName("unknown2", 1);
  9685. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9686. packet->setDataByName("language", language);
  9687. if (GetVersion() > 546)
  9688. packet->setDataByName("unknown5", 1, 4);
  9689. packet->setArrayLengthByName("num_pages", num_pages);
  9690. va_list args;
  9691. va_start(args, num_pages);
  9692. std::string endString("");
  9693. for (int8 p = 0; p < num_pages; p++)
  9694. {
  9695. std::string page = va_arg(args, string);
  9696. switch (GetVersion())
  9697. {
  9698. // release client
  9699. case 283:
  9700. {
  9701. endString.append(page);
  9702. break;
  9703. }
  9704. // DoF trial
  9705. case 546:
  9706. {
  9707. if (p == 0)
  9708. packet->setDataByName("cover_page", page.c_str());
  9709. else
  9710. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9711. break;
  9712. }
  9713. // all other clients
  9714. default:
  9715. {
  9716. packet->setArrayDataByName("page_text", page.c_str(), p);
  9717. break;
  9718. }
  9719. }
  9720. }
  9721. if (GetVersion() == 283)
  9722. {
  9723. packet->setDataByName("page_text", endString.c_str());
  9724. }
  9725. va_end(args);
  9726. QueuePacket(packet->serialize());
  9727. safe_delete(packet);
  9728. }
  9729. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  9730. {
  9731. if (!sender)
  9732. {
  9733. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9734. return;
  9735. }
  9736. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9737. if (!packet) {
  9738. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9739. return;
  9740. }
  9741. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9742. packet->setDataByName("book_title", title.c_str());
  9743. packet->setDataByName("book_type", "simple");
  9744. packet->setDataByName("unknown2", 1);
  9745. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9746. packet->setDataByName("language", language);
  9747. if (GetVersion() > 546)
  9748. packet->setDataByName("unknown5", 1, 4);
  9749. packet->setArrayLengthByName("num_pages", pages.size());
  9750. std::string endString("");
  9751. for (int8 p = 0; p < pages.size(); p++)
  9752. {
  9753. Item::BookPage* page = pages[p];
  9754. std::string pageText = string(page->page_text.data);
  9755. switch (GetVersion())
  9756. {
  9757. // release client
  9758. case 283:
  9759. {
  9760. endString.append(pageText);
  9761. break;
  9762. }
  9763. // DoF trial
  9764. case 546:
  9765. {
  9766. if (p == 0)
  9767. packet->setDataByName("cover_page", pageText.c_str());
  9768. else
  9769. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9770. break;
  9771. }
  9772. // all other clients
  9773. default:
  9774. {
  9775. int8 valign = int8(page->valign);
  9776. int8 halign = int8(page->halign);
  9777. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9778. packet->setArrayDataByName("page_text_valign", valign, p);
  9779. packet->setArrayDataByName("page_text_halign", halign, p);
  9780. break;
  9781. }
  9782. }
  9783. }
  9784. if (GetVersion() == 283)
  9785. {
  9786. packet->setDataByName("page_text", endString.c_str());
  9787. }
  9788. QueuePacket(packet->serialize());
  9789. safe_delete(packet);
  9790. }
  9791. void Client::ReplaceGroupClient(Client* new_client)
  9792. {
  9793. if (this->GetPlayer()->GetGroupMemberInfo())
  9794. {
  9795. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9796. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9797. if(group)
  9798. {
  9799. group->MGroupMembers.writelock();
  9800. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9801. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9802. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9803. group->MGroupMembers.releasewritelock();
  9804. }
  9805. else
  9806. {
  9807. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9808. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9809. this->GetPlayer()->SetGroupMemberInfo(0);
  9810. }
  9811. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9812. }
  9813. }
  9814. void Client::TempRemoveGroup()
  9815. {
  9816. if (this->GetPlayer()->GetGroupMemberInfo())
  9817. {
  9818. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9819. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9820. if(group)
  9821. {
  9822. group->MGroupMembers.writelock();
  9823. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9824. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9825. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9826. this->GetPlayer()->SetGroupMemberInfo(0);
  9827. group->MGroupMembers.releasewritelock();
  9828. group->RemoveClientReference(this);
  9829. }
  9830. else
  9831. {
  9832. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9833. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9834. this->GetPlayer()->SetGroupMemberInfo(0);
  9835. }
  9836. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9837. }
  9838. }
  9839. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9840. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9841. {
  9842. Mail mail;
  9843. mail.mail_id = 0;
  9844. mail.already_read = 0;
  9845. mail.postage_cost = 0;
  9846. mail.attachment_cost = 0;
  9847. mail.save_needed = 1;
  9848. //uhh...mail has std::strings so
  9849. //memset(&mail,0,sizeof(Mail));
  9850. mail.player_to_id = charID;
  9851. mail.player_from = fromName;
  9852. mail.subject = subjectName;
  9853. mail.mail_body = mailBody;
  9854. mail.mail_type = mailType;
  9855. mail.coin_copper = copper;
  9856. mail.coin_silver = silver;
  9857. mail.coin_gold = gold;
  9858. mail.coin_plat = platinum;
  9859. mail.char_item_id = item_id;
  9860. mail.stack = stack_size;
  9861. mail.time_sent = time_sent;
  9862. mail.expire_time = expire_time;
  9863. database.SavePlayerMail(&mail);
  9864. }
  9865. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9866. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9867. {
  9868. Mail* mail = new Mail();
  9869. mail->player_to_id = GetCharacterID();
  9870. mail->player_from = fromName;
  9871. mail->subject = subjectName;
  9872. mail->mail_body = mailBody;
  9873. mail->mail_type = mailType;
  9874. mail->coin_copper = copper;
  9875. mail->coin_silver = silver;
  9876. mail->coin_gold = gold;
  9877. mail->coin_plat = platinum;
  9878. mail->char_item_id = item_id;
  9879. mail->stack = stack_size;
  9880. mail->time_sent = time_sent;
  9881. mail->expire_time = expire_time;
  9882. mail->postage_cost = 0;
  9883. mail->save_needed = 1;
  9884. mail->already_read = 0;
  9885. database.SavePlayerMail(mail);
  9886. GetPlayer()->AddMail(mail);
  9887. }
  9888. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9889. {
  9890. if(slot < NUM_SLOTS)
  9891. {
  9892. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9893. if (app)
  9894. QueuePacket(app);
  9895. }
  9896. else
  9897. {
  9898. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9899. if (outapp)
  9900. QueuePacket(outapp);
  9901. }
  9902. }
  9903. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9904. {
  9905. if(spawn_player_id < 1)
  9906. return;
  9907. MQueueStateCmds.writelock();
  9908. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9909. MQueueStateCmds.releasewritelock();
  9910. }
  9911. void Client::ProcessStateCommands()
  9912. {
  9913. if(!IsReadyForUpdates())
  9914. return;
  9915. MQueueStateCmds.writelock();
  9916. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9917. for(; itr != queued_state_commands.end(); itr++)
  9918. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9919. queued_state_commands.clear();
  9920. MQueueStateCmds.releasewritelock();
  9921. }
  9922. void Client::PurgeItem(Item* item)
  9923. {
  9924. MConversation.writelock();
  9925. map<int32, Item*>::iterator itr;
  9926. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9927. {
  9928. if ( itr->second == item )
  9929. {
  9930. conversation_items.erase(itr);
  9931. break;
  9932. }
  9933. }
  9934. MConversation.releasewritelock();
  9935. }
  9936. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9937. {
  9938. if(GetPlayer()->StopSaveSpellEffects())
  9939. return;
  9940. if(item) {
  9941. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9942. if(item->GetItemScript() && lua_interface){
  9943. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9944. if (slot == 22)
  9945. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9946. else
  9947. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9948. }
  9949. if (item->details.count > 1) {
  9950. item->details.count -= 1;
  9951. item->save_needed = true;
  9952. }
  9953. else {
  9954. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9955. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9956. }
  9957. GetPlayer()->SetCharSheetChanged(true);
  9958. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9959. }
  9960. }
  9961. void Client::AwardCoins(int64 total_coins, std::string reason)
  9962. {
  9963. if (total_coins > 0) {
  9964. player->AddCoins(total_coins);
  9965. PlaySound("coin_cha_ching");
  9966. char tmp[64] = { 0 };
  9967. string message = "You receive ";
  9968. int32 val = 0;
  9969. if (total_coins >= 1000000) {
  9970. val = total_coins / 1000000;
  9971. total_coins -= 1000000 * val;
  9972. sprintf(tmp, "%u Platinum ", val);
  9973. message.append(tmp);
  9974. memset(tmp, 0, 64);
  9975. }
  9976. if (total_coins >= 10000) {
  9977. val = total_coins / 10000;
  9978. total_coins -= 10000 * val;
  9979. sprintf(tmp, "%u Gold ", val);
  9980. message.append(tmp);
  9981. memset(tmp, 0, 64);
  9982. }
  9983. if (total_coins >= 100) {
  9984. val = total_coins / 100;
  9985. total_coins -= 100 * val;
  9986. sprintf(tmp, "%u Silver ", val);
  9987. message.append(tmp);
  9988. memset(tmp, 0, 64);
  9989. }
  9990. if (total_coins > 0) {
  9991. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9992. message.append(tmp);
  9993. }
  9994. message.append(reason);
  9995. int8 type = CHANNEL_LOOT;
  9996. SimpleMessage(type, message.c_str());
  9997. }
  9998. }
  9999. void Client::TriggerSpellSave()
  10000. {
  10001. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  10002. // default to not have some bogus value in the rule
  10003. if(interval < 1)
  10004. interval = 100;
  10005. MSaveSpellStateMutex.lock();
  10006. if(!save_spell_state_timer.Enabled())
  10007. {
  10008. save_spell_state_time_bucket = 0;
  10009. save_spell_state_timer.Start(interval, true);
  10010. }
  10011. else
  10012. {
  10013. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  10014. save_spell_state_time_bucket += elapsed_time;
  10015. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  10016. // default to not have some bogus value in the rule
  10017. if(save_wait_cap < interval)
  10018. save_wait_cap = interval+1;
  10019. if(save_spell_state_time_bucket >= save_wait_cap)
  10020. {
  10021. // save immediately and disable timer
  10022. GetPlayer()->SaveSpellEffects();
  10023. save_spell_state_timer.Disable();
  10024. }
  10025. }
  10026. MSaveSpellStateMutex.unlock();
  10027. }
  10028. void Client::UpdateSentSpellList() {
  10029. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  10030. std::map<int32, int32>::iterator itr;
  10031. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  10032. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  10033. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  10034. QueuePacket(app);
  10035. }
  10036. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  10037. }
  10038. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  10039. tempPlacementSpawn = tmp;
  10040. hasSentTempPlacementSpawn = false;
  10041. if(tempPlacementSpawn)
  10042. temp_placement_timer.Start();
  10043. else
  10044. temp_placement_timer.Disable();
  10045. }
  10046. void Client::SetPlayer(Player* new_player) {
  10047. if (player && player != new_player)
  10048. zone_list.RemoveClientFromMap(player->GetName(), this);
  10049. player = new_player;
  10050. player->SetClient(this);
  10051. }
  10052. bool Client::UseItem(Item* item, Spawn* target) {
  10053. if (item && item->GetItemScript()) {
  10054. int16 item_index = item->details.index;
  10055. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  10056. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  10057. }
  10058. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  10059. Message(0, "%s requires an evil race.", item->name.c_str());
  10060. }
  10061. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  10062. Message(0, "%s requires a good race.", item->name.c_str());
  10063. }
  10064. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  10065. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  10066. return true;
  10067. }
  10068. else {
  10069. if (item->details.count > 0) {
  10070. std::string itemName = string(item->name);
  10071. int32 item_id = item->details.item_id;
  10072. sint64 flags = 0;
  10073. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  10074. {
  10075. //reobtain item make sure it wasn't removed
  10076. item = player->item_list.GetItemFromIndex(item_index);
  10077. if(!item) {
  10078. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, however after the item looks to be removed.", GetPlayer()->GetName(), itemName.c_str(), item_id);
  10079. return true;
  10080. }
  10081. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  10082. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10083. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10084. return true;
  10085. }
  10086. else
  10087. {
  10088. item->details.count--; // charges
  10089. item->save_needed = true;
  10090. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  10091. if(!item->details.count) {
  10092. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10093. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10094. }
  10095. return true;
  10096. }
  10097. }
  10098. else {
  10099. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, after it returned %i, bypassing any removal/update of items.", GetPlayer()->GetName(), itemName.c_str(), item_id, flags);
  10100. return true;
  10101. }
  10102. }
  10103. else
  10104. {
  10105. //reobtain item make sure it wasn't removed
  10106. item = player->item_list.GetItemFromIndex(item_index);
  10107. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10108. if(item) {
  10109. LogWrite(PLAYER__ERROR, 0, "Command", "%s: Item %s (%i) attempted to be used, however details.count is 0.", GetPlayer()->GetName(), item->name.c_str(), item->details.item_id);
  10110. }
  10111. }
  10112. }
  10113. }
  10114. return false;
  10115. }
  10116. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10117. VoiceOverStruct* garble, bool success, bool garble_success) {
  10118. VoiceOverStruct* resStruct = nullptr;
  10119. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10120. if(success) {
  10121. resStruct = non_garble;
  10122. }
  10123. }
  10124. else if(garble_success) {
  10125. resStruct = garble;
  10126. }
  10127. if(resStruct) {
  10128. GetPlayer()->GetZone()->PlayFlavor(this, spawn, resStruct->mp3_string.c_str(), resStruct->text_string.c_str(), resStruct->emote_string.c_str(), resStruct->key1, resStruct->key2, language);
  10129. }
  10130. }
  10131. void Client::SaveQuestRewardData(bool force_refresh) {
  10132. Query query;
  10133. if(force_refresh) {
  10134. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10135. GetCharacterID());
  10136. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10137. GetCharacterID());
  10138. }
  10139. vector<QuestRewardData*>::iterator itr;
  10140. vector<QuestRewardData*> tmp_quest_rewards;
  10141. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10142. int index = 0;
  10143. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10144. int32 questID = (*itr)->quest_id;
  10145. if(!(*itr)->db_saved || force_refresh) {
  10146. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_rewards (char_id, indexed, quest_id, is_temporary, is_collection, has_displayed, tmp_coin, tmp_status, description) values(%u, %u, %u, %u, %u, %u, %llu, %u, '%s')",
  10147. GetCharacterID(), index, questID, (*itr)->is_temporary, (*itr)->is_collection, (*itr)->has_displayed, (*itr)->tmp_coin, (*itr)->tmp_status, database.getSafeEscapeString((*itr)->description.c_str()).c_str());
  10148. (*itr)->db_saved = true;
  10149. (*itr)->db_index = index;
  10150. if((*itr)->is_temporary) {
  10151. std::vector<Item*> items;
  10152. Quest* quest = GetPlayer()->GetAnyQuest(questID);
  10153. if(quest) {
  10154. quest->GetTmpRewardItemsByID(&items);
  10155. if(!force_refresh && items.size() > 0) {
  10156. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10157. GetCharacterID(), questID);
  10158. }
  10159. for(int i=0;i<items.size();i++) {
  10160. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  10161. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  10162. }
  10163. }
  10164. }
  10165. }
  10166. index++;
  10167. }
  10168. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  10169. }
  10170. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  10171. if(!data)
  10172. return;
  10173. if(data->db_saved) {
  10174. Query query;
  10175. query.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, "update character_quest_rewards set is_temporary = %u, is_collection = %u, has_displayed = %u, tmp_coin = %llu, tmp_status = %u, description = '%s' where char_id=%u and indexed=%u and quest_id=%u",
  10176. data->is_temporary, data->is_collection, data->has_displayed, data->tmp_coin, data->tmp_status, database.getSafeEscapeString(data->description.c_str()).c_str(), GetCharacterID(), data->db_index, data->quest_id);
  10177. }
  10178. }
  10179. void Client::AddRecipeToPlayer(Recipe* recipe, PacketStruct* packet, int16* i) {
  10180. int index = 0;
  10181. if(recipe == nullptr)
  10182. return;
  10183. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  10184. if (prl->GetRecipe(recipe->GetID())) {
  10185. delete recipe;
  10186. return;
  10187. }
  10188. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  10189. if (res != devices.end())
  10190. index = res - devices.begin();
  10191. else
  10192. devices.push_back(recipe->GetDevice());
  10193. prl->AddRecipe(recipe);
  10194. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  10195. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  10196. if (packet && GetRecipeListSent()) {
  10197. packet->setArrayDataByName("id", recipe->GetID(), *i);
  10198. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  10199. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  10200. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  10201. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  10202. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  10203. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  10204. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  10205. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  10206. if (recipe_device != devices.end())
  10207. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  10208. else
  10209. {//TODO error should never get here
  10210. }
  10211. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  10212. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  10213. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  10214. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  10215. if(i) {
  10216. (*i)++;
  10217. }
  10218. }
  10219. }
  10220. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  10221. if(!spawn) {
  10222. pov_ghost_spawn_id = 0;
  10223. SendCharPOVGhost();
  10224. return true;
  10225. }
  10226. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  10227. if(ghost_id) {
  10228. pov_ghost_spawn_id = spawn->GetID();
  10229. SendCharPOVGhost();
  10230. return true;
  10231. }
  10232. return false;
  10233. }