client.cpp 393 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296
  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) : 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. }
  204. Client::~Client() {
  205. RemoveClientFromZone();
  206. //let the stream factory know were done with this stream
  207. if (eqs) {
  208. eqs->Close();
  209. try {
  210. eqs->ReleaseFromUse();
  211. }
  212. catch (...) {}
  213. }
  214. eqs = NULL;
  215. //safe_delete(autobootup_timeout);
  216. vector<QueuedQuest*>::iterator itr;
  217. QueuedQuest* queued_quest = 0;
  218. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  219. queued_quest = *itr;
  220. safe_delete(queued_quest);
  221. }
  222. quest_queue.clear();
  223. vector<QuestRewardData*>::iterator rwd_itr;
  224. QuestRewardData* quest_rwd_data = 0;
  225. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  226. quest_rwd_data = *rwd_itr;
  227. safe_delete(quest_rwd_data);
  228. }
  229. quest_pending_reward.clear();
  230. safe_delete(CLE_keepalive_timer);
  231. safe_delete(connect);
  232. --numclients;
  233. UpdateWindowTitle(0);
  234. }
  235. void Client::RemoveClientFromZone() {
  236. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  237. Spawn* tmp = GetTempPlacementSpawn();
  238. SetTempPlacementSpawn(nullptr);
  239. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  240. }
  241. if(player && player->GetZone())
  242. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  243. if (current_zone && player) {
  244. if (player->GetGroupMemberInfo())
  245. {
  246. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  247. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  248. else
  249. TempRemoveGroup();
  250. }
  251. world.GetGroupManager()->ClearPendingInvite(player);
  252. }
  253. if (lua_interface)
  254. lua_interface->RemoveDebugClients(this);
  255. if (player)
  256. zone_list.RemoveClientFromMap(player->GetName(), this);
  257. safe_delete(camp_timer);
  258. safe_delete(search_items);
  259. safe_delete(current_rez.expire_timer);
  260. safe_delete(pending_last_name);
  261. safe_delete_array(incoming_paperdoll.image_bytes);
  262. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  263. if (player && !player->GetPendingDeletion())
  264. safe_delete(player);
  265. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  266. deque<BuyBackItem*>::iterator itr;
  267. MBuyBack.writelock(__FUNCTION__, __LINE__);
  268. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  269. safe_delete(*itr);
  270. itr = buy_back_items.erase(itr);
  271. }
  272. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  273. }
  274. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  275. if (eqs) {
  276. if (!eqs->CheckActive()) {
  277. client_list.Remove(this);
  278. eqs = 0;
  279. }
  280. }
  281. if (app && eqs && version > 0)
  282. eqs->EQ2QueuePacket(app, attemptedCombine);
  283. else {
  284. safe_delete(app);
  285. }
  286. }
  287. void Client::PopulateSkillMap() {
  288. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  289. if (app)
  290. QueuePacket(app);
  291. else {
  292. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  293. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  294. }
  295. }
  296. void Client::SendLoginInfo() {
  297. if(GetPlayer()->IsReturningFromLD())
  298. firstlogin = true;
  299. if (firstlogin) {
  300. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  301. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  302. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  303. PopulateSkillMap();
  304. // 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!
  305. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  306. }
  307. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  308. database.ToggleCharacterOnline(this, 1);
  309. int32 count = 0;
  310. if(!GetPlayer()->IsReturningFromLD())
  311. {
  312. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  313. count = database.LoadCharacterSkills(GetCharacterID(), player);
  314. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  315. count = database.LoadCharacterSpells(GetCharacterID(), player);
  316. }
  317. else
  318. {
  319. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  320. }
  321. // get the latest character starting skills / spells, may have been updated after character creation
  322. world.SyncCharacterAbilities(this);
  323. if(!GetPlayer()->IsReturningFromLD())
  324. {
  325. count = database.LoadCharacterTitles(GetCharacterID(), player);
  326. if (count == 0) {
  327. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  328. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  329. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  330. }
  331. }
  332. if(!GetPlayer()->IsReturningFromLD())
  333. {
  334. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  335. if (count == 0)
  336. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  337. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  338. if (count == 0)
  339. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  340. }
  341. ClientPacketFunctions::SendLoginAccepted(this);
  342. ClientPacketFunctions::SendAbilities ( this );
  343. ClientPacketFunctions::SendCommandNamePacket(this);
  344. ClientPacketFunctions::SendQuickBarInit(this);
  345. // we only need to send the MOTD if it is the first time the person is logging in.
  346. if (firstlogin) {
  347. ClientPacketFunctions::SendMOTD(this);
  348. ClientPacketFunctions::SendCharacterMacros(this);
  349. zone_list.CheckFriendList(this);
  350. }
  351. if(!GetPlayer()->IsReturningFromLD())
  352. {
  353. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  354. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  355. {
  356. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  357. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  358. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  359. }
  360. database.LoadPlayerFactions(this);
  361. database.LoadCharacterQuests(this);
  362. database.LoadCharacterQuestRewards(this);
  363. database.LoadPlayerMail(this);
  364. }
  365. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  366. SendQuestJournal(true, 0, false);
  367. if (version > 546) // right version? possibly not!
  368. master_aa_list.DisplayAA(this, 0, 3);
  369. if (version > 283)
  370. SendCollectionList();
  371. SendBiography();
  372. map<int32, Quest*>::iterator itr;
  373. Quest* quest = 0;
  374. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  375. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  376. quest = itr->second;
  377. if (quest->IsTracked()) {
  378. quest->SetTracked(false);
  379. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  380. quest->SetTracked(true);
  381. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  382. }
  383. }
  384. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  385. // SendAchievementsList();
  386. /*Guild* guild = player->GetGuild();
  387. if (guild) {
  388. guild->UpdateGuildMemberInfo(GetPlayer());
  389. if (firstlogin)
  390. guild->SendGuildMOTD(this);
  391. guild->SendGuildUpdate(this);
  392. guild->SendGuildMember(GetPlayer(), firstlogin);
  393. guild->SendGuildEventList(this);
  394. guild->SendGuildBankEventList(this);
  395. guild->SendAllGuildEvents(this);
  396. guild->SendGuildMemberList(this);
  397. }*/
  398. if (version > 283) {
  399. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  400. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  401. if (outapp) {
  402. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  403. //DumpPacket(outapp);
  404. QueuePacket(outapp);
  405. }
  406. }
  407. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  408. ClientPacketFunctions::SendCommandList(this);
  409. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  410. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  411. ClientPacketFunctions::SendInstanceList(this);
  412. SendZoneInfo();
  413. /*Spell* spell = 0;
  414. vector<QuickBarItem*>::iterator itr;
  415. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  416. if((*itr)->type == 1){
  417. spell = master_spell_list.GetSpell((*itr)->id);
  418. if(spell)
  419. QueuePacket(spell->serialize(this, false, 0x20));
  420. }
  421. }*/
  422. }
  423. void Client::SendPlayerDeathWindow()
  424. {
  425. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  426. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  427. vector<RevivePoint*>::iterator itr;
  428. if (results && results->size() > 0)
  429. {
  430. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  431. if (packet)
  432. {
  433. packet->setArrayLengthByName("location_count", results->size());
  434. RevivePoint* point = 0;
  435. int32 i = 0;
  436. for (itr = results->begin(); itr != results->end(); itr++, i++)
  437. {
  438. point = *itr;
  439. if (point)
  440. {
  441. packet->setArrayDataByName("location_id", point->id, i);
  442. //zone_name = database.GetZoneName(point->zone_id);
  443. string zone_name = database.GetZoneDescription(point->zone_id);
  444. if (zone_name.length() > 0)
  445. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  446. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  447. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  448. }
  449. if (point->id == 0xFFFFFFFF)//tmp location
  450. safe_delete(point);
  451. }
  452. // done with the revive points so lets free up the pointer
  453. safe_delete(results);
  454. #if EQDEBUG >= 3
  455. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  456. packet->PrintPacket();
  457. #endif
  458. EQ2Packet* outapp = packet->serialize();
  459. QueuePacket(outapp);
  460. safe_delete(packet);
  461. }
  462. }
  463. }
  464. void Client::DisplayDeadWindow()
  465. {
  466. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  467. player->SetHP(0);
  468. player->SetPower(0);
  469. GetCurrentZone()->TriggerCharSheetTimer();
  470. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  471. if (packet)
  472. {
  473. packet->setDataByName("parameter1", 8);
  474. packet->setDataByName("value", 1);
  475. QueuePacket(packet->serialize());
  476. packet->setDataByName("parameter1", 16);
  477. QueuePacket(packet->serialize());
  478. safe_delete(packet);
  479. }
  480. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  481. if (packet)
  482. {
  483. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  484. QueuePacket(packet->serialize());
  485. safe_delete(packet);
  486. }
  487. SendPlayerDeathWindow();
  488. }
  489. void Client::HandlePlayerRevive(int32 point_id)
  490. {
  491. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  492. if (packet)
  493. {
  494. packet->setDataByName("parameter1", 8);
  495. QueuePacket(packet->serialize());
  496. packet->setDataByName("parameter1", 16);
  497. QueuePacket(packet->serialize());
  498. safe_delete(packet);
  499. }
  500. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  501. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  502. if (packet)
  503. {
  504. QueuePacket(packet->serialize());
  505. safe_delete(packet);
  506. }
  507. float origX, origY, origZ, origHeading = 0.0f;
  508. origX = player->GetX();
  509. origY = player->GetY();
  510. origZ = player->GetZ();
  511. origHeading = player->GetHeading();
  512. ZoneServer* originalZone = GetCurrentZone();
  513. int32 origGridID = GetPlayer()->appearance.pos.grid_id;
  514. float x, y, z, heading;
  515. RevivePoint* revive_point = 0;
  516. if (point_id != 0xFFFFFFFF)
  517. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  518. string zone_desc;
  519. const char* location_name = "Unknown";
  520. //revive at zone safe coords
  521. if (!revive_point)
  522. {
  523. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  524. x = GetCurrentZone()->GetSafeX();
  525. y = GetCurrentZone()->GetSafeY();
  526. z = GetCurrentZone()->GetSafeZ();
  527. heading = GetCurrentZone()->GetSafeHeading();
  528. zone_desc = GetCurrentZone()->GetZoneDescription();
  529. location_name = "Zone Safe Point";
  530. Zone(GetCurrentZone()->GetZoneName(), false);
  531. }
  532. else
  533. {
  534. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  535. x = revive_point->x;
  536. y = revive_point->y;
  537. z = revive_point->z;
  538. heading = revive_point->heading;
  539. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  540. location_name = revive_point->location_name.c_str();
  541. Zone(GetCurrentZone()->GetZoneName(), false);
  542. }
  543. player->SetResurrecting(true);
  544. player->SetX(x);
  545. player->SetY(y);
  546. player->SetZ(z);
  547. player->SetHeading(heading);
  548. player->SetHP(player->GetTotalHP());
  549. player->SetPower(player->GetTotalPower());
  550. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  551. zone_desc.c_str(),
  552. player->GetX(),
  553. player->GetY(),
  554. player->GetZ(),
  555. player->GetHeading(),
  556. player->GetHP(),
  557. player->GetPower(),
  558. location_name);
  559. //player->ClearEverything();
  560. Save();
  561. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  562. {
  563. string zone_name = database.GetZoneName(revive_point->zone_id);
  564. if (zone_name.length() == 0)
  565. {
  566. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  567. x = GetCurrentZone()->GetSafeX();
  568. y = GetCurrentZone()->GetSafeY();
  569. z = GetCurrentZone()->GetSafeZ();
  570. heading = GetCurrentZone()->GetSafeHeading();
  571. location_name = "Zone Safe Point";
  572. }
  573. else
  574. {
  575. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  576. location_name = revive_point->location_name.c_str();
  577. player->ClearEverything();
  578. Zone(zone_name.c_str(), false);
  579. }
  580. }
  581. zone_desc = GetCurrentZone()->GetZoneDescription();
  582. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  583. player->SetSpawnType(4);
  584. if (version > 283) {
  585. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  586. if (packet)
  587. {
  588. QueuePacket(packet->serialize());
  589. safe_delete(packet);
  590. }
  591. }
  592. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  593. if (packet)
  594. {
  595. packet->setDataByName("x", x);
  596. packet->setDataByName("y", y);
  597. packet->setDataByName("z", z);
  598. QueuePacket(packet->serialize());
  599. safe_delete(packet);
  600. }
  601. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  602. if (packet)
  603. {
  604. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  605. packet->setDataByName("speed", 32);
  606. packet->setDataByName("unknown2", 0);
  607. //DoF Merge: old value and speed wasn't included
  608. //packet->setDataByName("unknown2", 255);
  609. QueuePacket(packet->serialize());
  610. safe_delete(packet);
  611. }
  612. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  613. if (packet)
  614. {
  615. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  616. QueuePacket(packet->serialize());
  617. safe_delete(packet);
  618. }
  619. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  620. {
  621. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  622. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  623. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  624. originalZone->RemoveSpawn(player, false, true, true, true, true);
  625. originalZone->AddSpawn(shard);
  626. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  627. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  628. }
  629. m_resurrect.writelock(__FUNCTION__, __LINE__);
  630. if (current_rez.active)
  631. current_rez.should_delete = true;
  632. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  633. }
  634. void Client::SendCharInfo() {
  635. EQ2Packet* app;
  636. player->SetEquippedItemAppearances();
  637. ClientPacketFunctions::SendCharacterData(this);
  638. SendCharPOVGhost();
  639. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  640. if (packet) {
  641. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  642. packet->setDataByName("size", .56);
  643. packet->setDataByName("unknown2", 255);
  644. packet->setDataByName("speed", player->GetSpeed());
  645. packet->setDataByName("air_speed", player->GetAirSpeed());
  646. EQ2Packet* app = packet->serialize();
  647. QueuePacket(app);
  648. safe_delete(packet);
  649. }
  650. if (version <= 283) {
  651. //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
  652. Sleep(2000);
  653. }
  654. //sending bad spawn packet?
  655. //SendAchievementsList();
  656. ClientPacketFunctions::SendCharacterSheet(this);
  657. ClientPacketFunctions::SendTraitList(this);// moved from below
  658. ClientPacketFunctions::SendAbilities(this);
  659. ClientPacketFunctions::SendSkillBook(this);
  660. if (!IsReloadingZone() && !player->IsResurrecting()) {
  661. if(GetVersion() > 546) //we will send this later on for 546 and below
  662. ClientPacketFunctions::SendUpdateSpellBook(this);
  663. }
  664. else {
  665. player->SetResurrecting(false);
  666. }
  667. GetCurrentZone()->AddSpawn(player);
  668. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  669. GetPlayer()->SetX(zoning_x);
  670. GetPlayer()->SetY(zoning_y);
  671. GetPlayer()->SetZ(zoning_z);
  672. GetPlayer()->SetHeading(zoning_h);
  673. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  674. QueuePacket(packet);
  675. }
  676. //SendCollectionList();
  677. Guild* guild = player->GetGuild();
  678. if (guild)
  679. guild->GuildMemberLogin(this, firstlogin);
  680. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  681. if (app) {
  682. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  683. //DumpPacket(app);
  684. QueuePacket(app);
  685. }
  686. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  687. if (app) {
  688. QueuePacket(app);
  689. }
  690. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  691. if (app) {
  692. QueuePacket(app);
  693. }
  694. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  695. if (items && items->size() > 0) {
  696. for (int32 i = 0; i < items->size(); i++) {
  697. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  698. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  699. //DumpPacket(outapp);
  700. QueuePacket(outapp);
  701. }
  702. }
  703. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  704. QueuePacket(app);
  705. safe_delete(items);
  706. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  707. if (items && items->size() > 0) {
  708. for (int32 i = 0; i < items->size(); i++)
  709. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  710. }
  711. safe_delete(items);
  712. if (version > 283) {
  713. SendTitleUpdate();
  714. }
  715. GetPlayer()->ChangePrimaryWeapon();
  716. GetPlayer()->ChangeSecondaryWeapon();
  717. GetPlayer()->ChangeRangedWeapon();
  718. if(!GetPlayer()->IsReturningFromLD()) {
  719. database.LoadBuyBacks(this);
  720. }
  721. if (version > 546)
  722. master_aa_list.DisplayAA(this, 0, 0);
  723. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  724. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  725. string zone_motd_send = "Zone MOTD: " + zone_motd;
  726. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  727. }
  728. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  729. if (zone_script && lua_interface)
  730. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  731. this->client_zoning = false;
  732. this->zoning_id = 0;
  733. this->zoning_instance_id = 0;
  734. SetZoningDestination(nullptr);
  735. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  736. GetCurrentZone()->AddDamagedSpawn(player);
  737. if (firstlogin)
  738. firstlogin = false;
  739. player->ClearProcs();
  740. items = player->GetEquippedItemList();
  741. if (items && items->size() > 0) {
  742. for (int32 i = 0; i < items->size(); i++) {
  743. Item* item = items->at(i);
  744. if (item && item->GetItemScript() && lua_interface)
  745. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  746. }
  747. }
  748. //Allow this player to change their last name if they meet the level requirement
  749. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  750. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  751. safe_delete(items);
  752. if (!player->Alive())
  753. DisplayDeadWindow();
  754. ClientPacketFunctions::SendLocalizedTextMessage(this);
  755. if (GetCurrentZone()->GetInstanceID())
  756. {
  757. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  758. if (ph) {
  759. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  760. string name = string(GetPlayer()->GetName());
  761. if (name.compare(ph->player_name) == 0)
  762. SetHasOwnerOrEditAccess(true);
  763. }
  764. }
  765. if (version > 546)
  766. ClientPacketFunctions::SendHousingList(this);
  767. bool groupMentor = false;
  768. GetPlayer()->group_id = rejoin_group_id;
  769. if(!world.RejoinGroup(this, rejoin_group_id))
  770. GetPlayer()->group_id = 0;
  771. else
  772. {
  773. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  774. if(ent && ent->IsPlayer())
  775. {
  776. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  777. groupMentor = true;
  778. }
  779. }
  780. if(!groupMentor)
  781. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  782. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  783. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  784. GetPlayer()->SetSaveSpellEffects(false);
  785. GetPlayer()->SetCharSheetChanged(true);
  786. GetPlayer()->SetReturningFromLD(false);
  787. }
  788. void Client::SendZoneSpawns() {
  789. //Allows us to place spawns almost anywhere
  790. if (version > 283) {
  791. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  792. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  793. QueuePacket(app);
  794. }
  795. ClientPacketFunctions::SendSkillSlotMappings(this);
  796. ClientPacketFunctions::SendGameWorldTime(this);
  797. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  798. }
  799. void Client::SendCharPOVGhost() {
  800. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  801. if (set_pov) {
  802. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  803. EQ2Packet* app_pov = set_pov->serialize();
  804. QueuePacket(app_pov);
  805. safe_delete(set_pov);
  806. }
  807. }
  808. void Client::SendZoneInfo() {
  809. ZoneServer* zone = GetCurrentZone();
  810. if (zone) {
  811. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  812. QueuePacket(packet);
  813. if (version > 283) {
  814. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  815. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  816. #if EQDEBUG >= 9
  817. fog_packet->PrintPacket();
  818. #endif
  819. if (fog_packet) {
  820. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  821. QueuePacket(fog_packet->serialize());
  822. safe_delete(fog_packet);
  823. }
  824. zone->SendFlightPathsPackets(this);
  825. }
  826. }
  827. /*
  828. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  829. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  830. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  831. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  832. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  833. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  834. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  835. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  836. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  837. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  838. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  839. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  840. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  843. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  844. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0x00};
  864. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  865. QueuePacket(appA);
  866. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,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,0x01,0x00,0x00
  870. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  871. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  872. QueuePacket(appB);
  873. */
  874. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  875. SendFriendList();
  876. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  877. SendIgnoreList();
  878. }
  879. void Client::SendDefaultGroupOptions() {
  880. /*
  881. 0 - loot method
  882. 1 - loot items rarity
  883. 2 - Auto split coin
  884. 4 - default yell method
  885. 6 - group autolock
  886. 7 - solo autolock
  887. */
  888. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  889. if (default_options) {
  890. default_options->setDataByName("loot_method", 1);
  891. default_options->setDataByName("loot_items_rarity", 1);
  892. default_options->setDataByName("auto_split_coin", 1);
  893. default_options->setDataByName("default_yell_method", 1);
  894. EQ2Packet* app7 = default_options->serialize();
  895. QueuePacket(app7);
  896. safe_delete(default_options);
  897. }
  898. }
  899. bool Client::HandlePacket(EQApplicationPacket* app) {
  900. bool ret = true;
  901. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  902. //DumpPacket(app);
  903. #if EQDEBUG >= 9
  904. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  905. DumpPacket(app, true);
  906. #endif
  907. EmuOpcode opcode = app->GetOpcode();
  908. #if EQDEBUG >= 9
  909. const char* name = app->GetOpcodeName();
  910. if (name)
  911. cout << name;
  912. else
  913. cout << "Unknown";
  914. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  915. DumpPacket(app);
  916. #endif
  917. //if (opcode != OP_UpdatePositionMsg) {
  918. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  919. //}
  920. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  921. {
  922. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  923. }
  924. switch (opcode) {
  925. case _maxEmuOpcode:
  926. break;
  927. case OP_LoginByNumRequestMsg: {
  928. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  929. PacketStruct* request;
  930. request = configReader.getStruct("LoginByNumRequest", 1);
  931. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  932. // test the original location of Version for clients older than 1212
  933. version = request->getType_int16_ByName("version");
  934. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  935. // must be new client data version method, re-fetch the packet
  936. safe_delete(request);
  937. request = configReader.getStruct("LoginByNumRequest", 1208);
  938. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  939. // Xinux suggests using an INT16 here. Our first new version = 57000
  940. version = request->getType_int16_ByName("version");
  941. }
  942. else {
  943. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  944. break;
  945. }
  946. }
  947. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  948. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  949. ClientPacketFunctions::SendLoginDenied(this);
  950. return false;
  951. }
  952. int32 account_id = request->getType_int32_ByName("account_id");
  953. int32 access_code = request->getType_int32_ByName("access_code");
  954. if (!HandleNewLogin(account_id, access_code))
  955. return false;
  956. }
  957. safe_delete(request);
  958. break;
  959. }
  960. case OP_MapRequest: {
  961. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  962. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  963. if (packet && app->size > 2 && GetCurrentZone()) {
  964. packet->LoadPacketData(app->pBuffer, app->size);
  965. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  966. if (fog_packet) {
  967. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  968. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  969. fog_packet->setDataByName("unknown1", 1);
  970. fog_packet->setDataByName("unknown3", 1);
  971. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  972. //fog_packet->PrintPacket();
  973. QueuePacket(fog_packet->serialize());
  974. safe_delete(fog_packet);
  975. }
  976. safe_delete(packet);
  977. }
  978. break;
  979. }
  980. case OP_RequestCampMsg: {
  981. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  982. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  983. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  984. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  985. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  986. request->getType_int8_ByName("quit"),
  987. request->getType_int8_ByName("camp_desktop"),
  988. request->getType_int16_ByName("camp_char_select"),
  989. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  990. //DumpPacket(app->pBuffer, app->size);
  991. //request->PrintPacket();
  992. if (!camp_timer) {
  993. int16 camp_time = 20; // default if rule cannot be found
  994. if (GetAdminStatus() >= 100)
  995. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  996. else
  997. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  998. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  999. if (response) {
  1000. bool disconnect = false;
  1001. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1002. // Command: /camp desktop
  1003. // Command: /quit
  1004. response->setDataByName("camp_desktop", 1);
  1005. disconnect = true;
  1006. }
  1007. else {
  1008. // Command: /camp
  1009. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1010. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1011. response->setDataByName("seconds", camp_time);
  1012. }
  1013. camp_timer = new Timer(camp_time * 1000);
  1014. camp_timer->Enable();
  1015. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1016. // /camp {char_name}
  1017. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1018. }
  1019. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1020. // /camp (go back to char selection screen)
  1021. response->setDataByName("char_name", " ");
  1022. response->setDataByName("camp_char_select", 1);
  1023. }
  1024. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1025. response->getType_int8_ByName("seconds"),
  1026. response->getType_int8_ByName("camp_desktop"),
  1027. response->getType_int8_ByName("camp_char_select"),
  1028. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1029. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1030. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1031. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1032. //response->PrintPacket();
  1033. QueuePacket(response->serialize());
  1034. safe_delete(response);
  1035. if (disconnect)
  1036. Disconnect();
  1037. }
  1038. }
  1039. }
  1040. safe_delete(request);
  1041. break;
  1042. }
  1043. case OP_StoodMsg: {
  1044. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1045. if (camp_timer)
  1046. {
  1047. // JA: clear camping flag
  1048. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1049. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1050. safe_delete(camp_timer);
  1051. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1052. QueuePacket(outapp);
  1053. }
  1054. player->SetTempVisualState(0);
  1055. break;
  1056. }
  1057. case OP_StandMsg: {
  1058. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1059. if (camp_timer)
  1060. {
  1061. // JA: clear camping flag
  1062. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1063. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1064. safe_delete(camp_timer);
  1065. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1066. QueuePacket(outapp);
  1067. }
  1068. player->SetTempVisualState(539);
  1069. break;
  1070. }
  1071. case OP_SitMsg: {
  1072. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1073. player->SetTempVisualState(538);
  1074. break;
  1075. }
  1076. case OP_SatMsg: {
  1077. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1078. player->SetTempVisualState(540);
  1079. break;
  1080. }
  1081. case OP_QuestJournalOpenMsg:
  1082. case OP_QuestJournalInspectMsg: {
  1083. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1084. if (app->size < sizeof(int32))
  1085. break;
  1086. int32 quest_id = 0;
  1087. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1088. Quest* quest = GetActiveQuest(quest_id);
  1089. if (quest)
  1090. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1091. else {
  1092. quest = player->GetCompletedQuest(quest_id);
  1093. if (quest)
  1094. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1095. }
  1096. break;
  1097. }
  1098. case OP_QuestJournalSetVisibleMsg: {
  1099. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1100. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1101. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1102. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1103. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1104. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1105. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1106. if (player_quests) {
  1107. if (player_quests->count(quest_id) > 0)
  1108. player_quests->at(quest_id)->SetHidden(hidden);
  1109. else
  1110. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1111. }
  1112. else
  1113. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1114. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1115. safe_delete(packet);
  1116. }
  1117. break;
  1118. }
  1119. case OP_MacroUpdateMsg: {
  1120. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1121. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1122. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1123. vector<string>* update = new vector<string>;
  1124. int8 number = macro_update->getType_int8_ByName("number");
  1125. int16 icon = macro_update->getType_int16_ByName("icon");
  1126. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1127. int8 count = macro_update->getType_int8_ByName("macro_count");
  1128. if (GetVersion() <= 283) {
  1129. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1130. }
  1131. else {
  1132. for (int8 i = 0; i < count; i++) {
  1133. char tmp_command[15] = { 0 };
  1134. sprintf(tmp_command, "command_%i", i);
  1135. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1136. }
  1137. }
  1138. if (name.length() == 0)
  1139. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1140. else
  1141. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1142. safe_delete(update);
  1143. safe_delete(macro_update);
  1144. }
  1145. break;
  1146. }
  1147. case OP_DialogSelectMsg: {
  1148. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1149. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1150. if (packet) {
  1151. packet->LoadPacketData(app->pBuffer, app->size);
  1152. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1153. int32 response_index = packet->getType_int32_ByName("response");
  1154. if (GetCurrentZone()) {
  1155. MConversation.readlock();
  1156. int32 spawn_id = conversation_spawns[conversation_id];
  1157. Spawn* spawn = nullptr;
  1158. if(spawn_id) {
  1159. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  1160. }
  1161. Item* item = conversation_items[conversation_id];
  1162. MConversation.releasereadlock();
  1163. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1164. if (spawn)
  1165. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1166. else if (item && lua_interface && item->GetItemScript())
  1167. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1168. else
  1169. CloseDialog(conversation_id);
  1170. }
  1171. else
  1172. CloseDialog(conversation_id);
  1173. }
  1174. safe_delete(packet);
  1175. }
  1176. break;
  1177. }
  1178. case OP_CancelMoveObjectModeMsg: {
  1179. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1180. if (GetTempPlacementSpawn())
  1181. {
  1182. Spawn* tmp = GetTempPlacementSpawn();
  1183. SetTempPlacementSpawn(nullptr);
  1184. SetPlacementUniqueItemID(0);
  1185. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1186. break; // break out early if we are tied to a temp spawn
  1187. }
  1188. // if we are moving some other object? other use-cases not covered
  1189. break;
  1190. }
  1191. case OP_PositionMoveableObject: {
  1192. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1193. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1194. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1195. Spawn* spawn = 0;
  1196. if (GetTempPlacementSpawn())
  1197. spawn = GetTempPlacementSpawn();
  1198. else
  1199. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1200. if (!spawn) {
  1201. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1202. break;
  1203. }
  1204. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1205. {
  1206. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1207. break;
  1208. }
  1209. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1210. if(uniqueID) {
  1211. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1212. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1213. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1214. break;
  1215. }
  1216. }
  1217. // handles instantiation logic + adding to zone of a new house object
  1218. PopulateHouseSpawn(place_object);
  1219. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1220. char query[256];
  1221. switch (GetSpawnPlacementMode())
  1222. {
  1223. case ServerSpawnPlacementMode::OPEN_HEADING:
  1224. {
  1225. if (spawn && spawn->IsWidget())
  1226. {
  1227. Widget* widget = (Widget*)spawn;
  1228. widget->SetOpenHeading(newHeading);
  1229. widget->SetIncludeHeading(true);
  1230. spawn->position_changed = true;
  1231. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1232. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1233. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1234. }
  1235. else
  1236. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1237. break;
  1238. }
  1239. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1240. {
  1241. if (spawn && spawn->IsWidget())
  1242. {
  1243. Widget* widget = (Widget*)spawn;
  1244. widget->SetClosedHeading(newHeading);
  1245. widget->SetIncludeHeading(true);
  1246. spawn->position_changed = true;
  1247. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1248. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1249. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1250. if (spawn->GetSpawnLocationID())
  1251. {
  1252. Query query;
  1253. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1254. }
  1255. }
  1256. else
  1257. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1258. break;
  1259. }
  1260. default:
  1261. {
  1262. spawn->SetX(place_object->getType_float_ByName("x"));
  1263. spawn->SetY(place_object->getType_float_ByName("y"));
  1264. spawn->SetZ(place_object->getType_float_ByName("z"));
  1265. spawn->SetHeading(newHeading);
  1266. spawn->SetSpawnOrigX(spawn->GetX());
  1267. spawn->SetSpawnOrigY(spawn->GetY());
  1268. spawn->SetSpawnOrigZ(spawn->GetZ());
  1269. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1270. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1271. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1272. else if (spawn->GetSpawnLocationID() > 0)
  1273. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1274. }
  1275. }
  1276. PopulateHouseSpawnFinalize();
  1277. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1278. safe_delete(place_object);
  1279. }
  1280. break;
  1281. }
  1282. case OP_CampAbortedMsg: {
  1283. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1284. if (camp_timer)
  1285. {
  1286. // JA: clear camping flag
  1287. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1288. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1289. safe_delete(camp_timer);
  1290. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1291. QueuePacket(outapp);
  1292. }
  1293. break;
  1294. }
  1295. case OP_DoneLoadingUIResourcesMsg: {
  1296. ClientPacketFunctions::SendUpdateSpellBook(this);
  1297. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1298. QueuePacket(app);
  1299. if(!player_loading_complete)
  1300. {
  1301. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1302. if (zone_script && lua_interface)
  1303. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1304. player_loading_complete = true;
  1305. }
  1306. break;
  1307. }
  1308. case OP_DoneLoadingZoneResourcesMsg: {
  1309. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1310. SendZoneSpawns();
  1311. break;
  1312. }
  1313. case OP_DefaultGroupOptionsRequestMsg: {
  1314. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1315. SendDefaultGroupOptions();
  1316. break;
  1317. }
  1318. case OP_DoneLoadingEntityResourcesMsg: {
  1319. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1320. if (!IsReadyForSpawns())
  1321. SetReadyForSpawns(true);
  1322. SendCharInfo();
  1323. pos_update.Start();
  1324. quest_pos_timer.Start();
  1325. break;
  1326. }
  1327. case OP_LootItemsRequestMsg: {
  1328. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1329. HandleLoot(app);
  1330. break;
  1331. }
  1332. case OP_WaypointSelectMsg: {
  1333. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1334. if (packet) {
  1335. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1336. int32 selection = packet->getType_int32_ByName("selection");
  1337. if (selection > 0) {
  1338. SelectWaypoint(selection);
  1339. }
  1340. }
  1341. }
  1342. break;
  1343. }
  1344. case OP_KnowledgeWindowSlotMappingMsg: {
  1345. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1346. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1347. if (packet) {
  1348. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1349. int num_updates = packet->getType_int16_ByName("spell_count");
  1350. int32 spell_id = 0;
  1351. int16 slot_id = 0;
  1352. char tmp_spell_id[15];
  1353. char tmp_slot[15];
  1354. for (int i = 0; i < num_updates; i++) {
  1355. memset(tmp_spell_id, 0, 15);
  1356. memset(tmp_slot, 0, 15);
  1357. sprintf(tmp_spell_id, "spell_id_%i", i);
  1358. sprintf(tmp_slot, "slot_id_%i", i);
  1359. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1360. if (spell_id > 0) {
  1361. slot_id = packet->getType_int16_ByName(tmp_slot);
  1362. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1363. if (spell && spell->slot != slot_id) {
  1364. spell->slot = slot_id;
  1365. spell->save_needed = true;
  1366. }
  1367. }
  1368. }
  1369. }
  1370. safe_delete(packet);
  1371. }
  1372. //SendKnowledgeWindowSlot();
  1373. break;
  1374. }
  1375. case OP_ReadyToZoneMsg: {
  1376. if (!IsReadyForSpawns())
  1377. {
  1378. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1379. }
  1380. else
  1381. {
  1382. if(zoning_destination)
  1383. SetCurrentZone(zoning_destination);
  1384. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1385. bool succeed_override_zone = true;
  1386. if(!GetCurrentZone()) {
  1387. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1388. if(zoning_instance_id) {
  1389. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1390. if(!zone) {
  1391. 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);
  1392. succeed_override_zone = false;
  1393. }
  1394. else {
  1395. SetCurrentZone(zone);
  1396. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1397. }
  1398. }
  1399. else if(zoning_id) {
  1400. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1401. if(!zone) {
  1402. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1403. succeed_override_zone = false;
  1404. }
  1405. else {
  1406. SetCurrentZone(zone);
  1407. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1408. }
  1409. }
  1410. }
  1411. if (client_zoning)
  1412. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1413. else
  1414. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1415. Disconnect();
  1416. }
  1417. break;
  1418. }
  1419. case OP_ClientFellMsg: {
  1420. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1421. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1422. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1423. float height = request->getType_float_ByName("height");
  1424. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1425. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1426. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1427. break;
  1428. }*/
  1429. float safe_height = 13.0f;
  1430. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1431. GetPlayer()->MStats.lock();
  1432. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1433. GetPlayer()->MStats.unlock();
  1434. if (skill)
  1435. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1436. if (height > safe_height) {
  1437. int16 damage = (int16)ceil((height - safe_height) * 125);
  1438. if (height >= 80)
  1439. damage = 30000;
  1440. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1441. if (damage > 0) {
  1442. GetPlayer()->TakeDamage(damage);
  1443. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1444. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1445. if (!GetPlayer()->GetInvulnerable())
  1446. GetPlayer()->SetCharSheetChanged(true);
  1447. 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);
  1448. if (GetPlayer()->GetHP() == 0) {
  1449. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1450. }
  1451. }
  1452. }
  1453. safe_delete(request);
  1454. }
  1455. break;
  1456. }
  1457. case OP_MapFogDataUpdateMsg: {
  1458. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1459. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1460. break;
  1461. }
  1462. case OP_SelectZoneTeleporterDestinatio: {
  1463. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1464. ProcessTeleportLocation(app);
  1465. break;
  1466. }
  1467. case OP_SendLatestRequestMsg: {
  1468. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1469. uchar blah25[] = { 0x01 };
  1470. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1471. QueuePacket(app25);
  1472. break;
  1473. }
  1474. case OP_ShowCreateFromRecipeUIMsg: {
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1476. break;
  1477. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1478. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1479. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1480. QueuePacket(app);
  1481. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1482. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1483. QueuePacket(app);
  1484. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1485. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1486. ,0xff,0xff,0xff};
  1487. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1488. QueuePacket(app);
  1489. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1490. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1491. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1492. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1493. QueuePacket(app);
  1494. uchar blah5[] ={0x00,0x00};
  1495. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1496. QueuePacket(app);
  1497. break;*/
  1498. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1499. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1500. //QueuePacket(app);
  1501. }
  1502. case OP_BeginItemCreationMsg: {
  1503. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1504. //DumpPacket(app->pBuffer, app->size);
  1505. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1506. if (packet) {
  1507. packet->LoadPacketData(app->pBuffer, app->size);
  1508. int32 item = 0;
  1509. vector<int32> items;
  1510. char tmp_item_id[20];
  1511. item = packet->getType_int32_ByName("primary_component_id");
  1512. if (item > 0)
  1513. items.push_back(item);
  1514. item = 0;
  1515. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1516. for (int8 i = 0; i < build_components; i++) {
  1517. memset(tmp_item_id, 0, 20);
  1518. sprintf(tmp_item_id, "component_id_%i", i);
  1519. item = packet->getType_int32_ByName(tmp_item_id);
  1520. if (item > 0)
  1521. items.push_back(item);
  1522. item = 0;
  1523. }
  1524. item = packet->getType_int32_ByName("fuel_id");
  1525. if (item > 0)
  1526. items.push_back(item);
  1527. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1528. safe_delete(packet);
  1529. }
  1530. break;
  1531. }
  1532. case OP_StopItemCreationMsg: {
  1533. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1534. //DumpPacket(app->pBuffer, app->size);
  1535. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1536. break;
  1537. }
  1538. case OP_SysClient:
  1539. case OP_SignalMsg: {
  1540. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1541. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1542. if (packet) {
  1543. packet->LoadPacketData(app->pBuffer, app->size);
  1544. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1545. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1546. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1547. SetReloadingZone(false);
  1548. if(GetPlayer()->IsDeletedSpawn()) {
  1549. GetPlayer()->SetDeletedSpawn(false);
  1550. }
  1551. ResetZoningCoords();
  1552. SetReadyForUpdates();
  1553. GetPlayer()->SendSpawnChanges(true);
  1554. ProcessStateCommands();
  1555. GetPlayer()->changed = true;
  1556. GetPlayer()->info_changed = true;
  1557. GetPlayer()->vis_changed = true;
  1558. player_pos_changed = true;
  1559. GetPlayer()->AddChangedZoneSpawn();
  1560. }
  1561. else {
  1562. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1563. }
  1564. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1565. if (zone_script && lua_interface)
  1566. {
  1567. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1568. }
  1569. }
  1570. break;
  1571. }
  1572. case OP_EntityVerbsRequestMsg: {
  1573. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1574. HandleVerbRequest(app);
  1575. break;
  1576. }
  1577. case OP_EntityVerbsVerbMsg: {
  1578. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1579. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1580. if (packet) {
  1581. packet->LoadPacketData(app->pBuffer, app->size);
  1582. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1583. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1584. Spawn* spawn = player->GetTarget();
  1585. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1586. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1587. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1588. {
  1589. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1590. if (spawn->IsGroundSpawn())
  1591. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1592. else if (spawn->IsObject())
  1593. ((Object*)spawn)->HandleUse(this, command);
  1594. else if (spawn->IsWidget())
  1595. ((Widget*)spawn)->HandleUse(this, command);
  1596. else if (spawn->IsSign())
  1597. ((Sign*)spawn)->HandleUse(this, command);
  1598. }
  1599. }
  1600. }
  1601. else {
  1602. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1603. if (command.size > 0) {
  1604. string command_name = command.data;
  1605. if (command_name.find(" ") < 0xFFFFFFFF) {
  1606. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1607. string::size_type pos = command_name.find(" ");
  1608. while(pos != string::npos){
  1609. command_name.replace(pos, 1, "_");
  1610. pos = command_name.find(" ");
  1611. }
  1612. }
  1613. else
  1614. command_name = command_name.substr(0, command_name.find(" "));
  1615. }
  1616. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1617. if (handler != 0xFFFFFFFF) {
  1618. if (command.data == command_name) {
  1619. command.data = "";
  1620. command.size = 0;
  1621. }
  1622. else {
  1623. command.data = command.data.substr(command.data.find(" ") + 1);
  1624. command.size = command.data.length();
  1625. }
  1626. commands.Process(handler, &command, this);
  1627. }
  1628. else {
  1629. if (spawn && spawn->IsNPC()) {
  1630. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1631. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1632. command_name = command.data;
  1633. string::size_type pos = command_name.find(" ");
  1634. while (pos != string::npos) {
  1635. command_name.replace(pos, 1, "_");
  1636. pos = command_name.find(" ");
  1637. }
  1638. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1639. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1640. }
  1641. }
  1642. }
  1643. }
  1644. else
  1645. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1646. }
  1647. }
  1648. }
  1649. safe_delete(packet);
  1650. }
  1651. break;
  1652. }
  1653. case OP_SkillInfoRequest: {
  1654. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1655. HandleSkillInfoRequest(app);
  1656. break;
  1657. }
  1658. case OP_UpdateTargetMsg: {
  1659. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1660. int16 index = 0;
  1661. memcpy(&index, app->pBuffer, sizeof(int16));
  1662. if (index == 0xFFFF)
  1663. GetPlayer()->SetTarget(0);
  1664. else {
  1665. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1666. if(spawn)
  1667. GetPlayer()->SetTarget(spawn);
  1668. else {
  1669. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1670. }
  1671. }
  1672. if (GetPlayer()->GetTarget())
  1673. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1674. //player->SetTarget((int16*)app->pBuffer);
  1675. break;
  1676. }
  1677. case OP_ExamineInfoRequestMsg: {
  1678. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1679. HandleExamineInfoRequest(app);
  1680. break;
  1681. }
  1682. case OP_QuickbarUpdateMsg:
  1683. //case OP_QuickbarAddMsg:
  1684. {
  1685. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1686. HandleQuickbarUpdateRequest(app);
  1687. break;
  1688. }
  1689. case OP_PredictionUpdateMsg: {
  1690. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1691. if (version <= 546) {
  1692. int8 offset = 9;
  1693. if (app->pBuffer[0] == 0xFF)
  1694. offset += 2;
  1695. if (app->size > offset) {
  1696. if (player->IsCasting()) {
  1697. float distance = 0;
  1698. float x = player->GetX();
  1699. float y = player->GetY();
  1700. float z = player->GetZ();
  1701. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1702. distance = player->GetDistance(x, y, z, false);
  1703. if (distance > .5)
  1704. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1705. }
  1706. else
  1707. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1708. player_pos_changed = true;
  1709. //DumpPacket(app);
  1710. }
  1711. }
  1712. else {
  1713. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1714. QueuePacket(app);
  1715. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1716. }
  1717. break;
  1718. }
  1719. case OP_RemoteCmdMsg: {
  1720. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1721. if (app->size > 0) {
  1722. EQ2_CommandString remote(app->pBuffer, app->size);
  1723. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1724. #if EQDEBUG >= 9
  1725. DumpPacket(app);
  1726. #endif
  1727. commands.Process(remote.handler, &remote.command, this);
  1728. }
  1729. else //bad client, disconnect
  1730. Disconnect();
  1731. break;
  1732. }
  1733. case OP_CancelSpellCast: {
  1734. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1735. current_zone->Interrupted(player, 0, 0, true);
  1736. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1737. break;
  1738. }
  1739. case OP_UpdatePositionMsg: {
  1740. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1741. int8 offset = 13;
  1742. if (app->pBuffer[0] == 0xFF)
  1743. offset += 2;
  1744. if (app->size > offset) {
  1745. if (player->IsCasting()) {
  1746. float distance = 0;
  1747. float x = player->GetX();
  1748. float y = player->GetY();
  1749. float z = player->GetZ();
  1750. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1751. distance = player->GetDistance(x, y, z, false);
  1752. if (distance > .5)
  1753. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1754. }
  1755. else
  1756. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1757. player_pos_changed = true;
  1758. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1759. //DumpPacket(app);
  1760. }
  1761. break;
  1762. }
  1763. case OP_MailSendMessageMsg: {
  1764. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1765. HandleSentMail(app);
  1766. break;
  1767. }
  1768. case OP_StopTrackingMsg: {
  1769. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1770. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1771. break;
  1772. }
  1773. case OP_BeginTrackingMsg: {
  1774. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1775. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1776. if (packet) {
  1777. packet->LoadPacketData(app->pBuffer, app->size);
  1778. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1779. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1780. if (spawn) {
  1781. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1782. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1783. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1784. }
  1785. safe_delete(packet);
  1786. }
  1787. break;
  1788. }
  1789. case OP_BioUpdateMsg: {
  1790. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1791. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1792. if (packet) {
  1793. packet->LoadPacketData(app->pBuffer, app->size);
  1794. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1795. safe_delete(packet);
  1796. }
  1797. break;
  1798. }
  1799. case OP_RewardPackMsg: {
  1800. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1801. /* 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
  1802. when we come across it (scatman) */
  1803. const char* name = app->GetOpcodeName();
  1804. if (name)
  1805. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1806. else
  1807. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1808. //DumpPacket(app);
  1809. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1810. if (packet) {
  1811. packet->LoadPacketData(app->pBuffer, app->size);
  1812. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1813. /* Player has contacted a guild recruiter */
  1814. if (recruiter_name.length() > 0) {
  1815. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1816. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1817. if (recruiter && guild) {
  1818. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1819. 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()));
  1820. recruiter->PlaySound("ui_guild_page");
  1821. }
  1822. }
  1823. /* New picture taken for guild recruiting */
  1824. else {
  1825. //DumpPacket(app->pBuffer, app->size);
  1826. int32 guild_id = 0;
  1827. int16 picture_data_size = 0;
  1828. unsigned char* recruiter_picture_data = 0;
  1829. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1830. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1831. Guild* guild = guild_list.GetGuild(guild_id);
  1832. if (guild) {
  1833. GuildMember* gm = guild->GetGuildMember(player);
  1834. if (gm) {
  1835. safe_delete_array(gm->recruiter_picture_data);
  1836. recruiter_picture_data = new unsigned char[picture_data_size];
  1837. for (int16 i = 0; i < picture_data_size; i++)
  1838. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1839. gm->recruiter_picture_data = recruiter_picture_data;
  1840. gm->recruiter_picture_data_size = picture_data_size;
  1841. guild->SetMemberSaveNeeded(true);
  1842. }
  1843. }
  1844. }
  1845. safe_delete(packet);
  1846. }
  1847. break;
  1848. }
  1849. case OP_PetOptions: {
  1850. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1851. Spawn* target = player->GetTarget();
  1852. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1853. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1854. bool change = false;
  1855. packet->LoadPacketData(app->pBuffer, app->size);
  1856. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1857. if (strlen(name.c_str()) != 0) {
  1858. target->SetName(name.c_str());
  1859. player->GetInfoStruct()->set_pet_name(name);
  1860. GetCurrentZone()->SendUpdateTitles(target);
  1861. change = true;
  1862. }
  1863. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1864. // Check protect self setting and update if needed
  1865. if (packet->getType_int8_ByName("protect_self") == 1) {
  1866. if ((pet_behavior & 2) == 0) {
  1867. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1868. change = true;
  1869. }
  1870. }
  1871. else {
  1872. if ((pet_behavior & 2) != 0) {
  1873. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1874. change = true;
  1875. }
  1876. }
  1877. // Check protect master setting and update if needed
  1878. if (packet->getType_int8_ByName("protect_master") == 1) {
  1879. if ((pet_behavior & 1) == 0) {
  1880. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1881. change = true;
  1882. }
  1883. }
  1884. else {
  1885. if ((pet_behavior & 1) != 0) {
  1886. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1887. change = true;
  1888. }
  1889. }
  1890. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1891. // Check stay/follow setting and update if needed
  1892. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1893. if (pet_movement != 2) {
  1894. player->GetInfoStruct()->set_pet_movement(2);
  1895. change = true;
  1896. }
  1897. }
  1898. else {
  1899. if (pet_movement != 1) {
  1900. player->GetInfoStruct()->set_pet_movement(1);
  1901. change = true;
  1902. }
  1903. }
  1904. // Ranged/Melee settings are not implemented yet
  1905. if (change)
  1906. player->SetCharSheetChanged(true);
  1907. safe_delete(packet);
  1908. }
  1909. break;
  1910. }
  1911. case OP_RecipeBook: {
  1912. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1913. SendRecipeList();
  1914. break;
  1915. }
  1916. case OP_BuyPlayerHouseMsg: {
  1917. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1918. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1919. if (packet) {
  1920. packet->LoadPacketData(app->pBuffer, app->size);
  1921. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1922. if (hz) {
  1923. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1924. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1925. if (houses.size() > 24)
  1926. {
  1927. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1928. safe_delete(packet);
  1929. break;
  1930. }
  1931. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1932. {
  1933. std::string req = "You must be of ";
  1934. if (hz->alignment == 1)
  1935. req.append("Good");
  1936. else
  1937. req.append("Evil");
  1938. req.append(" alignment to purchase this house");
  1939. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1940. safe_delete(packet);
  1941. break;
  1942. }
  1943. int32 status_req = hz->upkeep_status + hz->cost_status;
  1944. int32 available_status = player->GetInfoStruct()->get_status_points();
  1945. if (status_req <= available_status &&
  1946. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1947. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1948. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1949. {
  1950. player->GetInfoStruct()->subtract_status_points(status_req);
  1951. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1952. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1953. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1954. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1955. //ClientPacketFunctions::SendHousingList(this);
  1956. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1957. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1958. PlaySound("coin_cha_ching");
  1959. }
  1960. else
  1961. {
  1962. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1963. PlaySound("buy_failed");
  1964. }
  1965. }
  1966. }
  1967. safe_delete(packet);
  1968. break;
  1969. }
  1970. case OP_EnterHouseMsg: {
  1971. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1972. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1973. if (packet) {
  1974. packet->LoadPacketData(app->pBuffer, app->size);
  1975. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1976. if (ph) {
  1977. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1978. if (hz) {
  1979. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1980. if (house) {
  1981. Zone(house, true);
  1982. }
  1983. }
  1984. }
  1985. }
  1986. safe_delete(packet);
  1987. break;
  1988. }
  1989. case OP_PayHouseUpkeepMsg: {
  1990. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1991. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1992. if (packet) {
  1993. packet->LoadPacketData(app->pBuffer, app->size);
  1994. int64 houseID = packet->getType_int64_ByName("house_id");
  1995. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1996. if (ph)
  1997. {
  1998. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1999. if (!hz)
  2000. {
  2001. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2002. safe_delete(packet);
  2003. break;
  2004. }
  2005. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2006. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2007. {
  2008. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2009. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2010. {
  2011. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2012. PlaySound("buy_failed");
  2013. safe_delete(packet);
  2014. break;
  2015. }
  2016. }
  2017. bool escrowChange = false;
  2018. int64 statusReq = hz->upkeep_status;
  2019. int64 tmpRecoverStatus = 0;
  2020. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2021. {
  2022. escrowChange = true;
  2023. tmpRecoverStatus = ph->escrow_status;
  2024. statusReq -= ph->escrow_status;
  2025. ph->escrow_status = 0;
  2026. }
  2027. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2028. {
  2029. escrowChange = true;
  2030. ph->escrow_status -= statusReq;
  2031. tmpRecoverStatus = statusReq;
  2032. statusReq = 0;
  2033. }
  2034. int64 coinReq = hz->upkeep_coin;
  2035. int64 tmpRecoverCoins = 0;
  2036. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2037. {
  2038. escrowChange = true;
  2039. tmpRecoverCoins = ph->escrow_coins;
  2040. coinReq -= ph->escrow_coins;
  2041. ph->escrow_coins = 0;
  2042. }
  2043. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2044. {
  2045. escrowChange = true;
  2046. // more than enough in escrow, subtract and make our cost 0!
  2047. ph->escrow_coins -= coinReq;
  2048. tmpRecoverCoins = coinReq;
  2049. coinReq = 0;
  2050. }
  2051. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2052. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2053. {
  2054. if(coinReq && player->RemoveCoins(coinReq))
  2055. coinReq = 0;
  2056. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2057. statusReq = 0;
  2058. }
  2059. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2060. {
  2061. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2062. if (escrowChange)
  2063. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2064. ph->upkeep_due = upkeep_due;
  2065. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2066. //ClientPacketFunctions::SendHousingList(this);
  2067. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  2068. PlaySound("coin_cha_ching");
  2069. }
  2070. else
  2071. {
  2072. // recover the escrow we were going to use but could not spend due to lack of funds
  2073. if (tmpRecoverCoins)
  2074. ph->escrow_coins += tmpRecoverCoins;
  2075. if(tmpRecoverStatus)
  2076. ph->escrow_status += tmpRecoverStatus;
  2077. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2078. PlaySound("buy_failed");
  2079. }
  2080. }
  2081. else
  2082. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2083. }
  2084. safe_delete(packet);
  2085. break;
  2086. }
  2087. case OP_ExitHouseMsg: {
  2088. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2089. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2090. if (instance_id > 0) {
  2091. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2092. if (ph) {
  2093. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2094. if (hz) {
  2095. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2096. // determine if this is an instanced zone that already exists
  2097. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2098. if (instance_zone || new_zone) {
  2099. GetPlayer()->SetX(hz->exit_x);
  2100. GetPlayer()->SetY(hz->exit_y);
  2101. GetPlayer()->SetZ(hz->exit_z);
  2102. GetPlayer()->SetHeading(hz->exit_heading);
  2103. if (instance_zone)
  2104. Zone(instance_zone->GetInstanceID(), false, true);
  2105. else
  2106. Zone(new_zone, false);
  2107. }
  2108. }
  2109. }
  2110. }
  2111. break;
  2112. }
  2113. case OP_QuestJournalWaypointMsg: {
  2114. //DumpPacket(app);
  2115. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2116. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2117. if (packet) {
  2118. packet->LoadPacketData(app->pBuffer, app->size);
  2119. int32 quests = packet->getType_int32_ByName("num_quests");
  2120. if (quests > 100) // just picking a number higher than max allowed
  2121. {
  2122. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2123. break;
  2124. }
  2125. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2126. for (int32 i = 0; i < quests; i++) {
  2127. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2128. if (id == 0)
  2129. continue;
  2130. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2131. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2132. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2133. if (player->player_quests.count(id) > 0) {
  2134. player->player_quests[id]->SetTracked(tracked);
  2135. player->player_quests[id]->SetSaveNeeded(true);
  2136. }
  2137. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2138. }
  2139. safe_delete(packet);
  2140. }
  2141. break;
  2142. }
  2143. case OP_PaperdollImage: {
  2144. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2145. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2146. //First check if this is a new image... delete an existing partial image if one exists
  2147. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2148. if (packet_index == 0) {
  2149. safe_delete_array(incoming_paperdoll.image_bytes);
  2150. incoming_paperdoll.last_received_packet_index = 0;
  2151. incoming_paperdoll.current_size_bytes = 0;
  2152. }
  2153. //return if this packet is not the one we are expecting...
  2154. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2155. safe_delete(packet);
  2156. break;
  2157. }
  2158. //Check how many packets we're supposed to be receiving for this/these images
  2159. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2160. //Check the image type, if this is a new type in the same series of packets we have a new image
  2161. int8 img_type = packet->getType_int8_ByName("image_type");
  2162. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2163. //We have a new image. Save the old data and clear before continuing
  2164. SavePlayerImages();
  2165. }
  2166. incoming_paperdoll.image_type = img_type;
  2167. //Get the size of the image data in this packet
  2168. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2169. if (image_size <= 0 || image_size > 1048576) {
  2170. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2171. safe_delete(packet);
  2172. break;
  2173. }
  2174. //Create a new array
  2175. int32 new_image_size = image_size;
  2176. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2177. if (incoming_paperdoll.image_bytes) {
  2178. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2179. safe_delete_array(incoming_paperdoll.image_bytes);
  2180. }
  2181. //variable i should be the index in the packet of the first PNG file byte
  2182. vector<DataStruct*>* d_structs = packet->getStructs();
  2183. vector<DataStruct*>::iterator itr;
  2184. int32 i = 0;
  2185. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2186. DataStruct* ds = (*itr);
  2187. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2188. i += ds->GetDataSizeInBytes();
  2189. else
  2190. break;
  2191. }
  2192. //Return if this packet is bad and we would read out of bounds
  2193. if (app->size - i < new_image_size) {
  2194. safe_delete(packet);
  2195. safe_delete_array(new_image);
  2196. break;
  2197. }
  2198. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2199. memcpy(tmp, app->pBuffer + i, new_image_size);
  2200. incoming_paperdoll.current_size_bytes += new_image_size;
  2201. incoming_paperdoll.image_bytes = new_image;
  2202. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2203. if (incoming_paperdoll.image_num_packets == 1 ||
  2204. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2205. SavePlayerImages();
  2206. }
  2207. incoming_paperdoll.last_received_packet_index = packet_index;
  2208. }
  2209. safe_delete(packet);
  2210. */
  2211. break;
  2212. }
  2213. case OP_ReadyForTakeOffMsg:
  2214. {
  2215. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2216. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2217. if (GetPendingFlightPath() > 0) {
  2218. if (index != -1) {
  2219. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2220. if (packet) {
  2221. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2222. packet->setDataByName("path_id", index);
  2223. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2224. QueuePacket(packet->serialize());
  2225. safe_delete(packet);
  2226. on_auto_mount = true;
  2227. }
  2228. }
  2229. else {
  2230. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2231. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2232. EndAutoMount();
  2233. }
  2234. SetPendingFlightPath(0);
  2235. }
  2236. else
  2237. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2238. break;
  2239. }
  2240. case OP_EarlyLandingRequestMsg:
  2241. {
  2242. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2243. EndAutoMount();
  2244. break;
  2245. }
  2246. case OP_SubmitCharCust:
  2247. {
  2248. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2249. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2250. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2251. int8 type = packet->getType_int8_ByName("type");
  2252. if (type == 0) {
  2253. if (player->custNPC) {
  2254. player->custNPCTarget->CustomizeAppearance(packet);
  2255. current_zone->SendSpawnChanges(player->custNPCTarget);
  2256. }
  2257. else {
  2258. player->CustomizeAppearance(packet);
  2259. current_zone->SendSpawnChanges(player);
  2260. }
  2261. }
  2262. }
  2263. if (player->custNPC) {
  2264. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2265. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2266. if (player->custNPCTarget->IsBot())
  2267. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2268. player->custNPC = false;
  2269. player->custNPCTarget = 0;
  2270. player->changed = true;
  2271. player->info_changed = true;
  2272. current_zone->SendSpawnChanges(player, this);
  2273. }
  2274. break;
  2275. }
  2276. default: {
  2277. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2278. const char* name = app->GetOpcodeName();
  2279. if (name)
  2280. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2281. else
  2282. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2283. //DumpPacket(app);
  2284. }
  2285. }
  2286. if (!eqs || !eqs->CheckActive()) {
  2287. return false;
  2288. }
  2289. return ret;
  2290. }
  2291. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2292. if (!item) {
  2293. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2294. return false;
  2295. }
  2296. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2297. int16 lore_stack_count = 0;
  2298. if(((conflictItemList = player->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2299. (conflictequipmentList = player->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2300. (conflictAppearanceEquipmentList = player->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2301. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2302. return false;
  2303. }
  2304. else if(conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2305. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2306. return false;
  2307. }
  2308. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2309. if (player->item_list.AssignItemToFreeSlot(item)) {
  2310. if(item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2311. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  2312. if (gmi && gmi->group_id)
  2313. {
  2314. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2315. if (group)
  2316. {
  2317. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2318. deque<GroupMemberInfo*>* members = group->GetMembers();
  2319. if(members) {
  2320. for (int8 i = 0; i < members->size(); i++) {
  2321. Entity* member = members->at(i)->member;
  2322. if(!member)
  2323. continue;
  2324. if ((member->GetZone() != this->GetPlayer()->GetZone()))
  2325. continue;
  2326. if(member->IsPlayer()) {
  2327. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2328. item->save_needed = true;
  2329. }
  2330. }
  2331. }
  2332. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2333. }
  2334. }
  2335. }
  2336. int8 type = CHANNEL_LOOT;
  2337. if (entity) {
  2338. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2339. }
  2340. else {
  2341. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2342. }
  2343. Guild* guild = player->GetGuild();
  2344. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2345. char adjective[32];
  2346. int8 type;
  2347. memset(adjective, 0, sizeof(adjective));
  2348. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2349. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2350. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2351. }
  2352. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2353. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2354. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2355. }
  2356. else {
  2357. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2358. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2359. }
  2360. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2361. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2362. }
  2363. if (item->GetItemScript() && lua_interface)
  2364. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2365. CheckPlayerQuestsItemUpdate(item);
  2366. return true;
  2367. }
  2368. else
  2369. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2370. }
  2371. else
  2372. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2373. return false;
  2374. }
  2375. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2376. if (!entity) {
  2377. return false;
  2378. }
  2379. Item* item = entity->LootItem(item_id);
  2380. bool success = false;
  2381. success = HandleLootItem(entity, item);
  2382. if(!success)
  2383. entity->AddLootItem(item);
  2384. return success;
  2385. }
  2386. void Client::HandleLoot(EQApplicationPacket* app) {
  2387. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2388. if (packet) {
  2389. packet->LoadPacketData(app->pBuffer, app->size);
  2390. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2391. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2392. safe_delete(packet);
  2393. int32 item_id = 0;
  2394. Item* item = 0;
  2395. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2396. if (player->HasPendingLootItems(loot_id)) {
  2397. Item* master_item = 0;
  2398. if (loot_all) {
  2399. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2400. if (items) {
  2401. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2402. master_item = items->at(i);
  2403. if (master_item) {
  2404. item = new Item(master_item);
  2405. if (item) {
  2406. loot_all = HandleLootItem(0, item);
  2407. if (loot_all)
  2408. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2409. }
  2410. }
  2411. }
  2412. safe_delete(items);
  2413. }
  2414. }
  2415. else {
  2416. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2417. if (packet) {
  2418. packet->LoadPacketData(app->pBuffer, app->size);
  2419. item_id = packet->getType_int32_ByName("item_id");
  2420. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2421. if (items) {
  2422. for (int32 i = 0; i < items->size(); i++) {
  2423. master_item = items->at(i);
  2424. if (master_item && master_item->details.item_id == item_id) {
  2425. item = new Item(master_item);
  2426. if (item && HandleLootItem(0, item))
  2427. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2428. break;
  2429. }
  2430. }
  2431. safe_delete(items);
  2432. }
  2433. safe_delete(packet);
  2434. }
  2435. }
  2436. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2437. if (outapp)
  2438. QueuePacket(outapp);
  2439. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2440. }
  2441. else {
  2442. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2443. if (loot_all) {
  2444. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2445. loot_all = HandleLootItem(spawn, item_id);
  2446. }
  2447. }
  2448. else {
  2449. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2450. if (packet) {
  2451. packet->LoadPacketData(app->pBuffer, app->size);
  2452. item_id = packet->getType_int32_ByName("item_id");
  2453. HandleLootItem(spawn, item_id);
  2454. safe_delete(packet);
  2455. }
  2456. }
  2457. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2458. if (outapp)
  2459. QueuePacket(outapp);
  2460. Loot(spawn);
  2461. if (!spawn->HasLoot()) {
  2462. CloseLoot(loot_id);
  2463. if (spawn->IsNPC())
  2464. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2465. }
  2466. }
  2467. else {
  2468. if (!spawn) {
  2469. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2470. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2471. }
  2472. else
  2473. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2474. }
  2475. }
  2476. }
  2477. }
  2478. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2479. PacketStruct* request = 0;
  2480. // cout << "Request: \n";
  2481. // DumpPacket(app);
  2482. switch (app->pBuffer[0]) {
  2483. case 0: { //items
  2484. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2485. if (request) {
  2486. request->LoadPacketData(app->pBuffer, app->size);
  2487. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2488. if (!item)
  2489. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2490. if (item) {
  2491. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2492. if (response) {
  2493. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2494. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2495. response->setSmallStringByName("name", item->name.c_str());
  2496. EQ2Packet* app2 = response->serialize();
  2497. //DumpPacket(app2);
  2498. QueuePacket(app2);
  2499. safe_delete(response);
  2500. }
  2501. }
  2502. }
  2503. break;
  2504. }
  2505. case 2: {//spells
  2506. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2507. if (request) {
  2508. request->LoadPacketData(app->pBuffer, app->size);
  2509. int32 id = request->getType_int32_ByName("id");
  2510. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2511. Spell* spell = master_spell_list.GetSpell(id, tier);
  2512. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2513. if (response) {
  2514. response->setDataByName("request_type", 2);
  2515. response->setDataByName("unique_id", tier);
  2516. response->setDataByName("id", id);
  2517. if (spell)
  2518. response->setSmallStringByName("name", spell->GetName());
  2519. else
  2520. response->setSmallStringByName("name", "Unknown Spell");
  2521. EQ2Packet* app2 = response->serialize();
  2522. // DumpPacket(app2);
  2523. QueuePacket(app2);
  2524. safe_delete(response);
  2525. }
  2526. }
  2527. break;
  2528. }
  2529. default: {
  2530. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2531. }
  2532. }
  2533. safe_delete(request);
  2534. }
  2535. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2536. PacketStruct* request = 0;
  2537. if (!app || app->size == 0)
  2538. return;
  2539. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2540. //DumpPacket(app);
  2541. int8 type = app->pBuffer[0];
  2542. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2543. if (version <= 283) {
  2544. if (type == 1)
  2545. type = 4;
  2546. else if (type == 2)
  2547. type = 5;
  2548. }
  2549. if (type == 3) {
  2550. Spell* spell = 0;
  2551. bool trait_display;
  2552. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2553. if (!request) {
  2554. return;
  2555. }
  2556. request->LoadPacketData(app->pBuffer, app->size);
  2557. int32 id = request->getType_int32_ByName("id");
  2558. int32 tier = request->getType_int32_ByName("tier");
  2559. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2560. bool display = true;
  2561. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2562. display = false;
  2563. else if (version <= 546)
  2564. display = request->getType_int8_ByName("display");
  2565. else if (version > 546)
  2566. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2567. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2568. if (trait_tier != 0xFFFFFFFF) {
  2569. spell = master_spell_list.GetSpell(id, trait_tier);
  2570. if (!spell) {
  2571. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2572. }
  2573. trait_display = true;
  2574. }
  2575. else {
  2576. spell = master_spell_list.GetSpell(id, tier);
  2577. trait_display = false;
  2578. }
  2579. // if we can't find it on the master spell list, see if it is a custom spell
  2580. if (!spell)
  2581. {
  2582. lua_interface->FindCustomSpellLock();
  2583. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2584. if (tmpSpell)
  2585. spell = tmpSpell->spell;
  2586. lua_interface->FindCustomSpellUnlock();
  2587. }
  2588. if (spell && !CountSentSpell(id, tier)) {
  2589. if (!spell->IsCopiedSpell())
  2590. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2591. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2592. //DumpPacket(app);
  2593. QueuePacket(app);
  2594. }
  2595. }
  2596. else if (type == 0) {
  2597. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2598. if (!request) {
  2599. return;
  2600. }
  2601. request->LoadPacketData(app->pBuffer, app->size);
  2602. int32 id = request->getType_int32_ByName("id");
  2603. Item* item = 0;
  2604. // translate from unique id to spawn id for houses
  2605. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2606. bool wasSpawn = false;
  2607. if (spawn)
  2608. {
  2609. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2610. if (item)
  2611. {
  2612. wasSpawn = true;
  2613. item = new Item(item);
  2614. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2615. }
  2616. }
  2617. if (!item)
  2618. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2619. if (!item)
  2620. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2621. if (!item)
  2622. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2623. if (!item)
  2624. item = master_item_list.GetItem(id);
  2625. if (item) {// && sent_item_details.count(id) == 0){
  2626. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2627. sent_item_details[id] = true;
  2628. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2629. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2630. //DumpPacket(app);
  2631. QueuePacket(app);
  2632. if (wasSpawn)
  2633. delete item;
  2634. }
  2635. else {
  2636. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2637. DumpPacket(app);
  2638. }
  2639. }
  2640. else if (type == 1) {
  2641. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2642. if (!request) {
  2643. return;
  2644. }
  2645. request->LoadPacketData(app->pBuffer, app->size);
  2646. int32 id = request->getType_int32_ByName("id");
  2647. int32 unique_id = request->getType_int32_ByName("unique_id");
  2648. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2649. if (!item)
  2650. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2651. if (!item)
  2652. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2653. if (!item)
  2654. item = master_item_list.GetItem(id);
  2655. if (item) {
  2656. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2657. sent_item_details[id] = true;
  2658. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2659. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2660. //DumpPacket(app);
  2661. QueuePacket(app);
  2662. }
  2663. else {
  2664. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2665. DumpPacket(app);
  2666. }
  2667. }
  2668. else if (type == 2) {
  2669. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2670. if (!request) {
  2671. return;
  2672. }
  2673. request->LoadPacketData(app->pBuffer, app->size);
  2674. int32 id = request->getType_int32_ByName("item_id");
  2675. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2676. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2677. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2678. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2679. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2680. //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);
  2681. Item* item = master_item_list.GetItem(id);
  2682. if (item) {
  2683. //only display popup for non merchant links
  2684. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2685. //DumpPacket(app);
  2686. QueuePacket(app);
  2687. }
  2688. else {
  2689. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2690. DumpPacket(app);
  2691. }
  2692. }
  2693. else if (type == 4) { //spell effect
  2694. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2695. if (!request) {
  2696. return;
  2697. }
  2698. request->LoadPacketData(app->pBuffer, app->size);
  2699. int32 id = request->getType_int32_ByName("id");
  2700. int16 display = request->getType_int8_ByName("partial_info");
  2701. SpellEffects* effect = player->GetSpellEffect(id);
  2702. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2703. if (effect) {
  2704. int8 tier = effect->tier;
  2705. Spell* spell = master_spell_list.GetSpell(id, tier);
  2706. // if we can't find it on the master spell list, see if it is a custom spell
  2707. if (!spell)
  2708. {
  2709. lua_interface->FindCustomSpellLock();
  2710. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2711. EQ2Packet* pack = 0;
  2712. if (tmpSpell)
  2713. spell = tmpSpell->spell;
  2714. lua_interface->FindCustomSpellUnlock();
  2715. }
  2716. if (spell && !CountSentSpell(id, tier)) {
  2717. if (!spell->IsCopiedSpell())
  2718. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2719. int8 type = 0;
  2720. if (version <= 283)
  2721. type = 1;
  2722. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2723. //DumpPacket(app);
  2724. QueuePacket(app);
  2725. }
  2726. }
  2727. }
  2728. else if (type == 5) { // recipe info
  2729. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2730. if (!request)
  2731. return;
  2732. request->LoadPacketData(app->pBuffer, app->size);
  2733. int32 id = request->getType_int32_ByName("unknown_id");
  2734. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2735. if (recipe) {
  2736. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2737. //DumpPacket(app);
  2738. QueuePacket(app);
  2739. }
  2740. }
  2741. else if (type == 6) { // AA spell info
  2742. Spell* spell = 0;
  2743. //Spell* spell2 = 0;
  2744. //AltAdvanceData* data = 0;
  2745. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2746. if (!request)
  2747. return;
  2748. request->LoadPacketData(app->pBuffer, app->size);
  2749. int32 id = request->getType_int32_ByName("id");
  2750. int32 tier = GetPlayer()->GetSpellTier(id);
  2751. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2752. //data = master_aa_list.GetAltAdvancement(id);
  2753. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2754. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2755. spell = master_spell_list.GetSpell(id, tier);
  2756. if (!spell)
  2757. spell = master_spell_list.GetSpell(id, 1);
  2758. if (!spell)
  2759. {
  2760. lua_interface->FindCustomSpellLock();
  2761. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2762. if (tmpSpell)
  2763. spell = tmpSpell->spell;
  2764. lua_interface->FindCustomSpellUnlock();
  2765. }
  2766. if (!spell)
  2767. {
  2768. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2769. return;
  2770. }
  2771. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2772. if (!spell->IsCopiedSpell())
  2773. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2774. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2775. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2776. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2777. //DumpPacket(app);
  2778. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2779. QueuePacket(app);
  2780. //}
  2781. }
  2782. else {
  2783. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2784. DumpPacket(app);
  2785. }
  2786. safe_delete(request);
  2787. }
  2788. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2789. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2790. if (request) {
  2791. request->LoadPacketData(app->pBuffer, app->size);
  2792. int32 id = request->getType_int32_ByName("id");
  2793. int32 bar = request->getType_int32_ByName("hotbar_number");
  2794. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2795. int32 type = request->getType_int32_ByName("type");
  2796. int8 tier = request->getType_int32_ByName("unique_id");
  2797. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2798. Spell* spell = 0;
  2799. if (type == 0xFFFFFFFF)
  2800. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2801. else {
  2802. if (type == QUICKBAR_NORMAL)
  2803. spell = master_spell_list.GetSpell(id, tier);
  2804. if (spell)
  2805. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2806. else
  2807. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2808. }
  2809. safe_delete(request);
  2810. }
  2811. }
  2812. bool Client::Process(bool zone_process) {
  2813. if (!eqs) {
  2814. return false;
  2815. }
  2816. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2817. return true;
  2818. }
  2819. if (new_client_login) {
  2820. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2821. SendLoginInfo();
  2822. new_client_login = false;
  2823. }
  2824. bool ret = true;
  2825. sockaddr_in to;
  2826. memset((char*)&to, 0, sizeof(to));
  2827. to.sin_family = AF_INET;
  2828. to.sin_port = port;
  2829. to.sin_addr.s_addr = ip;
  2830. /************ Get all packets from packet manager out queue and process them ************/
  2831. EQApplicationPacket* app = 0;
  2832. if (eqs && !eqs->CheckActive()) {
  2833. num_active_failures++;
  2834. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2835. if (num_active_failures > 100) {
  2836. return false;
  2837. }
  2838. return true;
  2839. }
  2840. while (ret && eqs && (app = eqs->PopPacket())) {
  2841. ret = HandlePacket(app);
  2842. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2843. delete app;
  2844. }
  2845. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2846. player->ApplyPassiveSpells();
  2847. //database.LoadCharacterActiveSpells(player);
  2848. player->UnlockAllSpells(true);
  2849. should_load_spells = false;
  2850. }
  2851. if(spawn_removal_timer.Check() && GetPlayer()) {
  2852. GetPlayer()->CheckSpawnStateQueue();
  2853. }
  2854. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2855. {
  2856. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2857. return false;
  2858. }
  2859. if (quest_updates) {
  2860. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2861. ProcessQuestUpdates();
  2862. }
  2863. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2864. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2865. CheckQuestQueue();
  2866. }
  2867. MSaveSpellStateMutex.lock();
  2868. if(save_spell_state_timer.Check())
  2869. {
  2870. save_spell_state_timer.Disable();
  2871. GetPlayer()->SaveSpellEffects();
  2872. }
  2873. MSaveSpellStateMutex.unlock();
  2874. if (temp_placement_timer.Check()) {
  2875. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2876. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2877. hasSentTempPlacementSpawn = true;
  2878. temp_placement_timer.Disable();
  2879. }
  2880. }
  2881. if (pos_update.Check())
  2882. {
  2883. ProcessStateCommands();
  2884. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2885. if(GetPlayer()->GetRegionMap())
  2886. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2887. if(player_pos_changed && IsReadyForUpdates()) {
  2888. //GetPlayer()->CalculateLocation();
  2889. client_list.CheckPlayersInvisStatus(this);
  2890. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2891. player_pos_changed = false;
  2892. GetCurrentZone()->CheckTransporters(this);
  2893. if(GetPlayer()->GetRegionMap())
  2894. {
  2895. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2896. {
  2897. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2898. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2899. }
  2900. else
  2901. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2902. }
  2903. }
  2904. }
  2905. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2906. lua_interface->UpdateDebugClients(this);
  2907. if (quest_pos_timer.Check())
  2908. CheckPlayerQuestsLocationUpdate();
  2909. if (player->GetSkills()->HasSkillUpdates()) {
  2910. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2911. if (skills) {
  2912. Skill* skill = 0;
  2913. vector<Skill*>::iterator itr;
  2914. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2915. skill = *itr;
  2916. SkillChanged(skill, skill->previous_val, skill->current_val);
  2917. }
  2918. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2919. if (app) QueuePacket(app);
  2920. safe_delete(skills);
  2921. }
  2922. }
  2923. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2924. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2925. safe_delete(current_rez.expire_timer);
  2926. current_rez.expire_timer = 0;
  2927. current_rez.active = false;
  2928. current_rez.caster = 0;
  2929. current_rez.crit = false;
  2930. current_rez.crit_mod = 0;
  2931. current_rez.expire_timer = 0;
  2932. current_rez.heal_name = "";
  2933. current_rez.hp_perc = 0;
  2934. current_rez.mp_perc = 0;
  2935. current_rez.no_calcs = false;
  2936. current_rez.range = 0;
  2937. current_rez.should_delete = false;
  2938. current_rez.spell_name = "";
  2939. current_rez.spell_visual = 0;
  2940. current_rez.subspell = 0;
  2941. }
  2942. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2943. // Quest timers
  2944. Quest* failed_step = 0;
  2945. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2946. if (quest_timers.size() > 0) {
  2947. vector<int32>::iterator itr;
  2948. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2949. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2950. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2951. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2952. Quest* quest = player_quests->at(*itr);
  2953. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2954. failed_step = quest;
  2955. break;
  2956. }
  2957. }
  2958. else {
  2959. itr = quest_timers.erase(itr);
  2960. break;
  2961. }
  2962. }
  2963. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  2964. }
  2965. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2966. if (failed_step)
  2967. failed_step->StepFailed(failed_step->GetTimerStep());
  2968. if (player->ControlFlagsChanged())
  2969. player->SendControlFlagUpdates(this);
  2970. if (camp_timer && camp_timer->Check()) {
  2971. ResetSendMail();
  2972. if(getConnection())
  2973. getConnection()->SendDisconnect(false);
  2974. safe_delete(camp_timer);
  2975. ret = false;
  2976. }
  2977. if (!eqs || (eqs && !eqs->CheckActive()))
  2978. ret = false;
  2979. // redundant to client disconnect
  2980. // if(!ret)
  2981. // Save();
  2982. return ret;
  2983. }
  2984. ClientList::ClientList() {
  2985. MClients.SetName("ClientList::MClients");
  2986. }
  2987. ClientList::~ClientList() {
  2988. }
  2989. void ClientList::ReloadQuests() {
  2990. list<Client*>::iterator client_iter;
  2991. Client* client = 0;
  2992. MClients.readlock(__FUNCTION__, __LINE__);
  2993. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2994. client = *client_iter;
  2995. if (client)
  2996. client->ReloadQuests();
  2997. }
  2998. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2999. }
  3000. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3001. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3002. return;
  3003. list<Client*>::iterator client_iter;
  3004. Client* client = 0;
  3005. MClients.readlock(__FUNCTION__, __LINE__);
  3006. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3007. client = *client_iter;
  3008. if (client == owner || client->GetPlayer() == NULL)
  3009. continue;
  3010. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3011. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3012. }
  3013. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3014. }
  3015. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3016. list<Client*>::iterator client_iter;
  3017. Client* client = 0;
  3018. MClients.readlock(__FUNCTION__, __LINE__);
  3019. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3020. client = *client_iter;
  3021. if (!client->GetPlayer())
  3022. continue;
  3023. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3024. }
  3025. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3026. }
  3027. int32 ClientList::Count() {
  3028. return client_list.size();
  3029. }
  3030. void ClientList::Add(Client* client) {
  3031. MClients.writelock(__FUNCTION__, __LINE__);
  3032. client_list.push_back(client);
  3033. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3034. }
  3035. Client* ClientList::FindByAccountID(int32 account_id) {
  3036. list<Client*>::iterator client_iter;
  3037. Client* client = 0;
  3038. Client* ret = 0;
  3039. MClients.readlock(__FUNCTION__, __LINE__);
  3040. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3041. client = *client_iter;
  3042. if (client->GetAccountID() == account_id) {
  3043. ret = client;
  3044. break;
  3045. }
  3046. }
  3047. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3048. return ret;
  3049. }
  3050. Client* ClientList::FindByName(char* charName) {
  3051. list<Client*>::iterator client_iter;
  3052. Client* client = 0;
  3053. Client* ret = 0;
  3054. MClients.readlock(__FUNCTION__, __LINE__);
  3055. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3056. client = *client_iter;
  3057. if (!client || !client->GetPlayer())
  3058. continue;
  3059. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3060. ret = client;
  3061. break;
  3062. }
  3063. }
  3064. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3065. return ret;
  3066. }
  3067. Client* ClientList::Get(int32 ip, int16 port) {
  3068. list<Client*>::iterator client_iter;
  3069. Client* client = 0;
  3070. Client* ret = 0;
  3071. MClients.readlock(__FUNCTION__, __LINE__);
  3072. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3073. client = *client_iter;
  3074. if (client->GetIP() == ip && client->GetPort() == port) {
  3075. ret = client;
  3076. break;
  3077. }
  3078. }
  3079. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3080. return ret;
  3081. }
  3082. void ClientList::Process() {
  3083. list<Client*>::iterator client_iter;
  3084. list<Client*>::iterator erase_iter;
  3085. Client* client = 0;
  3086. MClients.readlock(__FUNCTION__, __LINE__);
  3087. erase_iter = client_list.end();
  3088. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3089. client = *client_iter;
  3090. // have a sanity check because the client list can sometimes obtain null client pointers
  3091. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3092. erase_iter = client_iter;
  3093. break;
  3094. }
  3095. }
  3096. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3097. if (erase_iter != client_list.end()) {
  3098. client = *erase_iter;
  3099. MClients.writelock(__FUNCTION__, __LINE__);
  3100. client_list.erase(erase_iter);
  3101. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3102. if (client && !client->remove_from_list) {
  3103. struct in_addr in;
  3104. in.s_addr = client->GetIP();
  3105. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3106. safe_delete(client);
  3107. }
  3108. }
  3109. }
  3110. void ClientList::RemoveConnection(EQStream* eqs) {
  3111. Client* client;
  3112. if (eqs) {
  3113. list<Client*>::iterator client_iter;
  3114. MClients.readlock(__FUNCTION__, __LINE__);
  3115. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3116. client = *client_iter;
  3117. if (client->getConnection() == eqs)
  3118. client->Disconnect(true);
  3119. }
  3120. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3121. }
  3122. }
  3123. bool ClientList::ContainsStream(EQStream* eqs) {
  3124. if (!eqs) {
  3125. return false;
  3126. }
  3127. list<Client*>::iterator client_iter;
  3128. bool ret = false;
  3129. MClients.readlock(__FUNCTION__, __LINE__);
  3130. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3131. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3132. ret = true;
  3133. break;
  3134. }
  3135. }
  3136. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3137. return ret;
  3138. }
  3139. void ClientList::Remove(Client* client, bool remove_data) {
  3140. client->remove_from_list = true;
  3141. if (remove_data) {
  3142. safe_delete(client);
  3143. }
  3144. }
  3145. void Client::SetCurrentZone(int32 id) {
  3146. if (current_zone) {
  3147. //current_zone->GetCombat()->RemoveHate(player);
  3148. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3149. }
  3150. SetCurrentZone(zone_list.Get(id));
  3151. }
  3152. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3153. if (current_zone) {
  3154. //current_zone->GetCombat()->RemoveHate(player);
  3155. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3156. }
  3157. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3158. }
  3159. ZoneServer* Client::GetCurrentZone() {
  3160. return current_zone;
  3161. }
  3162. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3163. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3164. if (channel_type == CHANNEL_LOOT)
  3165. return CHANNEL_COLOR_NEW_LOOT;
  3166. }
  3167. else if (GetVersion() >= 973) {
  3168. if (channel_type == CHANNEL_LOOT)
  3169. return CHANNEL_COLOR_NEWEST_LOOT;
  3170. }
  3171. if (GetVersion() <= 283) {
  3172. if (channel_type <=12)
  3173. return channel_type;
  3174. switch (channel_type) {
  3175. case CHANNEL_GROUP_CHAT:
  3176. case CHANNEL_GROUP_SAY:
  3177. case CHANNEL_RAID_SAY:
  3178. case CHANNEL_GUILD_CHAT:
  3179. case CHANNEL_GUILD_SAY:
  3180. case CHANNEL_OFFICER_SAY:
  3181. case CHANNEL_GUILD_MOTD:
  3182. return channel_type - 1;
  3183. case CHANNEL_PRIVATE_CHAT:
  3184. case CHANNEL_NONPLAYER_TELL:
  3185. return channel_type - 5;
  3186. case CHANNEL_PRIVATE_TELL:
  3187. case CHANNEL_TELL_FROM_CS:
  3188. return channel_type - 6;
  3189. case CHANNEL_CHAT_CHANNEL_TEXT:
  3190. case CHANNEL_OUT_OF_CHARACTER:
  3191. case CHANNEL_AUCTION:
  3192. case CHANNEL_CUSTOM_CHANNEL:
  3193. case CHANNEL_CHARACTER_TEXT:
  3194. case CHANNEL_REWARD:
  3195. case CHANNEL_DEATH:
  3196. case CHANNEL_PET_CHAT:
  3197. case CHANNEL_SKILL:
  3198. return channel_type - 7;
  3199. case CHANNEL_SPELLS:
  3200. case CHANNEL_YOU_CAST:
  3201. case CHANNEL_YOU_FAIL:
  3202. return channel_type - 8;
  3203. case CHANNEL_FRIENDLY_CAST:
  3204. case CHANNEL_FRIENDLY_FAIL:
  3205. case CHANNEL_OTHER_CAST:
  3206. case CHANNEL_OTHER_FAIL:
  3207. case CHANNEL_HOSTILE_CAST:
  3208. case CHANNEL_HOSTILE_FAIL:
  3209. case CHANNEL_WORN_OFF:
  3210. case CHANNEL_SPELLS_OTHER:
  3211. return channel_type - 9;
  3212. case CHANNEL_COMBAT:
  3213. return channel_type - 15;
  3214. case CHANNEL_HEROIC_OPPORTUNITY:
  3215. case CHANNEL_NON_MELEE_DAMAGE:
  3216. case CHANNEL_DAMAGE_SHIELD:
  3217. return channel_type - 16;
  3218. case CHANNEL_MELEE_COMBAT:
  3219. case CHANNEL_WARNINGS:
  3220. case CHANNEL_YOU_HIT:
  3221. case CHANNEL_YOU_MISS:
  3222. case CHANNEL_ATTACKER_HITS:
  3223. case CHANNEL_ATTACKER_MISSES:
  3224. return channel_type - 18;
  3225. case CHANNEL_OTHER_HIT:
  3226. case CHANNEL_OTHER_MISSES:
  3227. case CHANNEL_CRITICAL_HIT:
  3228. return channel_type - 22;
  3229. case CHANNEL_OTHER:
  3230. case CHANNEL_MONEY_SPLIT:
  3231. case CHANNEL_LOOT:
  3232. return channel_type - 30;
  3233. case CHANNEL_COMMAND_TEXT:
  3234. case CHANNEL_BROADCAST:
  3235. case CHANNEL_WHO:
  3236. case CHANNEL_COMMANDS:
  3237. case CHANNEL_MERCHANT:
  3238. case CHANNEL_MERCHANT_BUY_SELL:
  3239. case CHANNEL_CONSIDER_MESSAGE:
  3240. case CHANNEL_CON_MINUS_2:
  3241. case CHANNEL_CON_MINUS_1:
  3242. case CHANNEL_CON_0:
  3243. case CHANNEL_CON_1:
  3244. case CHANNEL_CON_2:
  3245. return channel_type - 31;
  3246. default: {
  3247. return CHANNEL_DEFAULT;
  3248. }
  3249. }
  3250. }
  3251. else if (GetVersion() <= 546) {
  3252. if (channel_type < 20)
  3253. return channel_type;
  3254. switch (channel_type) {
  3255. case CHANNEL_GUILD_MOTD:
  3256. case CHANNEL_GUILD_MEMBER_ONLINE:
  3257. case CHANNEL_GUILD_EVENT:
  3258. return channel_type + 1;
  3259. case CHANNEL_PRIVATE_CHAT:
  3260. case CHANNEL_NONPLAYER_TELL:
  3261. return channel_type - 1;
  3262. case CHANNEL_PRIVATE_TELL:
  3263. case CHANNEL_TELL_FROM_CS:
  3264. case CHANNEL_ARENA:
  3265. case CHANNEL_CHAT_CHANNEL_TEXT:
  3266. case CHANNEL_OUT_OF_CHARACTER:
  3267. case CHANNEL_AUCTION:
  3268. case CHANNEL_CUSTOM_CHANNEL:
  3269. case CHANNEL_CHARACTER_TEXT:
  3270. case CHANNEL_REWARD:
  3271. case CHANNEL_DEATH:
  3272. case CHANNEL_PET_CHAT:
  3273. case CHANNEL_SKILL:
  3274. case CHANNEL_FACTION:
  3275. case CHANNEL_SPELLS:
  3276. case CHANNEL_YOU_CAST:
  3277. case CHANNEL_YOU_FAIL:
  3278. return channel_type - 2;
  3279. case CHANNEL_FRIENDLY_CAST:
  3280. case CHANNEL_FRIENDLY_FAIL:
  3281. case CHANNEL_OTHER_CAST:
  3282. case CHANNEL_OTHER_FAIL:
  3283. case CHANNEL_HOSTILE_CAST:
  3284. case CHANNEL_HOSTILE_FAIL:
  3285. case CHANNEL_WORN_OFF:
  3286. case CHANNEL_SPELLS_OTHER:
  3287. case CHANNEL_HEAL_SPELLS:
  3288. case CHANNEL_HEALS:
  3289. case CHANNEL_FRIENDLY_HEALS:
  3290. case CHANNEL_OTHER_HEALS:
  3291. case CHANNEL_HOSTILE_HEALS:
  3292. return channel_type - 3;
  3293. case CHANNEL_COMBAT:
  3294. case CHANNEL_GENERAL_COMBAT:
  3295. case CHANNEL_HEROIC_OPPORTUNITY:
  3296. case CHANNEL_NON_MELEE_DAMAGE:
  3297. case CHANNEL_DAMAGE_SHIELD:
  3298. case CHANNEL_WARD:
  3299. return channel_type - 4;
  3300. case CHANNEL_MELEE_COMBAT:
  3301. case CHANNEL_WARNINGS:
  3302. case CHANNEL_YOU_HIT:
  3303. case CHANNEL_YOU_MISS:
  3304. case CHANNEL_ATTACKER_HITS:
  3305. case CHANNEL_ATTACKER_MISSES:
  3306. case CHANNEL_YOUR_PET_HITS:
  3307. case CHANNEL_YOUR_PET_MISSES:
  3308. case CHANNEL_ATTACKER_HITS_PET:
  3309. case CHANNEL_ATTACKER_MISSES_PET:
  3310. case CHANNEL_OTHER_HIT:
  3311. case CHANNEL_OTHER_MISSES:
  3312. return channel_type - 5;
  3313. case CHANNEL_OTHER:
  3314. case CHANNEL_MONEY_SPLIT:
  3315. case CHANNEL_LOOT:
  3316. return channel_type - 14;
  3317. case CHANNEL_COMMAND_TEXT:
  3318. case CHANNEL_BROADCAST:
  3319. case CHANNEL_WHO:
  3320. case CHANNEL_COMMANDS:
  3321. case CHANNEL_MERCHANT:
  3322. case CHANNEL_MERCHANT_BUY_SELL:
  3323. case CHANNEL_CONSIDER_MESSAGE:
  3324. case CHANNEL_CON_MINUS_2:
  3325. case CHANNEL_CON_MINUS_1:
  3326. case CHANNEL_CON_0:
  3327. case CHANNEL_CON_1:
  3328. case CHANNEL_CON_2:
  3329. case CHANNEL_TRADESKILLS:
  3330. case CHANNEL_HARVESTING:
  3331. case CHANNEL_HARVESTING_WARNINGS:
  3332. return channel_type - 15;
  3333. default: {
  3334. return CHANNEL_DEFAULT;
  3335. }
  3336. }
  3337. }
  3338. else {
  3339. switch (channel_type) {
  3340. default: {
  3341. return channel_type;
  3342. }
  3343. }
  3344. }
  3345. return channel_type;
  3346. }
  3347. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3348. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3349. return;
  3350. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3351. if (packet) {
  3352. packet->setDataByName("from", from->GetPlayer()->GetName());
  3353. packet->setDataByName("to", to);
  3354. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3355. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3356. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3357. packet->setDataByName("unknown2", 1, 1);
  3358. packet->setDataByName("show_bubble", 1);
  3359. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3360. packet->setDataByName("understood", 1);
  3361. }
  3362. packet->setDataByName("time", 2);
  3363. packet->setDataByName("language", current_language_id);
  3364. packet->setMediumStringByName("message", message);
  3365. EQ2Packet* outpacket = packet->serialize();
  3366. QueuePacket(outpacket);
  3367. safe_delete(packet);
  3368. }
  3369. }
  3370. void Client::SimpleMessage(int8 color, const char* message) {
  3371. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3372. if (command_packet) {
  3373. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3374. command_packet->setMediumStringByName("text", message);
  3375. command_packet->setDataByName("unknown02", 0x00ff);
  3376. EQ2Packet* outapp = command_packet->serialize();
  3377. QueuePacket(outapp);
  3378. safe_delete(command_packet);
  3379. }
  3380. }
  3381. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3382. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3383. if (packet) {
  3384. int8 xxx = spell->GetSpellData()->is_aa;
  3385. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3386. packet->setDataByName("spell_id", spell->GetSpellID());
  3387. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3388. packet->setDataByName("spell_name", spell->GetName());
  3389. if(add_silently)
  3390. packet->setDataByName("add_silently", 1);
  3391. if(add_to_hotbar)
  3392. packet->setDataByName("add_to_hotbar", 1);
  3393. packet->setDataByName("unknown", xxx);
  3394. packet->setDataByName("display_spell_tier", 1);
  3395. packet->setDataByName("unknown3", 1);
  3396. packet->setDataByName("tier", spell->GetSpellTier());
  3397. packet->setDataByName("icon", spell->GetSpellIcon());
  3398. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3399. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3400. //packet->PrintPacket();
  3401. EQ2Packet* outapp = packet->serialize();
  3402. //DumpPacket(outapp);
  3403. QueuePacket(outapp);
  3404. safe_delete(packet);
  3405. }
  3406. }
  3407. void Client::Message(int8 type, const char* message, ...) {
  3408. va_list argptr;
  3409. char buffer[4096];
  3410. va_start(argptr, message);
  3411. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3412. va_end(argptr);
  3413. SimpleMessage(type, buffer);
  3414. }
  3415. void Client::Disconnect(bool send_disconnect)
  3416. {
  3417. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3418. this->Save();
  3419. this->GetPlayer()->WritePlayerStatistics();
  3420. SetConnected(false);
  3421. if (send_disconnect && getConnection())
  3422. getConnection()->SendDisconnect(true);
  3423. eqs = 0;
  3424. }
  3425. bool Client::Summon(const char* search_name) {
  3426. Spawn* target = 0;
  3427. if (search_name || GetPlayer()->GetTarget()) {
  3428. Client* search_client = 0;
  3429. if (search_name) {
  3430. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3431. if (target && target->IsPlayer())
  3432. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3433. if (!target) {
  3434. search_client = zone_list.GetClientByCharName(string(search_name));
  3435. if (search_client)
  3436. target = search_client->GetPlayer();
  3437. }
  3438. }
  3439. else
  3440. target = GetPlayer()->GetTarget();
  3441. if (target && target != GetPlayer()) {
  3442. target->SetX(GetPlayer()->GetX());
  3443. target->SetY(GetPlayer()->GetY());
  3444. target->SetZ(GetPlayer()->GetZ());
  3445. target->SetHeading(GetPlayer()->GetHeading());
  3446. if (!target->IsPlayer()) {
  3447. target->SetSpawnOrigX(target->GetX());
  3448. target->SetSpawnOrigY(target->GetY());
  3449. target->SetSpawnOrigZ(target->GetZ());
  3450. target->SetSpawnOrigHeading(target->GetHeading());
  3451. }
  3452. target->SetLocation(GetPlayer()->GetLocation());
  3453. }
  3454. else if (target)
  3455. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3456. if (search_client && search_client != this) {
  3457. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3458. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3459. if (search_client->GetCurrentZone() != GetCurrentZone())
  3460. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3461. else {
  3462. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3463. if (app)
  3464. search_client->QueuePacket(app);
  3465. }
  3466. }
  3467. }
  3468. if (!target)
  3469. return false;
  3470. else
  3471. return true;
  3472. }
  3473. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3474. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3475. if(instanceType < 1)
  3476. return std::string("");
  3477. ZoneServer* instance_zone = nullptr;
  3478. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3479. if (data) {
  3480. // If lockout instances check to see if we are locked out
  3481. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3482. int32 time = 0;
  3483. // Check success timer
  3484. if (data->last_success_timestamp > 0) {
  3485. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3486. // Timer has not expired yet can't re enter
  3487. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3488. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3489. }
  3490. }
  3491. // Check failure timer
  3492. if (data->last_failure_timestamp > 0) {
  3493. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3494. // Timer has not expired yet
  3495. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3496. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3497. }
  3498. }
  3499. // Time > 0 then we are locked out, make the message and send it and return true
  3500. if (time > 0) {
  3501. string time_msg = "";
  3502. int16 hour;
  3503. int8 min;
  3504. int8 sec;
  3505. hour = time / 3600;
  3506. time = time % 3600;
  3507. min = time / 60;
  3508. time = time % 60;
  3509. sec = time;
  3510. if (hour > 0) {
  3511. char temp[10];
  3512. snprintf(temp, 9," %i", hour);
  3513. time_msg.append(temp);
  3514. time_msg.append(" hour");
  3515. time_msg.append((hour > 1) ? "s" : "");
  3516. }
  3517. if (min > 0) {
  3518. char temp[5];
  3519. snprintf(temp, 4," %i", min);
  3520. time_msg.append(temp);
  3521. time_msg.append(" minute");
  3522. time_msg.append((min > 1) ? "s" : "");
  3523. }
  3524. // Only add seconds if minutes and hours are 0
  3525. if (hour == 0 && min == 0 && sec > 0) {
  3526. char temp[5];
  3527. snprintf(temp, 4," %i", sec);
  3528. time_msg.append(temp);
  3529. time_msg.append(" second");
  3530. time_msg.append((sec > 1) ? "s" : "");
  3531. }
  3532. if(displayClient)
  3533. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3534. return time_msg;
  3535. }
  3536. }
  3537. }
  3538. return std::string("");
  3539. }
  3540. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3541. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3542. if(instanceType < 1)
  3543. return nullptr;
  3544. ZoneServer* instance_zone = nullptr;
  3545. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3546. if (data) {
  3547. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3548. // If lockout instances check to see if we are locked out
  3549. if (lockoutTime.length() > 0) {
  3550. return nullptr;
  3551. }
  3552. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3553. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3554. // 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
  3555. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3556. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3557. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3558. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3559. }
  3560. else
  3561. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3562. data->instance_id = instance_zone->GetInstanceID();
  3563. }
  3564. }
  3565. return instance_zone;
  3566. }
  3567. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3568. ZoneServer* instance_zone = NULL;
  3569. int8 instanceType = 0;
  3570. // determine if this is a group instanced zone that already exists
  3571. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3572. if (instance_zone != NULL)
  3573. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3574. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3575. {
  3576. // best to check if we already have our own instance!
  3577. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3578. {
  3579. switch (instanceType)
  3580. {
  3581. case SOLO_LOCKOUT_INSTANCE:
  3582. case GROUP_LOCKOUT_INSTANCE:
  3583. case RAID_LOCKOUT_INSTANCE:
  3584. {
  3585. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3586. if (instance_zone) {
  3587. // 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
  3588. // so delete `instances` entry for the zone when it shuts down.
  3589. 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());
  3590. if (db_id > 0)
  3591. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3592. }
  3593. break;
  3594. }
  3595. case SOLO_PERSIST_INSTANCE:
  3596. case GROUP_PERSIST_INSTANCE:
  3597. case RAID_PERSIST_INSTANCE:
  3598. {
  3599. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3600. if (instance_zone) {
  3601. 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());
  3602. if (db_id > 0)
  3603. 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()));
  3604. }
  3605. break;
  3606. }
  3607. case PUBLIC_INSTANCE:
  3608. case TRADESKILL_INSTANCE:
  3609. {
  3610. // if its public/tradeskill, look for a public already setup
  3611. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3612. if (instance_zone) {
  3613. // Check the current population against the max population, if greater or equal start a new version
  3614. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3615. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3616. }
  3617. else
  3618. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3619. break;
  3620. }
  3621. case PERSONAL_HOUSE_INSTANCE:
  3622. case GUILD_HOUSE_INSTANCE:
  3623. {
  3624. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3625. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3626. // with the OP_EnterHouseMsg opcode
  3627. break;
  3628. }
  3629. case QUEST_INSTANCE:
  3630. {
  3631. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3632. break;
  3633. /*
  3634. 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`;
  3635. */
  3636. }
  3637. default:
  3638. {
  3639. // NONE
  3640. }
  3641. }
  3642. }
  3643. if (instance_zone != NULL)
  3644. Zone(instance_zone, zone_coords_valid);
  3645. }
  3646. if (instance_zone != NULL)
  3647. return true;
  3648. else
  3649. return false;
  3650. }
  3651. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3652. Spawn* target = 0;
  3653. if (search_name || GetPlayer()->GetTarget()) {
  3654. Client* search_client = 0;
  3655. if (search_name) {
  3656. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3657. if (!target) {
  3658. search_client = zone_list.GetClientByCharName(search_name);
  3659. if (search_client)
  3660. target = search_client->GetPlayer();
  3661. }
  3662. if (target)
  3663. GetPlayer()->SetTarget(target);
  3664. }
  3665. else
  3666. target = GetPlayer()->GetTarget();
  3667. if (target && target != GetPlayer()) {
  3668. GetPlayer()->SetX(target->GetX());
  3669. GetPlayer()->SetY(target->GetY());
  3670. GetPlayer()->SetZ(target->GetZ());
  3671. GetPlayer()->SetHeading(target->GetHeading());
  3672. GetPlayer()->SetLocation(target->GetLocation());
  3673. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3674. }
  3675. else if (target)
  3676. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3677. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3678. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3679. else if (target) {
  3680. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3681. if (app)
  3682. QueuePacket(app);
  3683. }
  3684. }
  3685. if (!target)
  3686. return false;
  3687. else
  3688. return true;
  3689. }
  3690. bool Client::CheckZoneAccess(const char* zoneName) {
  3691. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3692. ZoneServer* zone = zone_list.Get(zoneName, false);
  3693. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3694. if (zone && zone->GetZoneLockState())
  3695. {
  3696. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3697. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3698. return false;
  3699. }
  3700. sint16 zoneMinStatus = 0;
  3701. int16 zoneMinLevel = 0;
  3702. int16 zoneMaxLevel = 0;
  3703. int16 zoneMinVersion = 0;
  3704. if (!zone)
  3705. {
  3706. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3707. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3708. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3709. return true;
  3710. }
  3711. }
  3712. else
  3713. {
  3714. zoneMinStatus = zone->GetMinimumStatus();
  3715. zoneMinLevel = zone->GetMinimumLevel();
  3716. zoneMaxLevel = zone->GetMaximumLevel();
  3717. zoneMinVersion = zone->GetMinimumVersion();
  3718. }
  3719. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3720. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3721. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3722. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3723. {
  3724. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3725. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3726. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3727. return false;
  3728. }
  3729. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3730. {
  3731. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3732. {
  3733. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3734. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3735. return false;
  3736. }
  3737. }
  3738. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3739. {
  3740. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3741. {
  3742. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3743. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3744. return false;
  3745. }
  3746. }
  3747. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3748. {
  3749. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3750. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3751. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3752. {
  3753. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3754. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3755. return false;
  3756. }
  3757. }
  3758. return true;
  3759. }
  3760. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3761. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3762. }
  3763. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3764. if (!new_zone) {
  3765. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3766. return;
  3767. }
  3768. client_zoning = true;
  3769. zoning_id = new_zone->GetZoneID();
  3770. zoning_instance_id = new_zone->GetInstanceID();
  3771. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3772. player->SetResurrecting(true);
  3773. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3774. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3775. MSaveSpellStateMutex.lock();
  3776. player->SaveSpellEffects();
  3777. player->SetSaveSpellEffects(true);
  3778. MSaveSpellStateMutex.unlock();
  3779. ResetSendMail();
  3780. // Remove players pet from zone if there is one
  3781. ((Entity*)player)->DismissAllPets();
  3782. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3783. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3784. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3785. SetZoningDestination(new_zone);
  3786. SetCurrentZone(new_zone);
  3787. if (player->GetGroupMemberInfo())
  3788. {
  3789. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3790. player->UpdateGroupMemberInfo();
  3791. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3792. }
  3793. // block out the member info for the group
  3794. TempRemoveGroup();
  3795. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3796. if (set_coords)
  3797. {
  3798. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3799. __FUNCTION__,
  3800. GetCurrentZone()->GetSafeX(),
  3801. GetCurrentZone()->GetSafeY(),
  3802. GetCurrentZone()->GetSafeZ(),
  3803. GetCurrentZone()->GetSafeHeading(),
  3804. new_zone->GetZoneName()
  3805. );
  3806. player->SetX(GetCurrentZone()->GetSafeX());
  3807. player->SetY(GetCurrentZone()->GetSafeY());
  3808. player->SetZ(GetCurrentZone()->GetSafeZ());
  3809. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3810. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  3811. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  3812. }
  3813. else {
  3814. ResetZoningCoords();
  3815. }
  3816. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3817. Save();
  3818. char* new_zone_ip = 0;
  3819. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3820. new_zone_ip = net.GetInternalWorldAddress();
  3821. else
  3822. new_zone_ip = net.GetWorldAddress();
  3823. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3824. int32 key = Timer::GetUnixTimeStamp();
  3825. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3826. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3827. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3828. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3829. if (version > 283) {
  3830. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3831. if (packet)
  3832. {
  3833. QueuePacket(packet->serialize());
  3834. safe_delete(packet);
  3835. }
  3836. }
  3837. }
  3838. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3839. {
  3840. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3841. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3842. }
  3843. float Client::DistanceFrom(Client* client) {
  3844. float ret = 0;
  3845. if (client && client != this) {
  3846. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3847. ret = sqrt(ret);
  3848. }
  3849. return ret;
  3850. }
  3851. void Client::DetermineCharacterUpdates() {
  3852. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3853. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3854. cdu->account_id = GetAccountID();
  3855. cdu->char_id = GetCharacterID();
  3856. int32 timestamp = Timer::GetUnixTimeStamp();
  3857. int8 flag = GetTimeStampFlag();
  3858. if (flag & LEVEL_UPDATE_FLAG)
  3859. {
  3860. cdu->update_field = LEVEL_UPDATE_FLAG;
  3861. cdu->update_data = player->GetLevel();
  3862. loginserver.SendPacket(outpack);
  3863. }
  3864. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3865. if (flag & CLASS_UPDATE_FLAG)
  3866. {
  3867. cdu->update_field = CLASS_UPDATE_FLAG;
  3868. cdu->update_data = player->GetAdventureClass();
  3869. loginserver.SendPacket(outpack);
  3870. }
  3871. if (flag & GENDER_UPDATE_FLAG)
  3872. {
  3873. cdu->update_field = GENDER_UPDATE_FLAG;
  3874. cdu->update_data = player->GetGender();
  3875. loginserver.SendPacket(outpack);
  3876. }
  3877. if (flag & DELETE_UPDATE_FLAG) {
  3878. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3879. }
  3880. safe_delete(outpack); // Zone, armor and name use a different structure
  3881. if (flag & RACE_UPDATE_FLAG)
  3882. {
  3883. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3884. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3885. ru->account_id = GetAccountID();
  3886. ru->char_id = GetCharacterID();
  3887. ru->race = player->GetRace();
  3888. ru->model_type = player->GetModelType();
  3889. loginserver.SendPacket(outpack);
  3890. safe_delete(outpack);
  3891. }
  3892. if (flag & ZONE_UPDATE_FLAG) {
  3893. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3894. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3895. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3896. czu->account_id = GetAccountID();
  3897. czu->char_id = GetCharacterID();
  3898. czu->zone_id = GetCurrentZone()->GetZoneID();
  3899. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3900. czu->zone_length = strlen(zone_file);
  3901. if (czu->zone_length > 64)
  3902. czu->zone_length = 64;
  3903. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3904. loginserver.SendPacket(outpack);
  3905. safe_delete(outpack);
  3906. }
  3907. if (flag & ARMOR_UPDATE_FLAG) {
  3908. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3909. }
  3910. if (flag & NAME_UPDATE_FLAG) {
  3911. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3912. }
  3913. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3914. }
  3915. void Client::Save() {
  3916. if (GetCharacterID() == 0)
  3917. return;
  3918. if (current_zone) {
  3919. DetermineCharacterUpdates();
  3920. UpdateCharacterInstances();
  3921. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3922. database.Save(this);
  3923. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3924. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3925. GetPlayer()->ResetQuickbarNeeded();
  3926. }
  3927. database.SaveItems(this);
  3928. database.SaveBuyBacks(this);
  3929. GetPlayer()->SaveHistory();
  3930. GetPlayer()->SaveLUAHistory();
  3931. MSaveSpellStateMutex.lock();
  3932. GetPlayer()->SaveSpellEffects();
  3933. MSaveSpellStateMutex.unlock();
  3934. }
  3935. }
  3936. void Client::UpdateCharacterInstances() {
  3937. if (GetPlayer() != NULL)
  3938. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3939. /*if ( GetPlayer() != NULL )
  3940. {
  3941. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3942. // to use for applying the update to each instances timer
  3943. int32 lastSaveTS = GetLastSavedTimeStamp();
  3944. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3945. int32 diffTS = newSaveTS - lastSaveTS;
  3946. // update instance timers
  3947. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3948. // update with the new timestamp and save the db
  3949. this->SetLastSavedTimeStamp(newSaveTS);
  3950. }*/
  3951. }
  3952. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3953. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3954. if (packet) {
  3955. packet->LoadPacketData(app->pBuffer, app->size);
  3956. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3957. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3958. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3959. vector<EntityCommand*> commands;
  3960. vector<EntityCommand*> delete_commands;
  3961. if (out && spawn) {
  3962. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3963. {
  3964. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3965. if (!spawn->primary_command_list[i]->default_allow_list)
  3966. {
  3967. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3968. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3969. continue;
  3970. }
  3971. else
  3972. {
  3973. // default is allow list, only deny if added to the list as deny (false itr second)
  3974. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3975. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3976. continue;
  3977. }
  3978. commands.push_back(spawn->primary_command_list[i]);
  3979. }
  3980. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3981. commands.push_back(spawn->secondary_command_list[i]);
  3982. if (spawn->IsPlayer()) {
  3983. if (player->IsFriend(spawn->GetName()))
  3984. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3985. else
  3986. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3987. if (player->IsIgnored(spawn->GetName()))
  3988. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3989. else
  3990. {
  3991. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3992. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3993. }
  3994. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3995. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3996. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3997. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3998. }
  3999. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4000. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4001. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4002. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4003. }
  4004. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4005. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4006. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4007. }
  4008. out->setDataByName("spawn_id", spawn_id);
  4009. out->setArrayLengthByName("num_verbs", commands.size());
  4010. for (int32 i = 0; i < commands.size(); i++) {
  4011. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4012. out->setArrayDataByName("distance", commands[i]->distance, i);
  4013. if (commands[i]->error_text.length() == 0)
  4014. out->setArrayAddToPacketByName("error", false, i);
  4015. else {
  4016. out->setArrayDataByName("display_error", 1, i);
  4017. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4018. }
  4019. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4020. }
  4021. EQ2Packet* outapp = out->serialize();
  4022. //DumpPacket(outapp);
  4023. QueuePacket(outapp);
  4024. safe_delete(out);
  4025. for (int32 i = 0; i < delete_commands.size(); i++) {
  4026. safe_delete(delete_commands[i]);
  4027. }
  4028. }
  4029. safe_delete(packet);
  4030. }
  4031. }
  4032. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4033. if (previous_value != new_value) {
  4034. 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);
  4035. char tmp[200] = { 0 };
  4036. 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);
  4037. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4038. }
  4039. }
  4040. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4041. {
  4042. /* JA notes on the unknown:
  4043. 2 = ding glimmer
  4044. 16 = Achievement Unlocked
  4045. 6 no longer does anything
  4046. */
  4047. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4048. if (packet) {
  4049. packet->setDataByName("unknown", unknown);
  4050. packet->setMediumStringByName("text", text);
  4051. if (type && strlen(type) > 0)
  4052. packet->setMediumStringByName("message_type", type);
  4053. packet->setDataByName("size", size);
  4054. packet->setDataByName("red", red);
  4055. packet->setDataByName("green", green);
  4056. packet->setDataByName("blue", blue);
  4057. QueuePacket(packet->serialize());
  4058. safe_delete(packet);
  4059. }
  4060. }
  4061. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4062. if (new_level < 1) {
  4063. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4064. return;
  4065. }
  4066. if (player->GetLevel() != new_level) {
  4067. player->SetLevel(new_level);
  4068. if (player->GetGroupMemberInfo()) {
  4069. player->UpdateGroupMemberInfo();
  4070. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4071. }
  4072. }
  4073. if (new_level > old_level) {
  4074. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4075. }
  4076. if (player->GetPet()) {
  4077. NPC* pet = (NPC*)player->GetPet();
  4078. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4079. pet->SetLevel(new_level);
  4080. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4081. if (command_packet) {
  4082. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4083. command_packet->setDataByName("anim_type", 1753);
  4084. QueuePacket(command_packet->serialize());
  4085. safe_delete(command_packet);
  4086. }
  4087. }
  4088. }
  4089. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4090. if (level_update) {
  4091. level_update->setDataByName("old_level", old_level);
  4092. level_update->setDataByName("new_level", new_level);
  4093. QueuePacket(level_update->serialize());
  4094. safe_delete(level_update);
  4095. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4096. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4097. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4098. }
  4099. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4100. if (command_packet) {
  4101. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4102. command_packet->setDataByName("anim_type", 1753);
  4103. QueuePacket(command_packet->serialize());
  4104. safe_delete(command_packet);
  4105. }
  4106. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4107. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4108. SendNewSpells(player->GetAdventureClass());
  4109. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4110. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4111. GetPlayer()->ChangePrimaryWeapon();
  4112. GetPlayer()->ChangeSecondaryWeapon();
  4113. GetPlayer()->ChangeRangedWeapon();
  4114. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4115. // GetPlayer()->SetLevel(new_level);
  4116. 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__);
  4117. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4118. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4119. GetPlayer()->CalculateBonuses();
  4120. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4121. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4122. InfoStruct* info = player->GetInfoStruct();
  4123. info->set_agi_base(new_level * 2 + 15);
  4124. info->set_intel_base(new_level * 2 + 15);
  4125. info->set_wis_base(new_level * 2 + 15);
  4126. info->set_str_base(new_level * 2 + 15);
  4127. info->set_sta_base(new_level * 2 + 15);
  4128. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4129. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4130. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4131. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4132. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4133. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4134. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4135. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));
  4136. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4137. GetPlayer()->SetCharSheetChanged(true);
  4138. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4139. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4140. int16 new_skill_cap = 5 * new_level;
  4141. PlayerSkillList* player_skills = player->GetSkills();
  4142. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4143. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4144. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4145. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4146. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4147. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4148. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4149. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4150. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4151. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4152. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4153. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4154. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4155. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4156. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4157. if (new_level > player->GetTSLevel())
  4158. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4159. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4160. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4161. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4162. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4163. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4164. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4165. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4166. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4167. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4168. Guild* guild = GetPlayer()->GetGuild();
  4169. if (guild) {
  4170. int8 event_type = 0;
  4171. if (new_level < 10)
  4172. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4173. else if (new_level == 10)
  4174. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4175. else if (new_level >= 11 && new_level < 20)
  4176. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4177. else if (new_level == 20)
  4178. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4179. else if (new_level >= 21 && new_level < 30)
  4180. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4181. else if (new_level == 30)
  4182. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4183. else if (new_level >= 31 && new_level < 40)
  4184. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4185. else if (new_level == 40)
  4186. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4187. else if (new_level >= 41 && new_level < 50)
  4188. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4189. else if (new_level == 50)
  4190. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4191. else if (new_level >= 51 && new_level < 60)
  4192. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4193. else if (new_level == 60)
  4194. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4195. else if (new_level >= 61 && new_level < 70)
  4196. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4197. else if (new_level == 70)
  4198. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4199. else if (new_level >= 71 && new_level < 80)
  4200. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4201. else if (new_level == 80)
  4202. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4203. 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());
  4204. 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());
  4205. guild->UpdateGuildMemberInfo(GetPlayer());
  4206. guild->SendGuildMember(GetPlayer());
  4207. guild->SendGuildMemberList();
  4208. }
  4209. // Need to send the trait list every time the players level changes
  4210. // Also need to force the char sheet update or else there can be a large delay from when you level
  4211. // to when you are actually able to select traits.
  4212. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4213. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4214. if (version > 546)
  4215. master_aa_list.DisplayAA(this, 0, 0);
  4216. if (GetPlayer()->SpawnedBots.size() > 0) {
  4217. map<int32, int32>::iterator itr;
  4218. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4219. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4220. if (bot && bot->IsBot())
  4221. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4222. }
  4223. }
  4224. }
  4225. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4226. if (new_level < 1) {
  4227. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4228. return;
  4229. }
  4230. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4231. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4232. return;
  4233. }
  4234. if (new_level > old_level)
  4235. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4236. if (player->GetTSLevel() != new_level) {
  4237. player->SetTSLevel(new_level);
  4238. if (player->GetGroupMemberInfo()) {
  4239. player->UpdateGroupMemberInfo();
  4240. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4241. }
  4242. }
  4243. // Only tradeskill skills should increace, and then only those related to your class
  4244. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4245. if (level_update) {
  4246. level_update->setDataByName("old_level", old_level);
  4247. level_update->setDataByName("new_level", new_level);
  4248. level_update->setDataByName("type", 1);
  4249. QueuePacket(level_update->serialize());
  4250. safe_delete(level_update);
  4251. }
  4252. // Need to make tradeskill versions of the following
  4253. //SendNewSpells(player->GetAdventureClass());
  4254. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4255. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4256. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4257. if (command_packet) {
  4258. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4259. command_packet->setDataByName("anim_type", 1753);
  4260. QueuePacket(command_packet->serialize());
  4261. safe_delete(command_packet);
  4262. }
  4263. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4264. GetPlayer()->SetTSLevel(new_level);
  4265. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4266. GetPlayer()->SetCharSheetChanged(true);
  4267. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4268. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4269. PlayerSkillList* player_skills = player->GetSkills();
  4270. int16 specialize_skill_cap = new_level * 5;
  4271. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4272. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4273. int8 ts_class = player->GetTradeskillClass();
  4274. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4275. int32 skill_id_1, skill_id_2, skill_id_3;
  4276. switch (base_ts_class) {
  4277. case ARTISAN:
  4278. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4279. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4280. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4281. break;
  4282. case OUTFITTER:
  4283. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4284. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4285. skill_id_1 = SKILL_ID_TAILORING;
  4286. skill_id_2 = SKILL_ID_METALSHAPING;
  4287. skill_id_3 = SKILL_ID_METALWORKING;
  4288. if (ts_class == TAILOR) {
  4289. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4290. skill_id_1 = 0;
  4291. }
  4292. else if (ts_class == ARMORER) {
  4293. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4294. skill_id_2 = 0;
  4295. }
  4296. else if (ts_class == WEAPONSMITH) {
  4297. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4298. skill_id_3 = 0;
  4299. }
  4300. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4301. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4302. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4303. break;
  4304. case SCHOLAR:
  4305. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4306. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4307. skill_id_1 = SKILL_ID_SCRIBING;
  4308. skill_id_2 = SKILL_ID_CHEMISTRY;
  4309. skill_id_3 = SKILL_ID_ARTIFICING;
  4310. if (ts_class == SAGE) {
  4311. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4312. skill_id_1 = 0;
  4313. }
  4314. else if (ts_class == ALCHEMIST) {
  4315. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4316. skill_id_2 = 0;
  4317. }
  4318. else if (ts_class == JEWELER) {
  4319. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4320. skill_id_3 = 0;
  4321. }
  4322. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4323. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4324. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4325. break;
  4326. case CRAFTSMAN:
  4327. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4328. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4329. skill_id_1 = SKILL_ID_ARTISTRY;
  4330. skill_id_2 = SKILL_ID_FLETCHING;
  4331. skill_id_3 = SKILL_ID_SCULPTING;
  4332. if (ts_class == PROVISIONER) {
  4333. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4334. skill_id_1 = 0;
  4335. }
  4336. else if (ts_class == WOODWORKER) {
  4337. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4338. skill_id_2 = 0;
  4339. }
  4340. else if (ts_class == CARPENTER) {
  4341. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4342. skill_id_3 = 0;
  4343. }
  4344. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4345. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4346. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4347. break;
  4348. default:
  4349. break;
  4350. }
  4351. if (new_level > player->GetAdventureClass())
  4352. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4353. Guild* guild = GetPlayer()->GetGuild();
  4354. if (guild) {
  4355. int8 event_type = 0;
  4356. if (new_level < 10)
  4357. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4358. else if (new_level == 10)
  4359. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4360. else if (new_level >= 11 && new_level < 20)
  4361. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4362. else if (new_level == 20)
  4363. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4364. else if (new_level >= 21 && new_level < 30)
  4365. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4366. else if (new_level == 30)
  4367. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4368. else if (new_level >= 31 && new_level < 40)
  4369. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4370. else if (new_level == 40)
  4371. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4372. else if (new_level >= 41 && new_level < 50)
  4373. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4374. else if (new_level == 50)
  4375. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4376. else if (new_level >= 51 && new_level < 60)
  4377. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4378. else if (new_level == 60)
  4379. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4380. else if (new_level >= 61 && new_level < 70)
  4381. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4382. else if (new_level == 70)
  4383. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4384. else if (new_level >= 71 && new_level < 80)
  4385. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4386. else if (new_level == 80)
  4387. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4388. 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());
  4389. 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());
  4390. guild->UpdateGuildMemberInfo(GetPlayer());
  4391. guild->SendGuildMember(GetPlayer());
  4392. guild->SendGuildMemberList();
  4393. }
  4394. // Need to send the trait list every time the players level changes
  4395. // Also need to force the char sheet update or else there can be a large delay from when you level
  4396. // to when you are actually able to select traits.
  4397. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4398. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4399. }
  4400. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4401. if (entity)
  4402. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4403. }
  4404. void Client::CloseLoot(int32 spawn_id) {
  4405. if (GetVersion() > 546) {
  4406. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4407. if (packet) {
  4408. packet->setDataByName("window_id", 4);
  4409. EQ2Packet* outapp = packet->serialize();
  4410. if (outapp) {
  4411. //DumpPacket(outapp);
  4412. QueuePacket(outapp);
  4413. }
  4414. safe_delete(packet);
  4415. }
  4416. }
  4417. else if(spawn_id > 0){
  4418. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4419. if (packet) {
  4420. packet->setDataByName("spawn_id", spawn_id);
  4421. EQ2Packet* outapp = packet->serialize();
  4422. if (outapp)
  4423. QueuePacket(outapp);
  4424. safe_delete(packet);
  4425. }
  4426. }
  4427. }
  4428. string Client::GetCoinMessage(int32 total_coins) {
  4429. if (total_coins == 0) {
  4430. return " 0 Copper";
  4431. }
  4432. char tmp[64] = { 0 };
  4433. string message = "";
  4434. int32 val = 0;
  4435. if (total_coins >= 1000000) {
  4436. val = total_coins / 1000000;
  4437. total_coins -= 1000000 * val;
  4438. sprintf(tmp, " %u Platinum", val);
  4439. message.append(tmp);
  4440. memset(tmp, 0, 64);
  4441. }
  4442. if (total_coins >= 10000) {
  4443. val = total_coins / 10000;
  4444. total_coins -= 10000 * val;
  4445. sprintf(tmp, " %u Gold", val);
  4446. message.append(tmp);
  4447. memset(tmp, 0, 64);
  4448. }
  4449. if (total_coins >= 100) {
  4450. val = total_coins / 100;
  4451. total_coins -= 100 * val;
  4452. sprintf(tmp, " %u Silver", val);
  4453. message.append(tmp);
  4454. memset(tmp, 0, 64);
  4455. }
  4456. if (total_coins > 0) {
  4457. sprintf(tmp, " %u Copper", (int32)total_coins);
  4458. message.append(tmp);
  4459. }
  4460. return message;
  4461. }
  4462. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4463. if (!entity) {
  4464. CloseLoot(0);
  4465. return;
  4466. }
  4467. if (total_coins > 0) {
  4468. player->AddCoins(total_coins);
  4469. //PlaySound("coin_cha_ching");
  4470. string message = "";
  4471. if (entity->GetHP() == 0) {
  4472. message = "You loot ";
  4473. entity->SetLootCoins(0);
  4474. }
  4475. else
  4476. message = "You receive ";
  4477. message.append(GetCoinMessage(total_coins));
  4478. if (entity->GetHP() == 0)
  4479. message.append(" from the corpse of ").append(entity->GetName());
  4480. int8 type = CHANNEL_LOOT;
  4481. SimpleMessage(type, message.c_str());
  4482. }
  4483. if (!items || items->size() == 0)
  4484. CloseLoot(entity->GetID());
  4485. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4486. if (packet) {
  4487. vector<Item*>::iterator itr;
  4488. int32 packet_size = 0;
  4489. EQ2Packet* outapp = 0;
  4490. uchar* data = 0;
  4491. if (GetVersion() >= 284) {
  4492. if (GetVersion() > 546) {
  4493. if (items && items->size() > 0) {
  4494. packet->setDataByName("loot_count", items->size());
  4495. packet->setDataByName("display", 1);
  4496. }
  4497. packet->setDataByName("loot_type", 1);
  4498. if (version >= 1096)
  4499. packet->setDataByName("lotto_timeout", 0x78);
  4500. else
  4501. packet->setDataByName("lotto_timeout", 0x3C);
  4502. packet->setDataByName("loot_id", entity->GetID());
  4503. EQ2Packet* tmpPacket = packet->serialize();
  4504. packet_size += tmpPacket->size;
  4505. if (items && items->size() > 0) {
  4506. data = new uchar[items->size() * 1000 + packet_size];
  4507. memset(data, 0, items->size() * 1000 + packet_size);
  4508. }
  4509. else {
  4510. data = new uchar[packet_size];
  4511. memset(data, 0, packet_size);
  4512. }
  4513. uchar* ptr = data;
  4514. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4515. ptr += tmpPacket->size;
  4516. safe_delete(tmpPacket);
  4517. Item* item = 0;
  4518. if (items && items->size() > 0) {
  4519. for (itr = items->begin(); itr != items->end(); itr++) {
  4520. item = *itr;
  4521. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4522. ptr += sizeof(int32);
  4523. packet_size += sizeof(int32);
  4524. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4525. int8 offset = 0;
  4526. if (GetVersion() >= 1188) {
  4527. offset = 13;
  4528. }
  4529. else if (GetVersion() >= 860) {
  4530. offset = 11;
  4531. }
  4532. else if (GetVersion() <= 546) {
  4533. offset = 19;
  4534. }
  4535. else {
  4536. offset = 10;
  4537. }
  4538. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4539. ptr += tmpPacket->size - offset;
  4540. packet_size += tmpPacket->size - offset;
  4541. safe_delete(tmpPacket);
  4542. }
  4543. }
  4544. packet_size -= sizeof(int32);
  4545. memcpy(data, &packet_size, sizeof(int32));
  4546. packet_size += sizeof(int32);
  4547. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4548. }
  4549. else {
  4550. if (items && items->size() > 0) {
  4551. packet->setArrayLengthByName("loot_count", items->size());
  4552. Item* item = 0;
  4553. if (items && items->size() > 0) {
  4554. int i = 0;
  4555. for (itr = items->begin(); itr != items->end(); itr++) {
  4556. item = *itr;
  4557. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4558. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4559. i++;
  4560. }
  4561. }
  4562. packet->setDataByName("display", 1);
  4563. }
  4564. packet->setDataByName("loot_type", 1); // normal
  4565. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4566. packet->setDataByName("spawn_id", entity->GetID());
  4567. outapp = packet->serialize();
  4568. }
  4569. }
  4570. else {
  4571. if (items && items->size() > 0) {
  4572. packet->setArrayLengthByName("loot_count", items->size());
  4573. for (int i = 0; i < items->size(); i++) {
  4574. Item* item = (*items)[i];
  4575. packet->setArrayDataByName("name", item->name.c_str(), i);
  4576. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4577. packet->setArrayDataByName("count", item->details.count, i);
  4578. packet->setArrayDataByName("icon", item->details.icon, i);
  4579. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4580. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4581. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4582. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4583. else
  4584. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4585. }
  4586. }
  4587. packet->setDataByName("object_id", entity->GetID());
  4588. packet->setDataByName("unknown3", 1);
  4589. packet->setDataByName("unknown4", 1);
  4590. packet->setDataByName("unknown5", 60);
  4591. outapp = packet->serialize();
  4592. }
  4593. if (outapp) {
  4594. QueuePacket(outapp);
  4595. }
  4596. safe_delete_array(data);
  4597. safe_delete(packet);
  4598. }
  4599. }
  4600. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4601. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4602. int32 total_coins = entity->GetLootCoins();
  4603. entity->LockLoot();
  4604. Loot(total_coins, entity->GetLootItems(), entity);
  4605. entity->UnlockLoot();
  4606. OpenChest(entity, attemptDisarm);
  4607. }
  4608. else
  4609. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4610. }
  4611. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4612. {
  4613. if (!entity)
  4614. return;
  4615. int8 chest_difficulty = 0;
  4616. int32 state = 0;
  4617. // Check for the chest and set the action state
  4618. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4619. string modelName;
  4620. if (entity->GetModelType() == 4034) {
  4621. // small chest, open with copper coins
  4622. // does not include traps, however can be disarmed
  4623. chest_difficulty = 1;
  4624. state = 11899;
  4625. modelName.append("Small Chest");
  4626. }
  4627. else if (entity->GetModelType() == 5864) {
  4628. // treasure chest, open with silver coins
  4629. chest_difficulty = 2;
  4630. state = 11901;
  4631. modelName.append("Treasure Chest");
  4632. }
  4633. else if (entity->GetModelType() == 5865) {
  4634. // ornate chest, open with gold coins
  4635. chest_difficulty = 3;
  4636. state = 11900;
  4637. modelName.append("Ornate Chest");
  4638. }
  4639. else if (entity->GetModelType() == 4015) {
  4640. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4641. chest_difficulty = 5;
  4642. state = 11898;
  4643. modelName.append("Exquisite Chest");
  4644. }
  4645. bool firstChestOpen = false;
  4646. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4647. {
  4648. ChestTrap::ChestTrapInfo nextTrap;
  4649. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4650. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4651. firstChestOpen = true;
  4652. entity->SetTrapTriggered(true, state);
  4653. if (ret)
  4654. {
  4655. if (disarmSkill && attemptDisarm)
  4656. {
  4657. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4658. {
  4659. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4660. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4661. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4662. }
  4663. else
  4664. {
  4665. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4666. }
  4667. // despite fail/succeed we should always try to increase skill if disarm is available
  4668. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4669. }
  4670. else // no disarm skill, always fail
  4671. {
  4672. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4673. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4674. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4675. }
  4676. }
  4677. }
  4678. else if (!entity->HasTrapTriggered())
  4679. {
  4680. firstChestOpen = true;
  4681. entity->SetTrapTriggered(true, state);
  4682. }
  4683. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4684. // for those in range the SendStateCommand will cause it to animate open.
  4685. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4686. if (firstChestOpen)
  4687. GetCurrentZone()->SendStateCommand(entity, state);
  4688. }
  4689. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4690. {
  4691. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4692. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4693. if (source == NULL)
  4694. source = (Entity*)GetPlayer();
  4695. if (spell)
  4696. {
  4697. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4698. if (gmi && gmi->group_id)
  4699. {
  4700. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4701. if (group)
  4702. {
  4703. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4704. deque<GroupMemberInfo*>* members = group->GetMembers();
  4705. for (int8 i = 0; i < members->size(); i++) {
  4706. Entity* member = members->at(i)->member;
  4707. if(!member)
  4708. continue;
  4709. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4710. continue;
  4711. // if we have a radius provided then check if the group member is outside the radius or not
  4712. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4713. continue;
  4714. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4715. }
  4716. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4717. }
  4718. }
  4719. else
  4720. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4721. }
  4722. }
  4723. Spawn* Client::GetBanker() {
  4724. return banker;
  4725. }
  4726. void Client::SetBanker(Spawn* in_banker) {
  4727. banker = in_banker;
  4728. }
  4729. void Client::Bank(Spawn* banker, bool cancel) {
  4730. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4731. if (!cancel)
  4732. SetBanker(banker);
  4733. else
  4734. SetBanker(0);
  4735. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4736. if (packet) {
  4737. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4738. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4739. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4740. int32 coins1, coins2;
  4741. coins1 = ((int32*)&coins)[0];
  4742. coins2 = ((int32*)&coins)[1];
  4743. packet->setDataByName("bank_coins", coins1);
  4744. packet->setDataByName("bank_coins2", coins2);
  4745. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4746. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4747. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4748. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4749. if (!cancel)
  4750. packet->setDataByName("display", 1);
  4751. QueuePacket(packet->serialize());
  4752. safe_delete(packet);
  4753. }
  4754. }
  4755. }
  4756. void Client::BankWithdrawal(int64 amount) {
  4757. bool cheater = false;
  4758. if (GetBanker() && amount > 0) {
  4759. string withdrawal = "";
  4760. char withdrawal_data[512] = { 0 };
  4761. int32 tmp = 0;
  4762. if (amount >= 1000000) {
  4763. tmp = amount / 1000000;
  4764. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4765. if (tmp > bank_coins_plat)
  4766. cheater = true;
  4767. else {
  4768. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4769. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4770. amount -= (int64)tmp * 1000000;
  4771. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4772. withdrawal.append(withdrawal_data);
  4773. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4774. }
  4775. }
  4776. if (!cheater && amount >= 10000) {
  4777. tmp = amount / 10000;
  4778. if (tmp > GetPlayer()->GetBankCoinsGold())
  4779. cheater = true;
  4780. else {
  4781. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4782. bank_coins_gold -= tmp;
  4783. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4784. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4785. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4786. }
  4787. else
  4788. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4789. amount -= tmp * 10000;
  4790. sprintf(withdrawal_data, "%u Gold ", tmp);
  4791. withdrawal.append(withdrawal_data);
  4792. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4793. }
  4794. }
  4795. if (!cheater && amount >= 100) {
  4796. tmp = amount / 100;
  4797. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4798. if (tmp > bank_coins_silver)
  4799. cheater = true;
  4800. else {
  4801. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4802. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4803. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4804. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4805. }
  4806. else
  4807. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4808. amount -= tmp * 100;
  4809. sprintf(withdrawal_data, "%u Silver ", tmp);
  4810. withdrawal.append(withdrawal_data);
  4811. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4812. }
  4813. }
  4814. if (!cheater) {
  4815. if (amount > 0) {
  4816. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4817. withdrawal.append(withdrawal_data);
  4818. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4819. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4820. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4821. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4822. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4823. }
  4824. else
  4825. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4826. }
  4827. if (withdrawal.length() > 0) {
  4828. withdrawal.append("withdrawn ");
  4829. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4830. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4831. withdrawal.append(withdrawal_data);
  4832. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4833. }
  4834. }
  4835. else
  4836. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4837. player->SetCharSheetChanged(true);
  4838. Bank(banker);
  4839. }
  4840. }
  4841. void Client::BankDeposit(int64 amount) {
  4842. bool cheater = false;
  4843. if (GetBanker() && amount > 0) {
  4844. int32 tmp = 0;
  4845. char deposit_data[512] = { 0 };
  4846. string deposit = "";
  4847. if (amount >= 1000000) {
  4848. tmp = amount / 1000000;
  4849. if (tmp > GetPlayer()->GetCoinsPlat())
  4850. cheater = true;
  4851. else {
  4852. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4853. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4854. amount -= (int64)tmp * 1000000;
  4855. sprintf(deposit_data, "%u Platinum ", tmp);
  4856. deposit.append(deposit_data);
  4857. memset(deposit_data, 0, sizeof(deposit_data));
  4858. }
  4859. }
  4860. if (!cheater && amount >= 10000) {
  4861. tmp = amount / 10000;
  4862. if (tmp > GetPlayer()->GetCoinsGold())
  4863. cheater = true;
  4864. else {
  4865. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4866. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4867. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4868. }
  4869. else
  4870. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4871. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4872. amount -= tmp * 10000;
  4873. sprintf(deposit_data, "%u Gold ", tmp);
  4874. deposit.append(deposit_data);
  4875. memset(deposit_data, 0, sizeof(deposit_data));
  4876. }
  4877. }
  4878. if (!cheater && amount >= 100) {
  4879. tmp = amount / 100;
  4880. if (tmp > GetPlayer()->GetCoinsSilver())
  4881. cheater = true;
  4882. else {
  4883. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4884. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4885. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4886. }
  4887. else
  4888. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4889. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4890. amount -= tmp * 100;
  4891. sprintf(deposit_data, "%u Silver ", tmp);
  4892. deposit.append(deposit_data);
  4893. memset(deposit_data, 0, sizeof(deposit_data));
  4894. }
  4895. }
  4896. if (!cheater) {
  4897. if (amount > 0) {
  4898. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4899. deposit.append(deposit_data);
  4900. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4901. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4902. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4903. }
  4904. else
  4905. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4906. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4907. }
  4908. if (deposit.length() > 0) {
  4909. deposit.append("deposited ");
  4910. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4911. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4912. deposit.append(deposit_data);
  4913. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4914. }
  4915. }
  4916. else
  4917. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4918. player->SetCharSheetChanged(true);
  4919. Bank(banker);
  4920. }
  4921. }
  4922. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4923. {
  4924. MPendingQuestAccept.lock();
  4925. pending_quest_accept.push_back(quest->GetQuestID());
  4926. MPendingQuestAccept.unlock();
  4927. }
  4928. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  4929. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  4930. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  4931. quest_updates = update;
  4932. if(quest_updates) {
  4933. SaveQuestRewardData(true);
  4934. }
  4935. }
  4936. 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) {
  4937. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  4938. return;
  4939. QuestRewardData* data = new QuestRewardData;
  4940. data->quest_id = quest_id;
  4941. data->is_temporary = is_temporary;
  4942. data->is_collection = is_collection;
  4943. data->has_displayed = has_displayed;
  4944. data->tmp_coin = tmp_coin;
  4945. data->tmp_status = tmp_status;
  4946. data->description = std::string(description);
  4947. data->db_saved = db_saved;
  4948. data->db_index = index;
  4949. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4950. quest_pending_reward.push_back(data);
  4951. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4952. }
  4953. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  4954. bool success = false;
  4955. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  4956. if (quest_pending_reward.size() > 0) {
  4957. vector<QuestRewardData*>::iterator itr;
  4958. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  4959. int32 questID = (*itr)->quest_id;
  4960. bool temporary = (*itr)->is_temporary;
  4961. bool collection = (*itr)->is_collection;
  4962. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  4963. success = true;
  4964. break;
  4965. }
  4966. }
  4967. }
  4968. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  4969. return success;
  4970. }
  4971. void Client::RemoveQueuedQuestReward() {
  4972. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4973. if(quest_pending_reward.size() > 0) {
  4974. QuestRewardData* data = quest_pending_reward.at(0);
  4975. if(data->db_saved) {
  4976. Query query;
  4977. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  4978. if(data->is_temporary && data->quest_id) {
  4979. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  4980. }
  4981. }
  4982. quest_pending_reward.erase(quest_pending_reward.begin());
  4983. }
  4984. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4985. SaveQuestRewardData(true);
  4986. }
  4987. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4988. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4989. quest_pending_updates[quest_id][step_id] = progress;
  4990. quest_updates = true;
  4991. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4992. }
  4993. void Client::ProcessQuestUpdates() {
  4994. if(!GetPlayer()->IsFullyLoggedIn())
  4995. return;
  4996. if (quest_pending_updates.size() > 0) {
  4997. map<int32, map<int32, int32> > tmp_quest_updates;
  4998. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4999. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5000. quest_pending_updates.clear();
  5001. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5002. map<int32, map<int32, int32> >::iterator quest_itr;
  5003. map<int32, int32>::iterator step_itr;
  5004. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5005. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5006. if (step_itr->second == 0xFFFFFFFF) {
  5007. SetStepComplete(quest_itr->first, step_itr->first);
  5008. player->SendQuestRequiredSpawns(quest_itr->first);
  5009. }
  5010. else
  5011. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5012. }
  5013. }
  5014. }
  5015. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5016. if (quest_pending_reward.size() > 0) {
  5017. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5018. // only able to display one reward at a time
  5019. if(GetPlayer()->IsActiveReward())
  5020. return;
  5021. Query query;
  5022. vector<QuestRewardData*>::iterator itr;
  5023. vector<QuestRewardData*> tmp_quest_rewards;
  5024. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5025. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5026. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5027. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  5028. int32 questID = (*itr)->quest_id;
  5029. Quest* quest = 0;
  5030. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5031. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5032. GetPlayer()->SetActiveReward(true);
  5033. (*itr)->has_displayed = true;
  5034. UpdateCharacterRewardData((*itr));
  5035. }
  5036. else if(questID > 0 && (quest = GetPlayer()->GetAnyQuest(questID))) {
  5037. quest->SetQuestTemporaryState((*itr)->is_temporary, (*itr)->description);
  5038. if((*itr)->is_temporary) {
  5039. quest->SetStatusTmpReward((*itr)->tmp_status);
  5040. quest->SetCoinTmpReward((*itr)->tmp_coin);
  5041. }
  5042. GiveQuestReward(quest, (*itr)->has_displayed);
  5043. GetPlayer()->SetActiveReward(true);
  5044. (*itr)->has_displayed = true;
  5045. UpdateCharacterRewardData((*itr));
  5046. // only able to display one reward at a time
  5047. break;
  5048. } else {
  5049. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, skipping quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5050. }
  5051. }
  5052. } else {
  5053. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5054. }
  5055. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5056. if (quest_pending_reward.size() > 0) {
  5057. quest_updates = true;
  5058. }
  5059. else {
  5060. quest_updates = false;
  5061. }
  5062. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5063. }
  5064. void Client::CheckQuestQueue() {
  5065. MQuestQueue.writelock();
  5066. last_update_time = 0;
  5067. vector<QueuedQuest*>::iterator itr;
  5068. QueuedQuest* queued_quest = 0;
  5069. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5070. queued_quest = *itr;
  5071. Quest* quest = GetPlayer()->GetAnyQuest(queued_quest->quest_id);
  5072. if(quest) {
  5073. SendQuestUpdateStepImmediately(quest, queued_quest->step, queued_quest->display_quest_helper);
  5074. if(quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  5075. SendQuestJournal();
  5076. }
  5077. else {
  5078. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", queued_quest->quest_id, GetPlayer()->GetName());
  5079. }
  5080. safe_delete(queued_quest);
  5081. }
  5082. quest_queue.clear();
  5083. MQuestQueue.releasewritelock();
  5084. }
  5085. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5086. Quest* quest = player->SetStepComplete(quest_id, step);
  5087. if (quest) {
  5088. SendQuestUpdate(quest);
  5089. GetCurrentZone()->SendQuestUpdates(this);
  5090. }
  5091. }
  5092. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5093. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5094. if (quest) {
  5095. SendQuestUpdate(quest);
  5096. GetCurrentZone()->SendQuestUpdates(this);
  5097. }
  5098. }
  5099. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5100. bool hadUpdates = false;
  5101. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5102. if (quest_updates) {
  5103. for (int32 i = 0; i < quest_updates->size(); i++)
  5104. {
  5105. SendQuestUpdate(quest_updates->at(i));
  5106. hadUpdates = true;
  5107. }
  5108. }
  5109. safe_delete(quest_updates);
  5110. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5111. if (quest_failures) {
  5112. for (int32 i = 0; i < quest_failures->size(); i++)
  5113. {
  5114. SendQuestFailure(quest_failures->at(i));
  5115. hadUpdates = true;
  5116. }
  5117. }
  5118. safe_delete(quest_failures);
  5119. if (hadUpdates)
  5120. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5121. }
  5122. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5123. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5124. if (quest_updates) {
  5125. for (int32 i = 0; i < quest_updates->size(); i++)
  5126. SendQuestUpdate(quest_updates->at(i));
  5127. GetCurrentZone()->SendQuestUpdates(this);
  5128. }
  5129. safe_delete(quest_updates);
  5130. }
  5131. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5132. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5133. if (quest_updates) {
  5134. for (int32 i = 0; i < quest_updates->size(); i++)
  5135. SendQuestUpdate(quest_updates->at(i));
  5136. }
  5137. safe_delete(quest_updates);
  5138. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5139. if (quest_failures) {
  5140. for (int32 i = 0; i < quest_failures->size(); i++)
  5141. SendQuestFailure(quest_failures->at(i));
  5142. }
  5143. safe_delete(quest_failures);
  5144. }
  5145. void Client::CheckPlayerQuestsLocationUpdate() {
  5146. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5147. if (quest_updates) {
  5148. for (int32 i = 0; i < quest_updates->size(); i++)
  5149. SendQuestUpdate(quest_updates->at(i));
  5150. }
  5151. safe_delete(quest_updates);
  5152. }
  5153. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5154. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5155. if (quest_updates) {
  5156. for (int32 i = 0; i < quest_updates->size(); i++)
  5157. SendQuestUpdate(quest_updates->at(i));
  5158. }
  5159. safe_delete(quest_updates);
  5160. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5161. if (quest_failures) {
  5162. for (int32 i = 0; i < quest_failures->size(); i++)
  5163. SendQuestFailure(quest_failures->at(i));
  5164. }
  5165. safe_delete(quest_failures);
  5166. }
  5167. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5168. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5169. player->pending_quests[quest->GetQuestID()] = quest;
  5170. AcceptQuest(quest->GetQuestID());
  5171. }
  5172. else {
  5173. player->pending_quests[quest->GetQuestID()] = quest;
  5174. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5175. //DumpPacket(outapp);
  5176. QueuePacket(outapp);
  5177. }
  5178. }
  5179. Quest* Client::GetActiveQuest(int32 quest_id) {
  5180. Quest* quest = 0;
  5181. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  5182. if (player->player_quests.count(quest_id) > 0) {
  5183. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  5184. quest = player->player_quests[quest_id];
  5185. }
  5186. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  5187. return quest;
  5188. }
  5189. void Client::AcceptQuest(int32 id) {
  5190. Quest* quest = GetPendingQuest(id);
  5191. if (quest) {
  5192. RemovePendingQuest(quest);
  5193. AddPlayerQuest(quest);
  5194. GetCurrentZone()->SendQuestUpdates(this);
  5195. // If character has already completed this quest once update the given date in the database
  5196. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  5197. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  5198. if (quest2)
  5199. quest->SetCompleteCount(quest2->GetCompleteCount());
  5200. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  5201. }
  5202. }
  5203. }
  5204. Quest* Client::GetPendingQuest(int32 id) {
  5205. if (player->pending_quests.count(id) > 0) {
  5206. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  5207. return player->pending_quests[id];
  5208. }
  5209. return 0;
  5210. }
  5211. void Client::RemovePendingQuest(Quest* quest) {
  5212. player->pending_quests.erase(quest->GetQuestID());
  5213. }
  5214. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5215. if (!quest || !progress) {
  5216. return;
  5217. }
  5218. map<int32, int32>::iterator itr;
  5219. QuestStep* step = 0;
  5220. player->SetZone(GetCurrentZone(), GetVersion());
  5221. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5222. step = quest->GetQuestStep(itr->first);
  5223. if (step && itr->second > 0) {
  5224. step->SetStepProgress(itr->second);
  5225. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5226. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5227. }
  5228. }
  5229. if (lua_interface && step)
  5230. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5231. else if(!step) {
  5232. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5233. }
  5234. }
  5235. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5236. bool lockCleared = false;
  5237. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5238. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5239. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5240. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5241. int32 questID = quest->GetQuestID();
  5242. lockCleared = true;
  5243. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5244. RemovePlayerQuest(questID, false, false);
  5245. }
  5246. player->player_quests[quest->GetQuestID()] = quest;
  5247. if(!lockCleared)
  5248. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5249. quest->SetPlayer(player);
  5250. current_quest_id = quest->GetQuestID();
  5251. if (send_packets && quest->GetQuestGiver() > 0)
  5252. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5253. if (lua_interface && call_accepted)
  5254. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5255. if (send_packets) {
  5256. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5257. //SendQuestJournal();
  5258. SendQuestJournalUpdate(quest);
  5259. // sent twice to match live
  5260. quest->SetTracked(false);
  5261. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5262. quest->SetTracked(true);
  5263. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5264. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5265. }
  5266. //This isn't during a load screen, so update spawns with required quests
  5267. if (call_accepted)
  5268. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5269. }
  5270. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5271. if (current_quest_id == id)
  5272. current_quest_id = 0;
  5273. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5274. if (player->player_quests.count(id) > 0) {
  5275. if (delete_quest) {
  5276. player->player_quests[id]->SetDeleted(true);
  5277. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5278. }
  5279. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5280. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5281. if (send_update && quest_giver > 0)
  5282. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5283. if (send_update) {
  5284. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5285. SendQuestJournal(false, 0, true);
  5286. }
  5287. player->RemoveQuest(id, delete_quest);
  5288. if (send_update) {
  5289. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5290. SendQuestJournal(false, 0, true);
  5291. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5292. }
  5293. }
  5294. else {
  5295. // if we don't have any quests to count then release the write lock
  5296. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5297. }
  5298. }
  5299. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5300. if (quest) {
  5301. QuestStep* quest_step = quest->GetQuestStep(step);
  5302. if (quest_step) {
  5303. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5304. quest_step->WasUpdated(false);
  5305. }
  5306. }
  5307. }
  5308. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5309. QueuedQuest* item = new QueuedQuest;
  5310. item->quest_id = quest->GetQuestID();
  5311. item->step = step;
  5312. item->display_quest_helper = display_quest_helper;
  5313. MQuestQueue.writelock();
  5314. quest_queue.push_back(item);
  5315. last_update_time = Timer::GetCurrentTime2();
  5316. MQuestQueue.releasewritelock();
  5317. }
  5318. void Client::SendQuestFailure(Quest* quest) {
  5319. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5320. if (failures) {
  5321. QuestStep* step = 0;
  5322. for (int32 i = 0; i < failures->size(); i++) {
  5323. step = failures->at(i);
  5324. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5325. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5326. SendQuestJournal(false, 0, true);
  5327. }
  5328. failures->clear();
  5329. }
  5330. }
  5331. void Client::SendQuestUpdate(Quest* quest) {
  5332. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5333. if (updates) {
  5334. QuestStep* step = 0;
  5335. bool updated = false;
  5336. for (int32 i = 0; i < updates->size(); i++) {
  5337. step = updates->at(i);
  5338. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5339. {
  5340. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5341. SendQuestUpdateStep(quest, step->GetStepID());
  5342. updated = true;
  5343. }
  5344. if (step->WasUpdated()) {
  5345. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5346. SendQuestJournal(false, 0, true);
  5347. if(!updated)
  5348. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5349. updated = true;
  5350. }
  5351. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5352. }
  5353. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5354. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5355. SendQuestJournalUpdate(quest, true);
  5356. }
  5357. if (quest->GetCompleted()) {
  5358. if (quest->GetQuestReturnNPC() > 0)
  5359. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5360. if (quest->GetCompletedFlag())
  5361. quest->SetCompletedFlag(false);
  5362. }
  5363. updates->clear();
  5364. }
  5365. }
  5366. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5367. if (!client)
  5368. client = this;
  5369. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5370. if (packet) {
  5371. EQ2Packet* outapp = packet->serialize();
  5372. //DumpPacket(outapp);
  5373. client->QueuePacket(outapp);
  5374. safe_delete(packet);
  5375. }
  5376. }
  5377. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5378. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5379. if (packet) {
  5380. QueuePacket(packet->serialize());
  5381. safe_delete(packet);
  5382. }
  5383. }
  5384. void Client::ReloadQuests() {
  5385. vector<int32> ids = player->GetQuestIDs();
  5386. Quest* quest = 0;
  5387. for (int32 i = 0; i < ids.size(); i++) {
  5388. quest = master_quest_list.GetQuest(ids[i]);
  5389. if (quest)
  5390. AddPlayerQuest(quest, false);
  5391. else
  5392. RemovePlayerQuest(ids[i]);
  5393. }
  5394. }
  5395. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5396. bool found_quest = false;
  5397. vector<int32>::iterator itr;
  5398. vector<Item*>* items = 0;
  5399. int32 questID = 0;
  5400. Quest* quest = 0;
  5401. MPendingQuestAccept.lock();
  5402. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  5403. questID = *itr;
  5404. quest = GetPlayer()->GetAnyQuest(questID);
  5405. if(!quest) {
  5406. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  5407. pending_quest_accept.erase(itr);
  5408. continue;
  5409. }
  5410. if(quest->GetQuestTemporaryState())
  5411. items = quest->GetTmpRewardItems();
  5412. else
  5413. items = quest->GetRewardItems();
  5414. if (item_id == 0) {
  5415. found_quest = true;
  5416. }
  5417. else {
  5418. items = quest->GetSelectableRewardItems();
  5419. if (items && items->size() > 0) {
  5420. for (int32 i = 0; i < items->size(); i++) {
  5421. if (items->at(i)->details.item_id == item_id) {
  5422. found_quest = true;
  5423. break;
  5424. }
  5425. }
  5426. }
  5427. }
  5428. if (found_quest) {
  5429. pending_quest_accept.erase(itr);
  5430. break;
  5431. }
  5432. }
  5433. MPendingQuestAccept.unlock();
  5434. if (found_quest)
  5435. return quest;
  5436. return 0;
  5437. }
  5438. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5439. int8 num_slots_needed = 0;
  5440. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5441. Item* master_item = 0;
  5442. if (item_id > 0) {
  5443. num_slots_needed++;
  5444. master_item = master_item_list.GetItem(item_id);
  5445. }
  5446. int32 totalItems = 0;
  5447. vector<Item*>* items = 0;
  5448. vector<Item*>* tmpItems = 0;
  5449. bool isTempState = quest->GetQuestTemporaryState();
  5450. if(isTempState)
  5451. {
  5452. tmpItems = quest->GetTmpRewardItems();
  5453. if (tmpItems && tmpItems->size() > 0)
  5454. {
  5455. num_slots_needed += tmpItems->size();
  5456. totalItems += tmpItems->size();
  5457. }
  5458. }
  5459. else
  5460. {
  5461. items = quest->GetRewardItems();
  5462. if (items && items->size() > 0)
  5463. {
  5464. num_slots_needed += items->size();
  5465. totalItems += items->size();
  5466. }
  5467. }
  5468. RemoveQueuedQuestReward();
  5469. GetPlayer()->SetActiveReward(false);
  5470. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5471. if (master_item)
  5472. AddItem(item_id);
  5473. if (tmpItems && tmpItems->size() > 0) {
  5474. for (int32 i = 0; i < tmpItems->size(); i++)
  5475. AddItem(new Item(tmpItems->at(i)));
  5476. }
  5477. if (items && items->size() > 0) {
  5478. for (int32 i = 0; i < items->size(); i++)
  5479. AddItem(new Item(items->at(i)));
  5480. }
  5481. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5482. if (outapp)
  5483. QueuePacket(outapp);
  5484. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5485. map<int32, sint32>::iterator itr;
  5486. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5487. int32 faction_id = itr->first;
  5488. sint32 amount = itr->second;
  5489. if (amount > 0)
  5490. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5491. else
  5492. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5493. }
  5494. if(quest->GetQuestTemporaryState())
  5495. {
  5496. int64 total_coins = quest->GetCoinTmpReward();
  5497. if (total_coins > 0)
  5498. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5499. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5500. }
  5501. else {
  5502. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5503. }
  5504. quest->SetQuestTemporaryState(false);
  5505. player->SetCharSheetChanged(true);
  5506. }
  5507. else {
  5508. GetPlayer()->SetActiveReward(true);
  5509. AddPendingQuestAcceptReward(quest);
  5510. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5511. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5512. }
  5513. }
  5514. 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) {
  5515. 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))) {
  5516. /*if (quest)
  5517. text = quest->GetName();
  5518. else*/
  5519. return;//nothing to give
  5520. }
  5521. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  5522. GetPlayer()->ClearPendingItemRewards();
  5523. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5524. if (packet2) {
  5525. int32 source_id = 0;
  5526. if (quest)
  5527. source_id = quest->GetQuestID();
  5528. int64 rewarded_coin = 0;
  5529. if (quest) {
  5530. if (quest->GetCoinsReward() > 0) {
  5531. if (quest->GetCoinsRewardMax() > 0)
  5532. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5533. else
  5534. rewarded_coin = quest->GetCoinsReward();
  5535. }
  5536. quest->SetGeneratedCoin(rewarded_coin);
  5537. }
  5538. if (rewarded_coin > coin)
  5539. coin = rewarded_coin;
  5540. 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
  5541. if (coin > 0) {
  5542. player->AddCoins(coin);
  5543. PlaySound("coin_cha_ching");
  5544. }
  5545. }
  5546. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5547. packet2->setSubstructDataByName("reward_data", "reward", header);
  5548. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5549. if (player->GetGuild() && !was_displayed) {
  5550. 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
  5551. player->GetInfoStruct()->add_status_points(status_points);
  5552. player->SetCharSheetChanged(true);
  5553. }
  5554. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5555. }
  5556. if(text)
  5557. packet2->setSubstructDataByName("reward_data", "text", text);
  5558. if(rewards){
  5559. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5560. for (int i = 0; i < rewards->size(); i++) {
  5561. Item* item = rewards->at(i);
  5562. if (item) {
  5563. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5564. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5565. }
  5566. 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
  5567. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5568. }
  5569. }
  5570. if (selectable_rewards) {
  5571. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5572. for (int i = 0; i < selectable_rewards->size(); i++) {
  5573. Item* item = selectable_rewards->at(i);
  5574. if (item) {
  5575. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5576. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5577. 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
  5578. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5579. }
  5580. }
  5581. }
  5582. if (factions) {
  5583. map<int32, sint32>::iterator itr;
  5584. map<Faction*, signed int> factions_map;
  5585. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5586. Faction* faction = master_faction_list.GetFaction(itr->first);
  5587. if (faction)
  5588. factions_map[faction] = itr->second;
  5589. }
  5590. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5591. map<Faction*, signed int>::iterator faction_itr;
  5592. int8 i = 0;
  5593. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5594. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5595. sint32 amount = faction_itr->second;
  5596. packet2->setArrayDataByName("amount", amount, i);
  5597. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5598. if (amount > 0)
  5599. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5600. else
  5601. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5602. }
  5603. i++;
  5604. }
  5605. }
  5606. QueuePacket(packet2->serialize());
  5607. safe_delete(packet2);
  5608. }
  5609. }
  5610. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  5611. if (!quest)
  5612. return;
  5613. if (GetVersion() <= 546) {
  5614. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), customDescription.c_str(), was_displayed);
  5615. return;
  5616. }
  5617. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5618. if (packet) {
  5619. packet->setDataByName("title", "Quest Reward!");
  5620. packet->setDataByName("name", quest->GetName());
  5621. if(tempReward)
  5622. {
  5623. packet->setDataByName("description", customDescription.c_str());
  5624. }
  5625. else
  5626. packet->setDataByName("description", quest->GetCompletedDescription());
  5627. packet->setDataByName("level", quest->GetLevel());
  5628. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5629. int8 difficulty = 0;
  5630. if ((string)quest->GetType() == "Tradeskill")
  5631. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5632. else
  5633. difficulty = player->GetArrowColor(quest->GetLevel());
  5634. packet->setDataByName("difficulty", difficulty);
  5635. if(tempReward)
  5636. {
  5637. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5638. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5639. packet->setDataByName("status_points", quest->GetStatusPoints());
  5640. }
  5641. else
  5642. {
  5643. int64 rewarded_coin = 0;
  5644. if (quest->GetCoinsReward() > 0) {
  5645. if (quest->GetCoinsRewardMax() > 0)
  5646. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5647. else
  5648. rewarded_coin = quest->GetCoinsReward();
  5649. }
  5650. quest->SetGeneratedCoin(rewarded_coin);
  5651. packet->setDataByName("max_coin", rewarded_coin);
  5652. packet->setDataByName("min_coin", rewarded_coin);
  5653. packet->setDataByName("status_points", quest->GetStatusPoints());
  5654. }
  5655. vector<Item*>* items = quest->GetTmpRewardItems();
  5656. if(tempReward)
  5657. {
  5658. if (items) {
  5659. packet->setArrayLengthByName("num_rewards", items->size());
  5660. for (int32 i = 0; i < items->size(); i++) {
  5661. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5662. if (version < 860)
  5663. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5664. else if (version < 1193)
  5665. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5666. else
  5667. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5668. }
  5669. }
  5670. }
  5671. else
  5672. {
  5673. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5674. vector<Item*>* items = quest->GetRewardItems();
  5675. if (items) {
  5676. packet->setArrayLengthByName("num_rewards", items->size());
  5677. for (int32 i = 0; i < items->size(); i++) {
  5678. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5679. if (version < 860)
  5680. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5681. else if (version < 1193)
  5682. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5683. else
  5684. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5685. }
  5686. }
  5687. if (items2 && items2->size() > 0) {
  5688. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5689. for (int32 i = 0; i < items2->size(); i++) {
  5690. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5691. if (version < 860)
  5692. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5693. else if (version < 1193)
  5694. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5695. else
  5696. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5697. }
  5698. }
  5699. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5700. if (reward_factions && reward_factions->size() > 0) {
  5701. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5702. map<int32, sint32>::iterator itr;
  5703. int16 index = 0;
  5704. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5705. int32 faction_id = itr->first;
  5706. sint32 amount = itr->second;
  5707. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5708. if (faction_name) {
  5709. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5710. packet->setArrayDataByName("amount", amount, index);
  5711. }
  5712. index++;
  5713. }
  5714. }
  5715. }
  5716. EQ2Packet* outapp = packet->serialize();
  5717. // DumpPacket(outapp);
  5718. QueuePacket(outapp);
  5719. safe_delete(packet);
  5720. }
  5721. }
  5722. void Client::DisplayRandomizeFeatures(int32 flags) {
  5723. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5724. if (flags > 0) {
  5725. if (flags & RANDOMIZE_GENDER)
  5726. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5727. if (flags & RANDOMIZE_RACE)
  5728. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5729. if (flags & RANDOMIZE_MODEL_TYPE)
  5730. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5731. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5732. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5733. if (flags & RANDOMIZE_HAIR_TYPE)
  5734. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5735. if (flags & RANDOMIZE_WING_TYPE)
  5736. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5737. if (flags & RANDOMIZE_CHEEK_TYPE)
  5738. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5739. if (flags & RANDOMIZE_CHIN_TYPE)
  5740. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5741. if (flags & RANDOMIZE_EAR_TYPE)
  5742. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5743. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5744. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5745. if (flags & RANDOMIZE_EYE_TYPE)
  5746. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5747. if (flags & RANDOMIZE_LIP_TYPE)
  5748. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5749. if (flags & RANDOMIZE_NOSE_TYPE)
  5750. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5751. if (flags & RANDOMIZE_EYE_COLOR)
  5752. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5753. if (flags & RANDOMIZE_HAIR_COLOR1)
  5754. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5755. if (flags & RANDOMIZE_HAIR_COLOR2)
  5756. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5757. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5758. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5759. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5760. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5761. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5762. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5763. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5764. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5765. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5766. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5767. if (flags & RANDOMIZE_SKIN_COLOR)
  5768. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5769. if (flags & RANDOMIZE_WING_COLOR1)
  5770. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5771. if (flags & RANDOMIZE_WING_COLOR2)
  5772. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5773. }
  5774. else
  5775. {
  5776. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5777. }
  5778. }
  5779. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  5780. current_quest_id = 0;
  5781. if(!quest->GetQuestTemporaryState() && !has_displayed)
  5782. {
  5783. quest->IncrementCompleteCount();
  5784. player->AddCompletedQuest(quest);
  5785. }
  5786. AddPendingQuestAcceptReward(quest);
  5787. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5788. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5789. SendQuestJournal();
  5790. if(quest->GetQuestTemporaryState()) {
  5791. return;
  5792. }
  5793. if(!has_displayed) {
  5794. if (quest->GetExpReward() > 0) {
  5795. int32 xp = quest->GetExpReward();
  5796. player->AddXP(xp);
  5797. }
  5798. if (quest->GetTSExpReward() > 0) {
  5799. int8 ts_level = player->GetTSLevel();
  5800. int32 xp = quest->GetTSExpReward();
  5801. if (player->AddTSXP(xp)) {
  5802. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5803. if (player->GetTSLevel() != ts_level)
  5804. ChangeTSLevel(ts_level, player->GetTSLevel());
  5805. player->SetCharSheetChanged(true);
  5806. }
  5807. }
  5808. int64 total_coins = quest->GetGeneratedCoin();
  5809. if (total_coins > 0)
  5810. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5811. player->RemoveQuest(quest->GetQuestID(), false);
  5812. }
  5813. if (quest->GetQuestGiver() > 0)
  5814. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5815. if(!has_displayed) {
  5816. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5817. }
  5818. }
  5819. 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) {
  5820. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5821. if (packet) {
  5822. packet->setDataByName("conversation_id", conversation_id);
  5823. packet->setDataByName("text", text);
  5824. packet->setDataByName("language", language); // default 0
  5825. packet->setDataByName("can_close", can_close); // default 1
  5826. conversation_map[conversation_id].clear();
  5827. if (conversations) {
  5828. packet->setArrayLengthByName("num_responses", conversations->size());
  5829. for (int32 i = 0; i < conversations->size(); i++) {
  5830. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5831. if (conversations->at(i).function.length() > 0)
  5832. conversation_map[conversation_id][i] = conversations->at(i).function;
  5833. }
  5834. }
  5835. packet->setDataByName("spawn_id", spawn_id);
  5836. if (mp3) {
  5837. packet->setDataByName("voice", mp3);
  5838. packet->setDataByName("key1", key1);
  5839. packet->setDataByName("key2", key2);
  5840. }
  5841. QueuePacket(packet->serialize());
  5842. safe_delete(packet);
  5843. }
  5844. }
  5845. 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) {
  5846. if (!item || !text || !conversations || conversations->size() == 0) {
  5847. return;
  5848. }
  5849. int32 conversation_id = GetConversationID(0, item);
  5850. if (conversation_id == 0) {
  5851. next_conversation_id++;
  5852. conversation_id = next_conversation_id;
  5853. }
  5854. MConversation.writelock();
  5855. conversation_items[conversation_id] = item;
  5856. MConversation.releasewritelock();
  5857. if (type == 4)
  5858. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5859. else
  5860. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5861. }
  5862. 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) {
  5863. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5864. return;
  5865. }
  5866. int32 conversation_id = GetConversationID(src, 0);
  5867. if (conversation_id == 0) {
  5868. next_conversation_id++;
  5869. conversation_id = next_conversation_id;
  5870. }
  5871. MConversation.writelock();
  5872. conversation_spawns[conversation_id] = src->GetID();
  5873. MConversation.releasewritelock();
  5874. /* Spawns can start two different types of conversations.
  5875. * Type 1: The chat type with bubbles.
  5876. * Type 2: The dialog type with the blue box. */
  5877. if (type == 1)
  5878. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  5879. else if (type == 2)
  5880. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5881. else //if (type == 3)
  5882. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5883. }
  5884. void Client::CloseDialog(int32 conversation_id) {
  5885. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5886. if (packet) {
  5887. packet->setDataByName("conversation_id", conversation_id);
  5888. QueuePacket(packet->serialize());
  5889. safe_delete(packet);
  5890. }
  5891. MConversation.writelock();
  5892. std::map<int32, Item*>::iterator itr;
  5893. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5894. {
  5895. conversation_items.erase(itr);
  5896. }
  5897. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  5898. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5899. {
  5900. conversation_spawns.erase(itr2);
  5901. }
  5902. MConversation.releasewritelock();
  5903. }
  5904. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5905. int32 conversation_id = 0;
  5906. MConversation.readlock();
  5907. if (spawn) {
  5908. map<int32, int32>::iterator itr;
  5909. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5910. if (itr->second == spawn->GetID()) {
  5911. conversation_id = itr->first;
  5912. break;
  5913. }
  5914. }
  5915. }
  5916. else if (item) {
  5917. map<int32, Item*>::iterator itr;
  5918. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5919. if (itr->second == item) {
  5920. conversation_id = itr->first;
  5921. break;
  5922. }
  5923. }
  5924. }
  5925. MConversation.releasereadlock();
  5926. return conversation_id;
  5927. }
  5928. Spawn* Client::GetCombineSpawn() {
  5929. return combine_spawn;
  5930. }
  5931. bool Client::ShouldTarget() {
  5932. return should_target;
  5933. }
  5934. void Client::TargetSpawn(Spawn* spawn) {
  5935. should_target = false;
  5936. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5937. if (packet) {
  5938. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5939. QueuePacket(packet->serialize());
  5940. safe_delete(packet);
  5941. }
  5942. }
  5943. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5944. combine_spawn = spawn;
  5945. spawn->RemoveSpawnFromGroup(true);
  5946. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5947. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5948. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5949. should_target = true;
  5950. }
  5951. void Client::AddCombineSpawn(Spawn* spawn) {
  5952. if (combine_spawn && combine_spawn != spawn && spawn) {
  5953. combine_spawn->AddSpawnToGroup(spawn);
  5954. spawn->AddSpawnToGroup(combine_spawn);
  5955. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5956. }
  5957. else if (spawn)
  5958. combine_spawn = spawn;
  5959. should_target = true;
  5960. }
  5961. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5962. if (combine_spawn && spawn)
  5963. spawn->RemoveSpawnFromGroup();
  5964. if (combine_spawn == spawn)
  5965. combine_spawn->RemoveSpawnFromGroup(true);
  5966. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5967. if (combine_spawn == spawn)
  5968. combine_spawn = 0;
  5969. }
  5970. void Client::SaveCombineSpawns(const char* name) {
  5971. if (!combine_spawn) {
  5972. return;
  5973. }
  5974. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5975. if (!spawns) {
  5976. return;
  5977. }
  5978. int32 count = spawns->size();
  5979. int32 spawnLocationID = 0;
  5980. if (count == 1)
  5981. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5982. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5983. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5984. // we remove the spawn inside SaveCombinedSpawnLocation
  5985. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5986. }
  5987. else
  5988. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5989. safe_delete(spawns);
  5990. combine_spawn = 0;
  5991. }
  5992. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  5993. Item* master_item = master_item_list.GetItem(item_id);
  5994. Item* item = 0;
  5995. if (master_item)
  5996. item = new Item(master_item);
  5997. if (item) {
  5998. if (quantity > 0)
  5999. item->details.count = quantity;
  6000. return AddItem(item, nullptr, type);
  6001. }
  6002. else
  6003. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6004. return false;
  6005. }
  6006. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6007. if (!item) {
  6008. return false;
  6009. }
  6010. if (item->IsBag()) {
  6011. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  6012. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  6013. }
  6014. if (player->AddItem(item, type)) {
  6015. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6016. if (outapp) {
  6017. //DumpPacket(outapp);
  6018. QueuePacket(outapp);
  6019. //resend bag desc with new item name added
  6020. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6021. if (outapp) {
  6022. //DumpPacket(outapp);
  6023. QueuePacket(outapp);
  6024. }
  6025. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6026. DumpPacket(app);
  6027. client->QueuePacket(app);
  6028. */
  6029. }
  6030. CheckPlayerQuestsItemUpdate(item);
  6031. if (item->GetItemScript() && lua_interface)
  6032. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6033. }
  6034. else {
  6035. // likely lore conflict
  6036. safe_delete(item);
  6037. if(item_deleted)
  6038. *item_deleted = true;
  6039. return false;
  6040. }
  6041. return true;
  6042. }
  6043. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6044. Item* master_item = master_item_list.GetItem(item_id);
  6045. Item* item = 0;
  6046. if (master_item)
  6047. item = new Item(master_item);
  6048. if (item) {
  6049. if (quantity > 0)
  6050. item->details.count = quantity;
  6051. return AddItemToBank(item);
  6052. }
  6053. else
  6054. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6055. return false;
  6056. }
  6057. bool Client::AddItemToBank(Item* item) {
  6058. if (!item) {
  6059. return false;
  6060. }
  6061. if (player->AddItemToBank(item)) {
  6062. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6063. if (outapp) {
  6064. QueuePacket(outapp);
  6065. //resend bag desc with new item name added
  6066. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6067. if (outapp)
  6068. QueuePacket(outapp);
  6069. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6070. DumpPacket(app);
  6071. client->QueuePacket(app);
  6072. */
  6073. }
  6074. CheckPlayerQuestsItemUpdate(item);
  6075. if (item->GetItemScript() && lua_interface)
  6076. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6077. }
  6078. else {
  6079. // likely lore conflict
  6080. safe_delete(item);
  6081. return false;
  6082. }
  6083. return true;
  6084. }
  6085. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6086. EQ2Packet* outapp;
  6087. bool delete_item = false;
  6088. assert(item);
  6089. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6090. item->details.count -= quantity;
  6091. item->save_needed = true;
  6092. }
  6093. else {
  6094. database.DeleteItem(character_id, item, 0);
  6095. player->GetPlayerItemList()->RemoveItem(item, false);
  6096. delete_item = true;
  6097. }
  6098. if(force_override_no_delete)
  6099. delete_item = false;
  6100. if ((outapp = player->SendInventoryUpdate(version))) {
  6101. QueuePacket(outapp);
  6102. if (item->GetItemScript() && lua_interface)
  6103. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6104. if (delete_item)
  6105. {
  6106. PurgeItem(item);
  6107. safe_delete(item);
  6108. }
  6109. return true;
  6110. }
  6111. return false;
  6112. }
  6113. void Client::SetLuaDebugClient(bool val) {
  6114. if (val)
  6115. lua_debug_timer.Start();
  6116. lua_debug = val;
  6117. if (lua_interface && !val) {
  6118. lua_interface->RemoveDebugClients(this);
  6119. lua_debug_timer.Disable();
  6120. }
  6121. }
  6122. void Client::SetMerchantTransaction(Spawn* spawn) {
  6123. merchant_transaction = spawn;
  6124. }
  6125. Spawn* Client::GetMerchantTransaction() {
  6126. return merchant_transaction;
  6127. }
  6128. void Client::SetMailTransaction(Spawn* spawn) {
  6129. ResetSendMail(spawn ? false : true);
  6130. MMailWindowMutex.lock();
  6131. mail_transaction = spawn;
  6132. MMailWindowMutex.unlock();
  6133. }
  6134. Spawn* Client::GetMailTransaction() {
  6135. return mail_transaction;
  6136. }
  6137. void Client::PlaySound(const char* name) {
  6138. if (name) {
  6139. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6140. if (packet) {
  6141. packet->setMediumStringByName("name", name);
  6142. QueuePacket(packet->serialize());
  6143. safe_delete(packet);
  6144. }
  6145. }
  6146. }
  6147. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6148. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6149. if(multiplier){
  6150. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6151. float diff_low = faction_val - multiplier->faction_min;
  6152. if(diff_low < 0)
  6153. diff_low*=-1;
  6154. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6155. if(total_diff < 0)
  6156. total_diff*=-1;
  6157. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6158. float total1 = (diff_low/total_diff);
  6159. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6160. return final_buy_multiplier;
  6161. }*/
  6162. return 1;
  6163. }
  6164. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6165. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6166. if(multiplier){
  6167. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6168. float diff_low = faction_val - multiplier->faction_min;
  6169. if(diff_low < 0)
  6170. diff_low*=-1;
  6171. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6172. if(total_diff < 0)
  6173. total_diff*=-1;
  6174. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6175. float total1 = (diff_low/total_diff);
  6176. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6177. return final_sell_multiplier;
  6178. }*/
  6179. return 1;
  6180. }
  6181. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6182. Spawn* spawn = GetMerchantTransaction();
  6183. Guild* guild = GetPlayer()->GetGuild();
  6184. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6185. spawn->IsClientInMerchantLevelRange(this)) {
  6186. int32 total_sell_price = 0;
  6187. int32 total_status_sell_price = 0; //for status
  6188. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6189. int32 sell_price = 0;
  6190. int32 status_sell_price = 0; //for status
  6191. Item* master_item = master_item_list.GetItem(item_id);
  6192. Item* item = 0;
  6193. if (unique_id == 0)
  6194. item = player->item_list.GetItemFromID(item_id, quantity);
  6195. else
  6196. item = player->item_list.GetItemFromUniqueID(unique_id);
  6197. if (!item)
  6198. item = player->item_list.GetItemFromID(item_id);
  6199. if (item && master_item) {
  6200. if(item->details.item_locked)
  6201. {
  6202. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6203. return;
  6204. }
  6205. else if(item->CheckFlag(NO_VALUE))
  6206. {
  6207. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6208. return;
  6209. }
  6210. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6211. if (sell_price > item->sell_price)
  6212. sell_price = item->sell_price;
  6213. if (quantity > item->details.count)
  6214. quantity = item->details.count;
  6215. total_sell_price = sell_price * quantity;
  6216. //------------------------------For Selling Status Items
  6217. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6218. if (status_sell_price > item->sell_status)
  6219. status_sell_price = item->sell_status;
  6220. if (quantity > item->details.count)
  6221. quantity = item->details.count;
  6222. total_status_sell_price = status_sell_price * quantity;
  6223. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6224. total_status_sell_price = 0;
  6225. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6226. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6227. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6228. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6229. guild->SendGuildMemberList();
  6230. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6231. }
  6232. if (quantity > 1)
  6233. {
  6234. if(total_status_sell_price)
  6235. 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);
  6236. else
  6237. 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());
  6238. }
  6239. else
  6240. {
  6241. if(total_status_sell_price)
  6242. 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);
  6243. else
  6244. 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());
  6245. }
  6246. player->AddCoins(total_sell_price);
  6247. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6248. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6249. if (quantity >= item->details.count) {
  6250. database.DeleteItem(GetCharacterID(), item, 0);
  6251. player->item_list.DestroyItem(item->details.index);
  6252. }
  6253. else {
  6254. item->details.count -= quantity;
  6255. item->save_needed = true;
  6256. }
  6257. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6258. if (outapp)
  6259. QueuePacket(outapp);
  6260. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6261. SendBuyBackList();
  6262. }
  6263. }
  6264. }
  6265. void Client::BuyBack(int32 item_id, int16 quantity) {
  6266. Spawn* spawn = GetMerchantTransaction();
  6267. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6268. spawn->IsClientInMerchantLevelRange(this)) {
  6269. deque<BuyBackItem*>::iterator itr;
  6270. BuyBackItem* buyback = 0;
  6271. BuyBackItem* closest = 0;
  6272. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6273. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6274. buyback = *itr;
  6275. if (buyback->unique_id == item_id) {
  6276. closest = buyback;
  6277. quantity = buyback->quantity;
  6278. break;
  6279. }
  6280. }
  6281. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6282. if (closest) {
  6283. Item* item = 0;
  6284. Item* master_item = master_item_list.GetItem(closest->item_id);
  6285. if (master_item) {
  6286. item = new Item(master_item);
  6287. if (closest->quantity >= quantity)
  6288. item->details.count = quantity;
  6289. else
  6290. item->details.count = closest->quantity;
  6291. }
  6292. bool itemDeleted = false;
  6293. bool itemAdded = false;
  6294. sint64 dispFlags = 0;
  6295. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6296. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6297. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6298. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6299. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6300. bool removed = false;
  6301. if (closest->quantity == quantity) {
  6302. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6303. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6304. if (*itr == closest) {
  6305. buy_back_items.erase(itr);
  6306. removed = true;
  6307. break;
  6308. }
  6309. }
  6310. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6311. }
  6312. else {
  6313. closest->quantity -= quantity;
  6314. closest->save_needed = true;
  6315. }
  6316. itemAdded = AddItem(item, &itemDeleted);
  6317. if (removed) {
  6318. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6319. safe_delete(closest);
  6320. }
  6321. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6322. SendBuyBackList();
  6323. }
  6324. else
  6325. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6326. if(!itemAdded && !itemDeleted)
  6327. safe_delete(item);
  6328. }
  6329. }
  6330. }
  6331. void Client::BuyItem(int32 item_id, int16 quantity) {
  6332. // Get the merchant we are buying from
  6333. Spawn* spawn = GetMerchantTransaction();
  6334. // Make sure the spawn has a merchant list
  6335. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6336. int32 total_buy_price = 0;
  6337. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6338. int32 sell_price = 0;
  6339. Item* master_item = master_item_list.GetItem(item_id);
  6340. Item* item = 0;
  6341. int16 total_available = 0;
  6342. vector<MerchantItemInfo>* temp;
  6343. vector<MerchantItemInfo>::iterator itr;
  6344. MerchantItemInfo* ItemInfo = 0;
  6345. temp = world.GetMerchantList(spawn->GetMerchantID());
  6346. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6347. if ((*itr).item_id == item_id) {
  6348. ItemInfo = &(*itr);
  6349. break;
  6350. }
  6351. }
  6352. if (master_item && ItemInfo) {
  6353. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6354. quantity = 1;
  6355. total_available = 0xFFFF;
  6356. sell_price = master_item->sell_price;
  6357. }
  6358. else {
  6359. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6360. sell_price = (int32)(master_item->sell_price * multiplier);
  6361. if (quantity > total_available)
  6362. quantity = total_available;
  6363. }
  6364. sint64 dispFlags = 0;
  6365. 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))
  6366. {
  6367. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6368. return;
  6369. }
  6370. if(quantity < 1)
  6371. {
  6372. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6373. return;
  6374. }
  6375. total_buy_price = sell_price * quantity;
  6376. item = new Item(master_item);
  6377. item->details.count = quantity;
  6378. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6379. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6380. safe_delete(item);
  6381. }
  6382. else {
  6383. // Price not set in the merchant_inventory table, use the old method
  6384. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6385. if (player->RemoveCoins(total_buy_price)) {
  6386. item->SetMaxSellValue(sell_price);
  6387. if (quantity > 1)
  6388. 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());
  6389. else
  6390. 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());
  6391. bool itemDeleted = false;
  6392. AddItem(item, &itemDeleted);
  6393. if(!itemDeleted) {
  6394. CheckPlayerQuestsItemUpdate(item);
  6395. if (item && total_available < 0xFF) {
  6396. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6397. SendBuyMerchantList();
  6398. }
  6399. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6400. PlayLotto(total_buy_price, item->details.item_id);
  6401. }
  6402. }
  6403. else {
  6404. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6405. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6406. PlaySound("buy_failed");
  6407. }
  6408. }
  6409. else {
  6410. // Price set in merchant_inventory table
  6411. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6412. // TODO: need to add support for station cash
  6413. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6414. // Check items
  6415. int16 item_quantity = 0;
  6416. // Default these to true in case price_item_id or price_item2_id was never set
  6417. bool hasItem1 = true;
  6418. bool hasItem2 = true;
  6419. Item* tempItem1 = 0;
  6420. Item* tempItem2 = 0;
  6421. if (ItemInfo->price_item_id != 0) {
  6422. // Same item for whatever reason lets add the quantities together
  6423. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6424. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6425. else
  6426. item_quantity = ItemInfo->price_item_qty;
  6427. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6428. if (tempItem1) {
  6429. if (tempItem1->details.count < item_quantity)
  6430. hasItem1 = false;
  6431. }
  6432. else {
  6433. hasItem1 = false;
  6434. }
  6435. }
  6436. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6437. // as item1 and we already checked for it so we can skip this check
  6438. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6439. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6440. if (tempItem2) {
  6441. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6442. hasItem2 = false;
  6443. }
  6444. else {
  6445. hasItem2 = false;
  6446. }
  6447. }
  6448. // if we have every thing then remove the price and give the item
  6449. if (hasItem1 && hasItem2) {
  6450. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6451. // TODO: station cash
  6452. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6453. // so there is no need to send it more then that one time
  6454. if (tempItem1) {
  6455. if (tempItem1->details.count > item_quantity) {
  6456. tempItem1->details.count -= item_quantity;
  6457. tempItem1->save_needed = true;
  6458. }
  6459. else {
  6460. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6461. player->item_list.DestroyItem(tempItem1->details.index);
  6462. }
  6463. }
  6464. if (tempItem2) {
  6465. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6466. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6467. tempItem2->save_needed = true;
  6468. }
  6469. else {
  6470. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6471. player->item_list.DestroyItem(tempItem2->details.index);
  6472. }
  6473. }
  6474. // 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
  6475. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6476. item->SetMaxSellValue(sell_price);
  6477. if (quantity > 1)
  6478. 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());
  6479. else
  6480. 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());
  6481. bool itemDeleted = false;
  6482. AddItem(item, &itemDeleted);
  6483. if(!itemDeleted) {
  6484. CheckPlayerQuestsItemUpdate(item);
  6485. if (item && total_available < 0xFF) {
  6486. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6487. SendBuyMerchantList();
  6488. }
  6489. SendSellMerchantList();
  6490. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6491. PlayLotto(total_buy_price, item->details.item_id);
  6492. }
  6493. }
  6494. else {
  6495. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6496. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6497. PlaySound("buy_failed");
  6498. }
  6499. }
  6500. else {
  6501. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6502. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6503. PlaySound("buy_failed");
  6504. }
  6505. }
  6506. }
  6507. }
  6508. }
  6509. }
  6510. void Client::RepairItem(int32 item_id) {
  6511. Spawn* spawn = GetMerchantTransaction();
  6512. if (spawn) {
  6513. Item* item = player->item_list.GetItemFromID(item_id);
  6514. if (!item)
  6515. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6516. if (item) {
  6517. if(item->CheckFlag(NO_REPAIR)) {
  6518. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  6519. PlaySound("buy_failed");
  6520. }
  6521. else {
  6522. int32 repair_cost = item->CalculateRepairCost();
  6523. if (player->RemoveCoins((int32)repair_cost)) {
  6524. item->generic_info.condition = 100;
  6525. item->save_needed = true;
  6526. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6527. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6528. QueuePacket(item->serialize(version, false, player));
  6529. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6530. PlaySound("coin_cha_ching");
  6531. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6532. SendRepairList();
  6533. }
  6534. else {
  6535. string popup_text = "You do not have enough coin to repair ";
  6536. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  6537. popup_text.append(popup_item);
  6538. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6539. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6540. PlaySound("buy_failed");
  6541. }
  6542. }
  6543. }
  6544. }
  6545. }
  6546. void Client::RepairAllItems() {
  6547. Spawn* spawn = GetMerchantTransaction();
  6548. if (spawn) {
  6549. vector<Item*>* repairable_items = GetRepairableItems();
  6550. if (repairable_items && repairable_items->size() > 0) {
  6551. vector<Item*>::iterator itr;
  6552. int64 total_cost = 0;
  6553. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6554. total_cost += (*itr)->CalculateRepairCost();
  6555. if (player->RemoveCoins((int32)total_cost)) {
  6556. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6557. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6558. Item* item = *itr;
  6559. if (item) {
  6560. item->generic_info.condition = 100;
  6561. item->save_needed = true;
  6562. QueuePacket(item->serialize(version, false, player));
  6563. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6564. }
  6565. }
  6566. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6567. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6568. PlaySound("coin_cha_ching");
  6569. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6570. SendRepairList();
  6571. }
  6572. else {
  6573. string popup_text = "You do not have enough coin to repair all of your items. ";
  6574. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6575. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6576. PlaySound("buy_failed");
  6577. }
  6578. }
  6579. safe_delete(repairable_items);
  6580. }
  6581. }
  6582. void Client::SendAchievementsList()
  6583. {
  6584. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6585. map<int32, Achievement *>::iterator itr;
  6586. Achievement *achievement;
  6587. vector<AchievementRequirements *> *requirements = 0;
  6588. vector<AchievementRequirements *>::iterator itr2;
  6589. AchievementRequirements *requirement;
  6590. vector<AchievementRewards *> *rewards = 0;
  6591. vector<AchievementRewards *>::iterator itr3;
  6592. AchievementRewards *reward;
  6593. PacketStruct *packet;
  6594. int16 i = 0;
  6595. int16 j = 0;
  6596. int16 k = 0;
  6597. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6598. return;
  6599. }
  6600. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6601. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6602. achievement = itr->second;
  6603. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6604. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6605. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6606. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6607. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6608. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6609. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6610. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6611. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6612. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6613. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6614. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6615. requirements = achievement->GetRequirements();
  6616. rewards = achievement->GetRewards();
  6617. j = 0;
  6618. k = 0;
  6619. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6620. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6621. requirement = *itr2;
  6622. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6623. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6624. j++;
  6625. }
  6626. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6627. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6628. reward = *itr3;
  6629. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6630. k++;
  6631. }
  6632. i++;
  6633. }
  6634. //packet->PrintPacket();
  6635. EQ2Packet* data = packet->serialize();
  6636. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6637. safe_delete(packet);
  6638. safe_delete(data);
  6639. //DumpPacket(app);
  6640. QueuePacket(app);*/
  6641. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6642. SendAchievementUpdate(true);
  6643. }
  6644. void Client::SendAchievementUpdate(bool first_login) {
  6645. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6646. map<int32, AchievementUpdate*>::iterator itr;
  6647. AchievementUpdate* update;
  6648. vector<AchievementUpdateItems*>* update_items = 0;
  6649. vector<AchievementUpdateItems*>::iterator itr2;
  6650. AchievementUpdateItems* update_item;
  6651. int16 i = 0;
  6652. int16 j = 0;
  6653. PacketStruct* packet;
  6654. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6655. return;
  6656. }
  6657. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6658. packet->setArrayLengthByName("num_achievements", updates->size());
  6659. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6660. update = itr->second;
  6661. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6662. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6663. update_items = update->GetUpdateItems();
  6664. j = 0;
  6665. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6666. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6667. update_item = *itr2;
  6668. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6669. j++;
  6670. }
  6671. i++;
  6672. }
  6673. //packet->PrintPacket();
  6674. EQ2Packet* data = packet->serialize();
  6675. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6676. safe_delete(packet);
  6677. safe_delete(data);
  6678. //DumpPacket(app);
  6679. QueuePacket(app);
  6680. }
  6681. void Client::SendBuyMerchantList(bool sell) {
  6682. Spawn* spawn = GetMerchantTransaction();
  6683. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6684. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6685. if (items) {
  6686. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6687. if (packet) {
  6688. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6689. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6690. packet->setArrayLengthByName("num_items", items->size());
  6691. vector<MerchantItemInfo>::iterator itr;
  6692. sint8 item_difficulty = 0;
  6693. int32 sell_price = 0;
  6694. int i = 0;
  6695. int tmp_level = 0;
  6696. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6697. MerchantItemInfo ItemInfo = *itr;
  6698. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6699. if (!item)
  6700. continue;
  6701. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6702. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6703. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6704. packet->setArrayDataByName("icon", item->details.icon, i);
  6705. if (item->generic_info.adventure_default_level > 0)
  6706. tmp_level = item->generic_info.adventure_default_level;
  6707. else
  6708. tmp_level = item->generic_info.tradeskill_default_level;
  6709. packet->setArrayDataByName("level", tmp_level, i);
  6710. packet->setArrayDataByName("tier", item->details.tier, i);
  6711. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6712. item_difficulty = player->GetArrowColor(tmp_level);
  6713. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6714. item_difficulty = ARROW_COLOR_WHITE;
  6715. sint64 overrideValue = 0;
  6716. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6717. item_difficulty = (sint8)overrideValue;
  6718. item_difficulty -= 6;
  6719. if (item_difficulty < 0)
  6720. item_difficulty *= -1;
  6721. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6722. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6723. packet->setArrayDataByName("unknown5", 255, i);
  6724. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6725. sint64 dispFlags = 0;
  6726. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  6727. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6728. std::string overrideValueStr;
  6729. // 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)
  6730. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6731. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6732. // If no price set in the merchant_inventory table then use the old method
  6733. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6734. sell_price = (int32)(item->sell_price * multiplier);
  6735. packet->setArrayDataByName("price", sell_price, i);
  6736. }
  6737. else {
  6738. int8 count = 0;
  6739. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6740. count++;
  6741. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6742. count++;
  6743. if (count != 0) {
  6744. packet->setSubArrayLengthByName("num_tokens", count, i);
  6745. int8 index = 0;
  6746. Item* token = 0;
  6747. if (ItemInfo.price_item_id != 0) {
  6748. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6749. if (item) {
  6750. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6751. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6752. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6753. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6754. }
  6755. token = 0;
  6756. index++;
  6757. }
  6758. if (ItemInfo.price_item2_id != 0) {
  6759. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6760. if (item) {
  6761. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6762. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6763. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6764. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6765. }
  6766. }
  6767. }
  6768. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6769. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6770. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6771. }
  6772. }
  6773. if (GetVersion() <= 546) {
  6774. //buy is 0 so dont need to set it
  6775. if (sell)
  6776. packet->setDataByName("type", 1);
  6777. }
  6778. else {
  6779. if (sell)
  6780. packet->setDataByName("type", 130);
  6781. else
  6782. packet->setDataByName("type", 2);
  6783. }
  6784. EQ2Packet* outapp = packet->serialize();
  6785. // DumpPacket(outapp);
  6786. QueuePacket(outapp);
  6787. safe_delete(packet);
  6788. }
  6789. safe_delete(items);
  6790. }
  6791. else {
  6792. // Need to send an empty packet in the event there is no item list, otherwise the
  6793. // last item list sent to the player will show for this merchant
  6794. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6795. if (packet) {
  6796. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6797. if (GetVersion() <= 546) {
  6798. //buy is 0 so dont need to set it
  6799. if (sell)
  6800. packet->setDataByName("type", 1);
  6801. }
  6802. else {
  6803. if (sell)
  6804. packet->setDataByName("type", 130);
  6805. else
  6806. packet->setDataByName("type", 2);
  6807. }
  6808. EQ2Packet* outapp = packet->serialize();
  6809. QueuePacket(outapp);
  6810. safe_delete(packet);
  6811. }
  6812. }
  6813. }
  6814. }
  6815. void Client::SendSellMerchantList(bool sell) {
  6816. Spawn* spawn = GetMerchantTransaction();
  6817. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6818. return;
  6819. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6820. map<int32, Item*>* items = player->GetItemList();
  6821. if (items) {
  6822. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6823. if (packet) {
  6824. vector<Item*> sellable_items;
  6825. map<int32, Item*>::iterator test_itr;
  6826. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6827. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6828. sellable_items.push_back(test_itr->second);
  6829. }
  6830. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6831. packet->setArrayLengthByName("num_items", sellable_items.size());
  6832. vector<Item*>::iterator itr;
  6833. Item* item = 0;
  6834. sint8 item_difficulty = 0;
  6835. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6836. int32 sell_price = 0;
  6837. Item* master_item = 0;
  6838. int i = 0;
  6839. int tmp_level = 0;
  6840. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6841. item = *itr;
  6842. master_item = master_item_list.GetItem(item->details.item_id);
  6843. if (master_item)
  6844. sell_price = (int32)(master_item->sell_price * multiplier);
  6845. else
  6846. sell_price = 0;
  6847. if (sell_price > item->sell_price)
  6848. sell_price = item->sell_price;
  6849. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6850. string thename = item->name;
  6851. packet->setArrayDataByName("price", sell_price, i);
  6852. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6853. int8 dispFlags = 0;
  6854. // only city merchants allow selling for status
  6855. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6856. {
  6857. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6858. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6859. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6860. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6861. }
  6862. }
  6863. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6864. {
  6865. if(GetVersion() < 1188)
  6866. 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
  6867. else
  6868. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6869. }
  6870. if(item->no_sale)
  6871. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6872. packet->setArrayDataByName("display_flags", dispFlags, i);
  6873. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6874. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6875. packet->setArrayDataByName("stack_size", item->details.count, i);
  6876. packet->setArrayDataByName("icon", item->details.icon, i);
  6877. if (item->generic_info.adventure_default_level > 0)
  6878. tmp_level = item->generic_info.adventure_default_level;
  6879. else
  6880. tmp_level = item->generic_info.tradeskill_default_level;
  6881. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6882. packet->setArrayDataByName("tier", item->details.tier, i);
  6883. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6884. item_difficulty = player->GetArrowColor(tmp_level);
  6885. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6886. item_difficulty = ARROW_COLOR_WHITE;
  6887. sint64 overrideValue = 0;
  6888. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6889. item_difficulty = (sint8)overrideValue;
  6890. item_difficulty -= 6;
  6891. if (item_difficulty < 0)
  6892. item_difficulty *= -1;
  6893. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6894. if (item->details.count == 1)
  6895. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6896. else
  6897. packet->setArrayDataByName("quantity", item->details.count, i);
  6898. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6899. if (GetVersion() <= 1096)
  6900. packet->setArrayDataByName("description", item->description.c_str(), i);
  6901. }
  6902. if (GetVersion() <= 546) {
  6903. packet->setDataByName("type", 1);
  6904. }
  6905. else {
  6906. if (sell)
  6907. packet->setDataByName("type", 129);
  6908. else
  6909. packet->setDataByName("type", 1);
  6910. }
  6911. packet->setDataByName("unknown8a", 16256, 6);
  6912. packet->setDataByName("unknown8a", 16256, 10);
  6913. //packet->PrintPacket();
  6914. EQ2Packet* outapp = packet->serialize();
  6915. //DumpPacket(outapp);
  6916. QueuePacket(outapp);
  6917. safe_delete(packet);
  6918. }
  6919. safe_delete(items);
  6920. }
  6921. }
  6922. }
  6923. void Client::SendBuyBackList(bool sell) {
  6924. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6925. return;
  6926. Spawn* spawn = GetMerchantTransaction();
  6927. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6928. deque<BuyBackItem*>::iterator itr;
  6929. int i = 0;
  6930. Item* master_item = 0;
  6931. BuyBackItem* buyback = 0;
  6932. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6933. if (packet) {
  6934. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6935. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6936. sint8 item_difficulty = 0;
  6937. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6938. int tmp_level = 0;
  6939. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6940. buyback = *itr;
  6941. master_item = master_item_list.GetItem(buyback->item_id);
  6942. if (master_item) {
  6943. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6944. packet->setArrayDataByName("price", buyback->price, i);
  6945. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6946. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6947. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6948. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6949. if (master_item->generic_info.adventure_default_level > 0)
  6950. tmp_level = master_item->generic_info.adventure_default_level;
  6951. else
  6952. tmp_level = master_item->generic_info.tradeskill_default_level;
  6953. packet->setArrayDataByName("level", tmp_level, i);
  6954. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6955. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6956. item_difficulty = player->GetArrowColor(tmp_level);
  6957. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6958. item_difficulty = ARROW_COLOR_WHITE;
  6959. sint64 overrideValue = 0;
  6960. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  6961. item_difficulty = (sint8)overrideValue;
  6962. item_difficulty -= 6;
  6963. if (item_difficulty < 0)
  6964. item_difficulty *= -1;
  6965. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6966. sint64 dispFlags = 0;
  6967. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  6968. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6969. if (buyback->quantity == 1)
  6970. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6971. else
  6972. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6973. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6974. if (GetVersion() <= 1096)
  6975. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6976. }
  6977. }
  6978. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6979. if (sell)
  6980. packet->setDataByName("type", 640);
  6981. else
  6982. packet->setDataByName("type", 512);
  6983. EQ2Packet* outapp = packet->serialize();
  6984. // DumpPacket(outapp);
  6985. QueuePacket(outapp);
  6986. safe_delete(packet);
  6987. }
  6988. }
  6989. }
  6990. void Client::SendRepairList() {
  6991. Spawn* spawn = GetMerchantTransaction();
  6992. if (spawn) {
  6993. vector<Item*>* repairable_items = GetRepairableItems();
  6994. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6995. if (packet) {
  6996. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6997. packet->setArrayLengthByName("num_items", repairable_items->size());
  6998. Item* item = 0;
  6999. sint8 item_difficulty = 0;
  7000. int32 i = 0;
  7001. vector<Item*>::iterator itr;
  7002. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7003. item = *itr;
  7004. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7005. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7006. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7007. packet->setArrayDataByName("stack_size", item->details.count, i);
  7008. packet->setArrayDataByName("icon", item->details.icon, i);
  7009. /*if (item->generic_info.adventure_default_level > 0)
  7010. tmp_level = item->generic_info.adventure_default_level;
  7011. else
  7012. tmp_level = item->generic_info.tradeskill_default_level;
  7013. packet->setArrayDataByName("level", tmp_level, i);*/
  7014. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7015. packet->setArrayDataByName("tier", item->details.tier, i);
  7016. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7017. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7018. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7019. item_difficulty = ARROW_COLOR_WHITE;
  7020. item_difficulty -= 6;
  7021. if (item_difficulty < 0)
  7022. item_difficulty *= -1;
  7023. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7024. if (item->details.count == 1)
  7025. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7026. else
  7027. packet->setArrayDataByName("quantity", item->details.count, i);
  7028. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7029. if (GetVersion() <= 1096)
  7030. packet->setArrayDataByName("description", item->description.c_str(), i);
  7031. }
  7032. if (GetVersion() <= 546) {
  7033. packet->setDataByName("type", 16);
  7034. }
  7035. else {
  7036. packet->setDataByName("type", 96);
  7037. }
  7038. EQ2Packet* outapp = packet->serialize();
  7039. QueuePacket(outapp);
  7040. safe_delete(packet);
  7041. }
  7042. safe_delete(repairable_items);
  7043. }
  7044. }
  7045. void Client::ShowLottoWindow() {
  7046. Spawn* spawn = GetMerchantTransaction();
  7047. if (spawn) {
  7048. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7049. if (!item_id)
  7050. {
  7051. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7052. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7053. return;
  7054. }
  7055. else if (item_id == 0)
  7056. {
  7057. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7058. return;
  7059. }
  7060. Item* item = master_item_list.GetItem(item_id);
  7061. if (!item) {
  7062. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7063. return;
  7064. }
  7065. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7066. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7067. if (packet) {
  7068. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7069. packet->setArrayLengthByName("num_items", 1);
  7070. packet->setArrayDataByName("item_name", item->name.c_str());
  7071. packet->setArrayDataByName("price", item->sell_price);
  7072. packet->setArrayDataByName("item_id", item->details.item_id);
  7073. packet->setArrayDataByName("stack_size", item->details.count);
  7074. packet->setArrayDataByName("icon", item->details.icon);
  7075. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7076. packet->setArrayDataByName("tier", item->details.tier);
  7077. packet->setArrayDataByName("item_id2", item->details.item_id);
  7078. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7079. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7080. item_difficulty = ARROW_COLOR_WHITE;
  7081. item_difficulty -= 6;
  7082. if (item_difficulty < 0)
  7083. item_difficulty *= -1;
  7084. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7085. //if(item->details.count == 1)
  7086. packet->setArrayDataByName("quantity", 0xFFFF);
  7087. //else
  7088. // packet->setArrayDataByName("quantity", item->details.count);
  7089. packet->setArrayDataByName("stack_size2", item->details.count);
  7090. packet->setArrayDataByName("description", item->description.c_str());
  7091. if (GetVersion() <= 546) {
  7092. packet->setDataByName("type", 128);
  7093. }
  7094. else {
  7095. packet->setDataByName("type", 0x00000102);
  7096. }
  7097. QueuePacket(packet->serialize());
  7098. safe_delete(packet);
  7099. }
  7100. }
  7101. }
  7102. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7103. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7104. if (packet) {
  7105. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7106. int32 rolls[6] = { 0 };
  7107. int32 lottery_digits[6] = { 0 };
  7108. int8 num_matches = 0;
  7109. int64 jackpot = 0;
  7110. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7111. if (!item) {
  7112. return;
  7113. }
  7114. database.DeleteItem(GetCharacterID(), item, 0);
  7115. GetPlayer()->item_list.RemoveItem(item, true);
  7116. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7117. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7118. if (!winning_numbers) {
  7119. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7120. variables.AddVariable(winning_numbers);
  7121. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7122. }
  7123. if (strlen(winning_numbers->GetValue()) != 12) {
  7124. winning_numbers->SetValue("231205182236");
  7125. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7126. }
  7127. try {
  7128. for (int32 i = 0; i < 12; i += 2) {
  7129. char num[4];
  7130. strncpy(num, winning_numbers->GetValue() + i, 2);
  7131. lottery_digits[i / 2] = atoi(num);
  7132. }
  7133. }
  7134. catch (...) {
  7135. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7136. return;
  7137. }
  7138. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7139. if (!jackpot_var) {
  7140. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7141. variables.AddVariable(jackpot_var);
  7142. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7143. }
  7144. try {
  7145. jackpot = atoul(jackpot_var->GetValue());
  7146. if (jackpot < 10000)
  7147. jackpot = 10000;
  7148. }
  7149. catch (...) {
  7150. jackpot = 10000;
  7151. }
  7152. char new_jackpot[128] = { 0 };
  7153. sprintf(new_jackpot, "%llu", jackpot + price);
  7154. jackpot_var->SetValue(new_jackpot);
  7155. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7156. world.PickRandomLottoDigits(rolls);
  7157. packet->setDataByName("roll_digit1", rolls[0]);
  7158. packet->setDataByName("roll_digit2", rolls[1]);
  7159. packet->setDataByName("roll_digit3", rolls[2]);
  7160. packet->setDataByName("roll_digit4", rolls[3]);
  7161. packet->setDataByName("roll_digit5", rolls[4]);
  7162. packet->setDataByName("roll_digit6", rolls[5]);
  7163. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7164. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7165. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7166. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7167. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7168. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7169. QueuePacket(packet->serialize());
  7170. safe_delete(packet);
  7171. for (int32 i = 0; i < 6; i++) {
  7172. for (int32 j = 0; j < 6; j++) {
  7173. if (rolls[i] == lottery_digits[j]) {
  7174. num_matches++;
  7175. break;
  7176. }
  7177. }
  7178. }
  7179. char new_jackpot_str[16];
  7180. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7181. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7182. if (num_matches == 6) {
  7183. world.PickRandomLottoDigits(lottery_digits);
  7184. for (int32 i = 0; i < 12; i += 2)
  7185. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7186. winning_numbers->SetValue(new_jackpot_str);
  7187. jackpot_var->SetValue("10000");
  7188. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7189. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7190. }
  7191. }
  7192. }
  7193. void Client::SendGuildCreateWindow() {
  7194. if (GetVersion() <= 546) {
  7195. SimpleMessage(0, "Not implemented on this client...yet?");
  7196. }
  7197. else {
  7198. Spawn* spawn = GetPlayer()->GetTarget();
  7199. if (spawn) {
  7200. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7201. if (packet) {
  7202. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7203. packet->setArrayLengthByName("num_items", 0);
  7204. packet->setDataByName("type", 0x00008000);
  7205. QueuePacket(packet->serialize());
  7206. safe_delete(packet);
  7207. }
  7208. }
  7209. }
  7210. }
  7211. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7212. BuyBackItem* item = new BuyBackItem;
  7213. item->item_id = item_id;
  7214. item->unique_id = unique_id;
  7215. item->price = price;
  7216. item->quantity = quantity;
  7217. item->save_needed = save_needed;
  7218. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7219. buy_back_items.push_back(item);
  7220. if (buy_back_items.size() > 10) {
  7221. safe_delete(buy_back_items.front());
  7222. buy_back_items.pop_front();
  7223. }
  7224. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7225. }
  7226. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7227. return &buy_back_items;
  7228. }
  7229. vector<Item*>* Client::GetRepairableItems() {
  7230. vector<Item*>* repairable_items = new vector<Item*>;
  7231. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7232. map<int32, Item*>* items = player->GetItemList();
  7233. if (equipped_items && equipped_items->size() > 0) {
  7234. for (int32 i = 0; i < equipped_items->size(); i++) {
  7235. Item* item = equipped_items->at(i);
  7236. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7237. repairable_items->push_back(item);
  7238. }
  7239. }
  7240. if (items && items->size() > 0) {
  7241. map<int32, Item*>::iterator itr;
  7242. for (itr = items->begin(); itr != items->end(); itr++) {
  7243. Item* item = itr->second;
  7244. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7245. repairable_items->push_back(item);
  7246. }
  7247. }
  7248. safe_delete(equipped_items);
  7249. safe_delete(items);
  7250. return repairable_items;
  7251. }
  7252. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  7253. if(type == NO_EFFECT_TYPE)
  7254. return nullptr;
  7255. vector<Item*>* return_items = new vector<Item*>;
  7256. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7257. map<int32, Item*>* items = player->GetItemList();
  7258. if (equipped_items && equipped_items->size() > 0) {
  7259. for (int32 i = 0; i < equipped_items->size(); i++) {
  7260. Item* item = equipped_items->at(i);
  7261. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7262. return_items->push_back(item);
  7263. }
  7264. }
  7265. if (items && items->size() > 0) {
  7266. map<int32, Item*>::iterator itr;
  7267. for (itr = items->begin(); itr != items->end(); itr++) {
  7268. Item* item = itr->second;
  7269. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7270. return_items->push_back(item);
  7271. }
  7272. }
  7273. safe_delete(equipped_items);
  7274. safe_delete(items);
  7275. return return_items;
  7276. }
  7277. void Client::SendMailList() {
  7278. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7279. if (kiosk_id > 0) {
  7280. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7281. if (p) {
  7282. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7283. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7284. int32 i = 0;
  7285. p->setDataByName("kiosk_id", kiosk_id);
  7286. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7287. while (itr.Next()) {
  7288. Mail* mail = itr->second;
  7289. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7290. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7291. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7292. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7293. p->setArrayDataByName("unknown1", 0x0000, i);
  7294. p->setArrayDataByName("already_read", mail->already_read, i);
  7295. if(mail->expire_time)
  7296. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7297. else
  7298. p->setArrayDataByName("mail_deletion", 0, i);
  7299. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7300. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7301. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7302. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7303. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7304. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7305. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7306. //p->setArrayDataByName("unknown2", 0, i);
  7307. bool successItemAdd = false;
  7308. if(mail->stack || mail->char_item_id)
  7309. {
  7310. Item* item = master_item_list.GetItem(mail->char_item_id);
  7311. if(item)
  7312. {
  7313. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7314. if (version < 860)
  7315. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7316. else if (version < 1193)
  7317. p->setItemArrayDataByName("item", item, player, i);
  7318. else
  7319. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7320. successItemAdd = true;
  7321. }
  7322. }
  7323. if(!successItemAdd)
  7324. {
  7325. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7326. p->setArrayDataByName("end_tag3", 0xFF, i);
  7327. }
  7328. i++;
  7329. }
  7330. // GMs send mail for free!
  7331. if (GetAdminStatus() > 0)
  7332. {
  7333. p->setDataByName("postage_cost", 0);
  7334. p->setDataByName("attachment_cost", 0);
  7335. }
  7336. else
  7337. {
  7338. p->setDataByName("postage_cost", 10);
  7339. p->setDataByName("attachment_cost", 50);
  7340. }
  7341. p->setDataByName("unknown3", 0x01F4);
  7342. p->setDataByName("unknown4", 0x01000000);
  7343. EQ2Packet* pack = p->serialize();
  7344. QueuePacket(pack);
  7345. safe_delete(p);
  7346. }
  7347. }
  7348. else
  7349. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7350. }
  7351. void Client::DisplayMailMessage(int32 mail_id) {
  7352. Mail* mail = player->GetMail(mail_id);
  7353. if (mail) {
  7354. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7355. if (kiosk_id > 0) {
  7356. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7357. if (update) {
  7358. update->setDataByName("action", 0x03);
  7359. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7360. update->setDataByName("packetsubtype", 0xFF);
  7361. QueuePacket(update->serialize());
  7362. safe_delete(update);
  7363. }
  7364. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7365. if (packet) {
  7366. packet->setDataByName("kiosk_id", kiosk_id);
  7367. packet->setDataByName("mail_id", mail->mail_id);
  7368. packet->setDataByName("player_to_id", mail->player_to_id);
  7369. packet->setDataByName("player_from", mail->player_from.c_str());
  7370. packet->setDataByName("subject", mail->subject.c_str());
  7371. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7372. packet->setDataByName("unknown1", 1);
  7373. packet->setDataByName("unknown2", 0);
  7374. packet->setDataByName("lock_report_button", 1);
  7375. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7376. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7377. packet->setDataByName("coin_copper", mail->coin_copper);
  7378. packet->setDataByName("coin_silver", mail->coin_silver);
  7379. packet->setDataByName("coin_gold", mail->coin_gold);
  7380. packet->setDataByName("coin_plat", mail->coin_plat);
  7381. if(mail->stack || mail->char_item_id)
  7382. {
  7383. Item* item = master_item_list.GetItem(mail->char_item_id);
  7384. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7385. if (version < 860)
  7386. packet->setItemByName("item", item, player, 0, -1);
  7387. else if (version < 1193)
  7388. packet->setItemByName("item", item, player, 0, 0);
  7389. else
  7390. packet->setItemByName("item", item, player, 0, 2);
  7391. }
  7392. else
  7393. {
  7394. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7395. packet->setDataByName("end_tag3", 0xFF);
  7396. }
  7397. mail->already_read = true;
  7398. mail->save_needed = true;
  7399. EQ2Packet* pack = packet->serialize();
  7400. QueuePacket(pack);
  7401. safe_delete(packet);
  7402. // trying to update this causes the window not to open
  7403. //SendMailList();
  7404. }
  7405. }
  7406. else
  7407. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7408. }
  7409. }
  7410. /* 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
  7411. packet back to the client before the mail actually sent. */
  7412. void Client::HandleSentMail(EQApplicationPacket* app) {
  7413. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7414. if (packet) {
  7415. packet->LoadPacketData(app->pBuffer, app->size);
  7416. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7417. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7418. vector<int32>* ids = 0;
  7419. MMailWindowMutex.lock();
  7420. if (reply_packet) {
  7421. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7422. if (player_to.length() == 0)
  7423. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7424. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7425. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7426. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7427. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7428. else {
  7429. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7430. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7431. ids = database.GetAllPlayerIDs();
  7432. else
  7433. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7434. }
  7435. else {
  7436. ids = new vector<int32>;
  7437. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7438. }
  7439. if (ids) {
  7440. for (int32 i = 0; i < ids->size(); i++) {
  7441. int32 player_to_id = ids->at(i);
  7442. if (player_to_id > 0) {
  7443. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7444. Mail* mail = new Mail;
  7445. mail->mail_id = 0;
  7446. mail->player_to_id = player_to_id;
  7447. mail->player_from = string(GetPlayer()->GetName());
  7448. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7449. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7450. mail->already_read = 0;
  7451. mail->mail_type = MAIL_TYPE_REGULAR;
  7452. mail->coin_copper = mail_window.coin_copper;
  7453. mail->coin_silver = mail_window.coin_silver;
  7454. mail->coin_gold = mail_window.coin_gold;
  7455. mail->coin_plat = mail_window.coin_plat;
  7456. mail->char_item_id = mail_window.char_item_id;
  7457. mail->stack = mail_window.stack;
  7458. // GM's send mail for free!
  7459. if (GetAdminStatus() > 0)
  7460. {
  7461. mail->postage_cost = 0;
  7462. mail->attachment_cost = 0;
  7463. }
  7464. else
  7465. {
  7466. mail->postage_cost = 10;
  7467. mail->attachment_cost = 50;
  7468. }
  7469. mail->time_sent = Timer::GetUnixTimeStamp();
  7470. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7471. mail->save_needed = false;
  7472. database.SavePlayerMail(mail);
  7473. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7474. if (to_client) {
  7475. to_client->GetPlayer()->AddMail(mail);
  7476. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  7477. string popup_text = "You have unread mail!";
  7478. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7479. }
  7480. else {
  7481. // don't need the pointer the client doesn't exist currently
  7482. safe_delete(mail);
  7483. }
  7484. ResetSendMail(false, false);
  7485. }
  7486. else
  7487. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  7488. }
  7489. }
  7490. }
  7491. string players_to = "";
  7492. if (ids) {
  7493. for (int32 i = 0; i < ids->size(); i++) {
  7494. if (ids->at(i) != 0)
  7495. players_to.append(database.GetCharacterName(ids->at(i)));
  7496. if (i < (ids->size() - 1))
  7497. players_to.append(", ");
  7498. }
  7499. }
  7500. reply_packet->setDataByName("player_to", players_to.c_str());
  7501. reply_packet->setDataByName("reply_type", reply_type);
  7502. QueuePacket(reply_packet->serialize());
  7503. safe_delete(reply_packet);
  7504. safe_delete(ids);
  7505. }
  7506. safe_delete(packet);
  7507. MMailWindowMutex.unlock();
  7508. }
  7509. }
  7510. void Client::DeleteMail(int32 mail_id, bool from_database) {
  7511. player->DeleteMail(mail_id, from_database);
  7512. }
  7513. bool Client::AddMailItem(Item* item)
  7514. {
  7515. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  7516. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  7517. return false;
  7518. }
  7519. bool ret = false;
  7520. if (GetMailTransaction()) {
  7521. MMailWindowMutex.lock();
  7522. if(mail_window.char_item_id == 0)
  7523. {
  7524. mail_window.item = item;
  7525. mail_window.char_item_id = item->details.item_id;
  7526. mail_window.stack = item->details.count;
  7527. ret = true;
  7528. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7529. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7530. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7531. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7532. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7533. if(item)
  7534. {
  7535. packet->setDataByName("stack", mail_window.stack);
  7536. item->stack_count = mail_window.stack;
  7537. if (version < 860)
  7538. packet->setItemByName("item", item, player, 0, -1);
  7539. else if (version < 1193)
  7540. packet->setItemByName("item", item, player, 0, 0);
  7541. else
  7542. packet->setItemByName("item", item, player, 0, 2);
  7543. }
  7544. else
  7545. {
  7546. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7547. packet->setDataByName("end_tag3", 0xFF);
  7548. }
  7549. QueuePacket(packet->serialize());
  7550. }
  7551. MMailWindowMutex.unlock();
  7552. }
  7553. return ret;
  7554. }
  7555. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7556. bool ret = false;
  7557. if (GetMailTransaction()) {
  7558. MMailWindowMutex.lock();
  7559. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7560. if (packet) {
  7561. if (copper > 0) {
  7562. if (player->RemoveCoins(copper)) {
  7563. mail_window.coin_copper += copper;
  7564. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7565. ret = true;
  7566. }
  7567. }
  7568. else if (silver > 0) {
  7569. if (player->RemoveCoins(silver * 100)) {
  7570. mail_window.coin_silver += silver;
  7571. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7572. ret = true;
  7573. }
  7574. }
  7575. else if (gold > 0) {
  7576. if (player->RemoveCoins(gold * 10000)) {
  7577. mail_window.coin_gold += gold;
  7578. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7579. ret = true;
  7580. }
  7581. }
  7582. else if (plat > 0) {
  7583. if (player->RemoveCoins(plat * 1000000)) {
  7584. mail_window.coin_plat += plat;
  7585. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7586. ret = true;
  7587. }
  7588. }
  7589. if (ret) {
  7590. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7591. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7592. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7593. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7594. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7595. if(item)
  7596. {
  7597. packet->setDataByName("stack", mail_window.stack);
  7598. item->stack_count = mail_window.stack;
  7599. if (version < 860)
  7600. packet->setItemByName("item", item, player, 0, -1);
  7601. else if (version < 1193)
  7602. packet->setItemByName("item", item, player, 0, 0);
  7603. else
  7604. packet->setItemByName("item", item, player, 0, 2);
  7605. }
  7606. else
  7607. {
  7608. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7609. packet->setDataByName("end_tag3", 0xFF);
  7610. }
  7611. //packet->PrintPacket();
  7612. QueuePacket(packet->serialize());
  7613. }
  7614. else
  7615. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7616. safe_delete(packet);
  7617. }
  7618. MMailWindowMutex.unlock();
  7619. }
  7620. else
  7621. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7622. return ret;
  7623. }
  7624. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7625. bool ret = false;
  7626. if (GetMailTransaction()) {
  7627. MMailWindowMutex.lock();
  7628. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7629. if (packet) {
  7630. if (copper > 0) {
  7631. player->AddCoins(copper);
  7632. mail_window.coin_copper -= copper;
  7633. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7634. ret = true;
  7635. }
  7636. else if (silver > 0) {
  7637. player->AddCoins(silver * 100);
  7638. mail_window.coin_silver -= silver;
  7639. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7640. ret = true;
  7641. }
  7642. else if (gold > 0) {
  7643. player->AddCoins(gold * 10000);
  7644. mail_window.coin_gold -= gold;
  7645. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7646. ret = true;
  7647. }
  7648. else if (plat > 0) {
  7649. player->AddCoins(plat * 1000000);
  7650. mail_window.coin_plat -= plat;
  7651. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7652. ret = true;
  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. packet->setDataByName("stack", 0);
  7660. packet->setDataByName("packettype", 0x2BFE);
  7661. packet->setDataByName("packetsubtype", 0xFF);
  7662. packet->setDataByName("unknown2", 0);
  7663. QueuePacket(packet->serialize());
  7664. }
  7665. safe_delete(packet);
  7666. }
  7667. MMailWindowMutex.unlock();
  7668. }
  7669. else
  7670. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7671. return ret;
  7672. }
  7673. void Client::TakeMailAttachments(int32 mail_id) {
  7674. if (GetMailTransaction()) {
  7675. Mail* mail = player->GetMail(mail_id);
  7676. if (mail) {
  7677. int64 amount = 0;
  7678. if (mail->coin_copper > 0) {
  7679. amount += mail->coin_copper;
  7680. mail->coin_copper = 0;
  7681. }
  7682. if (mail->coin_silver > 0) {
  7683. amount += mail->coin_silver * 100;
  7684. mail->coin_silver = 0;
  7685. }
  7686. if (mail->coin_gold > 0) {
  7687. amount += mail->coin_gold * 10000;
  7688. mail->coin_gold = 0;
  7689. }
  7690. if (mail->coin_plat > 0) {
  7691. amount += mail->coin_plat * 1000000;
  7692. mail->coin_plat = 0;
  7693. }
  7694. if (mail->char_item_id > 0) {
  7695. AddItem(mail->char_item_id, mail->stack);
  7696. mail->char_item_id = 0;
  7697. mail->stack = 0;
  7698. }
  7699. /* 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
  7700. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7701. find it in any packet logs.*/
  7702. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7703. if (packet) {
  7704. packet->setDataByName("unknown", 0x03);
  7705. packet->setDataByName("coin_copper", mail->coin_copper);
  7706. packet->setDataByName("coin_silver", mail->coin_silver);
  7707. packet->setDataByName("coin_gold", mail->coin_gold);
  7708. packet->setDataByName("coin_plat", mail->coin_plat);
  7709. packet->setDataByName("stack", 0);
  7710. packet->setDataByName("packettype", 0x2BFE);
  7711. packet->setDataByName("packetsubtype", 0xFF);
  7712. packet->setDataByName("unknown2", 0);
  7713. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7714. DumpPacket(packet->serialize());
  7715. QueuePacket(packet->serialize());
  7716. safe_delete(packet);
  7717. }*/
  7718. database.SavePlayerMail(mail);
  7719. if (amount > 0)
  7720. player->AddCoins(amount);
  7721. SendMailList();
  7722. }
  7723. }
  7724. else
  7725. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7726. }
  7727. void Client::ResetSendMail(bool cancel, bool needslock) {
  7728. if(cancel && mail_transaction)
  7729. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7730. if(needslock)
  7731. MMailWindowMutex.lock();
  7732. if(cancel)
  7733. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7734. if(!cancel)
  7735. mail_transaction = 0;
  7736. mail_window.coin_copper = 0;
  7737. mail_window.coin_silver = 0;
  7738. mail_window.coin_gold = 0;
  7739. mail_window.coin_plat = 0;
  7740. mail_window.char_item_id = 0;
  7741. mail_window.stack = 0;
  7742. if(mail_window.item){
  7743. if(cancel)
  7744. AddItem(mail_window.item);
  7745. else
  7746. safe_delete(mail_window.item);
  7747. }
  7748. mail_window.item = nullptr;
  7749. if(needslock)
  7750. MMailWindowMutex.unlock();
  7751. }
  7752. bool Client::GateAllowed() {
  7753. ZoneServer* zone = GetCurrentZone();
  7754. if (zone){
  7755. bool cangate = zone->GetCanGate();
  7756. return cangate;
  7757. }
  7758. return false;
  7759. }
  7760. bool Client::BindAllowed() {
  7761. ZoneServer* zone = GetCurrentZone();
  7762. if (zone){
  7763. bool canbind = zone->GetCanBind();
  7764. return canbind;
  7765. }
  7766. return false;
  7767. }
  7768. bool Client::Bind() {
  7769. int canbind = BindAllowed();
  7770. if(canbind == 0) {
  7771. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  7772. return false;
  7773. }
  7774. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7775. player->GetPlayerInfo()->SetBindX(player->GetX());
  7776. player->GetPlayerInfo()->SetBindY(player->GetY());
  7777. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7778. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7779. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  7780. return true;
  7781. }
  7782. bool Client::Gate(bool is_spell) {
  7783. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  7784. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  7785. return false;
  7786. }
  7787. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7788. if (zone) {
  7789. int cangate = GateAllowed();
  7790. if(cangate == 0) {
  7791. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  7792. return false;
  7793. }
  7794. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7795. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7796. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7797. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7798. Zone(zone, false, is_spell);
  7799. return true;
  7800. }
  7801. return false;
  7802. }
  7803. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7804. if (!destinations || !spawn) {
  7805. return;
  7806. }
  7807. bool has_map = false;
  7808. if (transport_id > 0)
  7809. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7810. transport_spawn = spawn;
  7811. vector<TransportDestination*> transport_list;
  7812. vector<TransportDestination*>::iterator itr;
  7813. TransportDestination* destination = 0;
  7814. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7815. destination = *itr;
  7816. 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)))
  7817. transport_list.push_back(destination);
  7818. }
  7819. if (transport_list.size() == 0 && destination) {
  7820. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7821. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7822. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7823. else
  7824. {
  7825. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7826. if (app)
  7827. QueuePacket(app);
  7828. }
  7829. }
  7830. else {
  7831. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7832. // determine if this is an instanced zone that already exists
  7833. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7834. if (instance_zone || new_zone) {
  7835. GetPlayer()->SetX(destination->destination_x);
  7836. GetPlayer()->SetY(destination->destination_y);
  7837. GetPlayer()->SetZ(destination->destination_z);
  7838. GetPlayer()->SetHeading(destination->destination_heading);
  7839. if (instance_zone)
  7840. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7841. else
  7842. Zone(new_zone, false, is_spell);
  7843. }
  7844. }
  7845. if (destination->message.length() > 0)
  7846. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7847. }
  7848. else if (transport_list.size() > 0) {
  7849. if (!spawn->IsSoundsDisabled())
  7850. PlaySound("mariner_bell");
  7851. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7852. if (packet) {
  7853. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7854. // Put all the destinations the player can go in a new vector
  7855. vector<TransportDestination*> destinations;
  7856. for (int32 i = 0; i < transport_list.size(); i++) {
  7857. destination = transport_list.at(i);
  7858. // Check min level
  7859. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7860. continue;
  7861. // Check max level
  7862. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7863. continue;
  7864. // Check quest complete
  7865. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7866. continue;
  7867. // Check req quest and step
  7868. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7869. continue;
  7870. // 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
  7871. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7872. packet->setDataByName("current_zone", destination->display_name.c_str());
  7873. packet->setDataByName("current_map_x", destination->map_x);
  7874. packet->setDataByName("current_map_y", destination->map_y);
  7875. }
  7876. else {
  7877. destinations.push_back(destination);
  7878. }
  7879. }
  7880. // Use the new vector to create the packet
  7881. destination = 0;
  7882. packet->setArrayLengthByName("num_destinations", destinations.size());
  7883. for (int32 i = 0; i < destinations.size(); i++) {
  7884. destination = destinations.at(i);
  7885. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7886. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7887. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7888. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7889. packet->setArrayDataByName("cost", destination->cost, i);
  7890. if (has_map) {
  7891. packet->setArrayDataByName("map_x", destination->map_x, i);
  7892. packet->setArrayDataByName("map_y", destination->map_y, i);
  7893. }
  7894. }
  7895. if (has_map)
  7896. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7897. EQ2Packet* app = packet->serialize();
  7898. //DumpPacket(app);
  7899. if (destinations.size() > 0)
  7900. QueuePacket(app);
  7901. safe_delete(packet);
  7902. }
  7903. }
  7904. }
  7905. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7906. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7907. if (packet) {
  7908. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7909. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7910. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7911. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7912. int32 cost = packet->getType_int32_ByName("cost");
  7913. vector<TransportDestination*> destinations;
  7914. TransportDestination* destination = 0;
  7915. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7916. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7917. vector<TransportDestination*>::iterator itr;
  7918. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7919. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7920. destination = *itr;
  7921. break;
  7922. }
  7923. }
  7924. SetTemporaryTransportID(0);
  7925. if (!destination)
  7926. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7927. else {
  7928. if (cost == 0 || player->RemoveCoins(cost)) {
  7929. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7930. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7931. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7932. else
  7933. {
  7934. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7935. if (outapp)
  7936. QueuePacket(outapp);
  7937. }
  7938. }
  7939. else {
  7940. GetPlayer()->SetX(destination->destination_x);
  7941. GetPlayer()->SetY(destination->destination_y);
  7942. GetPlayer()->SetZ(destination->destination_z);
  7943. GetPlayer()->SetHeading(destination->destination_heading);
  7944. // Test if where we're going is an Instanced zone
  7945. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7946. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7947. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7948. Zone(new_zone, false);
  7949. }
  7950. }
  7951. if (destination->message.length() > 0)
  7952. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7953. }
  7954. else
  7955. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7956. }
  7957. }
  7958. safe_delete(packet);
  7959. }
  7960. }
  7961. void Client::SendNewSpells(int8 class_id) {
  7962. if (class_id > 0) {
  7963. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7964. vector<Spell*>::iterator itr;
  7965. Spell* spell = 0;
  7966. bool send_updates = false;
  7967. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7968. spell = *itr;
  7969. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7970. send_updates = true;
  7971. SendSpellUpdate(spell);
  7972. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7973. player->UnlockSpell(spell);
  7974. }
  7975. }
  7976. if (send_updates) {
  7977. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7978. if (outapp)
  7979. QueuePacket(outapp);
  7980. }
  7981. safe_delete(spells);
  7982. }
  7983. }
  7984. void Client::SetItemSearch(vector<Item*>* items) {
  7985. if (items) {
  7986. safe_delete(search_items);
  7987. search_items = items;
  7988. }
  7989. }
  7990. vector<Item*>* Client::GetSearchItems() {
  7991. return search_items;
  7992. }
  7993. void Client::SearchStore(int32 page) {
  7994. if (search_items) {
  7995. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7996. if (packet) {
  7997. int32 x = page * 8;
  7998. if (search_items->size() > 8) {
  7999. if ((search_items->size() - x) > 8)
  8000. packet->setArrayLengthByName("num_items", 8);
  8001. else
  8002. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8003. }
  8004. else
  8005. packet->setArrayLengthByName("num_items", search_items->size());
  8006. if (search_items->size() > 0) {
  8007. packet->setArrayLengthByName("num_sellers", 1);
  8008. packet->setArrayDataByName("seller_seller_id", 1);
  8009. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  8010. packet->setDataByName("per_page", 8);
  8011. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8012. packet->setDataByName("page", page);
  8013. Item* item = 0;
  8014. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8015. for (int32 i = 0; i < limit; i++, x++) {
  8016. if (x >= search_items->size())
  8017. break;
  8018. item = search_items->at(x);
  8019. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8020. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8021. packet->setArrayDataByName("icon", item->details.icon, i);
  8022. //packet->setArrayDataByName("unknown2b", i, i);
  8023. packet->setArrayDataByName("item_seller_id", 1, i);
  8024. if (item->stack_count == 0)
  8025. packet->setArrayDataByName("quantity", 1, i);
  8026. else
  8027. packet->setArrayDataByName("quantity", item->stack_count, i);
  8028. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8029. std::string tmpStr("");
  8030. tmpStr.append(item->name.c_str());
  8031. tmpStr.append(" (");
  8032. tmpStr.append(std::to_string(item->details.item_id));
  8033. tmpStr.append(")");
  8034. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8035. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8036. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8037. }
  8038. }
  8039. /*EQ2Packet* outapp = packet->serialize();
  8040. DumpPacket(outapp);
  8041. QueuePacket(outapp);*/
  8042. QueuePacket(packet->serialize());
  8043. safe_delete(packet);
  8044. }
  8045. }
  8046. }
  8047. void Client::SetReadyForUpdates() {
  8048. GetPlayer()->SetFullyLoggedIn(true);
  8049. if (!ready_for_updates)
  8050. database.loadCharacterProperties(this);
  8051. ready_for_updates = true;
  8052. }
  8053. void Client::SetReadyForSpawns(bool val) {
  8054. ready_for_spawns = val;
  8055. if (GetPlayer()->GetActivityStatus() > 0) {
  8056. GetPlayer()->SetActivityStatus(0);
  8057. if (GetPlayer()->GetGroupMemberInfo()) {
  8058. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8059. }
  8060. }
  8061. GetPlayer()->SetActiveReward(false);
  8062. zone_list.CheckFriendZoned(this);
  8063. }
  8064. void Client::SendChatRelationship(int8 type, const char* name) {
  8065. if (!name) {
  8066. return;
  8067. }
  8068. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8069. if (packet) {
  8070. packet->setDataByName("account_id", GetAccountID());
  8071. packet->setDataByName("type", type);
  8072. packet->setArrayLengthByName("num_names", 1);
  8073. packet->setArrayDataByName("name", name);
  8074. if (type == 0) {
  8075. Client* client = zone_list.GetClientByCharName(name);
  8076. if (client) {
  8077. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8078. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8079. }
  8080. }
  8081. QueuePacket(packet->serialize());
  8082. safe_delete(packet);
  8083. }
  8084. }
  8085. void Client::SendFriendList() {
  8086. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8087. if (packet) {
  8088. packet->setDataByName("account_id", GetAccountID());
  8089. map<string, int8>::iterator itr;
  8090. map<string, int8>* friends = player->GetFriends();
  8091. if (friends && friends->size() > 0) {
  8092. Client* client = 0;
  8093. vector<string> names;
  8094. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8095. if (itr->second == 2)
  8096. continue;
  8097. names.push_back(itr->first);
  8098. }
  8099. packet->setArrayLengthByName("num_names", names.size());
  8100. for (int32 i = 0; i < names.size(); i++) {
  8101. client = zone_list.GetClientByCharName(names[i]);
  8102. packet->setArrayDataByName("name", names[i].c_str(), i);
  8103. if (client) {
  8104. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8105. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8106. }
  8107. }
  8108. }
  8109. QueuePacket(packet->serialize());
  8110. safe_delete(packet);
  8111. }
  8112. }
  8113. void Client::SendIgnoreList() {
  8114. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8115. if (packet) {
  8116. packet->setDataByName("account_id", GetAccountID());
  8117. packet->setDataByName("type", 2);
  8118. map<string, int8>::iterator itr;
  8119. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8120. if (ignored && ignored->size() > 0) {
  8121. vector<string> names;
  8122. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8123. if (itr->second == 2)
  8124. continue;
  8125. names.push_back(itr->first);
  8126. }
  8127. packet->setArrayLengthByName("num_names", names.size());
  8128. for (int32 i = 0; i < names.size(); i++)
  8129. packet->setArrayDataByName("name", names[i].c_str(), i);
  8130. }
  8131. QueuePacket(packet->serialize());
  8132. safe_delete(packet);
  8133. }
  8134. }
  8135. void Client::AddWaypoint(string name, int8 type) {
  8136. waypoint_id++;
  8137. WaypointInfo info;
  8138. info.id = waypoint_id;
  8139. info.type = type;
  8140. waypoints[name] = info;
  8141. }
  8142. void Client::SendWaypoints() {
  8143. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8144. if (packet) {
  8145. packet->setArrayLengthByName("num_updates", waypoints.size());
  8146. map<string, WaypointInfo>::iterator itr;
  8147. int16 i = 0;
  8148. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8149. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8150. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8151. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8152. i++;
  8153. }
  8154. packet->setDataByName("unknown", 0xFFFFFFFF);
  8155. QueuePacket(packet->serialize());
  8156. safe_delete(packet);
  8157. }
  8158. }
  8159. void Client::SelectWaypoint(int32 id) {
  8160. string found_name = "";
  8161. map<string, WaypointInfo>::iterator itr;
  8162. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8163. if (itr->second.id == id) {
  8164. found_name = itr->first;
  8165. break;
  8166. }
  8167. }
  8168. if (found_name.length() > 0) {
  8169. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8170. ShowPathToTarget(spawn);
  8171. }
  8172. }
  8173. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8174. if (waypoint_name) {
  8175. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8176. if (packet) {
  8177. packet->setArrayLengthByName("num_updates", 1);
  8178. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8179. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8180. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8181. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8182. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8183. packet->setDataByName("unknown", 0xFFFFFFFF);
  8184. QueuePacket(packet->serialize());
  8185. safe_delete(packet);
  8186. }
  8187. }
  8188. }
  8189. void Client::ClearWaypoint() {
  8190. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8191. if (packet) {
  8192. QueuePacket(packet->serialize());
  8193. safe_delete(packet);
  8194. }
  8195. }
  8196. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8197. if (current_zone->pathing) {
  8198. if (GetPlayer()->GetMap()) {
  8199. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8200. return false;
  8201. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8202. return false;
  8203. auto loc = glm::vec3(x, z, y);
  8204. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  8205. if (new_z != BEST_Z_INVALID) //this is actually y
  8206. y = new_z;
  8207. }
  8208. bool partial = false;
  8209. bool stuck = false;
  8210. PathfinderOptions opts;
  8211. opts.smooth_path = true;
  8212. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8213. opts.offset = y_offset + 1.0f;
  8214. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8215. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8216. if (packet) {
  8217. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8218. packet->setArrayLengthByName("num_points", path.size());
  8219. int i = 0;
  8220. for (auto& node : path)
  8221. {
  8222. packet->setArrayDataByName("x", node.pos.x, i);
  8223. packet->setArrayDataByName("y", node.pos.z, i);
  8224. packet->setArrayDataByName("z", node.pos.y, i);
  8225. packet->setDataByName("waypoint_x", x);
  8226. packet->setDataByName("waypoint_y", y);
  8227. packet->setDataByName("waypoint_z", z);
  8228. i++;
  8229. }
  8230. if (i > 0)
  8231. QueuePacket(packet->serialize());
  8232. safe_delete(packet);
  8233. return (i > 0);
  8234. }
  8235. }
  8236. return false;
  8237. }
  8238. bool Client::ShowPathToTarget(Spawn* spawn) {
  8239. if (spawn) {
  8240. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  8241. }
  8242. return false;
  8243. }
  8244. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  8245. if (waypoint_name) {
  8246. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8247. if (packet) {
  8248. packet->setArrayLengthByName("num_points", 1);
  8249. packet->setArrayDataByName("x", x, 0);
  8250. packet->setArrayDataByName("y", y, 0);
  8251. packet->setArrayDataByName("z", z, 0);
  8252. packet->setDataByName("waypoint_x", x);
  8253. packet->setDataByName("waypoint_y", y);
  8254. packet->setDataByName("waypoint_z", z);
  8255. packet->setDataByName("waypoint_name", waypoint_name);
  8256. packet->setDataByName("unknown", 0);
  8257. QueuePacket(packet->serialize());
  8258. safe_delete(packet);
  8259. }
  8260. }
  8261. }
  8262. void Client::InspectPlayer(Player* player_to_inspect) {
  8263. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  8264. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  8265. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8266. if(pvp_allowed == true){
  8267. if(source_pvp_alignment != target_pvp_alignment){
  8268. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  8269. return;
  8270. }
  8271. }
  8272. if (player_to_inspect) {
  8273. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  8274. if (packet) {
  8275. packet->setDataByName("unknown", 0);
  8276. packet->setSmallStringByName("name", player_to_inspect->GetName());
  8277. packet->setDataByName("race", player_to_inspect->GetRace());
  8278. packet->setDataByName("gender", player_to_inspect->GetGender());
  8279. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  8280. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  8281. packet->setDataByName("adventure_level_effective", effective_level);
  8282. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  8283. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  8284. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  8285. packet->setDataByName("health", player_to_inspect->GetHP());
  8286. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  8287. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  8288. packet->setDataByName("power", player_to_inspect->GetPower());
  8289. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  8290. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  8291. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  8292. packet->setDataByName("unknown1", 0);
  8293. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  8294. packet->setDataByName("unknown2", 0);
  8295. packet->setDataByName("mitigation_percentage", 0);
  8296. packet->setDataByName("strength", player_to_inspect->GetStr());
  8297. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  8298. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8299. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8300. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8301. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8302. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8303. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8304. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8305. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8306. packet->setDataByName("unknown4", 0);
  8307. packet->setDataByName("unknown5", 0);
  8308. packet->setDataByName("unknown6", 0);
  8309. packet->setDataByName("unknown7", 0);
  8310. packet->setDataByName("unknown8", 0);
  8311. packet->setDataByName("unknown9", 0);
  8312. packet->setDataByName("unknown10", 0);
  8313. packet->setDataByName("unknown11", 0);
  8314. packet->setDataByName("unknown12", 0);
  8315. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8316. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8317. packet->setDataByName("heat_resist_percentage", 0);
  8318. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8319. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8320. packet->setDataByName("cold_resist_percentage", 0);
  8321. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8322. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8323. packet->setDataByName("magic_resist_percentage", 0);
  8324. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8325. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8326. packet->setDataByName("mental_resist_percentage", 0);
  8327. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8328. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8329. packet->setDataByName("divine_resist_percentage", 0);
  8330. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8331. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8332. packet->setDataByName("disease_resist_percentage", 0);
  8333. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8334. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8335. packet->setDataByName("poison_resist_percentage", 0);
  8336. packet->setArrayLengthByName("num_chars", 0x01FF);
  8337. string biography = player_to_inspect->GetBiography();
  8338. for (size_t i = 0; i < biography.length(); i++)
  8339. packet->setArrayDataByName("biography_char", biography[i], i);
  8340. for(int32 s=0;s<NUM_SLOTS;s++) {
  8341. int32 slot = s*2;
  8342. char item_slot_name[64], item_slot_name_appearance[64];
  8343. _snprintf(item_slot_name,64,"slot_%u",slot);
  8344. int32 slot_appearance = (s*2)+1;
  8345. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  8346. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(s);
  8347. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13);
  8348. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  8349. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  8350. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13);
  8351. }
  8352. else {
  8353. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13);
  8354. }
  8355. }
  8356. QueuePacket(packet->serialize());
  8357. safe_delete(packet);
  8358. }
  8359. }
  8360. }
  8361. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8362. pending_guild_invite.guild = guild;
  8363. pending_guild_invite.invited_by = invited_by;
  8364. }
  8365. void Client::ShowClaimWindow() {
  8366. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8367. if (packet) {
  8368. map<int32, Item*>* items = &master_item_list.items;
  8369. map<int32, Item*>::iterator itr;
  8370. int32 i = 0;
  8371. if (items->size() > 10)
  8372. packet->setArrayLengthByName("num_claim_items", 10);
  8373. else
  8374. packet->setArrayLengthByName("num_claim_items", items->size());
  8375. for (itr = items->begin(); itr != items->end(); itr++) {
  8376. if (i == 10)
  8377. break;
  8378. Item* item = itr->second;
  8379. packet->setArrayDataByName("id", i, i);
  8380. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8381. packet->setArrayDataByName("num_remaining", 5, i);
  8382. packet->setArrayDataByName("one_per_character", 1, i);
  8383. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8384. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8385. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8386. packet->setArrayDataByName("category", "Scott's Shit", i);
  8387. packet->setArrayDataByName("icon", item->details.icon, i);
  8388. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8389. i++;
  8390. }
  8391. packet->setDataByName("unknown3", 1);
  8392. QueuePacket(packet->serialize());
  8393. safe_delete(packet);
  8394. }
  8395. }
  8396. void Client::ShowGuildSearchWindow() {
  8397. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8398. if (packet) {
  8399. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8400. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8401. packet->setArrayLengthByName("num_guilds", guilds->size());
  8402. int32 i = 0;
  8403. while (itr.Next()) {
  8404. Guild* guild = itr.second;
  8405. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8406. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8407. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8408. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8409. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8410. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8411. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8412. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8413. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8414. packet->setArrayDataByName("unknown7", 0x02, i);
  8415. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8416. i++;
  8417. }
  8418. QueuePacket(packet->serialize());
  8419. safe_delete(packet);
  8420. }
  8421. }
  8422. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8423. PacketStruct* packet;
  8424. vector<int8>* slot_data;
  8425. vector<int8>::iterator itr;
  8426. int32 slots = 0;
  8427. assert(item);
  8428. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8429. return;
  8430. }
  8431. slot_data = &item->slot_data;
  8432. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8433. if (version >= 1188)
  8434. slots = *itr;
  8435. else
  8436. slots += (int8)pow(2.0, *itr);
  8437. }
  8438. packet->setDataByName("slot", slots);
  8439. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8440. if (slots == 2) {
  8441. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8442. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8443. }
  8444. else {
  8445. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8446. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8447. }
  8448. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8449. if (slots == 4) {
  8450. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8451. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8452. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8453. }
  8454. else if (slots == 7) {
  8455. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8456. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8457. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8458. }
  8459. else {
  8460. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8461. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8462. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8463. }
  8464. packet->setDataByName("icon", item->details.icon);
  8465. packet->setDataByName("item_id", item->details.item_id);
  8466. packet->setDataByName("item_crc", crc);
  8467. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8468. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8469. packet->setDataByName("unknown5", 0xFF, 9);
  8470. packet->setDataByName("unknown5", 0xFF, 10);
  8471. QueuePacket(packet->serialize());
  8472. safe_delete(packet);
  8473. }
  8474. void Client::SendCollectionList() {
  8475. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8476. map<int32, Collection*>::iterator itr;
  8477. vector<struct CollectionItem*>* collection_items;
  8478. Collection* collection;
  8479. struct CollectionItem* collection_item;
  8480. PacketStruct* packet = 0;
  8481. int16 i = 0, j;
  8482. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8483. return;
  8484. packet->setArrayLengthByName("num_collections", collections->size());
  8485. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8486. collection = itr->second;
  8487. collection_items = collection->GetCollectionItems();
  8488. packet->setArrayDataByName("unknown", 1, i);
  8489. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8490. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8491. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8492. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8493. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8494. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8495. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8496. for (j = 0; j < collection_items->size(); j++) {
  8497. collection_item = collection_items->at(j);
  8498. Item* item = master_item_list.GetItem(collection_item->item);
  8499. if (item) {
  8500. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8501. if (version < 955)
  8502. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8503. else
  8504. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8505. }
  8506. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8507. }
  8508. i++;
  8509. }
  8510. packet->setDataByName("new_collection_flag", 1);
  8511. QueuePacket(packet->serialize());
  8512. safe_delete(packet);
  8513. }
  8514. bool Client::SendCollectionsForItem(Item* item) {
  8515. map<int32, Collection*> collections_to_send;
  8516. map<int32, Collection*>* collections;
  8517. map<int32, Collection*>::iterator itr;
  8518. vector<struct CollectionItem*>* collection_items;
  8519. Collection* collection;
  8520. struct CollectionItem* collection_item;
  8521. PacketStruct* packet;
  8522. int16 i;
  8523. assert(item);
  8524. /* get any collections required by this item that the player already has */
  8525. collections = player->GetCollectionList()->GetCollections();
  8526. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8527. collection = itr->second;
  8528. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8529. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8530. collections_to_send[collection->GetID()] = collection;
  8531. }
  8532. }
  8533. /* get any collections required by this item that the player does not have and send it to the client */
  8534. collections = master_collection_list.GetCollections();
  8535. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8536. collection = itr->second;
  8537. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8538. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8539. return false;
  8540. }
  8541. packet->setArrayLengthByName("num_collections", 1);
  8542. packet->setArrayDataByName("unknown", 1, 0);
  8543. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8544. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8545. packet->setArrayDataByName("completed", 0, 0);
  8546. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8547. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8548. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8549. packet->setArrayDataByName("unknown3", 0x28, 0);
  8550. collection_items = collection->GetCollectionItems();
  8551. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8552. for (i = 0; i < collection_items->size(); i++) {
  8553. collection_item = collection_items->at(i);
  8554. Item* item2 = master_item_list.GetItem(collection_item->item);
  8555. if (item2) {
  8556. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8557. if (version < 955)
  8558. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8559. else
  8560. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8561. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8562. }
  8563. }
  8564. packet->setDataByName("new_collection_flag", 0);
  8565. QueuePacket(packet->serialize());
  8566. safe_delete(packet);
  8567. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8568. collections_to_send[collection->GetID()] = collection;
  8569. }
  8570. }
  8571. /* send the client a list of collections that should be filtered for this item */
  8572. if (collections_to_send.size() > 0) {
  8573. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8574. return false;
  8575. }
  8576. i = 0;
  8577. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8578. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8579. collection = itr->second;
  8580. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8581. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8582. i++;
  8583. }
  8584. packet->setDataByName("item_icon", item->details.icon);
  8585. packet->setDataByName("item_name", item->name.c_str());
  8586. packet->setDataByName("item_id", item->details.item_id);
  8587. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8588. QueuePacket(packet->serialize());
  8589. safe_delete(packet);
  8590. }
  8591. return collections_to_send.size() > 0;
  8592. }
  8593. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8594. Collection* collection;
  8595. struct CollectionItem* collection_item;
  8596. PacketStruct* packet;
  8597. char tmp[200] = { 0 };
  8598. assert(item);
  8599. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8600. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8601. /* get the item struct that represents the item for this collection */
  8602. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8603. SendCollectionList();
  8604. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8605. return;
  8606. }
  8607. /* sanity check */
  8608. if (collection_item->found) {
  8609. SendCollectionList();
  8610. 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());
  8611. return;
  8612. }
  8613. }
  8614. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8615. collection = new Collection(collection);
  8616. /* get the item struct that represents the item for this collection */
  8617. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8618. SendCollectionList();
  8619. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8620. safe_delete(collection);
  8621. return;
  8622. }
  8623. /* add the new collection to the player's collection list */
  8624. if (!player->GetCollectionList()->AddCollection(collection)) {
  8625. SendCollectionList();
  8626. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8627. safe_delete(collection);
  8628. return;
  8629. }
  8630. }
  8631. else {
  8632. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8633. return;
  8634. }
  8635. collection_item->found = 1;
  8636. collection->SetSaveNeeded(true);
  8637. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8638. SendCollectionList();
  8639. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8640. return;
  8641. }
  8642. packet->setDataByName("collection_id", collection_id);
  8643. packet->setDataByName("collection_item_num", collection_item->index);
  8644. packet->setDataByName("add", 1);
  8645. QueuePacket(packet->serialize());
  8646. Item* item2 = master_item_list.GetItem(collection_item->item);
  8647. if (item2) {
  8648. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8649. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8650. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8651. }
  8652. safe_delete(packet);
  8653. RemoveItem(item, 1);
  8654. SendCollectionList();
  8655. }
  8656. void Client::DisplayCollectionComplete(Collection* collection) {
  8657. vector<struct CollectionRewardItem*>* reward_items;
  8658. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8659. struct CollectionRewardItem* reward_item;
  8660. PacketStruct* packet;
  8661. int32 i;
  8662. assert(collection);
  8663. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8664. return;
  8665. }
  8666. reward_items = collection->GetRewardItems();
  8667. selectable_reward_items = collection->GetSelectableRewardItems();
  8668. packet->setDataByName("title", "Quest Reward!");
  8669. packet->setDataByName("name", collection->GetName());
  8670. packet->setDataByName("description", collection->GetCategory());
  8671. packet->setDataByName("level", collection->GetLevel());
  8672. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8673. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8674. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8675. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8676. for (i = 0; i < reward_items->size(); i++) {
  8677. reward_item = reward_items->at(i);
  8678. if(!reward_item->item)
  8679. {
  8680. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8681. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8682. continue;
  8683. }
  8684. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8685. if (version < 860)
  8686. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8687. else if (version < 1193)
  8688. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8689. else
  8690. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8691. }
  8692. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8693. for (i = 0; i < selectable_reward_items->size(); i++) {
  8694. reward_item = selectable_reward_items->at(i);
  8695. if(!reward_item->item)
  8696. {
  8697. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8698. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8699. continue;
  8700. }
  8701. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8702. if (version < 860)
  8703. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8704. else if (version < 1193)
  8705. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8706. else
  8707. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8708. }
  8709. QueuePacket(packet->serialize());
  8710. safe_delete(packet);
  8711. }
  8712. void Client::HandInCollections() {
  8713. map<int32, Collection*>* collections;
  8714. map<int32, Collection*>::iterator itr;
  8715. Collection* collection;
  8716. /* only show 1 collection reward dialog at a time */
  8717. if (player->GetPendingCollectionReward()) {
  8718. return;
  8719. }
  8720. collections = player->GetCollectionList()->GetCollections();
  8721. /* 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
  8722. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8723. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8724. collection = itr->second;
  8725. if (collection->GetIsReadyToTurnIn()) {
  8726. player->SetPendingCollectionReward(collection);
  8727. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  8728. QuestRewardData* data = new QuestRewardData;
  8729. data->quest_id = 0;
  8730. data->is_temporary = false;
  8731. data->description = std::string("");
  8732. data->is_collection = true;
  8733. data->has_displayed = false;
  8734. data->tmp_coin = 0;
  8735. data->tmp_status = 0;
  8736. data->db_saved = false;
  8737. data->db_index = 0;
  8738. quest_pending_reward.push_back(data);
  8739. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  8740. quest_updates = true;
  8741. break;
  8742. }
  8743. }
  8744. if(quest_updates) {
  8745. SaveQuestRewardData(true);
  8746. }
  8747. }
  8748. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8749. vector<struct CollectionRewardItem*>* reward_items;
  8750. vector<struct CollectionRewardItem*>::iterator itr;
  8751. struct CollectionRewardItem* reward_item;
  8752. int16 num_slots_needed;
  8753. int16 num_slots;
  8754. assert(collection);
  8755. reward_items = collection->GetRewardItems();
  8756. num_slots_needed = (int16)reward_items->size();
  8757. if (selectable_item_id > 0)
  8758. num_slots_needed++;
  8759. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8760. if (num_slots < num_slots_needed) {
  8761. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8762. DisplayCollectionComplete(collection);
  8763. return;
  8764. }
  8765. /* add manditory items */
  8766. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8767. reward_item = *itr;
  8768. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8769. }
  8770. /* find and add the selectable item if there's one */
  8771. if (selectable_item_id > 0) {
  8772. reward_items = collection->GetSelectableRewardItems();
  8773. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8774. reward_item = *itr;
  8775. if (reward_item->item->details.item_id == selectable_item_id) {
  8776. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8777. break;
  8778. }
  8779. }
  8780. }
  8781. if (collection->GetRewardXP() > 0) {
  8782. player->AddXP((int32)collection->GetRewardXP());
  8783. }
  8784. if (collection->GetRewardCoin() > 0) {
  8785. player->AddCoins(collection->GetRewardCoin());
  8786. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8787. }
  8788. collection->SetCompleted(true);
  8789. //update achievements for completeing collection here
  8790. collection->SetSaveNeeded(true);
  8791. SendCollectionList();
  8792. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8793. player->SetPendingCollectionReward(0);
  8794. RemoveQueuedQuestReward();
  8795. GetPlayer()->SetActiveReward(false);
  8796. HandInCollections();
  8797. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  8798. }
  8799. void Client::SendRecipeList() {
  8800. PacketStruct* packet = 0;
  8801. if (GetRecipeListSent()) {
  8802. return;
  8803. }
  8804. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8805. return;
  8806. }
  8807. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8808. map<int32, Recipe*>::iterator itr;
  8809. Recipe* recipe;
  8810. int16 i = 0;
  8811. int index = 0;
  8812. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8813. recipe = itr->second;
  8814. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  8815. if (res != devices.end())
  8816. index = res - devices.begin();
  8817. else
  8818. devices.push_back(recipe->GetDevice());
  8819. }
  8820. packet->setArrayLengthByName("num_recipes", recipes->size());
  8821. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8822. recipe = itr->second;
  8823. packet->setArrayDataByName("id", recipe->GetID(), i);
  8824. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8825. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8826. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8827. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8828. //packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8829. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8830. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8831. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  8832. if (recipe_device != devices.end())
  8833. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  8834. else
  8835. {//TODO error should never get here
  8836. }
  8837. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  8838. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8839. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8840. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8841. i++;
  8842. }
  8843. //packet->PrintPacket();
  8844. //DumpPacket(packet->serialize());
  8845. QueuePacket(packet->serialize());
  8846. safe_delete(packet);
  8847. SetRecipeListSent(true);
  8848. }
  8849. void Client::ShowRecipeBook() {
  8850. PacketStruct* packet = 0;
  8851. Spawn* target = 0;
  8852. int index = 0;
  8853. if (!(target = player->GetTarget())) {
  8854. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8855. return;
  8856. }
  8857. if (!target->IsObject()) {
  8858. return;
  8859. }
  8860. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8861. return;
  8862. }
  8863. packet->setDataByName("device", target->GetName());
  8864. packet->setDataByName("unknown1", 1);
  8865. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  8866. if (res != devices.end()){
  8867. index = res - devices.begin();
  8868. int32 deviceID = 0;
  8869. deviceID |= 1UL << index;
  8870. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8871. packet->setDataByName("unknown2", devices.size());
  8872. packet->setDataByName("unknown3", deviceID);
  8873. }
  8874. else
  8875. packet->setDataByName("unknown2", devices.size());
  8876. QueuePacket(packet->serialize());
  8877. safe_delete(packet);
  8878. }
  8879. void Client::SendTitleUpdate() {
  8880. // must call release read lock before leaving function on GetPlayerTitles
  8881. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8882. vector<Title*>::iterator itr;
  8883. Title* title;
  8884. sint32 i = 0;
  8885. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8886. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8887. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8888. if (packet) {
  8889. packet->setArrayLengthByName("num_titles", titles->size());
  8890. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8891. title = *itr;
  8892. packet->setArrayDataByName("title", title->GetName(), i);
  8893. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8894. i++;
  8895. }
  8896. packet->setDataByName("current_prefix", prefix_index);
  8897. packet->setDataByName("current_suffix", suffix_index);
  8898. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8899. #if EQDEBUG >= 9
  8900. packet->PrintPacket();
  8901. #endif
  8902. QueuePacket(packet->serialize());
  8903. safe_delete(packet);
  8904. SendUpdateTitles(prefix_index, suffix_index);
  8905. }
  8906. player->GetPlayerTitles()->ReleaseReadLock();
  8907. }
  8908. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8909. Title* suffix_title = 0;
  8910. Title* prefix_title = 0;
  8911. if (suffix != -1) {
  8912. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8913. if(suffix_title)
  8914. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8915. }
  8916. else
  8917. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8918. if (prefix != -1) {
  8919. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8920. if(prefix_title)
  8921. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8922. }
  8923. else
  8924. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8925. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8926. }
  8927. void Client::SendLanguagesUpdate(int32 id) {
  8928. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8929. list<Language*>::iterator itr;
  8930. Language* language;
  8931. int32 i = 0;
  8932. GetPlayer()->SetCurrentLanguage(id);
  8933. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8934. if (packet) {
  8935. packet->setArrayLengthByName("num_languages", languages->size());
  8936. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8937. language = *itr;
  8938. packet->setArrayDataByName("language_id", language->GetID(), i);
  8939. i++;
  8940. }
  8941. packet->setDataByName("current_language", id);
  8942. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8943. #if EQDEBUG >= 9
  8944. packet->PrintPacket();
  8945. #endif
  8946. QueuePacket(packet->serialize());
  8947. safe_delete(packet);
  8948. }
  8949. }
  8950. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8951. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8952. if (packet) {
  8953. if (pet_name)
  8954. packet->setDataByName("pet_name", pet_name);
  8955. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  8956. packet->setDataByName("protect_master", 1);
  8957. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  8958. packet->setDataByName("protect_self", 1);
  8959. if (player->GetInfoStruct()->get_pet_movement() == 2)
  8960. packet->setDataByName("stay_follow_toggle", 1);
  8961. packet->setDataByName("pet_type", type);
  8962. QueuePacket(packet->serialize());
  8963. }
  8964. safe_delete(packet);
  8965. }
  8966. bool Client::IsCrafting() {
  8967. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8968. }
  8969. void Client::SendBiography() {
  8970. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8971. if (packet) {
  8972. char biography[512];
  8973. if(player->GetInfoStruct()->get_biography().size() < 1)
  8974. {
  8975. safe_delete(packet);
  8976. return;
  8977. }
  8978. else
  8979. {
  8980. int16 size = player->GetInfoStruct()->get_biography().size();
  8981. if(size>511)
  8982. size = 511;
  8983. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  8984. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  8985. }
  8986. packet->setDataByName("biography", biography);
  8987. QueuePacket(packet->serialize());
  8988. }
  8989. safe_delete(packet);
  8990. }
  8991. PendingResurrection* Client::GetCurrentRez() {
  8992. return &current_rez;
  8993. }
  8994. Mutex* Client::GetResurrectMutex() {
  8995. return &m_resurrect;
  8996. }
  8997. void Client::SendResurrectionWindow() {
  8998. Spawn* caster = current_rez.caster;
  8999. if (!caster || !player)
  9000. return;
  9001. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9002. if (!packet)
  9003. return;
  9004. char* tmp = new char[512];
  9005. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  9006. packet->setMediumStringByName("text", tmp);
  9007. packet->setMediumStringByName("accept_text", "Yes");
  9008. packet->setMediumStringByName("cancel_text", "No");
  9009. sprintf(tmp, "accept_resurrection %u", player->GetID());
  9010. packet->setMediumStringByName("accept_command", tmp);
  9011. sprintf(tmp, "decline_resurrection %u", player->GetID());
  9012. packet->setMediumStringByName("cancel_command", tmp);
  9013. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  9014. QueuePacket(packet->serialize());
  9015. safe_delete(packet);
  9016. safe_delete_array(tmp);
  9017. }
  9018. void Client::AcceptResurrection() {
  9019. Spawn* caster = current_rez.caster;
  9020. if (!player || !caster)
  9021. return;
  9022. if (player->Alive())
  9023. return;
  9024. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9025. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9026. SendResurrectionWindow();
  9027. return;
  9028. }
  9029. player->GetZone()->ResurrectSpawn(player, this);
  9030. current_rez.should_delete = true;
  9031. }
  9032. void Client::SetPendingLastName(string last_name) {
  9033. pending_last_name = new string;
  9034. pending_last_name->assign(last_name);
  9035. }
  9036. string* Client::GetPendingLastName() {
  9037. return pending_last_name;
  9038. }
  9039. void Client::RemovePendingLastName() {
  9040. safe_delete(pending_last_name);
  9041. }
  9042. void Client::SendLastNameConfirmation() {
  9043. if (!pending_last_name)
  9044. return;
  9045. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9046. if (packet) {
  9047. char* text = new char[128];
  9048. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9049. packet->setDataByName("text", text);
  9050. packet->setDataByName("accept_text", "Yes");
  9051. packet->setDataByName("accept_command", "confirmedlastname");
  9052. packet->setDataByName("cancel_text", "No");
  9053. packet->setDataByName("max_length", 50);
  9054. packet->setDataByName("unknown4", 1);
  9055. packet->setDataByName("unknown5", 1);
  9056. QueuePacket(packet->serialize());
  9057. safe_delete(packet);
  9058. safe_delete_array(text);
  9059. }
  9060. }
  9061. void Client::AddQuestTimer(int32 quest_id) {
  9062. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9063. quest_timers.push_back(quest_id);
  9064. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9065. }
  9066. void Client::RemoveQuestTimer(int32 quest_id) {
  9067. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9068. vector<int32>::iterator itr;
  9069. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9070. if ((*itr) == quest_id) {
  9071. quest_timers.erase(itr);
  9072. break;
  9073. }
  9074. }
  9075. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9076. }
  9077. void Client::SavePlayerImages() {
  9078. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9079. // Save the paperdoll image if the server allows it
  9080. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9081. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9082. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9083. // Save the head shot if the server allows it
  9084. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9085. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9086. // Send the head shot to the login server
  9087. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9088. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9089. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9090. memset(packet->pBuffer, 0, size);
  9091. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9092. pic->account_id = GetAccountID();
  9093. pic->char_id = GetCharacterID();
  9094. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9095. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9096. loginserver.SendPacket(packet);
  9097. safe_delete(packet);
  9098. }
  9099. }
  9100. safe_delete_array(incoming_paperdoll.image_bytes);
  9101. incoming_paperdoll.current_size_bytes = 0;
  9102. }
  9103. void Client::EndAutoMount() {
  9104. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9105. if (packet) {
  9106. packet->setDataByName("parameter1", 128);
  9107. packet->setDataByName("parameter2", 64);
  9108. packet->setDataByName("value", 1);
  9109. QueuePacket(packet->serialize());
  9110. safe_delete(packet);
  9111. }
  9112. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9113. if (packet) {
  9114. packet->setDataByName("parameter3", 4);
  9115. packet->setDataByName("parameter5", 2);
  9116. packet->setDataByName("value", 0);
  9117. QueuePacket(packet->serialize());
  9118. safe_delete(packet);
  9119. }
  9120. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9121. if (packet) {
  9122. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  9123. QueuePacket(packet->serialize());
  9124. safe_delete(packet);
  9125. }
  9126. on_auto_mount = false;
  9127. player->SetMount(((Player*)player)->GetTempMount());
  9128. EQ2_Color mount_color = player->GetTempMountColor();
  9129. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  9130. player->SetMountColor(&mount_color);
  9131. player->SetMountSaddleColor(&saddle_color);
  9132. player->SetTempMount(0);
  9133. }
  9134. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  9135. const char* spawn_script = spawn->GetSpawnScript();
  9136. bool should_use_spawn = true;
  9137. if (spawn_script) {
  9138. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  9139. if (state) {
  9140. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  9141. if (state_mutex)
  9142. state_mutex->writelock(__FUNCTION__, __LINE__);
  9143. lua_getglobal(state, "can_use_command");
  9144. if (lua_isfunction(state, -1)) {
  9145. lua_interface->SetSpawnValue(state, spawn);
  9146. lua_interface->SetSpawnValue(state, GetPlayer());
  9147. lua_interface->SetStringValue(state, command ? command : "");
  9148. if (lua_pcall(state, 3, 1, 0) == 0) {
  9149. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  9150. }
  9151. }
  9152. lua_interface->ResetFunctionStack(state);
  9153. if (state_mutex)
  9154. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  9155. }
  9156. }
  9157. return should_use_spawn;
  9158. }
  9159. bool Client::IsCurrentTransmuteID(int32 req_id) {
  9160. return req_id == transmuteID;
  9161. }
  9162. void Client::SetTransmuteID(int32 trans_id) {
  9163. transmuteID = trans_id;
  9164. }
  9165. int32 Client::GetTransmuteID() {
  9166. return transmuteID;
  9167. }
  9168. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  9169. {
  9170. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  9171. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  9172. if (zar)
  9173. {
  9174. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  9175. if (database.IsActiveQuery(charID))
  9176. {
  9177. delayedLogin = true;
  9178. delayedAccountID = account_id;
  9179. delayedAccessKey = access_code;
  9180. delayTimer.Start(500);
  9181. 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);
  9182. return true;
  9183. }
  9184. delayedLogin = false;
  9185. delayTimer.Disable();
  9186. firstlogin = zar->isFirstLogin();
  9187. 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);
  9188. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  9189. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  9190. GetPlayer()->vis_changed = false;
  9191. GetPlayer()->info_changed = false;
  9192. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9193. if (pvp_allowed)
  9194. this->GetPlayer()->SetAttackable(1);
  9195. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  9196. Client* client = zone_list.GetClientByCharName(player->GetName());
  9197. if (client) {
  9198. if (client->getConnection())
  9199. client->getConnection()->SendDisconnect(true);
  9200. if (client->GetCurrentZone() && !client->IsZoning()) {
  9201. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  9202. if (client->GetVersion() == version) {
  9203. client->DisableSave();
  9204. client->ReplaceGroupClient(this);
  9205. Player* current_player = GetPlayer();
  9206. SetPlayer(client->GetPlayer());
  9207. GetPlayer()->SetClient(this);
  9208. GetPlayer()->SetReturningFromLD(true);
  9209. SetCurrentZone(GetPlayer()->GetZone());
  9210. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  9211. client->SetPlayer(current_player);
  9212. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  9213. GetPlayer()->ResetSavedSpawns();
  9214. }
  9215. ZoneServer* tmpZone = client->GetCurrentZone();
  9216. tmpZone->RemoveClientImmediately(client);
  9217. }
  9218. }
  9219. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  9220. if (!GetCurrentZone()) {
  9221. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  9222. ClientPacketFunctions::SendLoginDenied(this);
  9223. }
  9224. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  9225. getConnection()->SetClientVersion(version);
  9226. GetCurrentZone()->SetSpawnStructs(this);
  9227. connected_to_zone = true;
  9228. client_list.Remove(this); //remove from master client list
  9229. GetCurrentZone()->AddClient(this); //add to zones client list
  9230. zone_list.AddClientToMap(player->GetName(), this);
  9231. // 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.
  9232. new_client_login = true;
  9233. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  9234. if (zone_script && lua_interface)
  9235. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  9236. }
  9237. else {
  9238. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  9239. ClientPacketFunctions::SendLoginDenied(this);
  9240. return false;
  9241. }
  9242. }
  9243. else {
  9244. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  9245. ClientPacketFunctions::SendLoginDenied(this);
  9246. }
  9247. zone_auth.RemoveAuth(zar);
  9248. }
  9249. else
  9250. {
  9251. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  9252. Disconnect();
  9253. }
  9254. return true;
  9255. }
  9256. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  9257. if (!IsReadyForUpdates())
  9258. return;
  9259. map<int32, SpawnData> info_changes;
  9260. map<int32, SpawnData> pos_changes;
  9261. map<int32, SpawnData> vis_changes;
  9262. map<int32, SpawnData> empty_changes;
  9263. int32 info_size = 0;
  9264. int32 pos_size = 0;
  9265. int32 vis_size = 0;
  9266. int count = 0;
  9267. for (const auto& spawn : spawns) {
  9268. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  9269. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  9270. continue;
  9271. if (spawn->vis_changed)
  9272. {
  9273. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9274. if (vis_change) {
  9275. SpawnData data;
  9276. data.spawn = spawn;
  9277. data.data = vis_change;
  9278. data.size = spawn->vis_packet_size;
  9279. map<int32, SpawnData> tmp_vis_changes;
  9280. tmp_vis_changes[index] = data;
  9281. map<int32, SpawnData> tmp_info_changes;
  9282. map<int32, SpawnData> tmp_pos_changes;
  9283. int32 tmp_info_size = 0;
  9284. int32 tmp_pos_size = 0;
  9285. if (spawn->info_changed) {
  9286. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9287. if (info_change) {
  9288. SpawnData data;
  9289. data.spawn = spawn;
  9290. data.data = info_change;
  9291. data.size = spawn->info_packet_size;
  9292. tmp_info_size = data.size;
  9293. tmp_info_changes[index] = data;
  9294. }
  9295. }
  9296. if (spawn->position_changed) {
  9297. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9298. if (pos_change) {
  9299. SpawnData data;
  9300. data.spawn = spawn;
  9301. data.data = pos_change;
  9302. data.size = spawn->pos_packet_size;
  9303. tmp_pos_size = data.size;
  9304. tmp_pos_changes[index] = data;
  9305. }
  9306. }
  9307. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  9308. for (auto& kv : tmp_info_changes) {
  9309. safe_delete_array(kv.second.data);
  9310. }
  9311. for (auto& kv : tmp_pos_changes) {
  9312. safe_delete_array(kv.second.data);
  9313. }
  9314. for (auto& kv : tmp_vis_changes) {
  9315. safe_delete_array(kv.second.data);
  9316. }
  9317. continue;
  9318. }
  9319. }
  9320. if (spawn->info_changed) {
  9321. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9322. if (info_change) {
  9323. SpawnData data;
  9324. data.spawn = spawn;
  9325. data.data = info_change;
  9326. data.size = spawn->info_packet_size;
  9327. info_size += spawn->info_packet_size;
  9328. info_changes[index] = data;
  9329. }
  9330. count++;
  9331. }
  9332. if (spawn->position_changed) {
  9333. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9334. if (pos_change) {
  9335. SpawnData data;
  9336. data.spawn = spawn;
  9337. data.data = pos_change;
  9338. data.size = spawn->pos_packet_size;
  9339. pos_size += spawn->pos_packet_size;
  9340. pos_changes[index] = data;
  9341. }
  9342. count++;
  9343. }
  9344. if (spawn->vis_changed) {
  9345. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9346. if (vis_change) {
  9347. SpawnData data;
  9348. data.spawn = spawn;
  9349. data.data = vis_change;
  9350. data.size = spawn->vis_packet_size;
  9351. vis_size += spawn->vis_packet_size;
  9352. vis_changes[index] = data;
  9353. }
  9354. count++;
  9355. }
  9356. }
  9357. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9358. return;
  9359. }
  9360. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9361. for (auto& kv : info_changes) {
  9362. safe_delete_array(kv.second.data);
  9363. }
  9364. for (auto& kv : pos_changes) {
  9365. safe_delete_array(kv.second.data);
  9366. }
  9367. for (auto& kv : vis_changes) {
  9368. safe_delete_array(kv.second.data);
  9369. }
  9370. }
  9371. 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)
  9372. {
  9373. static const int8 oversized = 255;
  9374. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9375. int32 size = info_size + pos_size + vis_size + 8;
  9376. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9377. size += 3;
  9378. size += CheckOverLoadSize(info_size);
  9379. size += CheckOverLoadSize(pos_size);
  9380. size += CheckOverLoadSize(vis_size);
  9381. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9382. size += 2;
  9383. }
  9384. uchar* tmp = new uchar[size];
  9385. uchar* ptr = tmp;
  9386. memset(tmp, 0, size);
  9387. if (version <= 283) {
  9388. if (size >= 255) {
  9389. size -= 3;
  9390. memcpy(ptr, &oversized, sizeof(int8));
  9391. ptr += sizeof(int8);
  9392. memcpy(ptr, &size, sizeof(int16));
  9393. ptr += sizeof(int16);
  9394. size += 3;
  9395. }
  9396. else {
  9397. size -= 1;
  9398. memcpy(ptr, &size, sizeof(int8));
  9399. ptr += sizeof(int8);
  9400. size += 1;
  9401. }
  9402. }
  9403. else {
  9404. size -= 4;
  9405. memcpy(ptr, &size, sizeof(int32));
  9406. ptr += sizeof(int32);
  9407. size += 4;
  9408. }
  9409. memcpy(ptr, &oversized, sizeof(int8));
  9410. ptr += sizeof(int8);
  9411. memcpy(ptr, &opcode_val, sizeof(int16));
  9412. ptr += sizeof(int16);
  9413. int32 current_time = Timer::GetCurrentTime2();
  9414. memcpy(ptr, &current_time, sizeof(int32));
  9415. ptr += sizeof(int32);
  9416. ptr += DoOverLoad(info_size, ptr);
  9417. for (const auto& kv : info_changes) {
  9418. auto info = kv.second;
  9419. memcpy(ptr, info.data, info.size);
  9420. ptr += info.size;
  9421. }
  9422. ptr += DoOverLoad(pos_size, ptr);
  9423. for (const auto& kv : pos_changes) {
  9424. auto pos = kv.second;
  9425. memcpy(ptr, pos.data, pos.size);
  9426. ptr += pos.size;
  9427. }
  9428. ptr += DoOverLoad(vis_size, ptr);
  9429. for (const auto& kv : vis_changes) {
  9430. auto vis = kv.second;
  9431. memcpy(ptr, vis.data, vis.size);
  9432. ptr += vis.size;
  9433. }
  9434. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9435. if (packet) {
  9436. /*char blah[64];
  9437. snprintf(blah, 64, "Sending %i", current_time);
  9438. SimpleMessage(4, blah);*/
  9439. QueuePacket(packet);
  9440. }
  9441. delete[] tmp;
  9442. }
  9443. void Client::SendHailCommand(Spawn* spawn)
  9444. {
  9445. // hardcoded 'hail' entity commands
  9446. switch (spawn->secondary_command_list_id)
  9447. {
  9448. case 9:
  9449. case 1262:
  9450. case 1265:
  9451. case 1267:
  9452. {
  9453. EQ2_16BitString* command = new EQ2_16BitString();
  9454. command->data = "";
  9455. command->size = 0;
  9456. commands.Process(COMMAND_HAIL, command, this, spawn);
  9457. safe_delete(command);
  9458. break;
  9459. }
  9460. }
  9461. }
  9462. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9463. {
  9464. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9465. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9466. if (packet) {
  9467. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9468. packet->setMediumStringByName("command_name", command);
  9469. packet->setDataByName("distance", distance);
  9470. QueuePacket(packet->serialize());
  9471. safe_delete(packet);
  9472. }
  9473. }
  9474. }
  9475. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9476. {
  9477. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9478. return false;
  9479. if (command == "house_spawn_examine")
  9480. {
  9481. uint32 itemID = spawn->GetPickupItemID();
  9482. if (itemID)
  9483. {
  9484. Item* item = master_item_list.GetItem(itemID);
  9485. if (item)
  9486. {
  9487. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9488. //DumpPacket(app);
  9489. QueuePacket(app);
  9490. }
  9491. }
  9492. return true;
  9493. }
  9494. return false;
  9495. }
  9496. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9497. {
  9498. if (GetTempPlacementSpawn())
  9499. {
  9500. Spawn* tmp = GetTempPlacementSpawn();
  9501. int32 spawn_group_id = database.GetNextSpawnLocation();
  9502. tmp->SetSpawnLocationID(spawn_group_id);
  9503. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9504. int32 spawnDBID = 0;
  9505. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9506. {
  9507. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9508. tmp->SetDatabaseID(spawnDBID);
  9509. }
  9510. else
  9511. {
  9512. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9513. if (spawnDBID)
  9514. {
  9515. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9516. tmp->SetDatabaseID(spawnDBID);
  9517. }
  9518. }
  9519. tmp->SetX(place_object->getType_float_ByName("x"));
  9520. tmp->SetY(place_object->getType_float_ByName("y"));
  9521. tmp->SetZ(place_object->getType_float_ByName("z"));
  9522. tmp->SetHeading(newHeading);
  9523. tmp->SetSpawnOrigX(tmp->GetX());
  9524. tmp->SetSpawnOrigY(tmp->GetY());
  9525. tmp->SetSpawnOrigZ(tmp->GetZ());
  9526. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9527. database.SaveSpawnInfo(tmp);
  9528. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9529. if (!spawnDBID)
  9530. {
  9531. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9532. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  9533. }
  9534. return true;
  9535. }
  9536. return false;
  9537. }
  9538. bool Client::PopulateHouseSpawnFinalize()
  9539. {
  9540. if (GetTempPlacementSpawn())
  9541. {
  9542. Spawn* tmp = GetTempPlacementSpawn();
  9543. GetCurrentZone()->AddSpawn(tmp);
  9544. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9545. SetTempPlacementSpawn(nullptr);
  9546. int32 uniqueID = GetPlacementUniqueItemID();
  9547. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9548. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9549. tmp->SetPickupUniqueItemID(uniqueID);
  9550. if (uniqueItem)
  9551. {
  9552. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9553. {
  9554. Query query;
  9555. 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);
  9556. }
  9557. if(uniqueItem->GetItemScript() &&
  9558. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  9559. {
  9560. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9561. }
  9562. if(uniqueItem) {
  9563. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9564. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9565. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9566. }
  9567. SetPlacementUniqueItemID(0);
  9568. }
  9569. return true;
  9570. }
  9571. return false;
  9572. }
  9573. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9574. {
  9575. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9576. packet->setDataByName("placement_mode", placementMode);
  9577. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9578. packet->setDataByName("model_type", spawn->GetModelType());
  9579. packet->setDataByName("unknown", 1); //size
  9580. packet->setDataByName("unknown2", 1); //size 2
  9581. packet->setDataByName("unknown2", .5, 1); //size 3
  9582. packet->setDataByName("unknown2", 3, 2);
  9583. packet->setDataByName("unknown2", unknown2_3, 3);
  9584. packet->setDataByName("max_distance", 500);
  9585. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9586. QueuePacket(packet->serialize());
  9587. safe_delete(packet);
  9588. }
  9589. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9590. {
  9591. SetPendingFlightPath(path_id);
  9592. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9593. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9594. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9595. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9596. if (packet) {
  9597. QueuePacket(packet->serialize());
  9598. safe_delete(packet);
  9599. }
  9600. if (mount_id)
  9601. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9602. }
  9603. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  9604. {
  9605. if (!sender)
  9606. {
  9607. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9608. return;
  9609. }
  9610. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9611. if (!packet) {
  9612. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9613. return;
  9614. }
  9615. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9616. packet->setDataByName("book_title", title.c_str());
  9617. packet->setDataByName("book_type", "simple");
  9618. packet->setDataByName("unknown2", 1);
  9619. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9620. packet->setDataByName("language", language);
  9621. if (GetVersion() > 546)
  9622. packet->setDataByName("unknown5", 1, 4);
  9623. packet->setArrayLengthByName("num_pages", num_pages);
  9624. va_list args;
  9625. va_start(args, num_pages);
  9626. std::string endString("");
  9627. for (int8 p = 0; p < num_pages; p++)
  9628. {
  9629. std::string page = va_arg(args, string);
  9630. switch (GetVersion())
  9631. {
  9632. // release client
  9633. case 283:
  9634. {
  9635. endString.append(page);
  9636. break;
  9637. }
  9638. // DoF trial
  9639. case 546:
  9640. {
  9641. if (p == 0)
  9642. packet->setDataByName("cover_page", page.c_str());
  9643. else
  9644. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9645. break;
  9646. }
  9647. // all other clients
  9648. default:
  9649. {
  9650. packet->setArrayDataByName("page_text", page.c_str(), p);
  9651. break;
  9652. }
  9653. }
  9654. }
  9655. if (GetVersion() == 283)
  9656. {
  9657. packet->setDataByName("page_text", endString.c_str());
  9658. }
  9659. va_end(args);
  9660. QueuePacket(packet->serialize());
  9661. safe_delete(packet);
  9662. }
  9663. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  9664. {
  9665. if (!sender)
  9666. {
  9667. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9668. return;
  9669. }
  9670. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9671. if (!packet) {
  9672. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9673. return;
  9674. }
  9675. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9676. packet->setDataByName("book_title", title.c_str());
  9677. packet->setDataByName("book_type", "simple");
  9678. packet->setDataByName("unknown2", 1);
  9679. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9680. packet->setDataByName("language", language);
  9681. if (GetVersion() > 546)
  9682. packet->setDataByName("unknown5", 1, 4);
  9683. packet->setArrayLengthByName("num_pages", pages.size());
  9684. std::string endString("");
  9685. for (int8 p = 0; p < pages.size(); p++)
  9686. {
  9687. Item::BookPage* page = pages[p];
  9688. std::string pageText = string(page->page_text.data);
  9689. switch (GetVersion())
  9690. {
  9691. // release client
  9692. case 283:
  9693. {
  9694. endString.append(pageText);
  9695. break;
  9696. }
  9697. // DoF trial
  9698. case 546:
  9699. {
  9700. if (p == 0)
  9701. packet->setDataByName("cover_page", pageText.c_str());
  9702. else
  9703. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9704. break;
  9705. }
  9706. // all other clients
  9707. default:
  9708. {
  9709. int8 valign = int8(page->valign);
  9710. int8 halign = int8(page->halign);
  9711. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9712. packet->setArrayDataByName("page_text_valign", valign, p);
  9713. packet->setArrayDataByName("page_text_halign", halign, p);
  9714. break;
  9715. }
  9716. }
  9717. }
  9718. if (GetVersion() == 283)
  9719. {
  9720. packet->setDataByName("page_text", endString.c_str());
  9721. }
  9722. QueuePacket(packet->serialize());
  9723. safe_delete(packet);
  9724. }
  9725. void Client::ReplaceGroupClient(Client* new_client)
  9726. {
  9727. if (this->GetPlayer()->GetGroupMemberInfo())
  9728. {
  9729. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9730. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9731. if(group)
  9732. {
  9733. group->MGroupMembers.writelock();
  9734. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9735. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9736. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9737. group->MGroupMembers.releasewritelock();
  9738. }
  9739. else
  9740. {
  9741. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9742. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9743. this->GetPlayer()->SetGroupMemberInfo(0);
  9744. }
  9745. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9746. }
  9747. }
  9748. void Client::TempRemoveGroup()
  9749. {
  9750. if (this->GetPlayer()->GetGroupMemberInfo())
  9751. {
  9752. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9753. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9754. if(group)
  9755. {
  9756. group->MGroupMembers.writelock();
  9757. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9758. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9759. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9760. this->GetPlayer()->SetGroupMemberInfo(0);
  9761. group->MGroupMembers.releasewritelock();
  9762. group->RemoveClientReference(this);
  9763. }
  9764. else
  9765. {
  9766. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9767. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9768. this->GetPlayer()->SetGroupMemberInfo(0);
  9769. }
  9770. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9771. }
  9772. }
  9773. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9774. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9775. {
  9776. Mail mail;
  9777. mail.mail_id = 0;
  9778. mail.already_read = 0;
  9779. mail.postage_cost = 0;
  9780. mail.attachment_cost = 0;
  9781. mail.save_needed = 1;
  9782. //uhh...mail has std::strings so
  9783. //memset(&mail,0,sizeof(Mail));
  9784. mail.player_to_id = charID;
  9785. mail.player_from = fromName;
  9786. mail.subject = subjectName;
  9787. mail.mail_body = mailBody;
  9788. mail.mail_type = mailType;
  9789. mail.coin_copper = copper;
  9790. mail.coin_silver = silver;
  9791. mail.coin_gold = gold;
  9792. mail.coin_plat = platinum;
  9793. mail.char_item_id = item_id;
  9794. mail.stack = stack_size;
  9795. mail.time_sent = time_sent;
  9796. mail.expire_time = expire_time;
  9797. database.SavePlayerMail(&mail);
  9798. }
  9799. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9800. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9801. {
  9802. Mail* mail = new Mail();
  9803. mail->player_to_id = GetCharacterID();
  9804. mail->player_from = fromName;
  9805. mail->subject = subjectName;
  9806. mail->mail_body = mailBody;
  9807. mail->mail_type = mailType;
  9808. mail->coin_copper = copper;
  9809. mail->coin_silver = silver;
  9810. mail->coin_gold = gold;
  9811. mail->coin_plat = platinum;
  9812. mail->char_item_id = item_id;
  9813. mail->stack = stack_size;
  9814. mail->time_sent = time_sent;
  9815. mail->expire_time = expire_time;
  9816. mail->postage_cost = 0;
  9817. mail->save_needed = 1;
  9818. mail->already_read = 0;
  9819. database.SavePlayerMail(mail);
  9820. GetPlayer()->AddMail(mail);
  9821. }
  9822. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9823. {
  9824. if(slot < NUM_SLOTS)
  9825. {
  9826. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9827. if (app)
  9828. QueuePacket(app);
  9829. }
  9830. else
  9831. {
  9832. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9833. if (outapp)
  9834. QueuePacket(outapp);
  9835. }
  9836. }
  9837. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9838. {
  9839. if(spawn_player_id < 1)
  9840. return;
  9841. MQueueStateCmds.writelock();
  9842. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9843. MQueueStateCmds.releasewritelock();
  9844. }
  9845. void Client::ProcessStateCommands()
  9846. {
  9847. if(!IsReadyForUpdates())
  9848. return;
  9849. MQueueStateCmds.writelock();
  9850. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9851. for(; itr != queued_state_commands.end(); itr++)
  9852. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9853. queued_state_commands.clear();
  9854. MQueueStateCmds.releasewritelock();
  9855. }
  9856. void Client::PurgeItem(Item* item)
  9857. {
  9858. MConversation.writelock();
  9859. map<int32, Item*>::iterator itr;
  9860. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9861. {
  9862. if ( itr->second == item )
  9863. {
  9864. conversation_items.erase(itr);
  9865. break;
  9866. }
  9867. }
  9868. MConversation.releasewritelock();
  9869. }
  9870. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9871. {
  9872. if(GetPlayer()->StopSaveSpellEffects())
  9873. return;
  9874. if(item) {
  9875. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9876. if(item->GetItemScript() && lua_interface){
  9877. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9878. if (slot == 22)
  9879. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9880. else
  9881. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9882. }
  9883. if (item->details.count > 1) {
  9884. item->details.count -= 1;
  9885. item->save_needed = true;
  9886. }
  9887. else {
  9888. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9889. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9890. }
  9891. GetPlayer()->SetCharSheetChanged(true);
  9892. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9893. }
  9894. }
  9895. void Client::AwardCoins(int64 total_coins, std::string reason)
  9896. {
  9897. if (total_coins > 0) {
  9898. player->AddCoins(total_coins);
  9899. PlaySound("coin_cha_ching");
  9900. char tmp[64] = { 0 };
  9901. string message = "You receive ";
  9902. int32 val = 0;
  9903. if (total_coins >= 1000000) {
  9904. val = total_coins / 1000000;
  9905. total_coins -= 1000000 * val;
  9906. sprintf(tmp, "%u Platinum ", val);
  9907. message.append(tmp);
  9908. memset(tmp, 0, 64);
  9909. }
  9910. if (total_coins >= 10000) {
  9911. val = total_coins / 10000;
  9912. total_coins -= 10000 * val;
  9913. sprintf(tmp, "%u Gold ", val);
  9914. message.append(tmp);
  9915. memset(tmp, 0, 64);
  9916. }
  9917. if (total_coins >= 100) {
  9918. val = total_coins / 100;
  9919. total_coins -= 100 * val;
  9920. sprintf(tmp, "%u Silver ", val);
  9921. message.append(tmp);
  9922. memset(tmp, 0, 64);
  9923. }
  9924. if (total_coins > 0) {
  9925. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9926. message.append(tmp);
  9927. }
  9928. message.append(reason);
  9929. int8 type = CHANNEL_LOOT;
  9930. SimpleMessage(type, message.c_str());
  9931. }
  9932. }
  9933. void Client::TriggerSpellSave()
  9934. {
  9935. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  9936. // default to not have some bogus value in the rule
  9937. if(interval < 1)
  9938. interval = 100;
  9939. MSaveSpellStateMutex.lock();
  9940. if(!save_spell_state_timer.Enabled())
  9941. {
  9942. save_spell_state_time_bucket = 0;
  9943. save_spell_state_timer.Start(interval, true);
  9944. }
  9945. else
  9946. {
  9947. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  9948. save_spell_state_time_bucket += elapsed_time;
  9949. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  9950. // default to not have some bogus value in the rule
  9951. if(save_wait_cap < interval)
  9952. save_wait_cap = interval+1;
  9953. if(save_spell_state_time_bucket >= save_wait_cap)
  9954. {
  9955. // save immediately and disable timer
  9956. GetPlayer()->SaveSpellEffects();
  9957. save_spell_state_timer.Disable();
  9958. }
  9959. }
  9960. MSaveSpellStateMutex.unlock();
  9961. }
  9962. void Client::UpdateSentSpellList() {
  9963. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  9964. std::map<int32, int32>::iterator itr;
  9965. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  9966. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  9967. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  9968. QueuePacket(app);
  9969. }
  9970. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  9971. }
  9972. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  9973. tempPlacementSpawn = tmp;
  9974. hasSentTempPlacementSpawn = false;
  9975. if(tempPlacementSpawn)
  9976. temp_placement_timer.Start();
  9977. else
  9978. temp_placement_timer.Disable();
  9979. }
  9980. void Client::SetPlayer(Player* new_player) {
  9981. if (player && player != new_player)
  9982. zone_list.RemoveClientFromMap(player->GetName(), this);
  9983. player = new_player;
  9984. player->SetClient(this);
  9985. }
  9986. bool Client::UseItem(Item* item, Spawn* target) {
  9987. if (item && item->GetItemScript()) {
  9988. int16 item_index = item->details.index;
  9989. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  9990. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  9991. }
  9992. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  9993. Message(0, "%s requires an evil race.", item->name.c_str());
  9994. }
  9995. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  9996. Message(0, "%s requires a good race.", item->name.c_str());
  9997. }
  9998. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  9999. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  10000. return true;
  10001. }
  10002. else {
  10003. if (item->details.count > 0) {
  10004. std::string itemName = string(item->name);
  10005. int32 item_id = item->details.item_id;
  10006. sint64 flags = 0;
  10007. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  10008. {
  10009. //reobtain item make sure it wasn't removed
  10010. item = player->item_list.GetItemFromIndex(item_index);
  10011. if(!item) {
  10012. 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);
  10013. return true;
  10014. }
  10015. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  10016. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10017. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10018. return true;
  10019. }
  10020. else
  10021. {
  10022. item->details.count--; // charges
  10023. item->save_needed = true;
  10024. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  10025. if(!item->details.count) {
  10026. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10027. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10028. }
  10029. return true;
  10030. }
  10031. }
  10032. else {
  10033. 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);
  10034. return true;
  10035. }
  10036. }
  10037. else
  10038. {
  10039. //reobtain item make sure it wasn't removed
  10040. item = player->item_list.GetItemFromIndex(item_index);
  10041. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10042. if(item) {
  10043. 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);
  10044. }
  10045. }
  10046. }
  10047. }
  10048. return false;
  10049. }
  10050. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10051. VoiceOverStruct* garble, bool success, bool garble_success) {
  10052. VoiceOverStruct* resStruct = nullptr;
  10053. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10054. if(success) {
  10055. resStruct = non_garble;
  10056. }
  10057. }
  10058. else if(garble_success) {
  10059. resStruct = garble;
  10060. }
  10061. if(resStruct) {
  10062. 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);
  10063. }
  10064. }
  10065. void Client::SaveQuestRewardData(bool force_refresh) {
  10066. Query query;
  10067. if(force_refresh) {
  10068. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10069. GetCharacterID());
  10070. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10071. GetCharacterID());
  10072. }
  10073. vector<QuestRewardData*>::iterator itr;
  10074. vector<QuestRewardData*> tmp_quest_rewards;
  10075. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10076. int index = 0;
  10077. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10078. int32 questID = (*itr)->quest_id;
  10079. if(!(*itr)->db_saved || force_refresh) {
  10080. 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')",
  10081. 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());
  10082. (*itr)->db_saved = true;
  10083. (*itr)->db_index = index;
  10084. if((*itr)->is_temporary) {
  10085. std::vector<int32> items;
  10086. Quest* quest = GetPlayer()->GetAnyQuest(questID);
  10087. if(quest) {
  10088. quest->GetTmpRewardItemsByID(&items);
  10089. if(!force_refresh && items.size() > 0) {
  10090. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10091. GetCharacterID(), questID);
  10092. }
  10093. for(int i=0;i<items.size();i++) {
  10094. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id) values(%u, %u, %u)",
  10095. GetCharacterID(), questID, items[i]);
  10096. }
  10097. }
  10098. }
  10099. }
  10100. index++;
  10101. }
  10102. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  10103. }
  10104. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  10105. if(!data)
  10106. return;
  10107. if(data->db_saved) {
  10108. Query query;
  10109. 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",
  10110. 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);
  10111. }
  10112. }
  10113. void Client::AddRecipeToPlayer(Recipe* recipe, PacketStruct* packet, int16* i) {
  10114. if(recipe == nullptr)
  10115. return;
  10116. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  10117. if (prl->GetRecipe(recipe->GetID())) {
  10118. delete recipe;
  10119. return;
  10120. }
  10121. prl->AddRecipe(recipe);
  10122. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  10123. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  10124. if (packet && GetRecipeListSent()) {
  10125. packet->setArrayDataByName("id", recipe->GetID(), *i);
  10126. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  10127. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  10128. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  10129. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  10130. packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  10131. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  10132. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  10133. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), *i);
  10134. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  10135. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  10136. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  10137. if(i) {
  10138. (*i)++;
  10139. }
  10140. }
  10141. }