client.cpp 392 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254
  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. ClientPacketFunctions::SendLoginCommandMessages(this);
  668. GetCurrentZone()->AddSpawn(player);
  669. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  670. GetPlayer()->SetX(zoning_x);
  671. GetPlayer()->SetY(zoning_y);
  672. GetPlayer()->SetZ(zoning_z);
  673. GetPlayer()->SetHeading(zoning_h);
  674. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  675. QueuePacket(packet);
  676. }
  677. //SendCollectionList();
  678. Guild* guild = player->GetGuild();
  679. if (guild)
  680. guild->GuildMemberLogin(this, firstlogin);
  681. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  682. if (app) {
  683. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  684. //DumpPacket(app);
  685. QueuePacket(app);
  686. }
  687. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  688. if (app) {
  689. QueuePacket(app);
  690. }
  691. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  692. if (app) {
  693. QueuePacket(app);
  694. }
  695. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  696. if (items && items->size() > 0) {
  697. for (int32 i = 0; i < items->size(); i++) {
  698. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  699. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  700. //DumpPacket(outapp);
  701. QueuePacket(outapp);
  702. }
  703. }
  704. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  705. QueuePacket(app);
  706. safe_delete(items);
  707. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  708. if (items && items->size() > 0) {
  709. for (int32 i = 0; i < items->size(); i++)
  710. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  711. }
  712. safe_delete(items);
  713. if (version > 283) {
  714. SendTitleUpdate();
  715. }
  716. GetPlayer()->ChangePrimaryWeapon();
  717. GetPlayer()->ChangeSecondaryWeapon();
  718. GetPlayer()->ChangeRangedWeapon();
  719. if(!GetPlayer()->IsReturningFromLD()) {
  720. database.LoadBuyBacks(this);
  721. }
  722. if (version > 546)
  723. master_aa_list.DisplayAA(this, 0, 0);
  724. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  725. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  726. string zone_motd_send = "Zone MOTD: " + zone_motd;
  727. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  728. }
  729. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  730. if (zone_script && lua_interface)
  731. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  732. this->client_zoning = false;
  733. this->zoning_id = 0;
  734. this->zoning_instance_id = 0;
  735. SetZoningDestination(nullptr);
  736. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  737. GetCurrentZone()->AddDamagedSpawn(player);
  738. if (firstlogin)
  739. firstlogin = false;
  740. player->ClearProcs();
  741. items = player->GetEquippedItemList();
  742. if (items && items->size() > 0) {
  743. for (int32 i = 0; i < items->size(); i++) {
  744. Item* item = items->at(i);
  745. if (item && item->GetItemScript() && lua_interface)
  746. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  747. }
  748. }
  749. //Allow this player to change their last name if they meet the level requirement
  750. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  751. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  752. safe_delete(items);
  753. if (!player->Alive())
  754. DisplayDeadWindow();
  755. ClientPacketFunctions::SendLocalizedTextMessage(this);
  756. if (GetCurrentZone()->GetInstanceID())
  757. {
  758. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  759. if (ph) {
  760. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  761. string name = string(GetPlayer()->GetName());
  762. if (name.compare(ph->player_name) == 0)
  763. SetHasOwnerOrEditAccess(true);
  764. }
  765. }
  766. if (version > 546)
  767. ClientPacketFunctions::SendHousingList(this);
  768. bool groupMentor = false;
  769. GetPlayer()->group_id = rejoin_group_id;
  770. if(!world.RejoinGroup(this, rejoin_group_id))
  771. GetPlayer()->group_id = 0;
  772. else
  773. {
  774. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  775. if(ent && ent->IsPlayer())
  776. {
  777. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  778. groupMentor = true;
  779. }
  780. }
  781. if(!groupMentor)
  782. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  783. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  784. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  785. GetPlayer()->SetSaveSpellEffects(false);
  786. GetPlayer()->SetCharSheetChanged(true);
  787. GetPlayer()->SetReturningFromLD(false);
  788. }
  789. void Client::SendZoneSpawns() {
  790. //Allows us to place spawns almost anywhere
  791. if (version > 283) {
  792. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  793. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  794. QueuePacket(app);
  795. }
  796. ClientPacketFunctions::SendSkillSlotMappings(this);
  797. ClientPacketFunctions::SendGameWorldTime(this);
  798. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  799. }
  800. void Client::SendCharPOVGhost() {
  801. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  802. if (set_pov) {
  803. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  804. EQ2Packet* app_pov = set_pov->serialize();
  805. QueuePacket(app_pov);
  806. safe_delete(set_pov);
  807. }
  808. }
  809. void Client::SendZoneInfo() {
  810. ZoneServer* zone = GetCurrentZone();
  811. if (zone) {
  812. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  813. QueuePacket(packet);
  814. if (version > 283) {
  815. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  816. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  817. #if EQDEBUG >= 9
  818. fog_packet->PrintPacket();
  819. #endif
  820. if (fog_packet) {
  821. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  822. QueuePacket(fog_packet->serialize());
  823. safe_delete(fog_packet);
  824. }
  825. zone->SendFlightPathsPackets(this);
  826. }
  827. }
  828. /*
  829. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  830. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  831. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  832. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  833. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  834. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,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,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  865. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  866. QueuePacket(appA);
  867. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  871. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  872. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  873. QueuePacket(appB);
  874. */
  875. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  876. SendFriendList();
  877. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  878. SendIgnoreList();
  879. }
  880. void Client::SendDefaultGroupOptions() {
  881. /*
  882. 0 - loot method
  883. 1 - loot items rarity
  884. 2 - Auto split coin
  885. 4 - default yell method
  886. 6 - group autolock
  887. 7 - solo autolock
  888. */
  889. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  890. if (default_options) {
  891. default_options->setDataByName("loot_method", 1);
  892. default_options->setDataByName("loot_items_rarity", 1);
  893. default_options->setDataByName("auto_split_coin", 1);
  894. default_options->setDataByName("default_yell_method", 1);
  895. EQ2Packet* app7 = default_options->serialize();
  896. QueuePacket(app7);
  897. safe_delete(default_options);
  898. }
  899. }
  900. bool Client::HandlePacket(EQApplicationPacket* app) {
  901. bool ret = true;
  902. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  903. //DumpPacket(app);
  904. #if EQDEBUG >= 9
  905. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  906. DumpPacket(app, true);
  907. #endif
  908. EmuOpcode opcode = app->GetOpcode();
  909. #if EQDEBUG >= 9
  910. const char* name = app->GetOpcodeName();
  911. if (name)
  912. cout << name;
  913. else
  914. cout << "Unknown";
  915. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  916. DumpPacket(app);
  917. #endif
  918. //if (opcode != OP_UpdatePositionMsg) {
  919. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  920. //}
  921. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  922. {
  923. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  924. }
  925. switch (opcode) {
  926. case _maxEmuOpcode:
  927. break;
  928. case OP_LoginByNumRequestMsg: {
  929. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  930. PacketStruct* request;
  931. request = configReader.getStruct("LoginByNumRequest", 1);
  932. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  933. // test the original location of Version for clients older than 1212
  934. version = request->getType_int16_ByName("version");
  935. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  936. // must be new client data version method, re-fetch the packet
  937. safe_delete(request);
  938. request = configReader.getStruct("LoginByNumRequest", 1208);
  939. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  940. // Xinux suggests using an INT16 here. Our first new version = 57000
  941. version = request->getType_int16_ByName("version");
  942. }
  943. else {
  944. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  945. break;
  946. }
  947. }
  948. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  949. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  950. ClientPacketFunctions::SendLoginDenied(this);
  951. return false;
  952. }
  953. int32 account_id = request->getType_int32_ByName("account_id");
  954. int32 access_code = request->getType_int32_ByName("access_code");
  955. if (!HandleNewLogin(account_id, access_code))
  956. return false;
  957. }
  958. safe_delete(request);
  959. break;
  960. }
  961. case OP_MapRequest: {
  962. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  963. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  964. if (packet && app->size > 2 && GetCurrentZone()) {
  965. packet->LoadPacketData(app->pBuffer, app->size);
  966. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  967. if (fog_packet) {
  968. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  969. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  970. fog_packet->setDataByName("unknown1", 1);
  971. fog_packet->setDataByName("unknown3", 1);
  972. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  973. //fog_packet->PrintPacket();
  974. QueuePacket(fog_packet->serialize());
  975. safe_delete(fog_packet);
  976. }
  977. safe_delete(packet);
  978. }
  979. break;
  980. }
  981. case OP_RequestCampMsg: {
  982. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  983. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  984. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  985. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  986. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  987. request->getType_int8_ByName("quit"),
  988. request->getType_int8_ByName("camp_desktop"),
  989. request->getType_int16_ByName("camp_char_select"),
  990. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  991. //DumpPacket(app->pBuffer, app->size);
  992. //request->PrintPacket();
  993. if (!camp_timer) {
  994. int16 camp_time = 20; // default if rule cannot be found
  995. if (GetAdminStatus() >= 100)
  996. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  997. else
  998. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  999. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1000. if (response) {
  1001. bool disconnect = false;
  1002. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1003. // Command: /camp desktop
  1004. // Command: /quit
  1005. response->setDataByName("camp_desktop", 1);
  1006. disconnect = true;
  1007. }
  1008. else {
  1009. // Command: /camp
  1010. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1011. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1012. response->setDataByName("seconds", camp_time);
  1013. }
  1014. camp_timer = new Timer(camp_time * 1000);
  1015. camp_timer->Enable();
  1016. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1017. // /camp {char_name}
  1018. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1019. }
  1020. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1021. // /camp (go back to char selection screen)
  1022. response->setDataByName("char_name", " ");
  1023. response->setDataByName("camp_char_select", 1);
  1024. }
  1025. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1026. response->getType_int8_ByName("seconds"),
  1027. response->getType_int8_ByName("camp_desktop"),
  1028. response->getType_int8_ByName("camp_char_select"),
  1029. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1030. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1031. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1032. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1033. //response->PrintPacket();
  1034. QueuePacket(response->serialize());
  1035. safe_delete(response);
  1036. if (disconnect)
  1037. Disconnect();
  1038. }
  1039. }
  1040. }
  1041. safe_delete(request);
  1042. break;
  1043. }
  1044. case OP_StoodMsg: {
  1045. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1046. if (camp_timer)
  1047. {
  1048. // JA: clear camping flag
  1049. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1050. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1051. safe_delete(camp_timer);
  1052. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1053. QueuePacket(outapp);
  1054. }
  1055. player->SetTempVisualState(0);
  1056. break;
  1057. }
  1058. case OP_StandMsg: {
  1059. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1060. if (camp_timer)
  1061. {
  1062. // JA: clear camping flag
  1063. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1064. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1065. safe_delete(camp_timer);
  1066. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1067. QueuePacket(outapp);
  1068. }
  1069. player->SetTempVisualState(539);
  1070. break;
  1071. }
  1072. case OP_SitMsg: {
  1073. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1074. player->SetTempVisualState(538);
  1075. break;
  1076. }
  1077. case OP_SatMsg: {
  1078. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1079. player->SetTempVisualState(540);
  1080. break;
  1081. }
  1082. case OP_QuestJournalOpenMsg:
  1083. case OP_QuestJournalInspectMsg: {
  1084. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1085. if (app->size < sizeof(int32))
  1086. break;
  1087. int32 quest_id = 0;
  1088. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1089. Quest* quest = GetActiveQuest(quest_id);
  1090. if (quest)
  1091. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1092. else {
  1093. quest = player->GetCompletedQuest(quest_id);
  1094. if (quest)
  1095. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1096. }
  1097. break;
  1098. }
  1099. case OP_QuestJournalSetVisibleMsg: {
  1100. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1101. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1102. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1103. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1104. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1105. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1106. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1107. if (player_quests) {
  1108. if (player_quests->count(quest_id) > 0)
  1109. player_quests->at(quest_id)->SetHidden(hidden);
  1110. else
  1111. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1112. }
  1113. else
  1114. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1115. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1116. safe_delete(packet);
  1117. }
  1118. break;
  1119. }
  1120. case OP_MacroUpdateMsg: {
  1121. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1122. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1123. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1124. vector<string>* update = new vector<string>;
  1125. int8 number = macro_update->getType_int8_ByName("number");
  1126. int16 icon = macro_update->getType_int16_ByName("icon");
  1127. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1128. int8 count = macro_update->getType_int8_ByName("macro_count");
  1129. if (GetVersion() <= 283) {
  1130. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1131. }
  1132. else {
  1133. for (int8 i = 0; i < count; i++) {
  1134. char tmp_command[15] = { 0 };
  1135. sprintf(tmp_command, "command_%i", i);
  1136. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1137. }
  1138. }
  1139. if (name.length() == 0)
  1140. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1141. else
  1142. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1143. safe_delete(update);
  1144. safe_delete(macro_update);
  1145. }
  1146. break;
  1147. }
  1148. case OP_DialogSelectMsg: {
  1149. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1150. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1151. if (packet) {
  1152. packet->LoadPacketData(app->pBuffer, app->size);
  1153. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1154. int32 response_index = packet->getType_int32_ByName("response");
  1155. if (GetCurrentZone()) {
  1156. MConversation.readlock();
  1157. int32 spawn_id = conversation_spawns[conversation_id];
  1158. Spawn* spawn = nullptr;
  1159. if(spawn_id) {
  1160. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  1161. }
  1162. Item* item = conversation_items[conversation_id];
  1163. MConversation.releasereadlock();
  1164. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1165. if (spawn)
  1166. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1167. else if (item && lua_interface && item->GetItemScript())
  1168. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1169. else
  1170. CloseDialog(conversation_id);
  1171. }
  1172. else
  1173. CloseDialog(conversation_id);
  1174. }
  1175. safe_delete(packet);
  1176. }
  1177. break;
  1178. }
  1179. case OP_CancelMoveObjectModeMsg: {
  1180. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1181. if (GetTempPlacementSpawn())
  1182. {
  1183. Spawn* tmp = GetTempPlacementSpawn();
  1184. SetTempPlacementSpawn(nullptr);
  1185. SetPlacementUniqueItemID(0);
  1186. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1187. break; // break out early if we are tied to a temp spawn
  1188. }
  1189. // if we are moving some other object? other use-cases not covered
  1190. break;
  1191. }
  1192. case OP_PositionMoveableObject: {
  1193. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1194. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1195. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1196. Spawn* spawn = 0;
  1197. if (GetTempPlacementSpawn())
  1198. spawn = GetTempPlacementSpawn();
  1199. else
  1200. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1201. if (!spawn) {
  1202. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1203. break;
  1204. }
  1205. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1206. {
  1207. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1208. break;
  1209. }
  1210. // handles instantiation logic + adding to zone of a new house object
  1211. PopulateHouseSpawn(place_object);
  1212. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1213. char query[256];
  1214. switch (GetSpawnPlacementMode())
  1215. {
  1216. case ServerSpawnPlacementMode::OPEN_HEADING:
  1217. {
  1218. if (spawn && spawn->IsWidget())
  1219. {
  1220. Widget* widget = (Widget*)spawn;
  1221. widget->SetOpenHeading(newHeading);
  1222. widget->SetIncludeHeading(true);
  1223. spawn->position_changed = true;
  1224. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1225. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1226. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1227. }
  1228. else
  1229. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1230. break;
  1231. }
  1232. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1233. {
  1234. if (spawn && spawn->IsWidget())
  1235. {
  1236. Widget* widget = (Widget*)spawn;
  1237. widget->SetClosedHeading(newHeading);
  1238. widget->SetIncludeHeading(true);
  1239. spawn->position_changed = true;
  1240. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1241. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1242. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1243. if (spawn->GetSpawnLocationID())
  1244. {
  1245. Query query;
  1246. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1247. }
  1248. }
  1249. else
  1250. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1251. break;
  1252. }
  1253. default:
  1254. {
  1255. spawn->SetX(place_object->getType_float_ByName("x"));
  1256. spawn->SetY(place_object->getType_float_ByName("y"));
  1257. spawn->SetZ(place_object->getType_float_ByName("z"));
  1258. spawn->SetHeading(newHeading);
  1259. spawn->SetSpawnOrigX(spawn->GetX());
  1260. spawn->SetSpawnOrigY(spawn->GetY());
  1261. spawn->SetSpawnOrigZ(spawn->GetZ());
  1262. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1263. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1264. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1265. else if (spawn->GetSpawnLocationID() > 0)
  1266. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1267. }
  1268. }
  1269. PopulateHouseSpawnFinalize();
  1270. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1271. safe_delete(place_object);
  1272. }
  1273. break;
  1274. }
  1275. case OP_CampAbortedMsg: {
  1276. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1277. if (camp_timer)
  1278. {
  1279. // JA: clear camping flag
  1280. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1281. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1282. safe_delete(camp_timer);
  1283. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1284. QueuePacket(outapp);
  1285. }
  1286. break;
  1287. }
  1288. case OP_DoneLoadingUIResourcesMsg: {
  1289. ClientPacketFunctions::SendUpdateSpellBook(this);
  1290. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1291. QueuePacket(app);
  1292. if(!player_loading_complete)
  1293. {
  1294. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1295. if (zone_script && lua_interface)
  1296. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1297. player_loading_complete = true;
  1298. }
  1299. break;
  1300. }
  1301. case OP_DoneLoadingZoneResourcesMsg: {
  1302. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1303. SendZoneSpawns();
  1304. break;
  1305. }
  1306. case OP_DefaultGroupOptionsRequestMsg: {
  1307. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1308. SendDefaultGroupOptions();
  1309. break;
  1310. }
  1311. case OP_DoneLoadingEntityResourcesMsg: {
  1312. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1313. if (!IsReadyForSpawns())
  1314. SetReadyForSpawns(true);
  1315. SendCharInfo();
  1316. pos_update.Start();
  1317. quest_pos_timer.Start();
  1318. break;
  1319. }
  1320. case OP_LootItemsRequestMsg: {
  1321. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1322. HandleLoot(app);
  1323. break;
  1324. }
  1325. case OP_WaypointSelectMsg: {
  1326. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1327. if (packet) {
  1328. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1329. int32 selection = packet->getType_int32_ByName("selection");
  1330. if (selection > 0) {
  1331. SelectWaypoint(selection);
  1332. }
  1333. }
  1334. }
  1335. break;
  1336. }
  1337. case OP_KnowledgeWindowSlotMappingMsg: {
  1338. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1339. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1340. if (packet) {
  1341. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1342. int num_updates = packet->getType_int16_ByName("spell_count");
  1343. int32 spell_id = 0;
  1344. int16 slot_id = 0;
  1345. char tmp_spell_id[15];
  1346. char tmp_slot[15];
  1347. for (int i = 0; i < num_updates; i++) {
  1348. memset(tmp_spell_id, 0, 15);
  1349. memset(tmp_slot, 0, 15);
  1350. sprintf(tmp_spell_id, "spell_id_%i", i);
  1351. sprintf(tmp_slot, "slot_id_%i", i);
  1352. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1353. if (spell_id > 0) {
  1354. slot_id = packet->getType_int16_ByName(tmp_slot);
  1355. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1356. if (spell && spell->slot != slot_id) {
  1357. spell->slot = slot_id;
  1358. spell->save_needed = true;
  1359. }
  1360. }
  1361. }
  1362. }
  1363. safe_delete(packet);
  1364. }
  1365. //SendKnowledgeWindowSlot();
  1366. break;
  1367. }
  1368. case OP_ReadyToZoneMsg: {
  1369. if (!IsReadyForSpawns())
  1370. {
  1371. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1372. }
  1373. else
  1374. {
  1375. if(zoning_destination)
  1376. SetCurrentZone(zoning_destination);
  1377. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1378. bool succeed_override_zone = true;
  1379. if(!GetCurrentZone()) {
  1380. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1381. if(zoning_instance_id) {
  1382. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1383. if(!zone) {
  1384. 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);
  1385. succeed_override_zone = false;
  1386. }
  1387. else {
  1388. SetCurrentZone(zone);
  1389. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1390. }
  1391. }
  1392. else if(zoning_id) {
  1393. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1394. if(!zone) {
  1395. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1396. succeed_override_zone = false;
  1397. }
  1398. else {
  1399. SetCurrentZone(zone);
  1400. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1401. }
  1402. }
  1403. }
  1404. if (client_zoning)
  1405. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1406. else
  1407. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1408. Disconnect();
  1409. }
  1410. break;
  1411. }
  1412. case OP_ClientFellMsg: {
  1413. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1414. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1415. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1416. float height = request->getType_float_ByName("height");
  1417. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1418. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1419. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1420. break;
  1421. }*/
  1422. float safe_height = 13.0f;
  1423. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1424. GetPlayer()->MStats.lock();
  1425. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1426. GetPlayer()->MStats.unlock();
  1427. if (skill)
  1428. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1429. if (height > safe_height) {
  1430. int16 damage = (int16)ceil((height - safe_height) * 125);
  1431. if (height >= 80)
  1432. damage = 30000;
  1433. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1434. if (damage > 0) {
  1435. GetPlayer()->TakeDamage(damage);
  1436. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1437. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1438. if (!GetPlayer()->GetInvulnerable())
  1439. GetPlayer()->SetCharSheetChanged(true);
  1440. 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);
  1441. if (GetPlayer()->GetHP() == 0) {
  1442. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1443. }
  1444. }
  1445. }
  1446. safe_delete(request);
  1447. }
  1448. break;
  1449. }
  1450. case OP_MapFogDataUpdateMsg: {
  1451. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1452. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1453. break;
  1454. }
  1455. case OP_SelectZoneTeleporterDestinatio: {
  1456. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1457. ProcessTeleportLocation(app);
  1458. break;
  1459. }
  1460. case OP_SendLatestRequestMsg: {
  1461. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1462. uchar blah25[] = { 0x01 };
  1463. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1464. QueuePacket(app25);
  1465. break;
  1466. }
  1467. case OP_ShowCreateFromRecipeUIMsg: {
  1468. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1469. break;
  1470. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1471. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1472. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1473. QueuePacket(app);
  1474. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1475. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1476. QueuePacket(app);
  1477. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1478. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1479. ,0xff,0xff,0xff};
  1480. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1481. QueuePacket(app);
  1482. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1483. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1484. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1485. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1486. QueuePacket(app);
  1487. uchar blah5[] ={0x00,0x00};
  1488. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1489. QueuePacket(app);
  1490. break;*/
  1491. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1492. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1493. //QueuePacket(app);
  1494. }
  1495. case OP_BeginItemCreationMsg: {
  1496. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1497. //DumpPacket(app->pBuffer, app->size);
  1498. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1499. if (packet) {
  1500. packet->LoadPacketData(app->pBuffer, app->size);
  1501. int32 item = 0;
  1502. vector<int32> items;
  1503. char tmp_item_id[20];
  1504. item = packet->getType_int32_ByName("primary_component_id");
  1505. if (item > 0)
  1506. items.push_back(item);
  1507. item = 0;
  1508. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1509. for (int8 i = 0; i < build_components; i++) {
  1510. memset(tmp_item_id, 0, 20);
  1511. sprintf(tmp_item_id, "component_id_%i", i);
  1512. item = packet->getType_int32_ByName(tmp_item_id);
  1513. if (item > 0)
  1514. items.push_back(item);
  1515. item = 0;
  1516. }
  1517. item = packet->getType_int32_ByName("fuel_id");
  1518. if (item > 0)
  1519. items.push_back(item);
  1520. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1521. safe_delete(packet);
  1522. }
  1523. break;
  1524. }
  1525. case OP_StopItemCreationMsg: {
  1526. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1527. //DumpPacket(app->pBuffer, app->size);
  1528. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1529. break;
  1530. }
  1531. case OP_SysClient:
  1532. case OP_SignalMsg: {
  1533. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1534. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1535. if (packet) {
  1536. packet->LoadPacketData(app->pBuffer, app->size);
  1537. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1538. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1539. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1540. SetReloadingZone(false);
  1541. if(GetPlayer()->IsDeletedSpawn()) {
  1542. GetPlayer()->SetDeletedSpawn(false);
  1543. }
  1544. ResetZoningCoords();
  1545. SetReadyForUpdates();
  1546. GetPlayer()->SendSpawnChanges(true);
  1547. ProcessStateCommands();
  1548. GetPlayer()->changed = true;
  1549. GetPlayer()->info_changed = true;
  1550. GetPlayer()->vis_changed = true;
  1551. player_pos_changed = true;
  1552. GetPlayer()->AddChangedZoneSpawn();
  1553. }
  1554. else {
  1555. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1556. }
  1557. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1558. if (zone_script && lua_interface)
  1559. {
  1560. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1561. }
  1562. }
  1563. break;
  1564. }
  1565. case OP_EntityVerbsRequestMsg: {
  1566. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1567. HandleVerbRequest(app);
  1568. break;
  1569. }
  1570. case OP_EntityVerbsVerbMsg: {
  1571. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1572. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1573. if (packet) {
  1574. packet->LoadPacketData(app->pBuffer, app->size);
  1575. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1576. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1577. Spawn* spawn = player->GetTarget();
  1578. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1579. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1580. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1581. {
  1582. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1583. if (spawn->IsGroundSpawn())
  1584. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1585. else if (spawn->IsObject())
  1586. ((Object*)spawn)->HandleUse(this, command);
  1587. else if (spawn->IsWidget())
  1588. ((Widget*)spawn)->HandleUse(this, command);
  1589. else if (spawn->IsSign())
  1590. ((Sign*)spawn)->HandleUse(this, command);
  1591. }
  1592. }
  1593. }
  1594. else {
  1595. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1596. if (command.size > 0) {
  1597. string command_name = command.data;
  1598. if (command_name.find(" ") < 0xFFFFFFFF) {
  1599. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1600. string::size_type pos = command_name.find(" ");
  1601. while(pos != string::npos){
  1602. command_name.replace(pos, 1, "_");
  1603. pos = command_name.find(" ");
  1604. }
  1605. }
  1606. else
  1607. command_name = command_name.substr(0, command_name.find(" "));
  1608. }
  1609. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1610. if (handler != 0xFFFFFFFF) {
  1611. if (command.data == command_name) {
  1612. command.data = "";
  1613. command.size = 0;
  1614. }
  1615. else {
  1616. command.data = command.data.substr(command.data.find(" ") + 1);
  1617. command.size = command.data.length();
  1618. }
  1619. commands.Process(handler, &command, this);
  1620. }
  1621. else {
  1622. if (spawn && spawn->IsNPC()) {
  1623. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1624. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1625. command_name = command.data;
  1626. string::size_type pos = command_name.find(" ");
  1627. while (pos != string::npos) {
  1628. command_name.replace(pos, 1, "_");
  1629. pos = command_name.find(" ");
  1630. }
  1631. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1632. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1633. }
  1634. }
  1635. }
  1636. }
  1637. else
  1638. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1639. }
  1640. }
  1641. }
  1642. safe_delete(packet);
  1643. }
  1644. break;
  1645. }
  1646. case OP_SkillInfoRequest: {
  1647. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1648. HandleSkillInfoRequest(app);
  1649. break;
  1650. }
  1651. case OP_UpdateTargetMsg: {
  1652. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1653. int16 index = 0;
  1654. memcpy(&index, app->pBuffer, sizeof(int16));
  1655. if (index == 0xFFFF)
  1656. GetPlayer()->SetTarget(0);
  1657. else {
  1658. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1659. if(spawn)
  1660. GetPlayer()->SetTarget(spawn);
  1661. else {
  1662. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1663. }
  1664. }
  1665. if (GetPlayer()->GetTarget())
  1666. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1667. //player->SetTarget((int16*)app->pBuffer);
  1668. break;
  1669. }
  1670. case OP_ExamineInfoRequestMsg: {
  1671. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1672. HandleExamineInfoRequest(app);
  1673. break;
  1674. }
  1675. case OP_QuickbarUpdateMsg:
  1676. //case OP_QuickbarAddMsg:
  1677. {
  1678. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1679. HandleQuickbarUpdateRequest(app);
  1680. break;
  1681. }
  1682. case OP_PredictionUpdateMsg: {
  1683. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1684. if (version <= 546) {
  1685. int8 offset = 9;
  1686. if (app->pBuffer[0] == 0xFF)
  1687. offset += 2;
  1688. if (app->size > offset) {
  1689. if (player->IsCasting()) {
  1690. float distance = 0;
  1691. float x = player->GetX();
  1692. float y = player->GetY();
  1693. float z = player->GetZ();
  1694. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1695. distance = player->GetDistance(x, y, z, false);
  1696. if (distance > .5)
  1697. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1698. }
  1699. else
  1700. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1701. player_pos_changed = true;
  1702. //DumpPacket(app);
  1703. }
  1704. }
  1705. else {
  1706. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1707. QueuePacket(app);
  1708. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1709. }
  1710. break;
  1711. }
  1712. case OP_RemoteCmdMsg: {
  1713. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1714. if (app->size > 0) {
  1715. EQ2_CommandString remote(app->pBuffer, app->size);
  1716. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1717. #if EQDEBUG >= 9
  1718. DumpPacket(app);
  1719. #endif
  1720. commands.Process(remote.handler, &remote.command, this);
  1721. }
  1722. else //bad client, disconnect
  1723. Disconnect();
  1724. break;
  1725. }
  1726. case OP_CancelSpellCast: {
  1727. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1728. current_zone->Interrupted(player, 0, 0, true);
  1729. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1730. break;
  1731. }
  1732. case OP_UpdatePositionMsg: {
  1733. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1734. int8 offset = 13;
  1735. if (app->pBuffer[0] == 0xFF)
  1736. offset += 2;
  1737. if (app->size > offset) {
  1738. if (player->IsCasting()) {
  1739. float distance = 0;
  1740. float x = player->GetX();
  1741. float y = player->GetY();
  1742. float z = player->GetZ();
  1743. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1744. distance = player->GetDistance(x, y, z, false);
  1745. if (distance > .5)
  1746. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1747. }
  1748. else
  1749. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1750. player_pos_changed = true;
  1751. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1752. //DumpPacket(app);
  1753. }
  1754. break;
  1755. }
  1756. case OP_MailSendMessageMsg: {
  1757. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1758. HandleSentMail(app);
  1759. break;
  1760. }
  1761. case OP_StopTrackingMsg: {
  1762. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1763. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1764. break;
  1765. }
  1766. case OP_BeginTrackingMsg: {
  1767. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1768. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1769. if (packet) {
  1770. packet->LoadPacketData(app->pBuffer, app->size);
  1771. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1772. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1773. if (spawn) {
  1774. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1775. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1776. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1777. }
  1778. safe_delete(packet);
  1779. }
  1780. break;
  1781. }
  1782. case OP_BioUpdateMsg: {
  1783. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1784. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1785. if (packet) {
  1786. packet->LoadPacketData(app->pBuffer, app->size);
  1787. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1788. safe_delete(packet);
  1789. }
  1790. break;
  1791. }
  1792. case OP_RewardPackMsg: {
  1793. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1794. /* 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
  1795. when we come across it (scatman) */
  1796. const char* name = app->GetOpcodeName();
  1797. if (name)
  1798. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1799. else
  1800. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1801. //DumpPacket(app);
  1802. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1803. if (packet) {
  1804. packet->LoadPacketData(app->pBuffer, app->size);
  1805. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1806. /* Player has contacted a guild recruiter */
  1807. if (recruiter_name.length() > 0) {
  1808. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1809. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1810. if (recruiter && guild) {
  1811. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1812. 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()));
  1813. recruiter->PlaySound("ui_guild_page");
  1814. }
  1815. }
  1816. /* New picture taken for guild recruiting */
  1817. else {
  1818. //DumpPacket(app->pBuffer, app->size);
  1819. int32 guild_id = 0;
  1820. int16 picture_data_size = 0;
  1821. unsigned char* recruiter_picture_data = 0;
  1822. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1823. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1824. Guild* guild = guild_list.GetGuild(guild_id);
  1825. if (guild) {
  1826. GuildMember* gm = guild->GetGuildMember(player);
  1827. if (gm) {
  1828. safe_delete_array(gm->recruiter_picture_data);
  1829. recruiter_picture_data = new unsigned char[picture_data_size];
  1830. for (int16 i = 0; i < picture_data_size; i++)
  1831. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1832. gm->recruiter_picture_data = recruiter_picture_data;
  1833. gm->recruiter_picture_data_size = picture_data_size;
  1834. guild->SetMemberSaveNeeded(true);
  1835. }
  1836. }
  1837. }
  1838. safe_delete(packet);
  1839. }
  1840. break;
  1841. }
  1842. case OP_PetOptions: {
  1843. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1844. Spawn* target = player->GetTarget();
  1845. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1846. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1847. bool change = false;
  1848. packet->LoadPacketData(app->pBuffer, app->size);
  1849. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1850. if (strlen(name.c_str()) != 0) {
  1851. target->SetName(name.c_str());
  1852. player->GetInfoStruct()->set_pet_name(name);
  1853. GetCurrentZone()->SendUpdateTitles(target);
  1854. change = true;
  1855. }
  1856. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1857. // Check protect self setting and update if needed
  1858. if (packet->getType_int8_ByName("protect_self") == 1) {
  1859. if ((pet_behavior & 2) == 0) {
  1860. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1861. change = true;
  1862. }
  1863. }
  1864. else {
  1865. if ((pet_behavior & 2) != 0) {
  1866. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1867. change = true;
  1868. }
  1869. }
  1870. // Check protect master setting and update if needed
  1871. if (packet->getType_int8_ByName("protect_master") == 1) {
  1872. if ((pet_behavior & 1) == 0) {
  1873. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1874. change = true;
  1875. }
  1876. }
  1877. else {
  1878. if ((pet_behavior & 1) != 0) {
  1879. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1880. change = true;
  1881. }
  1882. }
  1883. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1884. // Check stay/follow setting and update if needed
  1885. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1886. if (pet_movement != 2) {
  1887. player->GetInfoStruct()->set_pet_movement(2);
  1888. change = true;
  1889. }
  1890. }
  1891. else {
  1892. if (pet_movement != 1) {
  1893. player->GetInfoStruct()->set_pet_movement(1);
  1894. change = true;
  1895. }
  1896. }
  1897. // Ranged/Melee settings are not implemented yet
  1898. if (change)
  1899. player->SetCharSheetChanged(true);
  1900. safe_delete(packet);
  1901. }
  1902. break;
  1903. }
  1904. case OP_RecipeBook: {
  1905. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1906. SendRecipeList();
  1907. break;
  1908. }
  1909. case OP_BuyPlayerHouseMsg: {
  1910. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1911. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1912. if (packet) {
  1913. packet->LoadPacketData(app->pBuffer, app->size);
  1914. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1915. if (hz) {
  1916. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1917. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1918. if (houses.size() > 24)
  1919. {
  1920. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1921. safe_delete(packet);
  1922. break;
  1923. }
  1924. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1925. {
  1926. std::string req = "You must be of ";
  1927. if (hz->alignment == 1)
  1928. req.append("Good");
  1929. else
  1930. req.append("Evil");
  1931. req.append(" alignment to purchase this house");
  1932. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1933. safe_delete(packet);
  1934. break;
  1935. }
  1936. int32 status_req = hz->upkeep_status + hz->cost_status;
  1937. int32 available_status = player->GetInfoStruct()->get_status_points();
  1938. if (status_req <= available_status &&
  1939. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1940. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1941. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1942. {
  1943. player->GetInfoStruct()->subtract_status_points(status_req);
  1944. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1945. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1946. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1947. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1948. //ClientPacketFunctions::SendHousingList(this);
  1949. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1950. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1951. PlaySound("coin_cha_ching");
  1952. }
  1953. else
  1954. {
  1955. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1956. PlaySound("buy_failed");
  1957. }
  1958. }
  1959. }
  1960. safe_delete(packet);
  1961. break;
  1962. }
  1963. case OP_EnterHouseMsg: {
  1964. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1965. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1966. if (packet) {
  1967. packet->LoadPacketData(app->pBuffer, app->size);
  1968. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1969. if (ph) {
  1970. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1971. if (hz) {
  1972. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1973. if (house) {
  1974. Zone(house, true);
  1975. }
  1976. }
  1977. }
  1978. }
  1979. safe_delete(packet);
  1980. break;
  1981. }
  1982. case OP_PayHouseUpkeepMsg: {
  1983. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1984. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1985. if (packet) {
  1986. packet->LoadPacketData(app->pBuffer, app->size);
  1987. int64 houseID = packet->getType_int64_ByName("house_id");
  1988. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1989. if (ph)
  1990. {
  1991. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1992. if (!hz)
  1993. {
  1994. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1995. safe_delete(packet);
  1996. break;
  1997. }
  1998. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1999. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2000. {
  2001. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2002. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2003. {
  2004. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2005. PlaySound("buy_failed");
  2006. safe_delete(packet);
  2007. break;
  2008. }
  2009. }
  2010. bool escrowChange = false;
  2011. int64 statusReq = hz->upkeep_status;
  2012. int64 tmpRecoverStatus = 0;
  2013. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2014. {
  2015. escrowChange = true;
  2016. tmpRecoverStatus = ph->escrow_status;
  2017. statusReq -= ph->escrow_status;
  2018. ph->escrow_status = 0;
  2019. }
  2020. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2021. {
  2022. escrowChange = true;
  2023. ph->escrow_status -= statusReq;
  2024. tmpRecoverStatus = statusReq;
  2025. statusReq = 0;
  2026. }
  2027. int64 coinReq = hz->upkeep_coin;
  2028. int64 tmpRecoverCoins = 0;
  2029. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2030. {
  2031. escrowChange = true;
  2032. tmpRecoverCoins = ph->escrow_coins;
  2033. coinReq -= ph->escrow_coins;
  2034. ph->escrow_coins = 0;
  2035. }
  2036. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2037. {
  2038. escrowChange = true;
  2039. // more than enough in escrow, subtract and make our cost 0!
  2040. ph->escrow_coins -= coinReq;
  2041. tmpRecoverCoins = coinReq;
  2042. coinReq = 0;
  2043. }
  2044. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2045. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2046. {
  2047. if(coinReq && player->RemoveCoins(coinReq))
  2048. coinReq = 0;
  2049. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2050. statusReq = 0;
  2051. }
  2052. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2053. {
  2054. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2055. if (escrowChange)
  2056. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2057. ph->upkeep_due = upkeep_due;
  2058. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2059. //ClientPacketFunctions::SendHousingList(this);
  2060. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  2061. PlaySound("coin_cha_ching");
  2062. }
  2063. else
  2064. {
  2065. // recover the escrow we were going to use but could not spend due to lack of funds
  2066. if (tmpRecoverCoins)
  2067. ph->escrow_coins += tmpRecoverCoins;
  2068. if(tmpRecoverStatus)
  2069. ph->escrow_status += tmpRecoverStatus;
  2070. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2071. PlaySound("buy_failed");
  2072. }
  2073. }
  2074. else
  2075. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2076. }
  2077. safe_delete(packet);
  2078. break;
  2079. }
  2080. case OP_ExitHouseMsg: {
  2081. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2082. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2083. if (instance_id > 0) {
  2084. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2085. if (ph) {
  2086. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2087. if (hz) {
  2088. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2089. // determine if this is an instanced zone that already exists
  2090. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2091. if (instance_zone || new_zone) {
  2092. GetPlayer()->SetX(hz->exit_x);
  2093. GetPlayer()->SetY(hz->exit_y);
  2094. GetPlayer()->SetZ(hz->exit_z);
  2095. GetPlayer()->SetHeading(hz->exit_heading);
  2096. if (instance_zone)
  2097. Zone(instance_zone->GetInstanceID(), false, true);
  2098. else
  2099. Zone(new_zone, false);
  2100. }
  2101. }
  2102. }
  2103. }
  2104. break;
  2105. }
  2106. case OP_QuestJournalWaypointMsg: {
  2107. //DumpPacket(app);
  2108. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2109. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2110. if (packet) {
  2111. packet->LoadPacketData(app->pBuffer, app->size);
  2112. int32 quests = packet->getType_int32_ByName("num_quests");
  2113. if (quests > 100) // just picking a number higher than max allowed
  2114. {
  2115. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2116. break;
  2117. }
  2118. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2119. for (int32 i = 0; i < quests; i++) {
  2120. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2121. if (id == 0)
  2122. continue;
  2123. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2124. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2125. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2126. if (player->player_quests.count(id) > 0) {
  2127. player->player_quests[id]->SetTracked(tracked);
  2128. player->player_quests[id]->SetSaveNeeded(true);
  2129. }
  2130. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2131. }
  2132. safe_delete(packet);
  2133. }
  2134. break;
  2135. }
  2136. case OP_PaperdollImage: {
  2137. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2138. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2139. //First check if this is a new image... delete an existing partial image if one exists
  2140. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2141. if (packet_index == 0) {
  2142. safe_delete_array(incoming_paperdoll.image_bytes);
  2143. incoming_paperdoll.last_received_packet_index = 0;
  2144. incoming_paperdoll.current_size_bytes = 0;
  2145. }
  2146. //return if this packet is not the one we are expecting...
  2147. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2148. safe_delete(packet);
  2149. break;
  2150. }
  2151. //Check how many packets we're supposed to be receiving for this/these images
  2152. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2153. //Check the image type, if this is a new type in the same series of packets we have a new image
  2154. int8 img_type = packet->getType_int8_ByName("image_type");
  2155. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2156. //We have a new image. Save the old data and clear before continuing
  2157. SavePlayerImages();
  2158. }
  2159. incoming_paperdoll.image_type = img_type;
  2160. //Get the size of the image data in this packet
  2161. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2162. if (image_size <= 0 || image_size > 1048576) {
  2163. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2164. safe_delete(packet);
  2165. break;
  2166. }
  2167. //Create a new array
  2168. int32 new_image_size = image_size;
  2169. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2170. if (incoming_paperdoll.image_bytes) {
  2171. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2172. safe_delete_array(incoming_paperdoll.image_bytes);
  2173. }
  2174. //variable i should be the index in the packet of the first PNG file byte
  2175. vector<DataStruct*>* d_structs = packet->getStructs();
  2176. vector<DataStruct*>::iterator itr;
  2177. int32 i = 0;
  2178. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2179. DataStruct* ds = (*itr);
  2180. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2181. i += ds->GetDataSizeInBytes();
  2182. else
  2183. break;
  2184. }
  2185. //Return if this packet is bad and we would read out of bounds
  2186. if (app->size - i < new_image_size) {
  2187. safe_delete(packet);
  2188. safe_delete_array(new_image);
  2189. break;
  2190. }
  2191. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2192. memcpy(tmp, app->pBuffer + i, new_image_size);
  2193. incoming_paperdoll.current_size_bytes += new_image_size;
  2194. incoming_paperdoll.image_bytes = new_image;
  2195. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2196. if (incoming_paperdoll.image_num_packets == 1 ||
  2197. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2198. SavePlayerImages();
  2199. }
  2200. incoming_paperdoll.last_received_packet_index = packet_index;
  2201. }
  2202. safe_delete(packet);
  2203. */
  2204. break;
  2205. }
  2206. case OP_ReadyForTakeOffMsg:
  2207. {
  2208. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2209. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2210. if (GetPendingFlightPath() > 0) {
  2211. if (index != -1) {
  2212. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2213. if (packet) {
  2214. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2215. packet->setDataByName("path_id", index);
  2216. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2217. QueuePacket(packet->serialize());
  2218. safe_delete(packet);
  2219. on_auto_mount = true;
  2220. }
  2221. }
  2222. else {
  2223. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2224. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2225. EndAutoMount();
  2226. }
  2227. SetPendingFlightPath(0);
  2228. }
  2229. else
  2230. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2231. break;
  2232. }
  2233. case OP_EarlyLandingRequestMsg:
  2234. {
  2235. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2236. EndAutoMount();
  2237. break;
  2238. }
  2239. case OP_SubmitCharCust:
  2240. {
  2241. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2242. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2243. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2244. int8 type = packet->getType_int8_ByName("type");
  2245. if (type == 0) {
  2246. if (player->custNPC) {
  2247. player->custNPCTarget->CustomizeAppearance(packet);
  2248. current_zone->SendSpawnChanges(player->custNPCTarget);
  2249. }
  2250. else {
  2251. player->CustomizeAppearance(packet);
  2252. current_zone->SendSpawnChanges(player);
  2253. }
  2254. }
  2255. }
  2256. if (player->custNPC) {
  2257. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2258. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2259. if (player->custNPCTarget->IsBot())
  2260. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2261. player->custNPC = false;
  2262. player->custNPCTarget = 0;
  2263. player->changed = true;
  2264. player->info_changed = true;
  2265. current_zone->SendSpawnChanges(player, this);
  2266. }
  2267. break;
  2268. }
  2269. default: {
  2270. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2271. const char* name = app->GetOpcodeName();
  2272. if (name)
  2273. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2274. else
  2275. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2276. //DumpPacket(app);
  2277. }
  2278. }
  2279. if (!eqs || !eqs->CheckActive()) {
  2280. return false;
  2281. }
  2282. return ret;
  2283. }
  2284. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2285. if (!item) {
  2286. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2287. return false;
  2288. }
  2289. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2290. int16 lore_stack_count = 0;
  2291. if(((conflictItemList = player->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2292. (conflictequipmentList = player->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2293. (conflictAppearanceEquipmentList = player->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2294. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2295. return false;
  2296. }
  2297. else if(conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2298. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2299. return false;
  2300. }
  2301. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2302. if (player->item_list.AssignItemToFreeSlot(item)) {
  2303. if(item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2304. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  2305. if (gmi && gmi->group_id)
  2306. {
  2307. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2308. if (group)
  2309. {
  2310. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2311. deque<GroupMemberInfo*>* members = group->GetMembers();
  2312. if(members) {
  2313. for (int8 i = 0; i < members->size(); i++) {
  2314. Entity* member = members->at(i)->member;
  2315. if(!member)
  2316. continue;
  2317. if ((member->GetZone() != this->GetPlayer()->GetZone()))
  2318. continue;
  2319. if(member->IsPlayer()) {
  2320. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2321. item->save_needed = true;
  2322. }
  2323. }
  2324. }
  2325. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2326. }
  2327. }
  2328. }
  2329. int8 type = CHANNEL_LOOT;
  2330. if (entity) {
  2331. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2332. }
  2333. else {
  2334. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2335. }
  2336. Guild* guild = player->GetGuild();
  2337. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2338. char adjective[32];
  2339. int8 type;
  2340. memset(adjective, 0, sizeof(adjective));
  2341. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2342. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2343. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2344. }
  2345. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2346. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2347. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2348. }
  2349. else {
  2350. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2351. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2352. }
  2353. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2354. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2355. }
  2356. if (item->GetItemScript() && lua_interface)
  2357. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2358. CheckPlayerQuestsItemUpdate(item);
  2359. return true;
  2360. }
  2361. else
  2362. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2363. }
  2364. else
  2365. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2366. return false;
  2367. }
  2368. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2369. if (!entity) {
  2370. return false;
  2371. }
  2372. Item* item = entity->LootItem(item_id);
  2373. bool success = false;
  2374. success = HandleLootItem(entity, item);
  2375. if(!success)
  2376. entity->AddLootItem(item);
  2377. return success;
  2378. }
  2379. void Client::HandleLoot(EQApplicationPacket* app) {
  2380. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2381. if (packet) {
  2382. packet->LoadPacketData(app->pBuffer, app->size);
  2383. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2384. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2385. safe_delete(packet);
  2386. int32 item_id = 0;
  2387. Item* item = 0;
  2388. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2389. if (player->HasPendingLootItems(loot_id)) {
  2390. Item* master_item = 0;
  2391. if (loot_all) {
  2392. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2393. if (items) {
  2394. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2395. master_item = items->at(i);
  2396. if (master_item) {
  2397. item = new Item(master_item);
  2398. if (item) {
  2399. loot_all = HandleLootItem(0, item);
  2400. if (loot_all)
  2401. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2402. }
  2403. }
  2404. }
  2405. safe_delete(items);
  2406. }
  2407. }
  2408. else {
  2409. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2410. if (packet) {
  2411. packet->LoadPacketData(app->pBuffer, app->size);
  2412. item_id = packet->getType_int32_ByName("item_id");
  2413. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2414. if (items) {
  2415. for (int32 i = 0; i < items->size(); i++) {
  2416. master_item = items->at(i);
  2417. if (master_item && master_item->details.item_id == item_id) {
  2418. item = new Item(master_item);
  2419. if (item && HandleLootItem(0, item))
  2420. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2421. break;
  2422. }
  2423. }
  2424. safe_delete(items);
  2425. }
  2426. safe_delete(packet);
  2427. }
  2428. }
  2429. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2430. if (outapp)
  2431. QueuePacket(outapp);
  2432. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2433. }
  2434. else {
  2435. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2436. if (loot_all) {
  2437. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2438. loot_all = HandleLootItem(spawn, item_id);
  2439. }
  2440. }
  2441. else {
  2442. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2443. if (packet) {
  2444. packet->LoadPacketData(app->pBuffer, app->size);
  2445. item_id = packet->getType_int32_ByName("item_id");
  2446. HandleLootItem(spawn, item_id);
  2447. safe_delete(packet);
  2448. }
  2449. }
  2450. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2451. if (outapp)
  2452. QueuePacket(outapp);
  2453. Loot(spawn);
  2454. if (!spawn->HasLoot()) {
  2455. CloseLoot(loot_id);
  2456. if (spawn->IsNPC())
  2457. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2458. }
  2459. }
  2460. else {
  2461. if (!spawn) {
  2462. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2463. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2464. }
  2465. else
  2466. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2467. }
  2468. }
  2469. }
  2470. }
  2471. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2472. PacketStruct* request = 0;
  2473. // cout << "Request: \n";
  2474. // DumpPacket(app);
  2475. switch (app->pBuffer[0]) {
  2476. case 0: { //items
  2477. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2478. if (request) {
  2479. request->LoadPacketData(app->pBuffer, app->size);
  2480. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2481. if (!item)
  2482. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2483. if (item) {
  2484. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2485. if (response) {
  2486. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2487. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2488. response->setSmallStringByName("name", item->name.c_str());
  2489. EQ2Packet* app2 = response->serialize();
  2490. //DumpPacket(app2);
  2491. QueuePacket(app2);
  2492. safe_delete(response);
  2493. }
  2494. }
  2495. }
  2496. break;
  2497. }
  2498. case 2: {//spells
  2499. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2500. if (request) {
  2501. request->LoadPacketData(app->pBuffer, app->size);
  2502. int32 id = request->getType_int32_ByName("id");
  2503. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2504. Spell* spell = master_spell_list.GetSpell(id, tier);
  2505. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2506. if (response) {
  2507. response->setDataByName("request_type", 2);
  2508. response->setDataByName("unique_id", tier);
  2509. response->setDataByName("id", id);
  2510. if (spell)
  2511. response->setSmallStringByName("name", spell->GetName());
  2512. else
  2513. response->setSmallStringByName("name", "Unknown Spell");
  2514. EQ2Packet* app2 = response->serialize();
  2515. // DumpPacket(app2);
  2516. QueuePacket(app2);
  2517. safe_delete(response);
  2518. }
  2519. }
  2520. break;
  2521. }
  2522. default: {
  2523. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2524. }
  2525. }
  2526. safe_delete(request);
  2527. }
  2528. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2529. PacketStruct* request = 0;
  2530. if (!app || app->size == 0)
  2531. return;
  2532. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2533. //DumpPacket(app);
  2534. int8 type = app->pBuffer[0];
  2535. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2536. if (version <= 283) {
  2537. if (type == 1)
  2538. type = 4;
  2539. else if (type == 2)
  2540. type = 5;
  2541. }
  2542. if (type == 3) {
  2543. Spell* spell = 0;
  2544. bool trait_display;
  2545. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2546. if (!request) {
  2547. return;
  2548. }
  2549. request->LoadPacketData(app->pBuffer, app->size);
  2550. int32 id = request->getType_int32_ByName("id");
  2551. int32 tier = request->getType_int32_ByName("tier");
  2552. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2553. bool display = true;
  2554. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2555. display = false;
  2556. else if (version <= 546)
  2557. display = request->getType_int8_ByName("display");
  2558. else if (version > 546)
  2559. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2560. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2561. if (trait_tier != 0xFFFFFFFF) {
  2562. spell = master_spell_list.GetSpell(id, trait_tier);
  2563. if (!spell) {
  2564. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2565. }
  2566. trait_display = true;
  2567. }
  2568. else {
  2569. spell = master_spell_list.GetSpell(id, tier);
  2570. trait_display = false;
  2571. }
  2572. // if we can't find it on the master spell list, see if it is a custom spell
  2573. if (!spell)
  2574. {
  2575. lua_interface->FindCustomSpellLock();
  2576. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2577. if (tmpSpell)
  2578. spell = tmpSpell->spell;
  2579. lua_interface->FindCustomSpellUnlock();
  2580. }
  2581. if (spell && !CountSentSpell(id, tier)) {
  2582. if (!spell->IsCopiedSpell())
  2583. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2584. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2585. //DumpPacket(app);
  2586. QueuePacket(app);
  2587. }
  2588. }
  2589. else if (type == 0) {
  2590. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2591. if (!request) {
  2592. return;
  2593. }
  2594. request->LoadPacketData(app->pBuffer, app->size);
  2595. int32 id = request->getType_int32_ByName("id");
  2596. Item* item = 0;
  2597. // translate from unique id to spawn id for houses
  2598. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2599. bool wasSpawn = false;
  2600. if (spawn)
  2601. {
  2602. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2603. if (item)
  2604. {
  2605. wasSpawn = true;
  2606. item = new Item(item);
  2607. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2608. }
  2609. }
  2610. if (!item)
  2611. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2612. if (!item)
  2613. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2614. if (!item)
  2615. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2616. if (!item)
  2617. item = master_item_list.GetItem(id);
  2618. if (item) {// && sent_item_details.count(id) == 0){
  2619. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2620. sent_item_details[id] = true;
  2621. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2622. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2623. //DumpPacket(app);
  2624. QueuePacket(app);
  2625. if (wasSpawn)
  2626. delete item;
  2627. }
  2628. else {
  2629. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2630. DumpPacket(app);
  2631. }
  2632. }
  2633. else if (type == 1) {
  2634. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2635. if (!request) {
  2636. return;
  2637. }
  2638. request->LoadPacketData(app->pBuffer, app->size);
  2639. int32 id = request->getType_int32_ByName("id");
  2640. int32 unique_id = request->getType_int32_ByName("unique_id");
  2641. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2642. if (!item)
  2643. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2644. if (!item)
  2645. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2646. if (!item)
  2647. item = master_item_list.GetItem(id);
  2648. if (item) {
  2649. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2650. sent_item_details[id] = true;
  2651. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2652. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2653. //DumpPacket(app);
  2654. QueuePacket(app);
  2655. }
  2656. else {
  2657. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2658. DumpPacket(app);
  2659. }
  2660. }
  2661. else if (type == 2) {
  2662. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2663. if (!request) {
  2664. return;
  2665. }
  2666. request->LoadPacketData(app->pBuffer, app->size);
  2667. int32 id = request->getType_int32_ByName("item_id");
  2668. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2669. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2670. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2671. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2672. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2673. //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);
  2674. Item* item = master_item_list.GetItem(id);
  2675. if (item) {
  2676. //only display popup for non merchant links
  2677. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2678. //DumpPacket(app);
  2679. QueuePacket(app);
  2680. }
  2681. else {
  2682. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2683. DumpPacket(app);
  2684. }
  2685. }
  2686. else if (type == 4) { //spell effect
  2687. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2688. if (!request) {
  2689. return;
  2690. }
  2691. request->LoadPacketData(app->pBuffer, app->size);
  2692. int32 id = request->getType_int32_ByName("id");
  2693. int16 display = request->getType_int8_ByName("partial_info");
  2694. SpellEffects* effect = player->GetSpellEffect(id);
  2695. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2696. if (effect) {
  2697. int8 tier = effect->tier;
  2698. Spell* spell = master_spell_list.GetSpell(id, tier);
  2699. // if we can't find it on the master spell list, see if it is a custom spell
  2700. if (!spell)
  2701. {
  2702. lua_interface->FindCustomSpellLock();
  2703. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2704. EQ2Packet* pack = 0;
  2705. if (tmpSpell)
  2706. spell = tmpSpell->spell;
  2707. lua_interface->FindCustomSpellUnlock();
  2708. }
  2709. if (spell && !CountSentSpell(id, tier)) {
  2710. if (!spell->IsCopiedSpell())
  2711. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2712. int8 type = 0;
  2713. if (version <= 283)
  2714. type = 1;
  2715. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2716. //DumpPacket(app);
  2717. QueuePacket(app);
  2718. }
  2719. }
  2720. }
  2721. else if (type == 5) { // recipe info
  2722. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2723. if (!request)
  2724. return;
  2725. request->LoadPacketData(app->pBuffer, app->size);
  2726. int32 id = request->getType_int32_ByName("unknown_id");
  2727. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2728. if (recipe) {
  2729. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2730. //DumpPacket(app);
  2731. QueuePacket(app);
  2732. }
  2733. }
  2734. else if (type == 6) { // AA spell info
  2735. Spell* spell = 0;
  2736. //Spell* spell2 = 0;
  2737. //AltAdvanceData* data = 0;
  2738. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2739. if (!request)
  2740. return;
  2741. request->LoadPacketData(app->pBuffer, app->size);
  2742. int32 id = request->getType_int32_ByName("id");
  2743. int32 tier = GetPlayer()->GetSpellTier(id);
  2744. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2745. //data = master_aa_list.GetAltAdvancement(id);
  2746. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2747. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2748. spell = master_spell_list.GetSpell(id, tier);
  2749. if (!spell)
  2750. spell = master_spell_list.GetSpell(id, 1);
  2751. if (!spell)
  2752. {
  2753. lua_interface->FindCustomSpellLock();
  2754. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2755. if (tmpSpell)
  2756. spell = tmpSpell->spell;
  2757. lua_interface->FindCustomSpellUnlock();
  2758. }
  2759. if (!spell)
  2760. {
  2761. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2762. return;
  2763. }
  2764. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2765. if (!spell->IsCopiedSpell())
  2766. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2767. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2768. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2769. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2770. //DumpPacket(app);
  2771. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2772. QueuePacket(app);
  2773. //}
  2774. }
  2775. else {
  2776. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2777. DumpPacket(app);
  2778. }
  2779. safe_delete(request);
  2780. }
  2781. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2782. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2783. if (request) {
  2784. request->LoadPacketData(app->pBuffer, app->size);
  2785. int32 id = request->getType_int32_ByName("id");
  2786. int32 bar = request->getType_int32_ByName("hotbar_number");
  2787. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2788. int32 type = request->getType_int32_ByName("type");
  2789. int8 tier = request->getType_int32_ByName("unique_id");
  2790. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2791. Spell* spell = 0;
  2792. if (type == 0xFFFFFFFF)
  2793. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2794. else {
  2795. if (type == QUICKBAR_NORMAL)
  2796. spell = master_spell_list.GetSpell(id, tier);
  2797. if (spell)
  2798. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2799. else
  2800. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2801. }
  2802. safe_delete(request);
  2803. }
  2804. }
  2805. bool Client::Process(bool zone_process) {
  2806. if (!eqs) {
  2807. return false;
  2808. }
  2809. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2810. return true;
  2811. }
  2812. if (new_client_login) {
  2813. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2814. SendLoginInfo();
  2815. new_client_login = false;
  2816. }
  2817. bool ret = true;
  2818. sockaddr_in to;
  2819. memset((char*)&to, 0, sizeof(to));
  2820. to.sin_family = AF_INET;
  2821. to.sin_port = port;
  2822. to.sin_addr.s_addr = ip;
  2823. /************ Get all packets from packet manager out queue and process them ************/
  2824. EQApplicationPacket* app = 0;
  2825. if (eqs && !eqs->CheckActive()) {
  2826. num_active_failures++;
  2827. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2828. if (num_active_failures > 100) {
  2829. return false;
  2830. }
  2831. return true;
  2832. }
  2833. while (ret && eqs && (app = eqs->PopPacket())) {
  2834. ret = HandlePacket(app);
  2835. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2836. delete app;
  2837. }
  2838. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2839. player->ApplyPassiveSpells();
  2840. //database.LoadCharacterActiveSpells(player);
  2841. player->UnlockAllSpells(true);
  2842. should_load_spells = false;
  2843. }
  2844. if(spawn_removal_timer.Check() && GetPlayer()) {
  2845. GetPlayer()->CheckSpawnStateQueue();
  2846. }
  2847. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2848. {
  2849. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2850. return false;
  2851. }
  2852. if (quest_updates) {
  2853. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2854. ProcessQuestUpdates();
  2855. }
  2856. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2857. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2858. CheckQuestQueue();
  2859. }
  2860. MSaveSpellStateMutex.lock();
  2861. if(save_spell_state_timer.Check())
  2862. {
  2863. save_spell_state_timer.Disable();
  2864. GetPlayer()->SaveSpellEffects();
  2865. }
  2866. MSaveSpellStateMutex.unlock();
  2867. if (temp_placement_timer.Check()) {
  2868. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2869. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2870. hasSentTempPlacementSpawn = true;
  2871. temp_placement_timer.Disable();
  2872. }
  2873. }
  2874. if (pos_update.Check())
  2875. {
  2876. ProcessStateCommands();
  2877. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2878. if(GetPlayer()->GetRegionMap())
  2879. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2880. if(player_pos_changed && IsReadyForUpdates()) {
  2881. //GetPlayer()->CalculateLocation();
  2882. client_list.CheckPlayersInvisStatus(this);
  2883. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2884. player_pos_changed = false;
  2885. GetCurrentZone()->CheckTransporters(this);
  2886. if(GetPlayer()->GetRegionMap())
  2887. {
  2888. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2889. {
  2890. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2891. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2892. }
  2893. else
  2894. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2895. }
  2896. }
  2897. }
  2898. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2899. lua_interface->UpdateDebugClients(this);
  2900. if (quest_pos_timer.Check())
  2901. CheckPlayerQuestsLocationUpdate();
  2902. if (player->GetSkills()->HasSkillUpdates()) {
  2903. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2904. if (skills) {
  2905. Skill* skill = 0;
  2906. vector<Skill*>::iterator itr;
  2907. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2908. skill = *itr;
  2909. SkillChanged(skill, skill->previous_val, skill->current_val);
  2910. }
  2911. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2912. if (app) QueuePacket(app);
  2913. safe_delete(skills);
  2914. }
  2915. }
  2916. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2917. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2918. safe_delete(current_rez.expire_timer);
  2919. current_rez.expire_timer = 0;
  2920. current_rez.active = false;
  2921. current_rez.caster = 0;
  2922. current_rez.crit = false;
  2923. current_rez.crit_mod = 0;
  2924. current_rez.expire_timer = 0;
  2925. current_rez.heal_name = "";
  2926. current_rez.hp_perc = 0;
  2927. current_rez.mp_perc = 0;
  2928. current_rez.no_calcs = false;
  2929. current_rez.range = 0;
  2930. current_rez.should_delete = false;
  2931. current_rez.spell_name = "";
  2932. current_rez.spell_visual = 0;
  2933. current_rez.subspell = 0;
  2934. }
  2935. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2936. // Quest timers
  2937. Quest* failed_step = 0;
  2938. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2939. if (quest_timers.size() > 0) {
  2940. vector<int32>::iterator itr;
  2941. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2942. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2943. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2944. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2945. Quest* quest = player_quests->at(*itr);
  2946. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2947. failed_step = quest;
  2948. break;
  2949. }
  2950. }
  2951. else {
  2952. itr = quest_timers.erase(itr);
  2953. break;
  2954. }
  2955. }
  2956. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  2957. }
  2958. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2959. if (failed_step)
  2960. failed_step->StepFailed(failed_step->GetTimerStep());
  2961. if (player->ControlFlagsChanged())
  2962. player->SendControlFlagUpdates(this);
  2963. if (camp_timer && camp_timer->Check()) {
  2964. ResetSendMail();
  2965. if(getConnection())
  2966. getConnection()->SendDisconnect(false);
  2967. safe_delete(camp_timer);
  2968. ret = false;
  2969. }
  2970. if (!eqs || (eqs && !eqs->CheckActive()))
  2971. ret = false;
  2972. // redundant to client disconnect
  2973. // if(!ret)
  2974. // Save();
  2975. return ret;
  2976. }
  2977. ClientList::ClientList() {
  2978. MClients.SetName("ClientList::MClients");
  2979. }
  2980. ClientList::~ClientList() {
  2981. }
  2982. void ClientList::ReloadQuests() {
  2983. list<Client*>::iterator client_iter;
  2984. Client* client = 0;
  2985. MClients.readlock(__FUNCTION__, __LINE__);
  2986. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2987. client = *client_iter;
  2988. if (client)
  2989. client->ReloadQuests();
  2990. }
  2991. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2992. }
  2993. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2994. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2995. return;
  2996. list<Client*>::iterator client_iter;
  2997. Client* client = 0;
  2998. MClients.readlock(__FUNCTION__, __LINE__);
  2999. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3000. client = *client_iter;
  3001. if (client == owner || client->GetPlayer() == NULL)
  3002. continue;
  3003. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3004. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3005. }
  3006. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3007. }
  3008. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3009. list<Client*>::iterator client_iter;
  3010. Client* client = 0;
  3011. MClients.readlock(__FUNCTION__, __LINE__);
  3012. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3013. client = *client_iter;
  3014. if (!client->GetPlayer())
  3015. continue;
  3016. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3017. }
  3018. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3019. }
  3020. int32 ClientList::Count() {
  3021. return client_list.size();
  3022. }
  3023. void ClientList::Add(Client* client) {
  3024. MClients.writelock(__FUNCTION__, __LINE__);
  3025. client_list.push_back(client);
  3026. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3027. }
  3028. Client* ClientList::FindByAccountID(int32 account_id) {
  3029. list<Client*>::iterator client_iter;
  3030. Client* client = 0;
  3031. Client* ret = 0;
  3032. MClients.readlock(__FUNCTION__, __LINE__);
  3033. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3034. client = *client_iter;
  3035. if (client->GetAccountID() == account_id) {
  3036. ret = client;
  3037. break;
  3038. }
  3039. }
  3040. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3041. return ret;
  3042. }
  3043. Client* ClientList::FindByName(char* charName) {
  3044. list<Client*>::iterator client_iter;
  3045. Client* client = 0;
  3046. Client* ret = 0;
  3047. MClients.readlock(__FUNCTION__, __LINE__);
  3048. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3049. client = *client_iter;
  3050. if (!client || !client->GetPlayer())
  3051. continue;
  3052. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3053. ret = client;
  3054. break;
  3055. }
  3056. }
  3057. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3058. return ret;
  3059. }
  3060. Client* ClientList::Get(int32 ip, int16 port) {
  3061. list<Client*>::iterator client_iter;
  3062. Client* client = 0;
  3063. Client* ret = 0;
  3064. MClients.readlock(__FUNCTION__, __LINE__);
  3065. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3066. client = *client_iter;
  3067. if (client->GetIP() == ip && client->GetPort() == port) {
  3068. ret = client;
  3069. break;
  3070. }
  3071. }
  3072. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3073. return ret;
  3074. }
  3075. void ClientList::Process() {
  3076. list<Client*>::iterator client_iter;
  3077. list<Client*>::iterator erase_iter;
  3078. Client* client = 0;
  3079. MClients.readlock(__FUNCTION__, __LINE__);
  3080. erase_iter = client_list.end();
  3081. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3082. client = *client_iter;
  3083. // have a sanity check because the client list can sometimes obtain null client pointers
  3084. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3085. erase_iter = client_iter;
  3086. break;
  3087. }
  3088. }
  3089. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3090. if (erase_iter != client_list.end()) {
  3091. client = *erase_iter;
  3092. MClients.writelock(__FUNCTION__, __LINE__);
  3093. client_list.erase(erase_iter);
  3094. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3095. if (client && !client->remove_from_list) {
  3096. struct in_addr in;
  3097. in.s_addr = client->GetIP();
  3098. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3099. safe_delete(client);
  3100. }
  3101. }
  3102. }
  3103. void ClientList::RemoveConnection(EQStream* eqs) {
  3104. Client* client;
  3105. if (eqs) {
  3106. list<Client*>::iterator client_iter;
  3107. MClients.readlock(__FUNCTION__, __LINE__);
  3108. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3109. client = *client_iter;
  3110. if (client->getConnection() == eqs)
  3111. client->Disconnect(true);
  3112. }
  3113. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3114. }
  3115. }
  3116. bool ClientList::ContainsStream(EQStream* eqs) {
  3117. if (!eqs) {
  3118. return false;
  3119. }
  3120. list<Client*>::iterator client_iter;
  3121. bool ret = false;
  3122. MClients.readlock(__FUNCTION__, __LINE__);
  3123. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3124. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3125. ret = true;
  3126. break;
  3127. }
  3128. }
  3129. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3130. return ret;
  3131. }
  3132. void ClientList::Remove(Client* client, bool remove_data) {
  3133. client->remove_from_list = true;
  3134. if (remove_data) {
  3135. safe_delete(client);
  3136. }
  3137. }
  3138. void Client::SetCurrentZone(int32 id) {
  3139. if (current_zone) {
  3140. //current_zone->GetCombat()->RemoveHate(player);
  3141. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3142. }
  3143. SetCurrentZone(zone_list.Get(id));
  3144. }
  3145. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  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.GetByInstanceID(id, zoneid));
  3151. }
  3152. ZoneServer* Client::GetCurrentZone() {
  3153. return current_zone;
  3154. }
  3155. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3156. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3157. if (channel_type == CHANNEL_LOOT)
  3158. return CHANNEL_COLOR_NEW_LOOT;
  3159. }
  3160. else if (GetVersion() >= 973) {
  3161. if (channel_type == CHANNEL_LOOT)
  3162. return CHANNEL_COLOR_NEWEST_LOOT;
  3163. }
  3164. if (GetVersion() <= 283) {
  3165. if (channel_type <=12)
  3166. return channel_type;
  3167. switch (channel_type) {
  3168. case CHANNEL_GROUP_CHAT:
  3169. case CHANNEL_GROUP_SAY:
  3170. case CHANNEL_RAID_SAY:
  3171. case CHANNEL_GUILD_CHAT:
  3172. case CHANNEL_GUILD_SAY:
  3173. case CHANNEL_OFFICER_SAY:
  3174. case CHANNEL_GUILD_MOTD:
  3175. return channel_type - 1;
  3176. case CHANNEL_PRIVATE_CHAT:
  3177. case CHANNEL_NONPLAYER_TELL:
  3178. return channel_type - 5;
  3179. case CHANNEL_PRIVATE_TELL:
  3180. case CHANNEL_TELL_FROM_CS:
  3181. return channel_type - 6;
  3182. case CHANNEL_CHAT_CHANNEL_TEXT:
  3183. case CHANNEL_OUT_OF_CHARACTER:
  3184. case CHANNEL_AUCTION:
  3185. case CHANNEL_CUSTOM_CHANNEL:
  3186. case CHANNEL_CHARACTER_TEXT:
  3187. case CHANNEL_REWARD:
  3188. case CHANNEL_DEATH:
  3189. case CHANNEL_PET_CHAT:
  3190. case CHANNEL_SKILL:
  3191. return channel_type - 7;
  3192. case CHANNEL_SPELLS:
  3193. case CHANNEL_YOU_CAST:
  3194. case CHANNEL_YOU_FAIL:
  3195. return channel_type - 8;
  3196. case CHANNEL_FRIENDLY_CAST:
  3197. case CHANNEL_FRIENDLY_FAIL:
  3198. case CHANNEL_OTHER_CAST:
  3199. case CHANNEL_OTHER_FAIL:
  3200. case CHANNEL_HOSTILE_CAST:
  3201. case CHANNEL_HOSTILE_FAIL:
  3202. case CHANNEL_WORN_OFF:
  3203. case CHANNEL_SPELLS_OTHER:
  3204. return channel_type - 9;
  3205. case CHANNEL_COMBAT:
  3206. return channel_type - 15;
  3207. case CHANNEL_HEROIC_OPPORTUNITY:
  3208. case CHANNEL_NON_MELEE_DAMAGE:
  3209. case CHANNEL_DAMAGE_SHIELD:
  3210. return channel_type - 16;
  3211. case CHANNEL_MELEE_COMBAT:
  3212. case CHANNEL_WARNINGS:
  3213. case CHANNEL_YOU_HIT:
  3214. case CHANNEL_YOU_MISS:
  3215. case CHANNEL_ATTACKER_HITS:
  3216. case CHANNEL_ATTACKER_MISSES:
  3217. return channel_type - 18;
  3218. case CHANNEL_OTHER_HIT:
  3219. case CHANNEL_OTHER_MISSES:
  3220. case CHANNEL_CRITICAL_HIT:
  3221. return channel_type - 22;
  3222. case CHANNEL_OTHER:
  3223. case CHANNEL_MONEY_SPLIT:
  3224. case CHANNEL_LOOT:
  3225. return channel_type - 30;
  3226. case CHANNEL_COMMAND_TEXT:
  3227. case CHANNEL_BROADCAST:
  3228. case CHANNEL_WHO:
  3229. case CHANNEL_COMMANDS:
  3230. case CHANNEL_MERCHANT:
  3231. case CHANNEL_MERCHANT_BUY_SELL:
  3232. case CHANNEL_CONSIDER_MESSAGE:
  3233. case CHANNEL_CON_MINUS_2:
  3234. case CHANNEL_CON_MINUS_1:
  3235. case CHANNEL_CON_0:
  3236. case CHANNEL_CON_1:
  3237. case CHANNEL_CON_2:
  3238. return channel_type - 31;
  3239. default: {
  3240. return CHANNEL_DEFAULT;
  3241. }
  3242. }
  3243. }
  3244. else if (GetVersion() <= 546) {
  3245. if (channel_type < 20)
  3246. return channel_type;
  3247. switch (channel_type) {
  3248. case CHANNEL_GUILD_MOTD:
  3249. case CHANNEL_GUILD_MEMBER_ONLINE:
  3250. case CHANNEL_GUILD_EVENT:
  3251. return channel_type + 1;
  3252. case CHANNEL_PRIVATE_CHAT:
  3253. case CHANNEL_NONPLAYER_TELL:
  3254. return channel_type - 1;
  3255. case CHANNEL_PRIVATE_TELL:
  3256. case CHANNEL_TELL_FROM_CS:
  3257. case CHANNEL_ARENA:
  3258. case CHANNEL_CHAT_CHANNEL_TEXT:
  3259. case CHANNEL_OUT_OF_CHARACTER:
  3260. case CHANNEL_AUCTION:
  3261. case CHANNEL_CUSTOM_CHANNEL:
  3262. case CHANNEL_CHARACTER_TEXT:
  3263. case CHANNEL_REWARD:
  3264. case CHANNEL_DEATH:
  3265. case CHANNEL_PET_CHAT:
  3266. case CHANNEL_SKILL:
  3267. case CHANNEL_FACTION:
  3268. case CHANNEL_SPELLS:
  3269. case CHANNEL_YOU_CAST:
  3270. case CHANNEL_YOU_FAIL:
  3271. return channel_type - 2;
  3272. case CHANNEL_FRIENDLY_CAST:
  3273. case CHANNEL_FRIENDLY_FAIL:
  3274. case CHANNEL_OTHER_CAST:
  3275. case CHANNEL_OTHER_FAIL:
  3276. case CHANNEL_HOSTILE_CAST:
  3277. case CHANNEL_HOSTILE_FAIL:
  3278. case CHANNEL_WORN_OFF:
  3279. case CHANNEL_SPELLS_OTHER:
  3280. case CHANNEL_HEAL_SPELLS:
  3281. case CHANNEL_HEALS:
  3282. case CHANNEL_FRIENDLY_HEALS:
  3283. case CHANNEL_OTHER_HEALS:
  3284. case CHANNEL_HOSTILE_HEALS:
  3285. return channel_type - 3;
  3286. case CHANNEL_COMBAT:
  3287. case CHANNEL_GENERAL_COMBAT:
  3288. case CHANNEL_HEROIC_OPPORTUNITY:
  3289. case CHANNEL_NON_MELEE_DAMAGE:
  3290. case CHANNEL_DAMAGE_SHIELD:
  3291. case CHANNEL_WARD:
  3292. return channel_type - 4;
  3293. case CHANNEL_MELEE_COMBAT:
  3294. case CHANNEL_WARNINGS:
  3295. case CHANNEL_YOU_HIT:
  3296. case CHANNEL_YOU_MISS:
  3297. case CHANNEL_ATTACKER_HITS:
  3298. case CHANNEL_ATTACKER_MISSES:
  3299. case CHANNEL_YOUR_PET_HITS:
  3300. case CHANNEL_YOUR_PET_MISSES:
  3301. case CHANNEL_ATTACKER_HITS_PET:
  3302. case CHANNEL_ATTACKER_MISSES_PET:
  3303. case CHANNEL_OTHER_HIT:
  3304. case CHANNEL_OTHER_MISSES:
  3305. return channel_type - 5;
  3306. case CHANNEL_OTHER:
  3307. case CHANNEL_MONEY_SPLIT:
  3308. case CHANNEL_LOOT:
  3309. return channel_type - 14;
  3310. case CHANNEL_COMMAND_TEXT:
  3311. case CHANNEL_BROADCAST:
  3312. case CHANNEL_WHO:
  3313. case CHANNEL_COMMANDS:
  3314. case CHANNEL_MERCHANT:
  3315. case CHANNEL_MERCHANT_BUY_SELL:
  3316. case CHANNEL_CONSIDER_MESSAGE:
  3317. case CHANNEL_CON_MINUS_2:
  3318. case CHANNEL_CON_MINUS_1:
  3319. case CHANNEL_CON_0:
  3320. case CHANNEL_CON_1:
  3321. case CHANNEL_CON_2:
  3322. case CHANNEL_TRADESKILLS:
  3323. case CHANNEL_HARVESTING:
  3324. case CHANNEL_HARVESTING_WARNINGS:
  3325. return channel_type - 15;
  3326. default: {
  3327. return CHANNEL_DEFAULT;
  3328. }
  3329. }
  3330. }
  3331. else {
  3332. switch (channel_type) {
  3333. default: {
  3334. return channel_type;
  3335. }
  3336. }
  3337. }
  3338. return channel_type;
  3339. }
  3340. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3341. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3342. return;
  3343. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3344. if (packet) {
  3345. packet->setDataByName("from", from->GetPlayer()->GetName());
  3346. packet->setDataByName("to", to);
  3347. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3348. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3349. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3350. packet->setDataByName("unknown2", 1, 1);
  3351. packet->setDataByName("show_bubble", 1);
  3352. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3353. packet->setDataByName("understood", 1);
  3354. }
  3355. packet->setDataByName("time", 2);
  3356. packet->setDataByName("language", current_language_id);
  3357. packet->setMediumStringByName("message", message);
  3358. EQ2Packet* outpacket = packet->serialize();
  3359. QueuePacket(outpacket);
  3360. safe_delete(packet);
  3361. }
  3362. }
  3363. void Client::SimpleMessage(int8 color, const char* message) {
  3364. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3365. if (command_packet) {
  3366. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3367. command_packet->setMediumStringByName("text", message);
  3368. command_packet->setDataByName("unknown02", 0x00ff);
  3369. EQ2Packet* outapp = command_packet->serialize();
  3370. QueuePacket(outapp);
  3371. safe_delete(command_packet);
  3372. }
  3373. }
  3374. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3375. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3376. if (packet) {
  3377. int8 xxx = spell->GetSpellData()->is_aa;
  3378. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3379. packet->setDataByName("spell_id", spell->GetSpellID());
  3380. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3381. packet->setDataByName("spell_name", spell->GetName());
  3382. if(add_silently)
  3383. packet->setDataByName("add_silently", 1);
  3384. if(add_to_hotbar)
  3385. packet->setDataByName("add_to_hotbar", 1);
  3386. packet->setDataByName("unknown", xxx);
  3387. packet->setDataByName("display_spell_tier", 1);
  3388. packet->setDataByName("unknown3", 1);
  3389. packet->setDataByName("tier", spell->GetSpellTier());
  3390. packet->setDataByName("icon", spell->GetSpellIcon());
  3391. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3392. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3393. //packet->PrintPacket();
  3394. EQ2Packet* outapp = packet->serialize();
  3395. //DumpPacket(outapp);
  3396. QueuePacket(outapp);
  3397. safe_delete(packet);
  3398. }
  3399. }
  3400. void Client::Message(int8 type, const char* message, ...) {
  3401. va_list argptr;
  3402. char buffer[4096];
  3403. va_start(argptr, message);
  3404. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3405. va_end(argptr);
  3406. SimpleMessage(type, buffer);
  3407. }
  3408. void Client::Disconnect(bool send_disconnect)
  3409. {
  3410. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3411. this->Save();
  3412. this->GetPlayer()->WritePlayerStatistics();
  3413. SetConnected(false);
  3414. if (send_disconnect && getConnection())
  3415. getConnection()->SendDisconnect(true);
  3416. eqs = 0;
  3417. }
  3418. bool Client::Summon(const char* search_name) {
  3419. Spawn* target = 0;
  3420. if (search_name || GetPlayer()->GetTarget()) {
  3421. Client* search_client = 0;
  3422. if (search_name) {
  3423. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3424. if (target && target->IsPlayer())
  3425. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3426. if (!target) {
  3427. search_client = zone_list.GetClientByCharName(string(search_name));
  3428. if (search_client)
  3429. target = search_client->GetPlayer();
  3430. }
  3431. }
  3432. else
  3433. target = GetPlayer()->GetTarget();
  3434. if (target && target != GetPlayer()) {
  3435. target->SetX(GetPlayer()->GetX());
  3436. target->SetY(GetPlayer()->GetY());
  3437. target->SetZ(GetPlayer()->GetZ());
  3438. target->SetHeading(GetPlayer()->GetHeading());
  3439. if (!target->IsPlayer()) {
  3440. target->SetSpawnOrigX(target->GetX());
  3441. target->SetSpawnOrigY(target->GetY());
  3442. target->SetSpawnOrigZ(target->GetZ());
  3443. target->SetSpawnOrigHeading(target->GetHeading());
  3444. }
  3445. target->SetLocation(GetPlayer()->GetLocation());
  3446. }
  3447. else if (target)
  3448. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3449. if (search_client && search_client != this) {
  3450. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3451. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3452. if (search_client->GetCurrentZone() != GetCurrentZone())
  3453. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3454. else {
  3455. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3456. if (app)
  3457. search_client->QueuePacket(app);
  3458. }
  3459. }
  3460. }
  3461. if (!target)
  3462. return false;
  3463. else
  3464. return true;
  3465. }
  3466. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3467. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3468. if(instanceType < 1)
  3469. return std::string("");
  3470. ZoneServer* instance_zone = nullptr;
  3471. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3472. if (data) {
  3473. // If lockout instances check to see if we are locked out
  3474. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3475. int32 time = 0;
  3476. // Check success timer
  3477. if (data->last_success_timestamp > 0) {
  3478. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3479. // Timer has not expired yet can't re enter
  3480. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3481. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3482. }
  3483. }
  3484. // Check failure timer
  3485. if (data->last_failure_timestamp > 0) {
  3486. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3487. // Timer has not expired yet
  3488. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3489. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3490. }
  3491. }
  3492. // Time > 0 then we are locked out, make the message and send it and return true
  3493. if (time > 0) {
  3494. string time_msg = "";
  3495. int16 hour;
  3496. int8 min;
  3497. int8 sec;
  3498. hour = time / 3600;
  3499. time = time % 3600;
  3500. min = time / 60;
  3501. time = time % 60;
  3502. sec = time;
  3503. if (hour > 0) {
  3504. char temp[10];
  3505. snprintf(temp, 9," %i", hour);
  3506. time_msg.append(temp);
  3507. time_msg.append(" hour");
  3508. time_msg.append((hour > 1) ? "s" : "");
  3509. }
  3510. if (min > 0) {
  3511. char temp[5];
  3512. snprintf(temp, 4," %i", min);
  3513. time_msg.append(temp);
  3514. time_msg.append(" minute");
  3515. time_msg.append((min > 1) ? "s" : "");
  3516. }
  3517. // Only add seconds if minutes and hours are 0
  3518. if (hour == 0 && min == 0 && sec > 0) {
  3519. char temp[5];
  3520. snprintf(temp, 4," %i", sec);
  3521. time_msg.append(temp);
  3522. time_msg.append(" second");
  3523. time_msg.append((sec > 1) ? "s" : "");
  3524. }
  3525. if(displayClient)
  3526. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3527. return time_msg;
  3528. }
  3529. }
  3530. }
  3531. return std::string("");
  3532. }
  3533. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3534. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3535. if(instanceType < 1)
  3536. return nullptr;
  3537. ZoneServer* instance_zone = nullptr;
  3538. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3539. if (data) {
  3540. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3541. // If lockout instances check to see if we are locked out
  3542. if (lockoutTime.length() > 0) {
  3543. return nullptr;
  3544. }
  3545. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3546. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3547. // 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
  3548. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3549. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3550. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3551. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3552. }
  3553. else
  3554. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3555. data->instance_id = instance_zone->GetInstanceID();
  3556. }
  3557. }
  3558. return instance_zone;
  3559. }
  3560. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3561. ZoneServer* instance_zone = NULL;
  3562. int8 instanceType = 0;
  3563. // determine if this is a group instanced zone that already exists
  3564. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3565. if (instance_zone != NULL)
  3566. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3567. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3568. {
  3569. // best to check if we already have our own instance!
  3570. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3571. {
  3572. switch (instanceType)
  3573. {
  3574. case SOLO_LOCKOUT_INSTANCE:
  3575. case GROUP_LOCKOUT_INSTANCE:
  3576. case RAID_LOCKOUT_INSTANCE:
  3577. {
  3578. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3579. if (instance_zone) {
  3580. // 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
  3581. // so delete `instances` entry for the zone when it shuts down.
  3582. 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());
  3583. if (db_id > 0)
  3584. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3585. }
  3586. break;
  3587. }
  3588. case SOLO_PERSIST_INSTANCE:
  3589. case GROUP_PERSIST_INSTANCE:
  3590. case RAID_PERSIST_INSTANCE:
  3591. {
  3592. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3593. if (instance_zone) {
  3594. 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());
  3595. if (db_id > 0)
  3596. 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()));
  3597. }
  3598. break;
  3599. }
  3600. case PUBLIC_INSTANCE:
  3601. case TRADESKILL_INSTANCE:
  3602. {
  3603. // if its public/tradeskill, look for a public already setup
  3604. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3605. if (instance_zone) {
  3606. // Check the current population against the max population, if greater or equal start a new version
  3607. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3608. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3609. }
  3610. else
  3611. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3612. break;
  3613. }
  3614. case PERSONAL_HOUSE_INSTANCE:
  3615. case GUILD_HOUSE_INSTANCE:
  3616. {
  3617. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3618. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3619. // with the OP_EnterHouseMsg opcode
  3620. break;
  3621. }
  3622. case QUEST_INSTANCE:
  3623. {
  3624. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3625. break;
  3626. /*
  3627. 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`;
  3628. */
  3629. }
  3630. default:
  3631. {
  3632. // NONE
  3633. }
  3634. }
  3635. }
  3636. if (instance_zone != NULL)
  3637. Zone(instance_zone, zone_coords_valid);
  3638. }
  3639. if (instance_zone != NULL)
  3640. return true;
  3641. else
  3642. return false;
  3643. }
  3644. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3645. Spawn* target = 0;
  3646. if (search_name || GetPlayer()->GetTarget()) {
  3647. Client* search_client = 0;
  3648. if (search_name) {
  3649. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3650. if (!target) {
  3651. search_client = zone_list.GetClientByCharName(search_name);
  3652. if (search_client)
  3653. target = search_client->GetPlayer();
  3654. }
  3655. if (target)
  3656. GetPlayer()->SetTarget(target);
  3657. }
  3658. else
  3659. target = GetPlayer()->GetTarget();
  3660. if (target && target != GetPlayer()) {
  3661. GetPlayer()->SetX(target->GetX());
  3662. GetPlayer()->SetY(target->GetY());
  3663. GetPlayer()->SetZ(target->GetZ());
  3664. GetPlayer()->SetHeading(target->GetHeading());
  3665. GetPlayer()->SetLocation(target->GetLocation());
  3666. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3667. }
  3668. else if (target)
  3669. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3670. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3671. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3672. else if (target) {
  3673. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3674. if (app)
  3675. QueuePacket(app);
  3676. }
  3677. }
  3678. if (!target)
  3679. return false;
  3680. else
  3681. return true;
  3682. }
  3683. bool Client::CheckZoneAccess(const char* zoneName) {
  3684. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3685. ZoneServer* zone = zone_list.Get(zoneName, false);
  3686. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3687. if (zone && zone->GetZoneLockState())
  3688. {
  3689. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3690. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3691. return false;
  3692. }
  3693. sint16 zoneMinStatus = 0;
  3694. int16 zoneMinLevel = 0;
  3695. int16 zoneMaxLevel = 0;
  3696. int16 zoneMinVersion = 0;
  3697. if (!zone)
  3698. {
  3699. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3700. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3701. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3702. return true;
  3703. }
  3704. }
  3705. else
  3706. {
  3707. zoneMinStatus = zone->GetMinimumStatus();
  3708. zoneMinLevel = zone->GetMinimumLevel();
  3709. zoneMaxLevel = zone->GetMaximumLevel();
  3710. zoneMinVersion = zone->GetMinimumVersion();
  3711. }
  3712. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3713. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3714. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3715. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3716. {
  3717. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3718. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3719. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3720. return false;
  3721. }
  3722. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3723. {
  3724. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3725. {
  3726. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3727. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3728. return false;
  3729. }
  3730. }
  3731. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3732. {
  3733. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3734. {
  3735. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3736. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3737. return false;
  3738. }
  3739. }
  3740. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3741. {
  3742. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3743. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3744. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3745. {
  3746. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3747. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3748. return false;
  3749. }
  3750. }
  3751. return true;
  3752. }
  3753. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3754. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3755. }
  3756. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3757. if (!new_zone) {
  3758. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3759. return;
  3760. }
  3761. client_zoning = true;
  3762. zoning_id = new_zone->GetZoneID();
  3763. zoning_instance_id = new_zone->GetInstanceID();
  3764. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3765. player->SetResurrecting(true);
  3766. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3767. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3768. MSaveSpellStateMutex.lock();
  3769. player->SaveSpellEffects();
  3770. player->SetSaveSpellEffects(true);
  3771. MSaveSpellStateMutex.unlock();
  3772. ResetSendMail();
  3773. // Remove players pet from zone if there is one
  3774. ((Entity*)player)->DismissAllPets();
  3775. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3776. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3777. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3778. SetZoningDestination(new_zone);
  3779. SetCurrentZone(new_zone);
  3780. if (player->GetGroupMemberInfo())
  3781. {
  3782. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3783. player->UpdateGroupMemberInfo();
  3784. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3785. }
  3786. // block out the member info for the group
  3787. TempRemoveGroup();
  3788. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3789. if (set_coords)
  3790. {
  3791. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3792. __FUNCTION__,
  3793. GetCurrentZone()->GetSafeX(),
  3794. GetCurrentZone()->GetSafeY(),
  3795. GetCurrentZone()->GetSafeZ(),
  3796. GetCurrentZone()->GetSafeHeading(),
  3797. new_zone->GetZoneName()
  3798. );
  3799. player->SetX(GetCurrentZone()->GetSafeX());
  3800. player->SetY(GetCurrentZone()->GetSafeY());
  3801. player->SetZ(GetCurrentZone()->GetSafeZ());
  3802. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3803. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  3804. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  3805. }
  3806. else {
  3807. ResetZoningCoords();
  3808. }
  3809. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3810. Save();
  3811. char* new_zone_ip = 0;
  3812. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3813. new_zone_ip = net.GetInternalWorldAddress();
  3814. else
  3815. new_zone_ip = net.GetWorldAddress();
  3816. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3817. int32 key = Timer::GetUnixTimeStamp();
  3818. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3819. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3820. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3821. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3822. if (version > 283) {
  3823. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3824. if (packet)
  3825. {
  3826. QueuePacket(packet->serialize());
  3827. safe_delete(packet);
  3828. }
  3829. }
  3830. }
  3831. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3832. {
  3833. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3834. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3835. }
  3836. float Client::DistanceFrom(Client* client) {
  3837. float ret = 0;
  3838. if (client && client != this) {
  3839. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3840. ret = sqrt(ret);
  3841. }
  3842. return ret;
  3843. }
  3844. void Client::DetermineCharacterUpdates() {
  3845. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3846. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3847. cdu->account_id = GetAccountID();
  3848. cdu->char_id = GetCharacterID();
  3849. int32 timestamp = Timer::GetUnixTimeStamp();
  3850. int8 flag = GetTimeStampFlag();
  3851. if (flag & LEVEL_UPDATE_FLAG)
  3852. {
  3853. cdu->update_field = LEVEL_UPDATE_FLAG;
  3854. cdu->update_data = player->GetLevel();
  3855. loginserver.SendPacket(outpack);
  3856. }
  3857. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3858. if (flag & CLASS_UPDATE_FLAG)
  3859. {
  3860. cdu->update_field = CLASS_UPDATE_FLAG;
  3861. cdu->update_data = player->GetAdventureClass();
  3862. loginserver.SendPacket(outpack);
  3863. }
  3864. if (flag & GENDER_UPDATE_FLAG)
  3865. {
  3866. cdu->update_field = GENDER_UPDATE_FLAG;
  3867. cdu->update_data = player->GetGender();
  3868. loginserver.SendPacket(outpack);
  3869. }
  3870. if (flag & DELETE_UPDATE_FLAG) {
  3871. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3872. }
  3873. safe_delete(outpack); // Zone, armor and name use a different structure
  3874. if (flag & RACE_UPDATE_FLAG)
  3875. {
  3876. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3877. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3878. ru->account_id = GetAccountID();
  3879. ru->char_id = GetCharacterID();
  3880. ru->race = player->GetRace();
  3881. ru->model_type = player->GetModelType();
  3882. loginserver.SendPacket(outpack);
  3883. safe_delete(outpack);
  3884. }
  3885. if (flag & ZONE_UPDATE_FLAG) {
  3886. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3887. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3888. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3889. czu->account_id = GetAccountID();
  3890. czu->char_id = GetCharacterID();
  3891. czu->zone_id = GetCurrentZone()->GetZoneID();
  3892. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3893. czu->zone_length = strlen(zone_file);
  3894. if (czu->zone_length > 64)
  3895. czu->zone_length = 64;
  3896. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3897. loginserver.SendPacket(outpack);
  3898. safe_delete(outpack);
  3899. }
  3900. if (flag & ARMOR_UPDATE_FLAG) {
  3901. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3902. }
  3903. if (flag & NAME_UPDATE_FLAG) {
  3904. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3905. }
  3906. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3907. }
  3908. void Client::Save() {
  3909. if (GetCharacterID() == 0)
  3910. return;
  3911. if (current_zone) {
  3912. DetermineCharacterUpdates();
  3913. UpdateCharacterInstances();
  3914. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3915. database.Save(this);
  3916. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3917. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3918. GetPlayer()->ResetQuickbarNeeded();
  3919. }
  3920. database.SaveItems(this);
  3921. database.SaveBuyBacks(this);
  3922. GetPlayer()->SaveHistory();
  3923. GetPlayer()->SaveLUAHistory();
  3924. MSaveSpellStateMutex.lock();
  3925. GetPlayer()->SaveSpellEffects();
  3926. MSaveSpellStateMutex.unlock();
  3927. }
  3928. }
  3929. void Client::UpdateCharacterInstances() {
  3930. if (GetPlayer() != NULL)
  3931. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3932. /*if ( GetPlayer() != NULL )
  3933. {
  3934. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3935. // to use for applying the update to each instances timer
  3936. int32 lastSaveTS = GetLastSavedTimeStamp();
  3937. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3938. int32 diffTS = newSaveTS - lastSaveTS;
  3939. // update instance timers
  3940. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3941. // update with the new timestamp and save the db
  3942. this->SetLastSavedTimeStamp(newSaveTS);
  3943. }*/
  3944. }
  3945. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3946. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3947. if (packet) {
  3948. packet->LoadPacketData(app->pBuffer, app->size);
  3949. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3950. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3951. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3952. vector<EntityCommand*> commands;
  3953. vector<EntityCommand*> delete_commands;
  3954. if (out && spawn) {
  3955. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3956. {
  3957. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3958. if (!spawn->primary_command_list[i]->default_allow_list)
  3959. {
  3960. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3961. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3962. continue;
  3963. }
  3964. else
  3965. {
  3966. // default is allow list, only deny if added to the list as deny (false itr second)
  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. commands.push_back(spawn->primary_command_list[i]);
  3972. }
  3973. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3974. commands.push_back(spawn->secondary_command_list[i]);
  3975. if (spawn->IsPlayer()) {
  3976. if (player->IsFriend(spawn->GetName()))
  3977. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3978. else
  3979. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3980. if (player->IsIgnored(spawn->GetName()))
  3981. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3982. else
  3983. {
  3984. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3985. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3986. }
  3987. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3988. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3989. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3990. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3991. }
  3992. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  3993. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  3994. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  3995. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  3996. }
  3997. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3998. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3999. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4000. }
  4001. out->setDataByName("spawn_id", spawn_id);
  4002. out->setArrayLengthByName("num_verbs", commands.size());
  4003. for (int32 i = 0; i < commands.size(); i++) {
  4004. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4005. out->setArrayDataByName("distance", commands[i]->distance, i);
  4006. if (commands[i]->error_text.length() == 0)
  4007. out->setArrayAddToPacketByName("error", false, i);
  4008. else {
  4009. out->setArrayDataByName("display_error", 1, i);
  4010. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4011. }
  4012. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4013. }
  4014. EQ2Packet* outapp = out->serialize();
  4015. //DumpPacket(outapp);
  4016. QueuePacket(outapp);
  4017. safe_delete(out);
  4018. for (int32 i = 0; i < delete_commands.size(); i++) {
  4019. safe_delete(delete_commands[i]);
  4020. }
  4021. }
  4022. safe_delete(packet);
  4023. }
  4024. }
  4025. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4026. if (previous_value != new_value) {
  4027. 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);
  4028. char tmp[200] = { 0 };
  4029. 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);
  4030. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4031. }
  4032. }
  4033. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4034. {
  4035. /* JA notes on the unknown:
  4036. 2 = ding glimmer
  4037. 16 = Achievement Unlocked
  4038. 6 no longer does anything
  4039. */
  4040. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4041. if (packet) {
  4042. packet->setDataByName("unknown", unknown);
  4043. packet->setMediumStringByName("text", text);
  4044. if (type && strlen(type) > 0)
  4045. packet->setMediumStringByName("message_type", type);
  4046. packet->setDataByName("size", size);
  4047. packet->setDataByName("red", red);
  4048. packet->setDataByName("green", green);
  4049. packet->setDataByName("blue", blue);
  4050. QueuePacket(packet->serialize());
  4051. safe_delete(packet);
  4052. }
  4053. }
  4054. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4055. if (new_level < 1) {
  4056. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4057. return;
  4058. }
  4059. if (player->GetLevel() != new_level) {
  4060. player->SetLevel(new_level);
  4061. if (player->GetGroupMemberInfo()) {
  4062. player->UpdateGroupMemberInfo();
  4063. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4064. }
  4065. }
  4066. if (new_level > old_level) {
  4067. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4068. }
  4069. if (player->GetPet()) {
  4070. NPC* pet = (NPC*)player->GetPet();
  4071. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4072. pet->SetLevel(new_level);
  4073. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4074. if (command_packet) {
  4075. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4076. command_packet->setDataByName("anim_type", 1753);
  4077. QueuePacket(command_packet->serialize());
  4078. safe_delete(command_packet);
  4079. }
  4080. }
  4081. }
  4082. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4083. if (level_update) {
  4084. level_update->setDataByName("old_level", old_level);
  4085. level_update->setDataByName("new_level", new_level);
  4086. QueuePacket(level_update->serialize());
  4087. safe_delete(level_update);
  4088. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4089. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4090. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4091. }
  4092. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4093. if (command_packet) {
  4094. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4095. command_packet->setDataByName("anim_type", 1753);
  4096. QueuePacket(command_packet->serialize());
  4097. safe_delete(command_packet);
  4098. }
  4099. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4100. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4101. SendNewSpells(player->GetAdventureClass());
  4102. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4103. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4104. GetPlayer()->ChangePrimaryWeapon();
  4105. GetPlayer()->ChangeSecondaryWeapon();
  4106. GetPlayer()->ChangeRangedWeapon();
  4107. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4108. // GetPlayer()->SetLevel(new_level);
  4109. 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__);
  4110. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4111. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4112. GetPlayer()->CalculateBonuses();
  4113. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4114. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4115. InfoStruct* info = player->GetInfoStruct();
  4116. info->set_agi_base(new_level * 2 + 15);
  4117. info->set_intel_base(new_level * 2 + 15);
  4118. info->set_wis_base(new_level * 2 + 15);
  4119. info->set_str_base(new_level * 2 + 15);
  4120. info->set_sta_base(new_level * 2 + 15);
  4121. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4122. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4123. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4124. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4125. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4126. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4127. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4128. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));
  4129. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4130. GetPlayer()->SetCharSheetChanged(true);
  4131. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4132. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4133. int16 new_skill_cap = 5 * new_level;
  4134. PlayerSkillList* player_skills = player->GetSkills();
  4135. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4136. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4137. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4138. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4139. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4140. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4141. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4142. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4143. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4144. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4145. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4146. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4147. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4148. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4149. if (new_level > player->GetTSLevel())
  4150. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4151. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4152. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4153. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4154. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4155. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4156. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4157. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4158. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4159. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4160. Guild* guild = GetPlayer()->GetGuild();
  4161. if (guild) {
  4162. int8 event_type = 0;
  4163. if (new_level < 10)
  4164. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4165. else if (new_level == 10)
  4166. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4167. else if (new_level >= 11 && new_level < 20)
  4168. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4169. else if (new_level == 20)
  4170. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4171. else if (new_level >= 21 && new_level < 30)
  4172. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4173. else if (new_level == 30)
  4174. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4175. else if (new_level >= 31 && new_level < 40)
  4176. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4177. else if (new_level == 40)
  4178. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4179. else if (new_level >= 41 && new_level < 50)
  4180. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4181. else if (new_level == 50)
  4182. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4183. else if (new_level >= 51 && new_level < 60)
  4184. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4185. else if (new_level == 60)
  4186. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4187. else if (new_level >= 61 && new_level < 70)
  4188. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4189. else if (new_level == 70)
  4190. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4191. else if (new_level >= 71 && new_level < 80)
  4192. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4193. else if (new_level == 80)
  4194. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4195. 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());
  4196. 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());
  4197. guild->UpdateGuildMemberInfo(GetPlayer());
  4198. guild->SendGuildMember(GetPlayer());
  4199. guild->SendGuildMemberList();
  4200. }
  4201. // Need to send the trait list every time the players level changes
  4202. // Also need to force the char sheet update or else there can be a large delay from when you level
  4203. // to when you are actually able to select traits.
  4204. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4205. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4206. if (version > 546)
  4207. master_aa_list.DisplayAA(this, 0, 0);
  4208. if (GetPlayer()->SpawnedBots.size() > 0) {
  4209. map<int32, int32>::iterator itr;
  4210. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4211. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4212. if (bot && bot->IsBot())
  4213. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4214. }
  4215. }
  4216. }
  4217. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4218. if (new_level < 1) {
  4219. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4220. return;
  4221. }
  4222. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4223. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4224. return;
  4225. }
  4226. if (new_level > old_level)
  4227. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4228. if (player->GetTSLevel() != new_level) {
  4229. player->SetTSLevel(new_level);
  4230. if (player->GetGroupMemberInfo()) {
  4231. player->UpdateGroupMemberInfo();
  4232. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4233. }
  4234. }
  4235. // Only tradeskill skills should increace, and then only those related to your class
  4236. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4237. if (level_update) {
  4238. level_update->setDataByName("old_level", old_level);
  4239. level_update->setDataByName("new_level", new_level);
  4240. level_update->setDataByName("type", 1);
  4241. QueuePacket(level_update->serialize());
  4242. safe_delete(level_update);
  4243. }
  4244. // Need to make tradeskill versions of the following
  4245. //SendNewSpells(player->GetAdventureClass());
  4246. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4247. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4248. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4249. if (command_packet) {
  4250. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4251. command_packet->setDataByName("anim_type", 1753);
  4252. QueuePacket(command_packet->serialize());
  4253. safe_delete(command_packet);
  4254. }
  4255. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4256. GetPlayer()->SetTSLevel(new_level);
  4257. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4258. GetPlayer()->SetCharSheetChanged(true);
  4259. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4260. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4261. PlayerSkillList* player_skills = player->GetSkills();
  4262. int16 specialize_skill_cap = new_level * 5;
  4263. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4264. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4265. int8 ts_class = player->GetTradeskillClass();
  4266. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4267. int32 skill_id_1, skill_id_2, skill_id_3;
  4268. switch (base_ts_class) {
  4269. case ARTISAN:
  4270. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4271. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4272. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4273. break;
  4274. case OUTFITTER:
  4275. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4276. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4277. skill_id_1 = SKILL_ID_TAILORING;
  4278. skill_id_2 = SKILL_ID_METALSHAPING;
  4279. skill_id_3 = SKILL_ID_METALWORKING;
  4280. if (ts_class == TAILOR) {
  4281. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4282. skill_id_1 = 0;
  4283. }
  4284. else if (ts_class == ARMORER) {
  4285. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4286. skill_id_2 = 0;
  4287. }
  4288. else if (ts_class == WEAPONSMITH) {
  4289. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4290. skill_id_3 = 0;
  4291. }
  4292. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4293. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4294. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4295. break;
  4296. case SCHOLAR:
  4297. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4298. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4299. skill_id_1 = SKILL_ID_SCRIBING;
  4300. skill_id_2 = SKILL_ID_CHEMISTRY;
  4301. skill_id_3 = SKILL_ID_ARTIFICING;
  4302. if (ts_class == SAGE) {
  4303. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4304. skill_id_1 = 0;
  4305. }
  4306. else if (ts_class == ALCHEMIST) {
  4307. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4308. skill_id_2 = 0;
  4309. }
  4310. else if (ts_class == JEWELER) {
  4311. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4312. skill_id_3 = 0;
  4313. }
  4314. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4315. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4316. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4317. break;
  4318. case CRAFTSMAN:
  4319. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4320. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4321. skill_id_1 = SKILL_ID_ARTISTRY;
  4322. skill_id_2 = SKILL_ID_FLETCHING;
  4323. skill_id_3 = SKILL_ID_SCULPTING;
  4324. if (ts_class == PROVISIONER) {
  4325. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4326. skill_id_1 = 0;
  4327. }
  4328. else if (ts_class == WOODWORKER) {
  4329. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4330. skill_id_2 = 0;
  4331. }
  4332. else if (ts_class == CARPENTER) {
  4333. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4334. skill_id_3 = 0;
  4335. }
  4336. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4337. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4338. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4339. break;
  4340. default:
  4341. break;
  4342. }
  4343. if (new_level > player->GetAdventureClass())
  4344. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4345. Guild* guild = GetPlayer()->GetGuild();
  4346. if (guild) {
  4347. int8 event_type = 0;
  4348. if (new_level < 10)
  4349. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4350. else if (new_level == 10)
  4351. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4352. else if (new_level >= 11 && new_level < 20)
  4353. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4354. else if (new_level == 20)
  4355. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4356. else if (new_level >= 21 && new_level < 30)
  4357. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4358. else if (new_level == 30)
  4359. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4360. else if (new_level >= 31 && new_level < 40)
  4361. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4362. else if (new_level == 40)
  4363. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4364. else if (new_level >= 41 && new_level < 50)
  4365. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4366. else if (new_level == 50)
  4367. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4368. else if (new_level >= 51 && new_level < 60)
  4369. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4370. else if (new_level == 60)
  4371. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4372. else if (new_level >= 61 && new_level < 70)
  4373. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4374. else if (new_level == 70)
  4375. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4376. else if (new_level >= 71 && new_level < 80)
  4377. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4378. else if (new_level == 80)
  4379. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4380. 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());
  4381. 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());
  4382. guild->UpdateGuildMemberInfo(GetPlayer());
  4383. guild->SendGuildMember(GetPlayer());
  4384. guild->SendGuildMemberList();
  4385. }
  4386. // Need to send the trait list every time the players level changes
  4387. // Also need to force the char sheet update or else there can be a large delay from when you level
  4388. // to when you are actually able to select traits.
  4389. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4390. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4391. }
  4392. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4393. if (entity)
  4394. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4395. }
  4396. void Client::CloseLoot(int32 spawn_id) {
  4397. if (GetVersion() > 546) {
  4398. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4399. if (packet) {
  4400. packet->setDataByName("window_id", 4);
  4401. EQ2Packet* outapp = packet->serialize();
  4402. if (outapp) {
  4403. //DumpPacket(outapp);
  4404. QueuePacket(outapp);
  4405. }
  4406. safe_delete(packet);
  4407. }
  4408. }
  4409. else if(spawn_id > 0){
  4410. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4411. if (packet) {
  4412. packet->setDataByName("spawn_id", spawn_id);
  4413. EQ2Packet* outapp = packet->serialize();
  4414. if (outapp)
  4415. QueuePacket(outapp);
  4416. safe_delete(packet);
  4417. }
  4418. }
  4419. }
  4420. string Client::GetCoinMessage(int32 total_coins) {
  4421. if (total_coins == 0) {
  4422. return " 0 Copper";
  4423. }
  4424. char tmp[64] = { 0 };
  4425. string message = "";
  4426. int32 val = 0;
  4427. if (total_coins >= 1000000) {
  4428. val = total_coins / 1000000;
  4429. total_coins -= 1000000 * val;
  4430. sprintf(tmp, " %u Platinum", val);
  4431. message.append(tmp);
  4432. memset(tmp, 0, 64);
  4433. }
  4434. if (total_coins >= 10000) {
  4435. val = total_coins / 10000;
  4436. total_coins -= 10000 * val;
  4437. sprintf(tmp, " %u Gold", val);
  4438. message.append(tmp);
  4439. memset(tmp, 0, 64);
  4440. }
  4441. if (total_coins >= 100) {
  4442. val = total_coins / 100;
  4443. total_coins -= 100 * val;
  4444. sprintf(tmp, " %u Silver", val);
  4445. message.append(tmp);
  4446. memset(tmp, 0, 64);
  4447. }
  4448. if (total_coins > 0) {
  4449. sprintf(tmp, " %u Copper", (int32)total_coins);
  4450. message.append(tmp);
  4451. }
  4452. return message;
  4453. }
  4454. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4455. if (!entity) {
  4456. CloseLoot(0);
  4457. return;
  4458. }
  4459. if (total_coins > 0) {
  4460. player->AddCoins(total_coins);
  4461. //PlaySound("coin_cha_ching");
  4462. string message = "";
  4463. if (entity->GetHP() == 0) {
  4464. message = "You loot ";
  4465. entity->SetLootCoins(0);
  4466. }
  4467. else
  4468. message = "You receive ";
  4469. message.append(GetCoinMessage(total_coins));
  4470. if (entity->GetHP() == 0)
  4471. message.append(" from the corpse of ").append(entity->GetName());
  4472. int8 type = CHANNEL_LOOT;
  4473. SimpleMessage(type, message.c_str());
  4474. }
  4475. if (!items || items->size() == 0)
  4476. CloseLoot(entity->GetID());
  4477. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4478. if (packet) {
  4479. vector<Item*>::iterator itr;
  4480. int32 packet_size = 0;
  4481. EQ2Packet* outapp = 0;
  4482. uchar* data = 0;
  4483. if (GetVersion() >= 284) {
  4484. if (GetVersion() > 546) {
  4485. if (items && items->size() > 0) {
  4486. packet->setDataByName("loot_count", items->size());
  4487. packet->setDataByName("display", 1);
  4488. }
  4489. packet->setDataByName("loot_type", 1);
  4490. if (version >= 1096)
  4491. packet->setDataByName("lotto_timeout", 0x78);
  4492. else
  4493. packet->setDataByName("lotto_timeout", 0x3C);
  4494. packet->setDataByName("loot_id", entity->GetID());
  4495. EQ2Packet* tmpPacket = packet->serialize();
  4496. packet_size += tmpPacket->size;
  4497. if (items && items->size() > 0) {
  4498. data = new uchar[items->size() * 1000 + packet_size];
  4499. memset(data, 0, items->size() * 1000 + packet_size);
  4500. }
  4501. else {
  4502. data = new uchar[packet_size];
  4503. memset(data, 0, packet_size);
  4504. }
  4505. uchar* ptr = data;
  4506. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4507. ptr += tmpPacket->size;
  4508. safe_delete(tmpPacket);
  4509. Item* item = 0;
  4510. if (items && items->size() > 0) {
  4511. for (itr = items->begin(); itr != items->end(); itr++) {
  4512. item = *itr;
  4513. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4514. ptr += sizeof(int32);
  4515. packet_size += sizeof(int32);
  4516. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4517. int8 offset = 0;
  4518. if (GetVersion() >= 1188) {
  4519. offset = 13;
  4520. }
  4521. else if (GetVersion() >= 860) {
  4522. offset = 11;
  4523. }
  4524. else if (GetVersion() <= 546) {
  4525. offset = 19;
  4526. }
  4527. else {
  4528. offset = 10;
  4529. }
  4530. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4531. ptr += tmpPacket->size - offset;
  4532. packet_size += tmpPacket->size - offset;
  4533. safe_delete(tmpPacket);
  4534. }
  4535. }
  4536. packet_size -= sizeof(int32);
  4537. memcpy(data, &packet_size, sizeof(int32));
  4538. packet_size += sizeof(int32);
  4539. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4540. }
  4541. else {
  4542. if (items && items->size() > 0) {
  4543. packet->setArrayLengthByName("loot_count", items->size());
  4544. Item* item = 0;
  4545. if (items && items->size() > 0) {
  4546. int i = 0;
  4547. for (itr = items->begin(); itr != items->end(); itr++) {
  4548. item = *itr;
  4549. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4550. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4551. i++;
  4552. }
  4553. }
  4554. packet->setDataByName("display", 1);
  4555. }
  4556. packet->setDataByName("loot_type", 1); // normal
  4557. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4558. packet->setDataByName("spawn_id", entity->GetID());
  4559. outapp = packet->serialize();
  4560. }
  4561. }
  4562. else {
  4563. if (items && items->size() > 0) {
  4564. packet->setArrayLengthByName("loot_count", items->size());
  4565. for (int i = 0; i < items->size(); i++) {
  4566. Item* item = (*items)[i];
  4567. packet->setArrayDataByName("name", item->name.c_str(), i);
  4568. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4569. packet->setArrayDataByName("count", item->details.count, i);
  4570. packet->setArrayDataByName("icon", item->details.icon, i);
  4571. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4572. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4573. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4574. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4575. else
  4576. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4577. }
  4578. }
  4579. packet->setDataByName("object_id", entity->GetID());
  4580. packet->setDataByName("unknown3", 1);
  4581. packet->setDataByName("unknown4", 1);
  4582. packet->setDataByName("unknown5", 60);
  4583. outapp = packet->serialize();
  4584. }
  4585. if (outapp) {
  4586. QueuePacket(outapp);
  4587. }
  4588. safe_delete_array(data);
  4589. safe_delete(packet);
  4590. }
  4591. }
  4592. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4593. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4594. int32 total_coins = entity->GetLootCoins();
  4595. entity->LockLoot();
  4596. Loot(total_coins, entity->GetLootItems(), entity);
  4597. entity->UnlockLoot();
  4598. OpenChest(entity, attemptDisarm);
  4599. }
  4600. else
  4601. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4602. }
  4603. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4604. {
  4605. if (!entity)
  4606. return;
  4607. int8 chest_difficulty = 0;
  4608. int32 state = 0;
  4609. // Check for the chest and set the action state
  4610. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4611. string modelName;
  4612. if (entity->GetModelType() == 4034) {
  4613. // small chest, open with copper coins
  4614. // does not include traps, however can be disarmed
  4615. chest_difficulty = 1;
  4616. state = 11899;
  4617. modelName.append("Small Chest");
  4618. }
  4619. else if (entity->GetModelType() == 5864) {
  4620. // treasure chest, open with silver coins
  4621. chest_difficulty = 2;
  4622. state = 11901;
  4623. modelName.append("Treasure Chest");
  4624. }
  4625. else if (entity->GetModelType() == 5865) {
  4626. // ornate chest, open with gold coins
  4627. chest_difficulty = 3;
  4628. state = 11900;
  4629. modelName.append("Ornate Chest");
  4630. }
  4631. else if (entity->GetModelType() == 4015) {
  4632. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4633. chest_difficulty = 5;
  4634. state = 11898;
  4635. modelName.append("Exquisite Chest");
  4636. }
  4637. bool firstChestOpen = false;
  4638. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4639. {
  4640. ChestTrap::ChestTrapInfo nextTrap;
  4641. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4642. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4643. firstChestOpen = true;
  4644. entity->SetTrapTriggered(true, state);
  4645. if (ret)
  4646. {
  4647. if (disarmSkill && attemptDisarm)
  4648. {
  4649. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4650. {
  4651. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4652. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4653. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4654. }
  4655. else
  4656. {
  4657. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4658. }
  4659. // despite fail/succeed we should always try to increase skill if disarm is available
  4660. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4661. }
  4662. else // no disarm skill, always fail
  4663. {
  4664. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4665. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4666. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4667. }
  4668. }
  4669. }
  4670. else if (!entity->HasTrapTriggered())
  4671. {
  4672. firstChestOpen = true;
  4673. entity->SetTrapTriggered(true, state);
  4674. }
  4675. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4676. // for those in range the SendStateCommand will cause it to animate open.
  4677. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4678. if (firstChestOpen)
  4679. GetCurrentZone()->SendStateCommand(entity, state);
  4680. }
  4681. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4682. {
  4683. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4684. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4685. if (source == NULL)
  4686. source = (Entity*)GetPlayer();
  4687. if (spell)
  4688. {
  4689. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4690. if (gmi && gmi->group_id)
  4691. {
  4692. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4693. if (group)
  4694. {
  4695. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4696. deque<GroupMemberInfo*>* members = group->GetMembers();
  4697. for (int8 i = 0; i < members->size(); i++) {
  4698. Entity* member = members->at(i)->member;
  4699. if(!member)
  4700. continue;
  4701. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4702. continue;
  4703. // if we have a radius provided then check if the group member is outside the radius or not
  4704. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4705. continue;
  4706. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4707. }
  4708. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4709. }
  4710. }
  4711. else
  4712. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4713. }
  4714. }
  4715. Spawn* Client::GetBanker() {
  4716. return banker;
  4717. }
  4718. void Client::SetBanker(Spawn* in_banker) {
  4719. banker = in_banker;
  4720. }
  4721. void Client::Bank(Spawn* banker, bool cancel) {
  4722. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4723. if (!cancel)
  4724. SetBanker(banker);
  4725. else
  4726. SetBanker(0);
  4727. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4728. if (packet) {
  4729. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4730. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4731. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4732. int32 coins1, coins2;
  4733. coins1 = ((int32*)&coins)[0];
  4734. coins2 = ((int32*)&coins)[1];
  4735. packet->setDataByName("bank_coins", coins1);
  4736. packet->setDataByName("bank_coins2", coins2);
  4737. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4738. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4739. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4740. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4741. if (!cancel)
  4742. packet->setDataByName("display", 1);
  4743. QueuePacket(packet->serialize());
  4744. safe_delete(packet);
  4745. }
  4746. }
  4747. }
  4748. void Client::BankWithdrawal(int64 amount) {
  4749. bool cheater = false;
  4750. if (GetBanker() && amount > 0) {
  4751. string withdrawal = "";
  4752. char withdrawal_data[512] = { 0 };
  4753. int32 tmp = 0;
  4754. if (amount >= 1000000) {
  4755. tmp = amount / 1000000;
  4756. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4757. if (tmp > bank_coins_plat)
  4758. cheater = true;
  4759. else {
  4760. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4761. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4762. amount -= (int64)tmp * 1000000;
  4763. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4764. withdrawal.append(withdrawal_data);
  4765. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4766. }
  4767. }
  4768. if (!cheater && amount >= 10000) {
  4769. tmp = amount / 10000;
  4770. if (tmp > GetPlayer()->GetBankCoinsGold())
  4771. cheater = true;
  4772. else {
  4773. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4774. bank_coins_gold -= tmp;
  4775. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4776. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4777. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4778. }
  4779. else
  4780. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4781. amount -= tmp * 10000;
  4782. sprintf(withdrawal_data, "%u Gold ", tmp);
  4783. withdrawal.append(withdrawal_data);
  4784. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4785. }
  4786. }
  4787. if (!cheater && amount >= 100) {
  4788. tmp = amount / 100;
  4789. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4790. if (tmp > bank_coins_silver)
  4791. cheater = true;
  4792. else {
  4793. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4794. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4795. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4796. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4797. }
  4798. else
  4799. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4800. amount -= tmp * 100;
  4801. sprintf(withdrawal_data, "%u Silver ", tmp);
  4802. withdrawal.append(withdrawal_data);
  4803. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4804. }
  4805. }
  4806. if (!cheater) {
  4807. if (amount > 0) {
  4808. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4809. withdrawal.append(withdrawal_data);
  4810. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4811. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4812. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4813. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4814. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4815. }
  4816. else
  4817. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4818. }
  4819. if (withdrawal.length() > 0) {
  4820. withdrawal.append("withdrawn ");
  4821. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4822. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4823. withdrawal.append(withdrawal_data);
  4824. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4825. }
  4826. }
  4827. else
  4828. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4829. player->SetCharSheetChanged(true);
  4830. Bank(banker);
  4831. }
  4832. }
  4833. void Client::BankDeposit(int64 amount) {
  4834. bool cheater = false;
  4835. if (GetBanker() && amount > 0) {
  4836. int32 tmp = 0;
  4837. char deposit_data[512] = { 0 };
  4838. string deposit = "";
  4839. if (amount >= 1000000) {
  4840. tmp = amount / 1000000;
  4841. if (tmp > GetPlayer()->GetCoinsPlat())
  4842. cheater = true;
  4843. else {
  4844. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4845. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4846. amount -= (int64)tmp * 1000000;
  4847. sprintf(deposit_data, "%u Platinum ", tmp);
  4848. deposit.append(deposit_data);
  4849. memset(deposit_data, 0, sizeof(deposit_data));
  4850. }
  4851. }
  4852. if (!cheater && amount >= 10000) {
  4853. tmp = amount / 10000;
  4854. if (tmp > GetPlayer()->GetCoinsGold())
  4855. cheater = true;
  4856. else {
  4857. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4858. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4859. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4860. }
  4861. else
  4862. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4863. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4864. amount -= tmp * 10000;
  4865. sprintf(deposit_data, "%u Gold ", tmp);
  4866. deposit.append(deposit_data);
  4867. memset(deposit_data, 0, sizeof(deposit_data));
  4868. }
  4869. }
  4870. if (!cheater && amount >= 100) {
  4871. tmp = amount / 100;
  4872. if (tmp > GetPlayer()->GetCoinsSilver())
  4873. cheater = true;
  4874. else {
  4875. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4876. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4877. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4878. }
  4879. else
  4880. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4881. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4882. amount -= tmp * 100;
  4883. sprintf(deposit_data, "%u Silver ", tmp);
  4884. deposit.append(deposit_data);
  4885. memset(deposit_data, 0, sizeof(deposit_data));
  4886. }
  4887. }
  4888. if (!cheater) {
  4889. if (amount > 0) {
  4890. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4891. deposit.append(deposit_data);
  4892. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4893. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4894. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4895. }
  4896. else
  4897. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4898. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4899. }
  4900. if (deposit.length() > 0) {
  4901. deposit.append("deposited ");
  4902. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4903. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4904. deposit.append(deposit_data);
  4905. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4906. }
  4907. }
  4908. else
  4909. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4910. player->SetCharSheetChanged(true);
  4911. Bank(banker);
  4912. }
  4913. }
  4914. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4915. {
  4916. MPendingQuestAccept.lock();
  4917. pending_quest_accept.push_back(quest->GetQuestID());
  4918. MPendingQuestAccept.unlock();
  4919. }
  4920. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  4921. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  4922. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  4923. quest_updates = update;
  4924. if(quest_updates) {
  4925. SaveQuestRewardData(true);
  4926. }
  4927. }
  4928. 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) {
  4929. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  4930. return;
  4931. QuestRewardData* data = new QuestRewardData;
  4932. data->quest_id = quest_id;
  4933. data->is_temporary = is_temporary;
  4934. data->is_collection = is_collection;
  4935. data->has_displayed = has_displayed;
  4936. data->tmp_coin = tmp_coin;
  4937. data->tmp_status = tmp_status;
  4938. data->description = std::string(description);
  4939. data->db_saved = db_saved;
  4940. data->db_index = index;
  4941. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4942. quest_pending_reward.push_back(data);
  4943. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4944. }
  4945. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  4946. bool success = false;
  4947. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  4948. if (quest_pending_reward.size() > 0) {
  4949. vector<QuestRewardData*>::iterator itr;
  4950. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  4951. int32 questID = (*itr)->quest_id;
  4952. bool temporary = (*itr)->is_temporary;
  4953. bool collection = (*itr)->is_collection;
  4954. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  4955. success = true;
  4956. break;
  4957. }
  4958. }
  4959. }
  4960. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  4961. return success;
  4962. }
  4963. void Client::RemoveQueuedQuestReward() {
  4964. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4965. if(quest_pending_reward.size() > 0) {
  4966. QuestRewardData* data = quest_pending_reward.at(0);
  4967. if(data->db_saved) {
  4968. Query query;
  4969. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  4970. if(data->is_temporary && data->quest_id) {
  4971. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  4972. }
  4973. }
  4974. quest_pending_reward.erase(quest_pending_reward.begin());
  4975. }
  4976. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4977. SaveQuestRewardData(true);
  4978. }
  4979. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4980. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4981. quest_pending_updates[quest_id][step_id] = progress;
  4982. quest_updates = true;
  4983. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4984. }
  4985. void Client::ProcessQuestUpdates() {
  4986. if(!GetPlayer()->IsFullyLoggedIn())
  4987. return;
  4988. if (quest_pending_updates.size() > 0) {
  4989. map<int32, map<int32, int32> > tmp_quest_updates;
  4990. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4991. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4992. quest_pending_updates.clear();
  4993. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4994. map<int32, map<int32, int32> >::iterator quest_itr;
  4995. map<int32, int32>::iterator step_itr;
  4996. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4997. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4998. if (step_itr->second == 0xFFFFFFFF) {
  4999. SetStepComplete(quest_itr->first, step_itr->first);
  5000. player->SendQuestRequiredSpawns(quest_itr->first);
  5001. }
  5002. else
  5003. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5004. }
  5005. }
  5006. }
  5007. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5008. if (quest_pending_reward.size() > 0) {
  5009. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5010. // only able to display one reward at a time
  5011. if(GetPlayer()->IsActiveReward())
  5012. return;
  5013. Query query;
  5014. vector<QuestRewardData*>::iterator itr;
  5015. vector<QuestRewardData*> tmp_quest_rewards;
  5016. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5017. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5018. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5019. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  5020. int32 questID = (*itr)->quest_id;
  5021. Quest* quest = 0;
  5022. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5023. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5024. GetPlayer()->SetActiveReward(true);
  5025. (*itr)->has_displayed = true;
  5026. UpdateCharacterRewardData((*itr));
  5027. }
  5028. else if(questID > 0 && (quest = GetPlayer()->GetAnyQuest(questID))) {
  5029. quest->SetQuestTemporaryState((*itr)->is_temporary, (*itr)->description);
  5030. if((*itr)->is_temporary) {
  5031. quest->SetStatusTmpReward((*itr)->tmp_status);
  5032. quest->SetCoinTmpReward((*itr)->tmp_coin);
  5033. }
  5034. GiveQuestReward(quest, (*itr)->has_displayed);
  5035. GetPlayer()->SetActiveReward(true);
  5036. (*itr)->has_displayed = true;
  5037. UpdateCharacterRewardData((*itr));
  5038. // only able to display one reward at a time
  5039. break;
  5040. } else {
  5041. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, skipping quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5042. }
  5043. }
  5044. } else {
  5045. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5046. }
  5047. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5048. if (quest_pending_reward.size() > 0) {
  5049. quest_updates = true;
  5050. }
  5051. else {
  5052. quest_updates = false;
  5053. }
  5054. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5055. }
  5056. void Client::CheckQuestQueue() {
  5057. MQuestQueue.writelock();
  5058. last_update_time = 0;
  5059. vector<QueuedQuest*>::iterator itr;
  5060. QueuedQuest* queued_quest = 0;
  5061. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5062. queued_quest = *itr;
  5063. Quest* quest = GetPlayer()->GetAnyQuest(queued_quest->quest_id);
  5064. if(quest) {
  5065. SendQuestUpdateStepImmediately(quest, queued_quest->step, queued_quest->display_quest_helper);
  5066. if(quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  5067. SendQuestJournal();
  5068. }
  5069. else {
  5070. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", queued_quest->quest_id, GetPlayer()->GetName());
  5071. }
  5072. safe_delete(queued_quest);
  5073. }
  5074. quest_queue.clear();
  5075. MQuestQueue.releasewritelock();
  5076. }
  5077. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5078. Quest* quest = player->SetStepComplete(quest_id, step);
  5079. if (quest) {
  5080. SendQuestUpdate(quest);
  5081. GetCurrentZone()->SendQuestUpdates(this);
  5082. }
  5083. }
  5084. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5085. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5086. if (quest) {
  5087. SendQuestUpdate(quest);
  5088. GetCurrentZone()->SendQuestUpdates(this);
  5089. }
  5090. }
  5091. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5092. bool hadUpdates = false;
  5093. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5094. if (quest_updates) {
  5095. for (int32 i = 0; i < quest_updates->size(); i++)
  5096. {
  5097. SendQuestUpdate(quest_updates->at(i));
  5098. hadUpdates = true;
  5099. }
  5100. }
  5101. safe_delete(quest_updates);
  5102. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5103. if (quest_failures) {
  5104. for (int32 i = 0; i < quest_failures->size(); i++)
  5105. {
  5106. SendQuestFailure(quest_failures->at(i));
  5107. hadUpdates = true;
  5108. }
  5109. }
  5110. safe_delete(quest_failures);
  5111. if (hadUpdates)
  5112. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5113. }
  5114. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5115. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5116. if (quest_updates) {
  5117. for (int32 i = 0; i < quest_updates->size(); i++)
  5118. SendQuestUpdate(quest_updates->at(i));
  5119. GetCurrentZone()->SendQuestUpdates(this);
  5120. }
  5121. safe_delete(quest_updates);
  5122. }
  5123. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5124. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5125. if (quest_updates) {
  5126. for (int32 i = 0; i < quest_updates->size(); i++)
  5127. SendQuestUpdate(quest_updates->at(i));
  5128. }
  5129. safe_delete(quest_updates);
  5130. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5131. if (quest_failures) {
  5132. for (int32 i = 0; i < quest_failures->size(); i++)
  5133. SendQuestFailure(quest_failures->at(i));
  5134. }
  5135. safe_delete(quest_failures);
  5136. }
  5137. void Client::CheckPlayerQuestsLocationUpdate() {
  5138. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5139. if (quest_updates) {
  5140. for (int32 i = 0; i < quest_updates->size(); i++)
  5141. SendQuestUpdate(quest_updates->at(i));
  5142. }
  5143. safe_delete(quest_updates);
  5144. }
  5145. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5146. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  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. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5153. if (quest_failures) {
  5154. for (int32 i = 0; i < quest_failures->size(); i++)
  5155. SendQuestFailure(quest_failures->at(i));
  5156. }
  5157. safe_delete(quest_failures);
  5158. }
  5159. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5160. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5161. player->pending_quests[quest->GetQuestID()] = quest;
  5162. AcceptQuest(quest->GetQuestID());
  5163. }
  5164. else {
  5165. player->pending_quests[quest->GetQuestID()] = quest;
  5166. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5167. //DumpPacket(outapp);
  5168. QueuePacket(outapp);
  5169. }
  5170. }
  5171. Quest* Client::GetActiveQuest(int32 quest_id) {
  5172. Quest* quest = 0;
  5173. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  5174. if (player->player_quests.count(quest_id) > 0) {
  5175. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  5176. quest = player->player_quests[quest_id];
  5177. }
  5178. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  5179. return quest;
  5180. }
  5181. void Client::AcceptQuest(int32 id) {
  5182. Quest* quest = GetPendingQuest(id);
  5183. if (quest) {
  5184. RemovePendingQuest(quest);
  5185. AddPlayerQuest(quest);
  5186. GetCurrentZone()->SendQuestUpdates(this);
  5187. // If character has already completed this quest once update the given date in the database
  5188. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  5189. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  5190. if (quest2)
  5191. quest->SetCompleteCount(quest2->GetCompleteCount());
  5192. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  5193. }
  5194. }
  5195. }
  5196. Quest* Client::GetPendingQuest(int32 id) {
  5197. if (player->pending_quests.count(id) > 0) {
  5198. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  5199. return player->pending_quests[id];
  5200. }
  5201. return 0;
  5202. }
  5203. void Client::RemovePendingQuest(Quest* quest) {
  5204. player->pending_quests.erase(quest->GetQuestID());
  5205. }
  5206. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5207. if (!quest || !progress) {
  5208. return;
  5209. }
  5210. map<int32, int32>::iterator itr;
  5211. QuestStep* step = 0;
  5212. player->SetZone(GetCurrentZone(), GetVersion());
  5213. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5214. step = quest->GetQuestStep(itr->first);
  5215. if (step && itr->second > 0) {
  5216. step->SetStepProgress(itr->second);
  5217. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5218. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5219. }
  5220. }
  5221. if (lua_interface && step)
  5222. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5223. else if(!step) {
  5224. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5225. }
  5226. }
  5227. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5228. bool lockCleared = false;
  5229. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5230. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5231. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5232. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5233. int32 questID = quest->GetQuestID();
  5234. lockCleared = true;
  5235. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5236. RemovePlayerQuest(questID, false, false);
  5237. }
  5238. player->player_quests[quest->GetQuestID()] = quest;
  5239. if(!lockCleared)
  5240. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5241. quest->SetPlayer(player);
  5242. current_quest_id = quest->GetQuestID();
  5243. if (send_packets && quest->GetQuestGiver() > 0)
  5244. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5245. if (lua_interface && call_accepted)
  5246. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5247. if (send_packets) {
  5248. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5249. //SendQuestJournal();
  5250. SendQuestJournalUpdate(quest);
  5251. // sent twice to match live
  5252. quest->SetTracked(false);
  5253. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5254. quest->SetTracked(true);
  5255. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5256. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5257. }
  5258. //This isn't during a load screen, so update spawns with required quests
  5259. if (call_accepted)
  5260. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5261. }
  5262. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5263. if (current_quest_id == id)
  5264. current_quest_id = 0;
  5265. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5266. if (player->player_quests.count(id) > 0) {
  5267. if (delete_quest) {
  5268. player->player_quests[id]->SetDeleted(true);
  5269. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5270. }
  5271. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5272. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5273. if (send_update && quest_giver > 0)
  5274. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5275. if (send_update) {
  5276. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5277. SendQuestJournal(false, 0, true);
  5278. }
  5279. player->RemoveQuest(id, delete_quest);
  5280. if (send_update) {
  5281. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5282. SendQuestJournal(false, 0, true);
  5283. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5284. }
  5285. }
  5286. else {
  5287. // if we don't have any quests to count then release the write lock
  5288. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5289. }
  5290. }
  5291. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5292. if (quest) {
  5293. QuestStep* quest_step = quest->GetQuestStep(step);
  5294. if (quest_step) {
  5295. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5296. quest_step->WasUpdated(false);
  5297. }
  5298. }
  5299. }
  5300. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5301. QueuedQuest* item = new QueuedQuest;
  5302. item->quest_id = quest->GetQuestID();
  5303. item->step = step;
  5304. item->display_quest_helper = display_quest_helper;
  5305. MQuestQueue.writelock();
  5306. quest_queue.push_back(item);
  5307. last_update_time = Timer::GetCurrentTime2();
  5308. MQuestQueue.releasewritelock();
  5309. }
  5310. void Client::SendQuestFailure(Quest* quest) {
  5311. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5312. if (failures) {
  5313. QuestStep* step = 0;
  5314. for (int32 i = 0; i < failures->size(); i++) {
  5315. step = failures->at(i);
  5316. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5317. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5318. SendQuestJournal(false, 0, true);
  5319. }
  5320. failures->clear();
  5321. }
  5322. }
  5323. void Client::SendQuestUpdate(Quest* quest) {
  5324. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5325. if (updates) {
  5326. QuestStep* step = 0;
  5327. bool updated = false;
  5328. for (int32 i = 0; i < updates->size(); i++) {
  5329. step = updates->at(i);
  5330. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5331. {
  5332. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5333. SendQuestUpdateStep(quest, step->GetStepID());
  5334. updated = true;
  5335. }
  5336. if (step->WasUpdated()) {
  5337. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5338. SendQuestJournal(false, 0, true);
  5339. if(!updated)
  5340. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5341. updated = true;
  5342. }
  5343. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5344. }
  5345. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5346. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5347. SendQuestJournalUpdate(quest, true);
  5348. }
  5349. if (quest->GetCompleted()) {
  5350. if (quest->GetQuestReturnNPC() > 0)
  5351. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5352. if (quest->GetCompletedFlag())
  5353. quest->SetCompletedFlag(false);
  5354. }
  5355. updates->clear();
  5356. }
  5357. }
  5358. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5359. if (!client)
  5360. client = this;
  5361. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5362. if (packet) {
  5363. EQ2Packet* outapp = packet->serialize();
  5364. //DumpPacket(outapp);
  5365. client->QueuePacket(outapp);
  5366. safe_delete(packet);
  5367. }
  5368. }
  5369. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5370. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5371. if (packet) {
  5372. QueuePacket(packet->serialize());
  5373. safe_delete(packet);
  5374. }
  5375. }
  5376. void Client::ReloadQuests() {
  5377. vector<int32> ids = player->GetQuestIDs();
  5378. Quest* quest = 0;
  5379. for (int32 i = 0; i < ids.size(); i++) {
  5380. quest = master_quest_list.GetQuest(ids[i]);
  5381. if (quest)
  5382. AddPlayerQuest(quest, false);
  5383. else
  5384. RemovePlayerQuest(ids[i]);
  5385. }
  5386. }
  5387. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5388. bool found_quest = false;
  5389. vector<int32>::iterator itr;
  5390. vector<Item*>* items = 0;
  5391. int32 questID = 0;
  5392. Quest* quest = 0;
  5393. MPendingQuestAccept.lock();
  5394. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  5395. questID = *itr;
  5396. quest = GetPlayer()->GetAnyQuest(questID);
  5397. if(!quest) {
  5398. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  5399. pending_quest_accept.erase(itr);
  5400. continue;
  5401. }
  5402. if(quest->GetQuestTemporaryState())
  5403. items = quest->GetTmpRewardItems();
  5404. else
  5405. items = quest->GetRewardItems();
  5406. if (item_id == 0) {
  5407. found_quest = true;
  5408. }
  5409. else {
  5410. items = quest->GetSelectableRewardItems();
  5411. if (items && items->size() > 0) {
  5412. for (int32 i = 0; i < items->size(); i++) {
  5413. if (items->at(i)->details.item_id == item_id) {
  5414. found_quest = true;
  5415. break;
  5416. }
  5417. }
  5418. }
  5419. }
  5420. if (found_quest) {
  5421. pending_quest_accept.erase(itr);
  5422. break;
  5423. }
  5424. }
  5425. MPendingQuestAccept.unlock();
  5426. if (found_quest)
  5427. return quest;
  5428. return 0;
  5429. }
  5430. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5431. int8 num_slots_needed = 0;
  5432. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5433. Item* master_item = 0;
  5434. if (item_id > 0) {
  5435. num_slots_needed++;
  5436. master_item = master_item_list.GetItem(item_id);
  5437. }
  5438. int32 totalItems = 0;
  5439. vector<Item*>* items = 0;
  5440. vector<Item*>* tmpItems = 0;
  5441. bool isTempState = quest->GetQuestTemporaryState();
  5442. if(isTempState)
  5443. {
  5444. tmpItems = quest->GetTmpRewardItems();
  5445. if (tmpItems && tmpItems->size() > 0)
  5446. {
  5447. num_slots_needed += tmpItems->size();
  5448. totalItems += tmpItems->size();
  5449. }
  5450. }
  5451. else
  5452. {
  5453. items = quest->GetRewardItems();
  5454. if (items && items->size() > 0)
  5455. {
  5456. num_slots_needed += items->size();
  5457. totalItems += items->size();
  5458. }
  5459. }
  5460. RemoveQueuedQuestReward();
  5461. GetPlayer()->SetActiveReward(false);
  5462. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5463. if (master_item)
  5464. AddItem(item_id);
  5465. if (tmpItems && tmpItems->size() > 0) {
  5466. for (int32 i = 0; i < tmpItems->size(); i++)
  5467. AddItem(new Item(tmpItems->at(i)));
  5468. }
  5469. if (items && items->size() > 0) {
  5470. for (int32 i = 0; i < items->size(); i++)
  5471. AddItem(new Item(items->at(i)));
  5472. }
  5473. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5474. if (outapp)
  5475. QueuePacket(outapp);
  5476. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5477. map<int32, sint32>::iterator itr;
  5478. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5479. int32 faction_id = itr->first;
  5480. sint32 amount = itr->second;
  5481. if (amount > 0)
  5482. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5483. else
  5484. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5485. }
  5486. if(quest->GetQuestTemporaryState())
  5487. {
  5488. int64 total_coins = quest->GetCoinTmpReward();
  5489. if (total_coins > 0)
  5490. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5491. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5492. }
  5493. else {
  5494. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5495. }
  5496. quest->SetQuestTemporaryState(false);
  5497. player->SetCharSheetChanged(true);
  5498. }
  5499. else {
  5500. GetPlayer()->SetActiveReward(true);
  5501. AddPendingQuestAcceptReward(quest);
  5502. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5503. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5504. }
  5505. }
  5506. 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) {
  5507. 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))) {
  5508. /*if (quest)
  5509. text = quest->GetName();
  5510. else*/
  5511. return;//nothing to give
  5512. }
  5513. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  5514. GetPlayer()->ClearPendingItemRewards();
  5515. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5516. if (packet2) {
  5517. int32 source_id = 0;
  5518. if (quest)
  5519. source_id = quest->GetQuestID();
  5520. int64 rewarded_coin = 0;
  5521. if (quest) {
  5522. if (quest->GetCoinsReward() > 0) {
  5523. if (quest->GetCoinsRewardMax() > 0)
  5524. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5525. else
  5526. rewarded_coin = quest->GetCoinsReward();
  5527. }
  5528. quest->SetGeneratedCoin(rewarded_coin);
  5529. }
  5530. if (rewarded_coin > coin)
  5531. coin = rewarded_coin;
  5532. 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
  5533. if (coin > 0) {
  5534. player->AddCoins(coin);
  5535. PlaySound("coin_cha_ching");
  5536. }
  5537. }
  5538. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5539. packet2->setSubstructDataByName("reward_data", "reward", header);
  5540. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5541. if (player->GetGuild() && !was_displayed) {
  5542. 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
  5543. player->GetInfoStruct()->add_status_points(status_points);
  5544. player->SetCharSheetChanged(true);
  5545. }
  5546. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5547. }
  5548. if(text)
  5549. packet2->setSubstructDataByName("reward_data", "text", text);
  5550. if(rewards){
  5551. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5552. for (int i = 0; i < rewards->size(); i++) {
  5553. Item* item = rewards->at(i);
  5554. if (item) {
  5555. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5556. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5557. }
  5558. 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
  5559. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5560. }
  5561. }
  5562. if (selectable_rewards) {
  5563. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5564. for (int i = 0; i < selectable_rewards->size(); i++) {
  5565. Item* item = selectable_rewards->at(i);
  5566. if (item) {
  5567. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5568. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5569. 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
  5570. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5571. }
  5572. }
  5573. }
  5574. if (factions) {
  5575. map<int32, sint32>::iterator itr;
  5576. map<Faction*, signed int> factions_map;
  5577. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5578. Faction* faction = master_faction_list.GetFaction(itr->first);
  5579. if (faction)
  5580. factions_map[faction] = itr->second;
  5581. }
  5582. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5583. map<Faction*, signed int>::iterator faction_itr;
  5584. int8 i = 0;
  5585. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5586. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5587. sint32 amount = faction_itr->second;
  5588. packet2->setArrayDataByName("amount", amount, i);
  5589. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5590. if (amount > 0)
  5591. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5592. else
  5593. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5594. }
  5595. i++;
  5596. }
  5597. }
  5598. QueuePacket(packet2->serialize());
  5599. safe_delete(packet2);
  5600. }
  5601. }
  5602. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  5603. if (!quest)
  5604. return;
  5605. if (GetVersion() <= 546) {
  5606. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), customDescription.c_str(), was_displayed);
  5607. return;
  5608. }
  5609. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5610. if (packet) {
  5611. packet->setDataByName("title", "Quest Reward!");
  5612. packet->setDataByName("name", quest->GetName());
  5613. if(customDescription.size() > 0)
  5614. {
  5615. packet->setDataByName("description", customDescription.c_str());
  5616. }
  5617. else
  5618. packet->setDataByName("description", quest->GetDescription());
  5619. packet->setDataByName("level", quest->GetLevel());
  5620. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5621. int8 difficulty = 0;
  5622. if ((string)quest->GetType() == "Tradeskill")
  5623. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5624. else
  5625. difficulty = player->GetArrowColor(quest->GetLevel());
  5626. packet->setDataByName("difficulty", difficulty);
  5627. if(tempReward)
  5628. {
  5629. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5630. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5631. packet->setDataByName("status_points", quest->GetStatusPoints());
  5632. }
  5633. else
  5634. {
  5635. int64 rewarded_coin = 0;
  5636. if (quest->GetCoinsReward() > 0) {
  5637. if (quest->GetCoinsRewardMax() > 0)
  5638. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5639. else
  5640. rewarded_coin = quest->GetCoinsReward();
  5641. }
  5642. quest->SetGeneratedCoin(rewarded_coin);
  5643. packet->setDataByName("max_coin", rewarded_coin);
  5644. packet->setDataByName("min_coin", rewarded_coin);
  5645. packet->setDataByName("status_points", quest->GetStatusPoints());
  5646. }
  5647. vector<Item*>* items = quest->GetTmpRewardItems();
  5648. if(tempReward)
  5649. {
  5650. if (items) {
  5651. packet->setArrayLengthByName("num_rewards", items->size());
  5652. for (int32 i = 0; i < items->size(); i++) {
  5653. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5654. if (version < 860)
  5655. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5656. else if (version < 1193)
  5657. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5658. else
  5659. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5660. }
  5661. }
  5662. }
  5663. else
  5664. {
  5665. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5666. vector<Item*>* items = quest->GetRewardItems();
  5667. if (items) {
  5668. packet->setArrayLengthByName("num_rewards", items->size());
  5669. for (int32 i = 0; i < items->size(); i++) {
  5670. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5671. if (version < 860)
  5672. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5673. else if (version < 1193)
  5674. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5675. else
  5676. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5677. }
  5678. }
  5679. if (items2 && items2->size() > 0) {
  5680. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5681. for (int32 i = 0; i < items2->size(); i++) {
  5682. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5683. if (version < 860)
  5684. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5685. else if (version < 1193)
  5686. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5687. else
  5688. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5689. }
  5690. }
  5691. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5692. if (reward_factions && reward_factions->size() > 0) {
  5693. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5694. map<int32, sint32>::iterator itr;
  5695. int16 index = 0;
  5696. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5697. int32 faction_id = itr->first;
  5698. sint32 amount = itr->second;
  5699. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5700. if (faction_name) {
  5701. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5702. packet->setArrayDataByName("amount", amount, index);
  5703. }
  5704. index++;
  5705. }
  5706. }
  5707. }
  5708. EQ2Packet* outapp = packet->serialize();
  5709. // DumpPacket(outapp);
  5710. QueuePacket(outapp);
  5711. safe_delete(packet);
  5712. }
  5713. }
  5714. void Client::DisplayRandomizeFeatures(int32 flags) {
  5715. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5716. if (flags > 0) {
  5717. if (flags & RANDOMIZE_GENDER)
  5718. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5719. if (flags & RANDOMIZE_RACE)
  5720. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5721. if (flags & RANDOMIZE_MODEL_TYPE)
  5722. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5723. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5724. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5725. if (flags & RANDOMIZE_HAIR_TYPE)
  5726. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5727. if (flags & RANDOMIZE_WING_TYPE)
  5728. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5729. if (flags & RANDOMIZE_CHEEK_TYPE)
  5730. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5731. if (flags & RANDOMIZE_CHIN_TYPE)
  5732. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5733. if (flags & RANDOMIZE_EAR_TYPE)
  5734. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5735. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5736. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5737. if (flags & RANDOMIZE_EYE_TYPE)
  5738. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5739. if (flags & RANDOMIZE_LIP_TYPE)
  5740. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5741. if (flags & RANDOMIZE_NOSE_TYPE)
  5742. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5743. if (flags & RANDOMIZE_EYE_COLOR)
  5744. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5745. if (flags & RANDOMIZE_HAIR_COLOR1)
  5746. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5747. if (flags & RANDOMIZE_HAIR_COLOR2)
  5748. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5749. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5750. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5751. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5752. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5753. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5754. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5755. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5756. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5757. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5758. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5759. if (flags & RANDOMIZE_SKIN_COLOR)
  5760. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5761. if (flags & RANDOMIZE_WING_COLOR1)
  5762. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5763. if (flags & RANDOMIZE_WING_COLOR2)
  5764. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5765. }
  5766. else
  5767. {
  5768. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5769. }
  5770. }
  5771. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  5772. current_quest_id = 0;
  5773. if(!quest->GetQuestTemporaryState() && !has_displayed)
  5774. {
  5775. quest->IncrementCompleteCount();
  5776. player->AddCompletedQuest(quest);
  5777. }
  5778. AddPendingQuestAcceptReward(quest);
  5779. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5780. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5781. SendQuestJournal();
  5782. if(quest->GetQuestTemporaryState()) {
  5783. return;
  5784. }
  5785. if(!has_displayed) {
  5786. if (quest->GetExpReward() > 0) {
  5787. int16 level = player->GetLevel();
  5788. int32 xp = quest->GetExpReward();
  5789. if (player->AddXP(xp)) {
  5790. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5791. if (player->GetLevel() != level)
  5792. ChangeLevel(level, player->GetLevel());
  5793. player->SetCharSheetChanged(true);
  5794. }
  5795. }
  5796. if (quest->GetTSExpReward() > 0) {
  5797. int8 ts_level = player->GetTSLevel();
  5798. int32 xp = quest->GetTSExpReward();
  5799. if (player->AddTSXP(xp)) {
  5800. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5801. if (player->GetTSLevel() != ts_level)
  5802. ChangeTSLevel(ts_level, player->GetTSLevel());
  5803. player->SetCharSheetChanged(true);
  5804. }
  5805. }
  5806. int64 total_coins = quest->GetGeneratedCoin();
  5807. if (total_coins > 0)
  5808. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5809. player->RemoveQuest(quest->GetQuestID(), false);
  5810. }
  5811. if (quest->GetQuestGiver() > 0)
  5812. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5813. if(!has_displayed) {
  5814. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5815. }
  5816. }
  5817. 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) {
  5818. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5819. if (packet) {
  5820. packet->setDataByName("conversation_id", conversation_id);
  5821. packet->setDataByName("text", text);
  5822. packet->setDataByName("language", language); // default 0
  5823. packet->setDataByName("can_close", can_close); // default 1
  5824. conversation_map[conversation_id].clear();
  5825. if (conversations) {
  5826. packet->setArrayLengthByName("num_responses", conversations->size());
  5827. for (int32 i = 0; i < conversations->size(); i++) {
  5828. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5829. if (conversations->at(i).function.length() > 0)
  5830. conversation_map[conversation_id][i] = conversations->at(i).function;
  5831. }
  5832. }
  5833. packet->setDataByName("spawn_id", spawn_id);
  5834. if (mp3) {
  5835. packet->setDataByName("voice", mp3);
  5836. packet->setDataByName("key1", key1);
  5837. packet->setDataByName("key2", key2);
  5838. }
  5839. QueuePacket(packet->serialize());
  5840. safe_delete(packet);
  5841. }
  5842. }
  5843. 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) {
  5844. if (!item || !text || !conversations || conversations->size() == 0) {
  5845. return;
  5846. }
  5847. int32 conversation_id = GetConversationID(0, item);
  5848. if (conversation_id == 0) {
  5849. next_conversation_id++;
  5850. conversation_id = next_conversation_id;
  5851. }
  5852. MConversation.writelock();
  5853. conversation_items[conversation_id] = item;
  5854. MConversation.releasewritelock();
  5855. if (type == 4)
  5856. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5857. else
  5858. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5859. }
  5860. 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) {
  5861. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5862. return;
  5863. }
  5864. int32 conversation_id = GetConversationID(src, 0);
  5865. if (conversation_id == 0) {
  5866. next_conversation_id++;
  5867. conversation_id = next_conversation_id;
  5868. }
  5869. MConversation.writelock();
  5870. conversation_spawns[conversation_id] = src->GetID();
  5871. MConversation.releasewritelock();
  5872. /* Spawns can start two different types of conversations.
  5873. * Type 1: The chat type with bubbles.
  5874. * Type 2: The dialog type with the blue box. */
  5875. if (type == 1)
  5876. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  5877. else if (type == 2)
  5878. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5879. else //if (type == 3)
  5880. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5881. }
  5882. void Client::CloseDialog(int32 conversation_id) {
  5883. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5884. if (packet) {
  5885. packet->setDataByName("conversation_id", conversation_id);
  5886. QueuePacket(packet->serialize());
  5887. safe_delete(packet);
  5888. }
  5889. MConversation.writelock();
  5890. std::map<int32, Item*>::iterator itr;
  5891. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5892. {
  5893. conversation_items.erase(itr);
  5894. }
  5895. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  5896. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5897. {
  5898. conversation_spawns.erase(itr2);
  5899. }
  5900. MConversation.releasewritelock();
  5901. }
  5902. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5903. int32 conversation_id = 0;
  5904. MConversation.readlock();
  5905. if (spawn) {
  5906. map<int32, int32>::iterator itr;
  5907. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5908. if (itr->second == spawn->GetID()) {
  5909. conversation_id = itr->first;
  5910. break;
  5911. }
  5912. }
  5913. }
  5914. else if (item) {
  5915. map<int32, Item*>::iterator itr;
  5916. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5917. if (itr->second == item) {
  5918. conversation_id = itr->first;
  5919. break;
  5920. }
  5921. }
  5922. }
  5923. MConversation.releasereadlock();
  5924. return conversation_id;
  5925. }
  5926. Spawn* Client::GetCombineSpawn() {
  5927. return combine_spawn;
  5928. }
  5929. bool Client::ShouldTarget() {
  5930. return should_target;
  5931. }
  5932. void Client::TargetSpawn(Spawn* spawn) {
  5933. should_target = false;
  5934. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5935. if (packet) {
  5936. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5937. QueuePacket(packet->serialize());
  5938. safe_delete(packet);
  5939. }
  5940. }
  5941. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5942. combine_spawn = spawn;
  5943. spawn->RemoveSpawnFromGroup(true);
  5944. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5945. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5946. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5947. should_target = true;
  5948. }
  5949. void Client::AddCombineSpawn(Spawn* spawn) {
  5950. if (combine_spawn && combine_spawn != spawn && spawn) {
  5951. combine_spawn->AddSpawnToGroup(spawn);
  5952. spawn->AddSpawnToGroup(combine_spawn);
  5953. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5954. }
  5955. else if (spawn)
  5956. combine_spawn = spawn;
  5957. should_target = true;
  5958. }
  5959. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5960. if (combine_spawn && spawn)
  5961. spawn->RemoveSpawnFromGroup();
  5962. if (combine_spawn == spawn)
  5963. combine_spawn->RemoveSpawnFromGroup(true);
  5964. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5965. if (combine_spawn == spawn)
  5966. combine_spawn = 0;
  5967. }
  5968. void Client::SaveCombineSpawns(const char* name) {
  5969. if (!combine_spawn) {
  5970. return;
  5971. }
  5972. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5973. if (!spawns) {
  5974. return;
  5975. }
  5976. int32 count = spawns->size();
  5977. int32 spawnLocationID = 0;
  5978. if (count == 1)
  5979. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5980. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5981. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5982. // we remove the spawn inside SaveCombinedSpawnLocation
  5983. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5984. }
  5985. else
  5986. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5987. safe_delete(spawns);
  5988. combine_spawn = 0;
  5989. }
  5990. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  5991. Item* master_item = master_item_list.GetItem(item_id);
  5992. Item* item = 0;
  5993. if (master_item)
  5994. item = new Item(master_item);
  5995. if (item) {
  5996. if (quantity > 0)
  5997. item->details.count = quantity;
  5998. return AddItem(item, nullptr, type);
  5999. }
  6000. else
  6001. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6002. return false;
  6003. }
  6004. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6005. if (!item) {
  6006. return false;
  6007. }
  6008. if (item->IsBag()) {
  6009. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  6010. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  6011. }
  6012. if (player->AddItem(item, type)) {
  6013. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6014. if (outapp) {
  6015. //DumpPacket(outapp);
  6016. QueuePacket(outapp);
  6017. //resend bag desc with new item name added
  6018. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6019. if (outapp) {
  6020. //DumpPacket(outapp);
  6021. QueuePacket(outapp);
  6022. }
  6023. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6024. DumpPacket(app);
  6025. client->QueuePacket(app);
  6026. */
  6027. }
  6028. CheckPlayerQuestsItemUpdate(item);
  6029. if (item->GetItemScript() && lua_interface)
  6030. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6031. }
  6032. else {
  6033. // likely lore conflict
  6034. safe_delete(item);
  6035. if(item_deleted)
  6036. *item_deleted = true;
  6037. return false;
  6038. }
  6039. return true;
  6040. }
  6041. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6042. Item* master_item = master_item_list.GetItem(item_id);
  6043. Item* item = 0;
  6044. if (master_item)
  6045. item = new Item(master_item);
  6046. if (item) {
  6047. if (quantity > 0)
  6048. item->details.count = quantity;
  6049. return AddItemToBank(item);
  6050. }
  6051. else
  6052. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6053. return false;
  6054. }
  6055. bool Client::AddItemToBank(Item* item) {
  6056. if (!item) {
  6057. return false;
  6058. }
  6059. if (player->AddItemToBank(item)) {
  6060. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6061. if (outapp) {
  6062. QueuePacket(outapp);
  6063. //resend bag desc with new item name added
  6064. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6065. if (outapp)
  6066. QueuePacket(outapp);
  6067. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6068. DumpPacket(app);
  6069. client->QueuePacket(app);
  6070. */
  6071. }
  6072. CheckPlayerQuestsItemUpdate(item);
  6073. if (item->GetItemScript() && lua_interface)
  6074. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6075. }
  6076. else {
  6077. // likely lore conflict
  6078. safe_delete(item);
  6079. return false;
  6080. }
  6081. return true;
  6082. }
  6083. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6084. EQ2Packet* outapp;
  6085. bool delete_item = false;
  6086. assert(item);
  6087. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6088. item->details.count -= quantity;
  6089. item->save_needed = true;
  6090. }
  6091. else {
  6092. database.DeleteItem(character_id, item, 0);
  6093. player->GetPlayerItemList()->RemoveItem(item, false);
  6094. delete_item = true;
  6095. }
  6096. if(force_override_no_delete)
  6097. delete_item = false;
  6098. if ((outapp = player->SendInventoryUpdate(version))) {
  6099. QueuePacket(outapp);
  6100. if (item->GetItemScript() && lua_interface)
  6101. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6102. if (delete_item)
  6103. {
  6104. PurgeItem(item);
  6105. safe_delete(item);
  6106. }
  6107. return true;
  6108. }
  6109. return false;
  6110. }
  6111. void Client::SetLuaDebugClient(bool val) {
  6112. if (val)
  6113. lua_debug_timer.Start();
  6114. lua_debug = val;
  6115. if (lua_interface && !val) {
  6116. lua_interface->RemoveDebugClients(this);
  6117. lua_debug_timer.Disable();
  6118. }
  6119. }
  6120. void Client::SetMerchantTransaction(Spawn* spawn) {
  6121. merchant_transaction = spawn;
  6122. }
  6123. Spawn* Client::GetMerchantTransaction() {
  6124. return merchant_transaction;
  6125. }
  6126. void Client::SetMailTransaction(Spawn* spawn) {
  6127. ResetSendMail(spawn ? false : true);
  6128. MMailWindowMutex.lock();
  6129. mail_transaction = spawn;
  6130. MMailWindowMutex.unlock();
  6131. }
  6132. Spawn* Client::GetMailTransaction() {
  6133. return mail_transaction;
  6134. }
  6135. void Client::PlaySound(const char* name) {
  6136. if (name) {
  6137. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6138. if (packet) {
  6139. packet->setMediumStringByName("name", name);
  6140. QueuePacket(packet->serialize());
  6141. safe_delete(packet);
  6142. }
  6143. }
  6144. }
  6145. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6146. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6147. if(multiplier){
  6148. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6149. float diff_low = faction_val - multiplier->faction_min;
  6150. if(diff_low < 0)
  6151. diff_low*=-1;
  6152. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6153. if(total_diff < 0)
  6154. total_diff*=-1;
  6155. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6156. float total1 = (diff_low/total_diff);
  6157. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6158. return final_buy_multiplier;
  6159. }*/
  6160. return 1;
  6161. }
  6162. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6163. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6164. if(multiplier){
  6165. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6166. float diff_low = faction_val - multiplier->faction_min;
  6167. if(diff_low < 0)
  6168. diff_low*=-1;
  6169. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6170. if(total_diff < 0)
  6171. total_diff*=-1;
  6172. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6173. float total1 = (diff_low/total_diff);
  6174. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6175. return final_sell_multiplier;
  6176. }*/
  6177. return 1;
  6178. }
  6179. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6180. Spawn* spawn = GetMerchantTransaction();
  6181. Guild* guild = GetPlayer()->GetGuild();
  6182. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6183. spawn->IsClientInMerchantLevelRange(this)) {
  6184. int32 total_sell_price = 0;
  6185. int32 total_status_sell_price = 0; //for status
  6186. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6187. int32 sell_price = 0;
  6188. int32 status_sell_price = 0; //for status
  6189. Item* master_item = master_item_list.GetItem(item_id);
  6190. Item* item = 0;
  6191. if (unique_id == 0)
  6192. item = player->item_list.GetItemFromID(item_id, quantity);
  6193. else
  6194. item = player->item_list.GetItemFromUniqueID(unique_id);
  6195. if (!item)
  6196. item = player->item_list.GetItemFromID(item_id);
  6197. if (item && master_item) {
  6198. if(item->details.item_locked)
  6199. {
  6200. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6201. return;
  6202. }
  6203. else if(item->CheckFlag(NO_VALUE))
  6204. {
  6205. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6206. return;
  6207. }
  6208. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6209. if (sell_price > item->sell_price)
  6210. sell_price = item->sell_price;
  6211. if (quantity > item->details.count)
  6212. quantity = item->details.count;
  6213. total_sell_price = sell_price * quantity;
  6214. //------------------------------For Selling Status Items
  6215. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6216. if (status_sell_price > item->sell_status)
  6217. status_sell_price = item->sell_status;
  6218. if (quantity > item->details.count)
  6219. quantity = item->details.count;
  6220. total_status_sell_price = status_sell_price * quantity;
  6221. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6222. total_status_sell_price = 0;
  6223. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6224. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6225. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6226. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6227. guild->SendGuildMemberList();
  6228. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6229. }
  6230. if (quantity > 1)
  6231. {
  6232. if(total_status_sell_price)
  6233. 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);
  6234. else
  6235. 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());
  6236. }
  6237. else
  6238. {
  6239. if(total_status_sell_price)
  6240. 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);
  6241. else
  6242. 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());
  6243. }
  6244. player->AddCoins(total_sell_price);
  6245. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6246. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6247. if (quantity >= item->details.count) {
  6248. database.DeleteItem(GetCharacterID(), item, 0);
  6249. player->item_list.DestroyItem(item->details.index);
  6250. }
  6251. else {
  6252. item->details.count -= quantity;
  6253. item->save_needed = true;
  6254. }
  6255. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6256. if (outapp)
  6257. QueuePacket(outapp);
  6258. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6259. SendBuyBackList();
  6260. }
  6261. }
  6262. }
  6263. void Client::BuyBack(int32 item_id, int16 quantity) {
  6264. Spawn* spawn = GetMerchantTransaction();
  6265. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6266. spawn->IsClientInMerchantLevelRange(this)) {
  6267. deque<BuyBackItem*>::iterator itr;
  6268. BuyBackItem* buyback = 0;
  6269. BuyBackItem* closest = 0;
  6270. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6271. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6272. buyback = *itr;
  6273. if (buyback->unique_id == item_id) {
  6274. closest = buyback;
  6275. quantity = buyback->quantity;
  6276. break;
  6277. }
  6278. }
  6279. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6280. if (closest) {
  6281. Item* item = 0;
  6282. Item* master_item = master_item_list.GetItem(closest->item_id);
  6283. if (master_item) {
  6284. item = new Item(master_item);
  6285. if (closest->quantity >= quantity)
  6286. item->details.count = quantity;
  6287. else
  6288. item->details.count = closest->quantity;
  6289. }
  6290. bool itemDeleted = false;
  6291. bool itemAdded = false;
  6292. sint64 dispFlags = 0;
  6293. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6294. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6295. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6296. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6297. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6298. bool removed = false;
  6299. if (closest->quantity == quantity) {
  6300. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6301. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6302. if (*itr == closest) {
  6303. buy_back_items.erase(itr);
  6304. removed = true;
  6305. break;
  6306. }
  6307. }
  6308. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6309. }
  6310. else {
  6311. closest->quantity -= quantity;
  6312. closest->save_needed = true;
  6313. }
  6314. itemAdded = AddItem(item, &itemDeleted);
  6315. if (removed) {
  6316. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6317. safe_delete(closest);
  6318. }
  6319. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6320. SendBuyBackList();
  6321. }
  6322. else
  6323. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6324. if(!itemAdded && !itemDeleted)
  6325. safe_delete(item);
  6326. }
  6327. }
  6328. }
  6329. void Client::BuyItem(int32 item_id, int16 quantity) {
  6330. // Get the merchant we are buying from
  6331. Spawn* spawn = GetMerchantTransaction();
  6332. // Make sure the spawn has a merchant list
  6333. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6334. int32 total_buy_price = 0;
  6335. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6336. int32 sell_price = 0;
  6337. Item* master_item = master_item_list.GetItem(item_id);
  6338. Item* item = 0;
  6339. int16 total_available = 0;
  6340. vector<MerchantItemInfo>* temp;
  6341. vector<MerchantItemInfo>::iterator itr;
  6342. MerchantItemInfo* ItemInfo = 0;
  6343. temp = world.GetMerchantList(spawn->GetMerchantID());
  6344. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6345. if ((*itr).item_id == item_id) {
  6346. ItemInfo = &(*itr);
  6347. break;
  6348. }
  6349. }
  6350. if (master_item && ItemInfo) {
  6351. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6352. quantity = 1;
  6353. total_available = 0xFFFF;
  6354. sell_price = master_item->sell_price;
  6355. }
  6356. else {
  6357. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6358. sell_price = (int32)(master_item->sell_price * multiplier);
  6359. if (quantity > total_available)
  6360. quantity = total_available;
  6361. }
  6362. sint64 dispFlags = 0;
  6363. 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))
  6364. {
  6365. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6366. return;
  6367. }
  6368. if(quantity < 1)
  6369. {
  6370. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6371. return;
  6372. }
  6373. total_buy_price = sell_price * quantity;
  6374. item = new Item(master_item);
  6375. item->details.count = quantity;
  6376. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6377. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6378. safe_delete(item);
  6379. }
  6380. else {
  6381. // Price not set in the merchant_inventory table, use the old method
  6382. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6383. if (player->RemoveCoins(total_buy_price)) {
  6384. item->SetMaxSellValue(sell_price);
  6385. if (quantity > 1)
  6386. 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());
  6387. else
  6388. 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());
  6389. bool itemDeleted = false;
  6390. AddItem(item, &itemDeleted);
  6391. if(!itemDeleted) {
  6392. CheckPlayerQuestsItemUpdate(item);
  6393. if (item && total_available < 0xFF) {
  6394. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6395. SendBuyMerchantList();
  6396. }
  6397. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6398. PlayLotto(total_buy_price, item->details.item_id);
  6399. }
  6400. }
  6401. else {
  6402. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6403. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6404. PlaySound("buy_failed");
  6405. }
  6406. }
  6407. else {
  6408. // Price set in merchant_inventory table
  6409. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6410. // TODO: need to add support for station cash
  6411. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6412. // Check items
  6413. int16 item_quantity = 0;
  6414. // Default these to true in case price_item_id or price_item2_id was never set
  6415. bool hasItem1 = true;
  6416. bool hasItem2 = true;
  6417. Item* tempItem1 = 0;
  6418. Item* tempItem2 = 0;
  6419. if (ItemInfo->price_item_id != 0) {
  6420. // Same item for whatever reason lets add the quantities together
  6421. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6422. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6423. else
  6424. item_quantity = ItemInfo->price_item_qty;
  6425. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6426. if (tempItem1) {
  6427. if (tempItem1->details.count < item_quantity)
  6428. hasItem1 = false;
  6429. }
  6430. else {
  6431. hasItem1 = false;
  6432. }
  6433. }
  6434. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6435. // as item1 and we already checked for it so we can skip this check
  6436. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6437. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6438. if (tempItem2) {
  6439. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6440. hasItem2 = false;
  6441. }
  6442. else {
  6443. hasItem2 = false;
  6444. }
  6445. }
  6446. // if we have every thing then remove the price and give the item
  6447. if (hasItem1 && hasItem2) {
  6448. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6449. // TODO: station cash
  6450. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6451. // so there is no need to send it more then that one time
  6452. if (tempItem1) {
  6453. if (tempItem1->details.count > item_quantity) {
  6454. tempItem1->details.count -= item_quantity;
  6455. tempItem1->save_needed = true;
  6456. }
  6457. else {
  6458. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6459. player->item_list.DestroyItem(tempItem1->details.index);
  6460. }
  6461. }
  6462. if (tempItem2) {
  6463. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6464. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6465. tempItem2->save_needed = true;
  6466. }
  6467. else {
  6468. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6469. player->item_list.DestroyItem(tempItem2->details.index);
  6470. }
  6471. }
  6472. // 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
  6473. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6474. item->SetMaxSellValue(sell_price);
  6475. if (quantity > 1)
  6476. 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());
  6477. else
  6478. 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());
  6479. bool itemDeleted = false;
  6480. AddItem(item, &itemDeleted);
  6481. if(!itemDeleted) {
  6482. CheckPlayerQuestsItemUpdate(item);
  6483. if (item && total_available < 0xFF) {
  6484. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6485. SendBuyMerchantList();
  6486. }
  6487. SendSellMerchantList();
  6488. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6489. PlayLotto(total_buy_price, item->details.item_id);
  6490. }
  6491. }
  6492. else {
  6493. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6494. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6495. PlaySound("buy_failed");
  6496. }
  6497. }
  6498. else {
  6499. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6500. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6501. PlaySound("buy_failed");
  6502. }
  6503. }
  6504. }
  6505. }
  6506. }
  6507. }
  6508. void Client::RepairItem(int32 item_id) {
  6509. Spawn* spawn = GetMerchantTransaction();
  6510. if (spawn) {
  6511. Item* item = player->item_list.GetItemFromID(item_id);
  6512. if (!item)
  6513. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6514. if (item) {
  6515. if(item->CheckFlag(NO_REPAIR)) {
  6516. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  6517. PlaySound("buy_failed");
  6518. }
  6519. else {
  6520. int32 repair_cost = item->CalculateRepairCost();
  6521. if (player->RemoveCoins((int32)repair_cost)) {
  6522. item->generic_info.condition = 100;
  6523. item->save_needed = true;
  6524. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6525. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6526. QueuePacket(item->serialize(version, false, player));
  6527. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6528. PlaySound("coin_cha_ching");
  6529. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6530. SendRepairList();
  6531. }
  6532. else {
  6533. string popup_text = "You do not have enough coin to repair ";
  6534. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  6535. popup_text.append(popup_item);
  6536. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6537. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6538. PlaySound("buy_failed");
  6539. }
  6540. }
  6541. }
  6542. }
  6543. }
  6544. void Client::RepairAllItems() {
  6545. Spawn* spawn = GetMerchantTransaction();
  6546. if (spawn) {
  6547. vector<Item*>* repairable_items = GetRepairableItems();
  6548. if (repairable_items && repairable_items->size() > 0) {
  6549. vector<Item*>::iterator itr;
  6550. int64 total_cost = 0;
  6551. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6552. total_cost += (*itr)->CalculateRepairCost();
  6553. if (player->RemoveCoins((int32)total_cost)) {
  6554. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6555. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6556. Item* item = *itr;
  6557. if (item) {
  6558. item->generic_info.condition = 100;
  6559. item->save_needed = true;
  6560. QueuePacket(item->serialize(version, false, player));
  6561. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6562. }
  6563. }
  6564. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6565. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6566. PlaySound("coin_cha_ching");
  6567. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6568. SendRepairList();
  6569. }
  6570. else {
  6571. string popup_text = "You do not have enough coin to repair all of your items. ";
  6572. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6573. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6574. PlaySound("buy_failed");
  6575. }
  6576. }
  6577. safe_delete(repairable_items);
  6578. }
  6579. }
  6580. void Client::SendAchievementsList()
  6581. {
  6582. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6583. map<int32, Achievement *>::iterator itr;
  6584. Achievement *achievement;
  6585. vector<AchievementRequirements *> *requirements = 0;
  6586. vector<AchievementRequirements *>::iterator itr2;
  6587. AchievementRequirements *requirement;
  6588. vector<AchievementRewards *> *rewards = 0;
  6589. vector<AchievementRewards *>::iterator itr3;
  6590. AchievementRewards *reward;
  6591. PacketStruct *packet;
  6592. int16 i = 0;
  6593. int16 j = 0;
  6594. int16 k = 0;
  6595. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6596. return;
  6597. }
  6598. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6599. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6600. achievement = itr->second;
  6601. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6602. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6603. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6604. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6605. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6606. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6607. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6608. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6609. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6610. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6611. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6612. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6613. requirements = achievement->GetRequirements();
  6614. rewards = achievement->GetRewards();
  6615. j = 0;
  6616. k = 0;
  6617. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6618. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6619. requirement = *itr2;
  6620. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6621. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6622. j++;
  6623. }
  6624. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6625. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6626. reward = *itr3;
  6627. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6628. k++;
  6629. }
  6630. i++;
  6631. }
  6632. //packet->PrintPacket();
  6633. EQ2Packet* data = packet->serialize();
  6634. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6635. safe_delete(packet);
  6636. safe_delete(data);
  6637. //DumpPacket(app);
  6638. QueuePacket(app);*/
  6639. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6640. SendAchievementUpdate(true);
  6641. }
  6642. void Client::SendAchievementUpdate(bool first_login) {
  6643. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6644. map<int32, AchievementUpdate*>::iterator itr;
  6645. AchievementUpdate* update;
  6646. vector<AchievementUpdateItems*>* update_items = 0;
  6647. vector<AchievementUpdateItems*>::iterator itr2;
  6648. AchievementUpdateItems* update_item;
  6649. int16 i = 0;
  6650. int16 j = 0;
  6651. PacketStruct* packet;
  6652. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6653. return;
  6654. }
  6655. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6656. packet->setArrayLengthByName("num_achievements", updates->size());
  6657. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6658. update = itr->second;
  6659. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6660. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6661. update_items = update->GetUpdateItems();
  6662. j = 0;
  6663. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6664. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6665. update_item = *itr2;
  6666. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6667. j++;
  6668. }
  6669. i++;
  6670. }
  6671. //packet->PrintPacket();
  6672. EQ2Packet* data = packet->serialize();
  6673. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6674. safe_delete(packet);
  6675. safe_delete(data);
  6676. //DumpPacket(app);
  6677. QueuePacket(app);
  6678. }
  6679. void Client::SendBuyMerchantList(bool sell) {
  6680. Spawn* spawn = GetMerchantTransaction();
  6681. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6682. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6683. if (items) {
  6684. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6685. if (packet) {
  6686. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6687. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6688. packet->setArrayLengthByName("num_items", items->size());
  6689. vector<MerchantItemInfo>::iterator itr;
  6690. sint8 item_difficulty = 0;
  6691. int32 sell_price = 0;
  6692. int i = 0;
  6693. int tmp_level = 0;
  6694. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6695. MerchantItemInfo ItemInfo = *itr;
  6696. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6697. if (!item)
  6698. continue;
  6699. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6700. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6701. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6702. packet->setArrayDataByName("icon", item->details.icon, i);
  6703. if (item->generic_info.adventure_default_level > 0)
  6704. tmp_level = item->generic_info.adventure_default_level;
  6705. else
  6706. tmp_level = item->generic_info.tradeskill_default_level;
  6707. packet->setArrayDataByName("level", tmp_level, i);
  6708. packet->setArrayDataByName("tier", item->details.tier, i);
  6709. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6710. item_difficulty = player->GetArrowColor(tmp_level);
  6711. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6712. item_difficulty = ARROW_COLOR_WHITE;
  6713. sint64 overrideValue = 0;
  6714. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6715. item_difficulty = (sint8)overrideValue;
  6716. item_difficulty -= 6;
  6717. if (item_difficulty < 0)
  6718. item_difficulty *= -1;
  6719. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6720. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6721. packet->setArrayDataByName("unknown5", 255, i);
  6722. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6723. sint64 dispFlags = 0;
  6724. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  6725. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6726. std::string overrideValueStr;
  6727. // 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)
  6728. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6729. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6730. // If no price set in the merchant_inventory table then use the old method
  6731. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6732. sell_price = (int32)(item->sell_price * multiplier);
  6733. packet->setArrayDataByName("price", sell_price, i);
  6734. }
  6735. else {
  6736. int8 count = 0;
  6737. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6738. count++;
  6739. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6740. count++;
  6741. if (count != 0) {
  6742. packet->setSubArrayLengthByName("num_tokens", count, i);
  6743. int8 index = 0;
  6744. Item* token = 0;
  6745. if (ItemInfo.price_item_id != 0) {
  6746. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6747. if (item) {
  6748. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6749. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6750. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6751. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6752. }
  6753. token = 0;
  6754. index++;
  6755. }
  6756. if (ItemInfo.price_item2_id != 0) {
  6757. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6758. if (item) {
  6759. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6760. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6761. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6762. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6763. }
  6764. }
  6765. }
  6766. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6767. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6768. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6769. }
  6770. }
  6771. if (GetVersion() <= 546) {
  6772. //buy is 0 so dont need to set it
  6773. if (sell)
  6774. packet->setDataByName("type", 1);
  6775. }
  6776. else {
  6777. if (sell)
  6778. packet->setDataByName("type", 130);
  6779. else
  6780. packet->setDataByName("type", 2);
  6781. }
  6782. EQ2Packet* outapp = packet->serialize();
  6783. // DumpPacket(outapp);
  6784. QueuePacket(outapp);
  6785. safe_delete(packet);
  6786. }
  6787. safe_delete(items);
  6788. }
  6789. else {
  6790. // Need to send an empty packet in the event there is no item list, otherwise the
  6791. // last item list sent to the player will show for this merchant
  6792. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6793. if (packet) {
  6794. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6795. if (GetVersion() <= 546) {
  6796. //buy is 0 so dont need to set it
  6797. if (sell)
  6798. packet->setDataByName("type", 1);
  6799. }
  6800. else {
  6801. if (sell)
  6802. packet->setDataByName("type", 130);
  6803. else
  6804. packet->setDataByName("type", 2);
  6805. }
  6806. EQ2Packet* outapp = packet->serialize();
  6807. QueuePacket(outapp);
  6808. safe_delete(packet);
  6809. }
  6810. }
  6811. }
  6812. }
  6813. void Client::SendSellMerchantList(bool sell) {
  6814. Spawn* spawn = GetMerchantTransaction();
  6815. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6816. return;
  6817. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6818. map<int32, Item*>* items = player->GetItemList();
  6819. if (items) {
  6820. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6821. if (packet) {
  6822. vector<Item*> sellable_items;
  6823. map<int32, Item*>::iterator test_itr;
  6824. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6825. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6826. sellable_items.push_back(test_itr->second);
  6827. }
  6828. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6829. packet->setArrayLengthByName("num_items", sellable_items.size());
  6830. vector<Item*>::iterator itr;
  6831. Item* item = 0;
  6832. sint8 item_difficulty = 0;
  6833. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6834. int32 sell_price = 0;
  6835. Item* master_item = 0;
  6836. int i = 0;
  6837. int tmp_level = 0;
  6838. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6839. item = *itr;
  6840. master_item = master_item_list.GetItem(item->details.item_id);
  6841. if (master_item)
  6842. sell_price = (int32)(master_item->sell_price * multiplier);
  6843. else
  6844. sell_price = 0;
  6845. if (sell_price > item->sell_price)
  6846. sell_price = item->sell_price;
  6847. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6848. string thename = item->name;
  6849. packet->setArrayDataByName("price", sell_price, i);
  6850. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6851. int8 dispFlags = 0;
  6852. // only city merchants allow selling for status
  6853. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6854. {
  6855. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6856. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6857. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6858. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6859. }
  6860. }
  6861. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6862. {
  6863. if(GetVersion() < 1188)
  6864. 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
  6865. else
  6866. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6867. }
  6868. if(item->no_sale)
  6869. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6870. packet->setArrayDataByName("display_flags", dispFlags, i);
  6871. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6872. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6873. packet->setArrayDataByName("stack_size", item->details.count, i);
  6874. packet->setArrayDataByName("icon", item->details.icon, i);
  6875. if (item->generic_info.adventure_default_level > 0)
  6876. tmp_level = item->generic_info.adventure_default_level;
  6877. else
  6878. tmp_level = item->generic_info.tradeskill_default_level;
  6879. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6880. packet->setArrayDataByName("tier", item->details.tier, i);
  6881. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6882. item_difficulty = player->GetArrowColor(tmp_level);
  6883. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6884. item_difficulty = ARROW_COLOR_WHITE;
  6885. sint64 overrideValue = 0;
  6886. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6887. item_difficulty = (sint8)overrideValue;
  6888. item_difficulty -= 6;
  6889. if (item_difficulty < 0)
  6890. item_difficulty *= -1;
  6891. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6892. if (item->details.count == 1)
  6893. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6894. else
  6895. packet->setArrayDataByName("quantity", item->details.count, i);
  6896. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6897. if (GetVersion() <= 1096)
  6898. packet->setArrayDataByName("description", item->description.c_str(), i);
  6899. }
  6900. if (GetVersion() <= 546) {
  6901. packet->setDataByName("type", 1);
  6902. }
  6903. else {
  6904. if (sell)
  6905. packet->setDataByName("type", 129);
  6906. else
  6907. packet->setDataByName("type", 1);
  6908. }
  6909. packet->setDataByName("unknown8a", 16256, 6);
  6910. packet->setDataByName("unknown8a", 16256, 10);
  6911. //packet->PrintPacket();
  6912. EQ2Packet* outapp = packet->serialize();
  6913. //DumpPacket(outapp);
  6914. QueuePacket(outapp);
  6915. safe_delete(packet);
  6916. }
  6917. safe_delete(items);
  6918. }
  6919. }
  6920. }
  6921. void Client::SendBuyBackList(bool sell) {
  6922. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6923. return;
  6924. Spawn* spawn = GetMerchantTransaction();
  6925. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6926. deque<BuyBackItem*>::iterator itr;
  6927. int i = 0;
  6928. Item* master_item = 0;
  6929. BuyBackItem* buyback = 0;
  6930. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6931. if (packet) {
  6932. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6933. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6934. sint8 item_difficulty = 0;
  6935. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6936. int tmp_level = 0;
  6937. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6938. buyback = *itr;
  6939. master_item = master_item_list.GetItem(buyback->item_id);
  6940. if (master_item) {
  6941. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6942. packet->setArrayDataByName("price", buyback->price, i);
  6943. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6944. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6945. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6946. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6947. if (master_item->generic_info.adventure_default_level > 0)
  6948. tmp_level = master_item->generic_info.adventure_default_level;
  6949. else
  6950. tmp_level = master_item->generic_info.tradeskill_default_level;
  6951. packet->setArrayDataByName("level", tmp_level, i);
  6952. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6953. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6954. item_difficulty = player->GetArrowColor(tmp_level);
  6955. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6956. item_difficulty = ARROW_COLOR_WHITE;
  6957. sint64 overrideValue = 0;
  6958. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  6959. item_difficulty = (sint8)overrideValue;
  6960. item_difficulty -= 6;
  6961. if (item_difficulty < 0)
  6962. item_difficulty *= -1;
  6963. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6964. sint64 dispFlags = 0;
  6965. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  6966. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6967. if (buyback->quantity == 1)
  6968. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6969. else
  6970. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6971. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6972. if (GetVersion() <= 1096)
  6973. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6974. }
  6975. }
  6976. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6977. if (sell)
  6978. packet->setDataByName("type", 640);
  6979. else
  6980. packet->setDataByName("type", 512);
  6981. EQ2Packet* outapp = packet->serialize();
  6982. // DumpPacket(outapp);
  6983. QueuePacket(outapp);
  6984. safe_delete(packet);
  6985. }
  6986. }
  6987. }
  6988. void Client::SendRepairList() {
  6989. Spawn* spawn = GetMerchantTransaction();
  6990. if (spawn) {
  6991. vector<Item*>* repairable_items = GetRepairableItems();
  6992. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6993. if (packet) {
  6994. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6995. packet->setArrayLengthByName("num_items", repairable_items->size());
  6996. Item* item = 0;
  6997. sint8 item_difficulty = 0;
  6998. int32 i = 0;
  6999. vector<Item*>::iterator itr;
  7000. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7001. item = *itr;
  7002. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7003. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7004. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7005. packet->setArrayDataByName("stack_size", item->details.count, i);
  7006. packet->setArrayDataByName("icon", item->details.icon, i);
  7007. /*if (item->generic_info.adventure_default_level > 0)
  7008. tmp_level = item->generic_info.adventure_default_level;
  7009. else
  7010. tmp_level = item->generic_info.tradeskill_default_level;
  7011. packet->setArrayDataByName("level", tmp_level, i);*/
  7012. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7013. packet->setArrayDataByName("tier", item->details.tier, i);
  7014. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7015. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7016. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7017. item_difficulty = ARROW_COLOR_WHITE;
  7018. item_difficulty -= 6;
  7019. if (item_difficulty < 0)
  7020. item_difficulty *= -1;
  7021. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7022. if (item->details.count == 1)
  7023. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7024. else
  7025. packet->setArrayDataByName("quantity", item->details.count, i);
  7026. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7027. if (GetVersion() <= 1096)
  7028. packet->setArrayDataByName("description", item->description.c_str(), i);
  7029. }
  7030. if (GetVersion() <= 546) {
  7031. packet->setDataByName("type", 16);
  7032. }
  7033. else {
  7034. packet->setDataByName("type", 96);
  7035. }
  7036. EQ2Packet* outapp = packet->serialize();
  7037. QueuePacket(outapp);
  7038. safe_delete(packet);
  7039. }
  7040. safe_delete(repairable_items);
  7041. }
  7042. }
  7043. void Client::ShowLottoWindow() {
  7044. Spawn* spawn = GetMerchantTransaction();
  7045. if (spawn) {
  7046. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7047. if (!item_id)
  7048. {
  7049. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7050. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7051. return;
  7052. }
  7053. else if (item_id == 0)
  7054. {
  7055. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7056. return;
  7057. }
  7058. Item* item = master_item_list.GetItem(item_id);
  7059. if (!item) {
  7060. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7061. return;
  7062. }
  7063. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7064. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7065. if (packet) {
  7066. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7067. packet->setArrayLengthByName("num_items", 1);
  7068. packet->setArrayDataByName("item_name", item->name.c_str());
  7069. packet->setArrayDataByName("price", item->sell_price);
  7070. packet->setArrayDataByName("item_id", item->details.item_id);
  7071. packet->setArrayDataByName("stack_size", item->details.count);
  7072. packet->setArrayDataByName("icon", item->details.icon);
  7073. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7074. packet->setArrayDataByName("tier", item->details.tier);
  7075. packet->setArrayDataByName("item_id2", item->details.item_id);
  7076. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7077. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7078. item_difficulty = ARROW_COLOR_WHITE;
  7079. item_difficulty -= 6;
  7080. if (item_difficulty < 0)
  7081. item_difficulty *= -1;
  7082. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7083. //if(item->details.count == 1)
  7084. packet->setArrayDataByName("quantity", 0xFFFF);
  7085. //else
  7086. // packet->setArrayDataByName("quantity", item->details.count);
  7087. packet->setArrayDataByName("stack_size2", item->details.count);
  7088. packet->setArrayDataByName("description", item->description.c_str());
  7089. if (GetVersion() <= 546) {
  7090. packet->setDataByName("type", 128);
  7091. }
  7092. else {
  7093. packet->setDataByName("type", 0x00000102);
  7094. }
  7095. QueuePacket(packet->serialize());
  7096. safe_delete(packet);
  7097. }
  7098. }
  7099. }
  7100. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7101. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7102. if (packet) {
  7103. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7104. int32 rolls[6] = { 0 };
  7105. int32 lottery_digits[6] = { 0 };
  7106. int8 num_matches = 0;
  7107. int64 jackpot = 0;
  7108. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7109. if (!item) {
  7110. return;
  7111. }
  7112. database.DeleteItem(GetCharacterID(), item, 0);
  7113. GetPlayer()->item_list.RemoveItem(item, true);
  7114. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7115. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7116. if (!winning_numbers) {
  7117. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7118. variables.AddVariable(winning_numbers);
  7119. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7120. }
  7121. if (strlen(winning_numbers->GetValue()) != 12) {
  7122. winning_numbers->SetValue("231205182236");
  7123. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7124. }
  7125. try {
  7126. for (int32 i = 0; i < 12; i += 2) {
  7127. char num[4];
  7128. strncpy(num, winning_numbers->GetValue() + i, 2);
  7129. lottery_digits[i / 2] = atoi(num);
  7130. }
  7131. }
  7132. catch (...) {
  7133. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7134. return;
  7135. }
  7136. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7137. if (!jackpot_var) {
  7138. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7139. variables.AddVariable(jackpot_var);
  7140. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7141. }
  7142. try {
  7143. jackpot = atoul(jackpot_var->GetValue());
  7144. if (jackpot < 10000)
  7145. jackpot = 10000;
  7146. }
  7147. catch (...) {
  7148. jackpot = 10000;
  7149. }
  7150. char new_jackpot[128] = { 0 };
  7151. sprintf(new_jackpot, "%llu", jackpot + price);
  7152. jackpot_var->SetValue(new_jackpot);
  7153. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7154. world.PickRandomLottoDigits(rolls);
  7155. packet->setDataByName("roll_digit1", rolls[0]);
  7156. packet->setDataByName("roll_digit2", rolls[1]);
  7157. packet->setDataByName("roll_digit3", rolls[2]);
  7158. packet->setDataByName("roll_digit4", rolls[3]);
  7159. packet->setDataByName("roll_digit5", rolls[4]);
  7160. packet->setDataByName("roll_digit6", rolls[5]);
  7161. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7162. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7163. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7164. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7165. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7166. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7167. QueuePacket(packet->serialize());
  7168. safe_delete(packet);
  7169. for (int32 i = 0; i < 6; i++) {
  7170. for (int32 j = 0; j < 6; j++) {
  7171. if (rolls[i] == lottery_digits[j]) {
  7172. num_matches++;
  7173. break;
  7174. }
  7175. }
  7176. }
  7177. char new_jackpot_str[16];
  7178. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7179. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7180. if (num_matches == 6) {
  7181. world.PickRandomLottoDigits(lottery_digits);
  7182. for (int32 i = 0; i < 12; i += 2)
  7183. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7184. winning_numbers->SetValue(new_jackpot_str);
  7185. jackpot_var->SetValue("10000");
  7186. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7187. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7188. }
  7189. }
  7190. }
  7191. void Client::SendGuildCreateWindow() {
  7192. if (GetVersion() <= 546) {
  7193. SimpleMessage(0, "Not implemented on this client...yet?");
  7194. }
  7195. else {
  7196. Spawn* spawn = GetPlayer()->GetTarget();
  7197. if (spawn) {
  7198. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7199. if (packet) {
  7200. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7201. packet->setArrayLengthByName("num_items", 0);
  7202. packet->setDataByName("type", 0x00008000);
  7203. QueuePacket(packet->serialize());
  7204. safe_delete(packet);
  7205. }
  7206. }
  7207. }
  7208. }
  7209. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7210. BuyBackItem* item = new BuyBackItem;
  7211. item->item_id = item_id;
  7212. item->unique_id = unique_id;
  7213. item->price = price;
  7214. item->quantity = quantity;
  7215. item->save_needed = save_needed;
  7216. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7217. buy_back_items.push_back(item);
  7218. if (buy_back_items.size() > 10) {
  7219. safe_delete(buy_back_items.front());
  7220. buy_back_items.pop_front();
  7221. }
  7222. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7223. }
  7224. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7225. return &buy_back_items;
  7226. }
  7227. vector<Item*>* Client::GetRepairableItems() {
  7228. vector<Item*>* repairable_items = new vector<Item*>;
  7229. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7230. map<int32, Item*>* items = player->GetItemList();
  7231. if (equipped_items && equipped_items->size() > 0) {
  7232. for (int32 i = 0; i < equipped_items->size(); i++) {
  7233. Item* item = equipped_items->at(i);
  7234. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7235. repairable_items->push_back(item);
  7236. }
  7237. }
  7238. if (items && items->size() > 0) {
  7239. map<int32, Item*>::iterator itr;
  7240. for (itr = items->begin(); itr != items->end(); itr++) {
  7241. Item* item = itr->second;
  7242. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7243. repairable_items->push_back(item);
  7244. }
  7245. }
  7246. safe_delete(equipped_items);
  7247. safe_delete(items);
  7248. return repairable_items;
  7249. }
  7250. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  7251. if(type == NO_EFFECT_TYPE)
  7252. return nullptr;
  7253. vector<Item*>* return_items = new vector<Item*>;
  7254. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7255. map<int32, Item*>* items = player->GetItemList();
  7256. if (equipped_items && equipped_items->size() > 0) {
  7257. for (int32 i = 0; i < equipped_items->size(); i++) {
  7258. Item* item = equipped_items->at(i);
  7259. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7260. return_items->push_back(item);
  7261. }
  7262. }
  7263. if (items && items->size() > 0) {
  7264. map<int32, Item*>::iterator itr;
  7265. for (itr = items->begin(); itr != items->end(); itr++) {
  7266. Item* item = itr->second;
  7267. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7268. return_items->push_back(item);
  7269. }
  7270. }
  7271. safe_delete(equipped_items);
  7272. safe_delete(items);
  7273. return return_items;
  7274. }
  7275. void Client::SendMailList() {
  7276. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7277. if (kiosk_id > 0) {
  7278. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7279. if (p) {
  7280. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7281. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7282. int32 i = 0;
  7283. p->setDataByName("kiosk_id", kiosk_id);
  7284. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7285. while (itr.Next()) {
  7286. Mail* mail = itr->second;
  7287. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7288. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7289. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7290. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7291. p->setArrayDataByName("unknown1", 0x0000, i);
  7292. p->setArrayDataByName("already_read", mail->already_read, i);
  7293. if(mail->expire_time)
  7294. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7295. else
  7296. p->setArrayDataByName("mail_deletion", 0, i);
  7297. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7298. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7299. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7300. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7301. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7302. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7303. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7304. //p->setArrayDataByName("unknown2", 0, i);
  7305. bool successItemAdd = false;
  7306. if(mail->stack || mail->char_item_id)
  7307. {
  7308. Item* item = master_item_list.GetItem(mail->char_item_id);
  7309. if(item)
  7310. {
  7311. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7312. if (version < 860)
  7313. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7314. else if (version < 1193)
  7315. p->setItemArrayDataByName("item", item, player, i);
  7316. else
  7317. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7318. successItemAdd = true;
  7319. }
  7320. }
  7321. if(!successItemAdd)
  7322. {
  7323. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7324. p->setArrayDataByName("end_tag3", 0xFF, i);
  7325. }
  7326. i++;
  7327. }
  7328. // GMs send mail for free!
  7329. if (GetAdminStatus() > 0)
  7330. {
  7331. p->setDataByName("postage_cost", 0);
  7332. p->setDataByName("attachment_cost", 0);
  7333. }
  7334. else
  7335. {
  7336. p->setDataByName("postage_cost", 10);
  7337. p->setDataByName("attachment_cost", 50);
  7338. }
  7339. p->setDataByName("unknown3", 0x01F4);
  7340. p->setDataByName("unknown4", 0x01000000);
  7341. EQ2Packet* pack = p->serialize();
  7342. QueuePacket(pack);
  7343. safe_delete(p);
  7344. }
  7345. }
  7346. else
  7347. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7348. }
  7349. void Client::DisplayMailMessage(int32 mail_id) {
  7350. Mail* mail = player->GetMail(mail_id);
  7351. if (mail) {
  7352. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7353. if (kiosk_id > 0) {
  7354. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7355. if (update) {
  7356. update->setDataByName("action", 0x03);
  7357. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7358. update->setDataByName("packetsubtype", 0xFF);
  7359. QueuePacket(update->serialize());
  7360. safe_delete(update);
  7361. }
  7362. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7363. if (packet) {
  7364. packet->setDataByName("kiosk_id", kiosk_id);
  7365. packet->setDataByName("mail_id", mail->mail_id);
  7366. packet->setDataByName("player_to_id", mail->player_to_id);
  7367. packet->setDataByName("player_from", mail->player_from.c_str());
  7368. packet->setDataByName("subject", mail->subject.c_str());
  7369. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7370. packet->setDataByName("unknown1", 1);
  7371. packet->setDataByName("unknown2", 0);
  7372. packet->setDataByName("lock_report_button", 1);
  7373. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7374. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7375. packet->setDataByName("coin_copper", mail->coin_copper);
  7376. packet->setDataByName("coin_silver", mail->coin_silver);
  7377. packet->setDataByName("coin_gold", mail->coin_gold);
  7378. packet->setDataByName("coin_plat", mail->coin_plat);
  7379. if(mail->stack || mail->char_item_id)
  7380. {
  7381. Item* item = master_item_list.GetItem(mail->char_item_id);
  7382. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7383. if (version < 860)
  7384. packet->setItemByName("item", item, player, 0, -1);
  7385. else if (version < 1193)
  7386. packet->setItemByName("item", item, player, 0, 0);
  7387. else
  7388. packet->setItemByName("item", item, player, 0, 2);
  7389. }
  7390. else
  7391. {
  7392. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7393. packet->setDataByName("end_tag3", 0xFF);
  7394. }
  7395. mail->already_read = true;
  7396. mail->save_needed = true;
  7397. EQ2Packet* pack = packet->serialize();
  7398. QueuePacket(pack);
  7399. safe_delete(packet);
  7400. // trying to update this causes the window not to open
  7401. //SendMailList();
  7402. }
  7403. }
  7404. else
  7405. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7406. }
  7407. }
  7408. /* 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
  7409. packet back to the client before the mail actually sent. */
  7410. void Client::HandleSentMail(EQApplicationPacket* app) {
  7411. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7412. if (packet) {
  7413. packet->LoadPacketData(app->pBuffer, app->size);
  7414. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7415. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7416. vector<int32>* ids = 0;
  7417. MMailWindowMutex.lock();
  7418. if (reply_packet) {
  7419. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7420. if (player_to.length() == 0)
  7421. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7422. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7423. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7424. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7425. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7426. else {
  7427. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7428. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7429. ids = database.GetAllPlayerIDs();
  7430. else
  7431. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7432. }
  7433. else {
  7434. ids = new vector<int32>;
  7435. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7436. }
  7437. if (ids) {
  7438. for (int32 i = 0; i < ids->size(); i++) {
  7439. int32 player_to_id = ids->at(i);
  7440. if (player_to_id > 0) {
  7441. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7442. Mail* mail = new Mail;
  7443. mail->mail_id = 0;
  7444. mail->player_to_id = player_to_id;
  7445. mail->player_from = string(GetPlayer()->GetName());
  7446. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7447. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7448. mail->already_read = 0;
  7449. mail->mail_type = MAIL_TYPE_REGULAR;
  7450. mail->coin_copper = mail_window.coin_copper;
  7451. mail->coin_silver = mail_window.coin_silver;
  7452. mail->coin_gold = mail_window.coin_gold;
  7453. mail->coin_plat = mail_window.coin_plat;
  7454. mail->char_item_id = mail_window.char_item_id;
  7455. mail->stack = mail_window.stack;
  7456. // GM's send mail for free!
  7457. if (GetAdminStatus() > 0)
  7458. {
  7459. mail->postage_cost = 0;
  7460. mail->attachment_cost = 0;
  7461. }
  7462. else
  7463. {
  7464. mail->postage_cost = 10;
  7465. mail->attachment_cost = 50;
  7466. }
  7467. mail->time_sent = Timer::GetUnixTimeStamp();
  7468. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7469. //int16 packettype = packet->getType_int16_ByName("packettype");
  7470. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  7471. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  7472. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  7473. if (postage_cost > 0 || attachment_cost > 0)
  7474. PlaySoundA("coin_cha_ching");*/
  7475. mail->save_needed = false;
  7476. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7477. if (to_client) {
  7478. to_client->GetPlayer()->AddMail(mail);
  7479. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  7480. string popup_text = "You have unread mail!";
  7481. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7482. }
  7483. database.SavePlayerMail(mail);
  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. //packet->setDataByName("packettype", GetItemPacketType(version));
  7550. //packet->setDataByName("packetsubtype", 0xFF);
  7551. //packet->setDataByName("unknown2", 0);
  7552. //packet->PrintPacket();
  7553. QueuePacket(packet->serialize());
  7554. }
  7555. MMailWindowMutex.unlock();
  7556. }
  7557. return ret;
  7558. }
  7559. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7560. bool ret = false;
  7561. if (GetMailTransaction()) {
  7562. MMailWindowMutex.lock();
  7563. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7564. if (packet) {
  7565. if (copper > 0) {
  7566. if (player->RemoveCoins(copper)) {
  7567. mail_window.coin_copper += copper;
  7568. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7569. ret = true;
  7570. }
  7571. }
  7572. else if (silver > 0) {
  7573. if (player->RemoveCoins(silver * 100)) {
  7574. mail_window.coin_silver += silver;
  7575. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7576. ret = true;
  7577. }
  7578. }
  7579. else if (gold > 0) {
  7580. if (player->RemoveCoins(gold * 10000)) {
  7581. mail_window.coin_gold += gold;
  7582. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7583. ret = true;
  7584. }
  7585. }
  7586. else if (plat > 0) {
  7587. if (player->RemoveCoins(plat * 1000000)) {
  7588. mail_window.coin_plat += plat;
  7589. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7590. ret = true;
  7591. }
  7592. }
  7593. if (ret) {
  7594. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7595. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7596. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7597. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7598. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7599. if(item)
  7600. {
  7601. packet->setDataByName("stack", mail_window.stack);
  7602. item->stack_count = mail_window.stack;
  7603. if (version < 860)
  7604. packet->setItemByName("item", item, player, 0, -1);
  7605. else if (version < 1193)
  7606. packet->setItemByName("item", item, player, 0, 0);
  7607. else
  7608. packet->setItemByName("item", item, player, 0, 2);
  7609. }
  7610. else
  7611. {
  7612. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7613. packet->setDataByName("end_tag3", 0xFF);
  7614. }
  7615. //packet->PrintPacket();
  7616. QueuePacket(packet->serialize());
  7617. }
  7618. else
  7619. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7620. safe_delete(packet);
  7621. }
  7622. MMailWindowMutex.unlock();
  7623. }
  7624. else
  7625. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7626. return ret;
  7627. }
  7628. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7629. bool ret = false;
  7630. if (GetMailTransaction()) {
  7631. MMailWindowMutex.lock();
  7632. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7633. if (packet) {
  7634. if (copper > 0) {
  7635. player->AddCoins(copper);
  7636. mail_window.coin_copper -= copper;
  7637. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7638. ret = true;
  7639. }
  7640. else if (silver > 0) {
  7641. player->AddCoins(silver * 100);
  7642. mail_window.coin_silver -= silver;
  7643. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7644. ret = true;
  7645. }
  7646. else if (gold > 0) {
  7647. player->AddCoins(gold * 10000);
  7648. mail_window.coin_gold -= gold;
  7649. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7650. ret = true;
  7651. }
  7652. else if (plat > 0) {
  7653. player->AddCoins(plat * 1000000);
  7654. mail_window.coin_plat -= plat;
  7655. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7656. ret = true;
  7657. }
  7658. if (ret) {
  7659. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7660. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7661. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7662. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7663. packet->setDataByName("stack", 0);
  7664. packet->setDataByName("packettype", 0x2BFE);
  7665. packet->setDataByName("packetsubtype", 0xFF);
  7666. packet->setDataByName("unknown2", 0);
  7667. QueuePacket(packet->serialize());
  7668. }
  7669. safe_delete(packet);
  7670. }
  7671. MMailWindowMutex.unlock();
  7672. }
  7673. else
  7674. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7675. return ret;
  7676. }
  7677. void Client::TakeMailAttachments(int32 mail_id) {
  7678. if (GetMailTransaction()) {
  7679. Mail* mail = player->GetMail(mail_id);
  7680. if (mail) {
  7681. int64 amount = 0;
  7682. if (mail->coin_copper > 0) {
  7683. amount += mail->coin_copper;
  7684. mail->coin_copper = 0;
  7685. }
  7686. if (mail->coin_silver > 0) {
  7687. amount += mail->coin_silver * 100;
  7688. mail->coin_silver = 0;
  7689. }
  7690. if (mail->coin_gold > 0) {
  7691. amount += mail->coin_gold * 10000;
  7692. mail->coin_gold = 0;
  7693. }
  7694. if (mail->coin_plat > 0) {
  7695. amount += mail->coin_plat * 1000000;
  7696. mail->coin_plat = 0;
  7697. }
  7698. if (mail->char_item_id > 0) {
  7699. AddItem(mail->char_item_id, mail->stack);
  7700. mail->char_item_id = 0;
  7701. mail->stack = 0;
  7702. }
  7703. /* 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
  7704. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7705. find it in any packet logs.*/
  7706. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7707. if (packet) {
  7708. packet->setDataByName("unknown", 0x03);
  7709. packet->setDataByName("coin_copper", mail->coin_copper);
  7710. packet->setDataByName("coin_silver", mail->coin_silver);
  7711. packet->setDataByName("coin_gold", mail->coin_gold);
  7712. packet->setDataByName("coin_plat", mail->coin_plat);
  7713. packet->setDataByName("stack", 0);
  7714. packet->setDataByName("packettype", 0x2BFE);
  7715. packet->setDataByName("packetsubtype", 0xFF);
  7716. packet->setDataByName("unknown2", 0);
  7717. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7718. DumpPacket(packet->serialize());
  7719. QueuePacket(packet->serialize());
  7720. safe_delete(packet);
  7721. }*/
  7722. database.SavePlayerMail(mail);
  7723. if (amount > 0)
  7724. player->AddCoins(amount);
  7725. SendMailList();
  7726. }
  7727. }
  7728. else
  7729. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7730. }
  7731. void Client::ResetSendMail(bool cancel, bool needslock) {
  7732. if(cancel && mail_transaction)
  7733. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7734. if(needslock)
  7735. MMailWindowMutex.lock();
  7736. if(cancel)
  7737. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7738. if(!cancel)
  7739. mail_transaction = 0;
  7740. mail_window.coin_copper = 0;
  7741. mail_window.coin_silver = 0;
  7742. mail_window.coin_gold = 0;
  7743. mail_window.coin_plat = 0;
  7744. mail_window.char_item_id = 0;
  7745. mail_window.stack = 0;
  7746. if(mail_window.item){
  7747. if(cancel)
  7748. AddItem(mail_window.item);
  7749. else
  7750. safe_delete(mail_window.item);
  7751. }
  7752. mail_window.item = nullptr;
  7753. if(needslock)
  7754. MMailWindowMutex.unlock();
  7755. }
  7756. bool Client::GateAllowed() {
  7757. ZoneServer* zone = GetCurrentZone();
  7758. if (zone){
  7759. bool cangate = zone->GetCanGate();
  7760. return cangate;
  7761. }
  7762. return false;
  7763. }
  7764. bool Client::BindAllowed() {
  7765. ZoneServer* zone = GetCurrentZone();
  7766. if (zone){
  7767. bool canbind = zone->GetCanBind();
  7768. return canbind;
  7769. }
  7770. return false;
  7771. }
  7772. bool Client::Bind() {
  7773. int canbind = BindAllowed();
  7774. if(canbind == 0) {
  7775. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  7776. return false;
  7777. }
  7778. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7779. player->GetPlayerInfo()->SetBindX(player->GetX());
  7780. player->GetPlayerInfo()->SetBindY(player->GetY());
  7781. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7782. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7783. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  7784. return true;
  7785. }
  7786. bool Client::Gate(bool is_spell) {
  7787. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  7788. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  7789. return false;
  7790. }
  7791. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7792. if (zone) {
  7793. int cangate = GateAllowed();
  7794. if(cangate == 0) {
  7795. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  7796. return false;
  7797. }
  7798. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7799. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7800. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7801. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7802. Zone(zone, false, is_spell);
  7803. return true;
  7804. }
  7805. return false;
  7806. }
  7807. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7808. if (!destinations || !spawn) {
  7809. return;
  7810. }
  7811. bool has_map = false;
  7812. if (transport_id > 0)
  7813. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7814. transport_spawn = spawn;
  7815. vector<TransportDestination*> transport_list;
  7816. vector<TransportDestination*>::iterator itr;
  7817. TransportDestination* destination = 0;
  7818. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7819. destination = *itr;
  7820. 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)))
  7821. transport_list.push_back(destination);
  7822. }
  7823. if (transport_list.size() == 0 && destination) {
  7824. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7825. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7826. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7827. else
  7828. {
  7829. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7830. if (app)
  7831. QueuePacket(app);
  7832. }
  7833. }
  7834. else {
  7835. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7836. // determine if this is an instanced zone that already exists
  7837. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7838. if (instance_zone || new_zone) {
  7839. GetPlayer()->SetX(destination->destination_x);
  7840. GetPlayer()->SetY(destination->destination_y);
  7841. GetPlayer()->SetZ(destination->destination_z);
  7842. GetPlayer()->SetHeading(destination->destination_heading);
  7843. if (instance_zone)
  7844. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7845. else
  7846. Zone(new_zone, false, is_spell);
  7847. }
  7848. }
  7849. if (destination->message.length() > 0)
  7850. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7851. }
  7852. else if (transport_list.size() > 0) {
  7853. if (!spawn->IsSoundsDisabled())
  7854. PlaySound("mariner_bell");
  7855. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7856. if (packet) {
  7857. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7858. // Put all the destinations the player can go in a new vector
  7859. vector<TransportDestination*> destinations;
  7860. for (int32 i = 0; i < transport_list.size(); i++) {
  7861. destination = transport_list.at(i);
  7862. // Check min level
  7863. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7864. continue;
  7865. // Check max level
  7866. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7867. continue;
  7868. // Check quest complete
  7869. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7870. continue;
  7871. // Check req quest and step
  7872. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7873. continue;
  7874. // 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
  7875. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7876. packet->setDataByName("current_zone", destination->display_name.c_str());
  7877. packet->setDataByName("current_map_x", destination->map_x);
  7878. packet->setDataByName("current_map_y", destination->map_y);
  7879. }
  7880. else {
  7881. destinations.push_back(destination);
  7882. }
  7883. }
  7884. // Use the new vector to create the packet
  7885. destination = 0;
  7886. packet->setArrayLengthByName("num_destinations", destinations.size());
  7887. for (int32 i = 0; i < destinations.size(); i++) {
  7888. destination = destinations.at(i);
  7889. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7890. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7891. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7892. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7893. packet->setArrayDataByName("cost", destination->cost, i);
  7894. if (has_map) {
  7895. packet->setArrayDataByName("map_x", destination->map_x, i);
  7896. packet->setArrayDataByName("map_y", destination->map_y, i);
  7897. }
  7898. }
  7899. if (has_map)
  7900. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7901. EQ2Packet* app = packet->serialize();
  7902. //DumpPacket(app);
  7903. if (destinations.size() > 0)
  7904. QueuePacket(app);
  7905. safe_delete(packet);
  7906. }
  7907. }
  7908. }
  7909. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7910. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7911. if (packet) {
  7912. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7913. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7914. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7915. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7916. int32 cost = packet->getType_int32_ByName("cost");
  7917. vector<TransportDestination*> destinations;
  7918. TransportDestination* destination = 0;
  7919. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7920. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7921. vector<TransportDestination*>::iterator itr;
  7922. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7923. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7924. destination = *itr;
  7925. break;
  7926. }
  7927. }
  7928. SetTemporaryTransportID(0);
  7929. if (!destination)
  7930. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7931. else {
  7932. if (cost == 0 || player->RemoveCoins(cost)) {
  7933. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7934. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7935. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7936. else
  7937. {
  7938. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7939. if (outapp)
  7940. QueuePacket(outapp);
  7941. }
  7942. }
  7943. else {
  7944. GetPlayer()->SetX(destination->destination_x);
  7945. GetPlayer()->SetY(destination->destination_y);
  7946. GetPlayer()->SetZ(destination->destination_z);
  7947. GetPlayer()->SetHeading(destination->destination_heading);
  7948. // Test if where we're going is an Instanced zone
  7949. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7950. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7951. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7952. Zone(new_zone, false);
  7953. }
  7954. }
  7955. if (destination->message.length() > 0)
  7956. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7957. }
  7958. else
  7959. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7960. }
  7961. }
  7962. safe_delete(packet);
  7963. }
  7964. }
  7965. void Client::SendNewSpells(int8 class_id) {
  7966. if (class_id > 0) {
  7967. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7968. vector<Spell*>::iterator itr;
  7969. Spell* spell = 0;
  7970. bool send_updates = false;
  7971. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7972. spell = *itr;
  7973. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7974. send_updates = true;
  7975. SendSpellUpdate(spell);
  7976. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7977. player->UnlockSpell(spell);
  7978. }
  7979. }
  7980. if (send_updates) {
  7981. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7982. if (outapp)
  7983. QueuePacket(outapp);
  7984. }
  7985. safe_delete(spells);
  7986. }
  7987. }
  7988. void Client::SetItemSearch(vector<Item*>* items) {
  7989. if (items) {
  7990. safe_delete(search_items);
  7991. search_items = items;
  7992. }
  7993. }
  7994. vector<Item*>* Client::GetSearchItems() {
  7995. return search_items;
  7996. }
  7997. void Client::SearchStore(int32 page) {
  7998. if (search_items) {
  7999. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8000. if (packet) {
  8001. int32 x = page * 8;
  8002. if (search_items->size() > 8) {
  8003. if ((search_items->size() - x) > 8)
  8004. packet->setArrayLengthByName("num_items", 8);
  8005. else
  8006. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8007. }
  8008. else
  8009. packet->setArrayLengthByName("num_items", search_items->size());
  8010. if (search_items->size() > 0) {
  8011. packet->setArrayLengthByName("num_sellers", 1);
  8012. packet->setArrayDataByName("seller_seller_id", 1);
  8013. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  8014. packet->setDataByName("per_page", 8);
  8015. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8016. packet->setDataByName("page", page);
  8017. Item* item = 0;
  8018. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8019. for (int32 i = 0; i < limit; i++, x++) {
  8020. if (x >= search_items->size())
  8021. break;
  8022. item = search_items->at(x);
  8023. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8024. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8025. packet->setArrayDataByName("icon", item->details.icon, i);
  8026. //packet->setArrayDataByName("unknown2b", i, i);
  8027. packet->setArrayDataByName("item_seller_id", 1, i);
  8028. if (item->stack_count == 0)
  8029. packet->setArrayDataByName("quantity", 1, i);
  8030. else
  8031. packet->setArrayDataByName("quantity", item->stack_count, i);
  8032. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8033. std::string tmpStr("");
  8034. tmpStr.append(item->name.c_str());
  8035. tmpStr.append(" (");
  8036. tmpStr.append(std::to_string(item->details.item_id));
  8037. tmpStr.append(")");
  8038. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8039. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8040. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8041. }
  8042. }
  8043. /*EQ2Packet* outapp = packet->serialize();
  8044. DumpPacket(outapp);
  8045. QueuePacket(outapp);*/
  8046. QueuePacket(packet->serialize());
  8047. safe_delete(packet);
  8048. }
  8049. }
  8050. }
  8051. void Client::SetReadyForUpdates() {
  8052. GetPlayer()->SetFullyLoggedIn(true);
  8053. if (!ready_for_updates)
  8054. database.loadCharacterProperties(this);
  8055. ready_for_updates = true;
  8056. }
  8057. void Client::SetReadyForSpawns(bool val) {
  8058. ready_for_spawns = val;
  8059. if (GetPlayer()->GetActivityStatus() > 0) {
  8060. GetPlayer()->SetActivityStatus(0);
  8061. if (GetPlayer()->GetGroupMemberInfo()) {
  8062. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8063. }
  8064. }
  8065. GetPlayer()->SetActiveReward(false);
  8066. zone_list.CheckFriendZoned(this);
  8067. }
  8068. void Client::SendChatRelationship(int8 type, const char* name) {
  8069. if (!name) {
  8070. return;
  8071. }
  8072. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8073. if (packet) {
  8074. packet->setDataByName("account_id", GetAccountID());
  8075. packet->setDataByName("type", type);
  8076. packet->setArrayLengthByName("num_names", 1);
  8077. packet->setArrayDataByName("name", name);
  8078. if (type == 0) {
  8079. Client* client = zone_list.GetClientByCharName(name);
  8080. if (client) {
  8081. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8082. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8083. }
  8084. }
  8085. QueuePacket(packet->serialize());
  8086. safe_delete(packet);
  8087. }
  8088. }
  8089. void Client::SendFriendList() {
  8090. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8091. if (packet) {
  8092. packet->setDataByName("account_id", GetAccountID());
  8093. map<string, int8>::iterator itr;
  8094. map<string, int8>* friends = player->GetFriends();
  8095. if (friends && friends->size() > 0) {
  8096. Client* client = 0;
  8097. vector<string> names;
  8098. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8099. if (itr->second == 2)
  8100. continue;
  8101. names.push_back(itr->first);
  8102. }
  8103. packet->setArrayLengthByName("num_names", names.size());
  8104. for (int32 i = 0; i < names.size(); i++) {
  8105. client = zone_list.GetClientByCharName(names[i]);
  8106. packet->setArrayDataByName("name", names[i].c_str(), i);
  8107. if (client) {
  8108. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8109. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8110. }
  8111. }
  8112. }
  8113. QueuePacket(packet->serialize());
  8114. safe_delete(packet);
  8115. }
  8116. }
  8117. void Client::SendIgnoreList() {
  8118. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8119. if (packet) {
  8120. packet->setDataByName("account_id", GetAccountID());
  8121. packet->setDataByName("type", 2);
  8122. map<string, int8>::iterator itr;
  8123. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8124. if (ignored && ignored->size() > 0) {
  8125. vector<string> names;
  8126. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8127. if (itr->second == 2)
  8128. continue;
  8129. names.push_back(itr->first);
  8130. }
  8131. packet->setArrayLengthByName("num_names", names.size());
  8132. for (int32 i = 0; i < names.size(); i++)
  8133. packet->setArrayDataByName("name", names[i].c_str(), i);
  8134. }
  8135. QueuePacket(packet->serialize());
  8136. safe_delete(packet);
  8137. }
  8138. }
  8139. void Client::AddWaypoint(string name, int8 type) {
  8140. waypoint_id++;
  8141. WaypointInfo info;
  8142. info.id = waypoint_id;
  8143. info.type = type;
  8144. waypoints[name] = info;
  8145. }
  8146. void Client::SendWaypoints() {
  8147. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8148. if (packet) {
  8149. packet->setArrayLengthByName("num_updates", waypoints.size());
  8150. map<string, WaypointInfo>::iterator itr;
  8151. int16 i = 0;
  8152. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8153. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8154. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8155. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8156. i++;
  8157. }
  8158. packet->setDataByName("unknown", 0xFFFFFFFF);
  8159. QueuePacket(packet->serialize());
  8160. safe_delete(packet);
  8161. }
  8162. }
  8163. void Client::SelectWaypoint(int32 id) {
  8164. string found_name = "";
  8165. map<string, WaypointInfo>::iterator itr;
  8166. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8167. if (itr->second.id == id) {
  8168. found_name = itr->first;
  8169. break;
  8170. }
  8171. }
  8172. if (found_name.length() > 0) {
  8173. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8174. ShowPathToTarget(spawn);
  8175. }
  8176. }
  8177. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8178. if (waypoint_name) {
  8179. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8180. if (packet) {
  8181. packet->setArrayLengthByName("num_updates", 1);
  8182. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8183. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8184. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8185. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8186. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8187. packet->setDataByName("unknown", 0xFFFFFFFF);
  8188. QueuePacket(packet->serialize());
  8189. safe_delete(packet);
  8190. }
  8191. }
  8192. }
  8193. void Client::ClearWaypoint() {
  8194. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8195. if (packet) {
  8196. QueuePacket(packet->serialize());
  8197. safe_delete(packet);
  8198. }
  8199. }
  8200. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8201. if (current_zone->pathing) {
  8202. if (GetPlayer()->GetMap()) {
  8203. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8204. return false;
  8205. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8206. return false;
  8207. auto loc = glm::vec3(x, z, y);
  8208. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  8209. if (new_z != BEST_Z_INVALID) //this is actually y
  8210. y = new_z;
  8211. }
  8212. bool partial = false;
  8213. bool stuck = false;
  8214. PathfinderOptions opts;
  8215. opts.smooth_path = true;
  8216. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8217. opts.offset = y_offset + 1.0f;
  8218. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8219. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8220. if (packet) {
  8221. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8222. packet->setArrayLengthByName("num_points", path.size());
  8223. int i = 0;
  8224. for (auto& node : path)
  8225. {
  8226. packet->setArrayDataByName("x", node.pos.x, i);
  8227. packet->setArrayDataByName("y", node.pos.z, i);
  8228. packet->setArrayDataByName("z", node.pos.y, i);
  8229. packet->setDataByName("waypoint_x", x);
  8230. packet->setDataByName("waypoint_y", y);
  8231. packet->setDataByName("waypoint_z", z);
  8232. i++;
  8233. }
  8234. if (i > 0)
  8235. QueuePacket(packet->serialize());
  8236. safe_delete(packet);
  8237. return (i > 0);
  8238. }
  8239. }
  8240. return false;
  8241. }
  8242. bool Client::ShowPathToTarget(Spawn* spawn) {
  8243. if (spawn) {
  8244. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  8245. }
  8246. return false;
  8247. }
  8248. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  8249. if (waypoint_name) {
  8250. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8251. if (packet) {
  8252. packet->setArrayLengthByName("num_points", 1);
  8253. packet->setArrayDataByName("x", x, 0);
  8254. packet->setArrayDataByName("y", y, 0);
  8255. packet->setArrayDataByName("z", z, 0);
  8256. packet->setDataByName("waypoint_x", x);
  8257. packet->setDataByName("waypoint_y", y);
  8258. packet->setDataByName("waypoint_z", z);
  8259. packet->setDataByName("waypoint_name", waypoint_name);
  8260. packet->setDataByName("unknown", 0);
  8261. QueuePacket(packet->serialize());
  8262. safe_delete(packet);
  8263. }
  8264. }
  8265. }
  8266. void Client::InspectPlayer(Player* player_to_inspect) {
  8267. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  8268. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  8269. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8270. if(pvp_allowed == true){
  8271. if(source_pvp_alignment != target_pvp_alignment){
  8272. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  8273. return;
  8274. }
  8275. }
  8276. if (player_to_inspect) {
  8277. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  8278. if (packet) {
  8279. packet->setDataByName("unknown", 0);
  8280. packet->setSmallStringByName("name", player_to_inspect->GetName());
  8281. packet->setDataByName("race", player_to_inspect->GetRace());
  8282. packet->setDataByName("gender", player_to_inspect->GetGender());
  8283. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  8284. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  8285. packet->setDataByName("adventure_level_effective", effective_level);
  8286. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  8287. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  8288. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  8289. packet->setDataByName("health", player_to_inspect->GetHP());
  8290. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  8291. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  8292. packet->setDataByName("power", player_to_inspect->GetPower());
  8293. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  8294. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  8295. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  8296. packet->setDataByName("unknown1", 0);
  8297. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  8298. packet->setDataByName("unknown2", 0);
  8299. packet->setDataByName("mitigation_percentage", 0);
  8300. packet->setDataByName("strength", player_to_inspect->GetStr());
  8301. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  8302. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8303. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8304. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8305. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8306. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8307. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8308. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8309. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8310. packet->setDataByName("unknown4", 0);
  8311. packet->setDataByName("unknown5", 0);
  8312. packet->setDataByName("unknown6", 0);
  8313. packet->setDataByName("unknown7", 0);
  8314. packet->setDataByName("unknown8", 0);
  8315. packet->setDataByName("unknown9", 0);
  8316. packet->setDataByName("unknown10", 0);
  8317. packet->setDataByName("unknown11", 0);
  8318. packet->setDataByName("unknown12", 0);
  8319. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8320. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8321. packet->setDataByName("heat_resist_percentage", 0);
  8322. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8323. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8324. packet->setDataByName("cold_resist_percentage", 0);
  8325. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8326. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8327. packet->setDataByName("magic_resist_percentage", 0);
  8328. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8329. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8330. packet->setDataByName("mental_resist_percentage", 0);
  8331. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8332. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8333. packet->setDataByName("divine_resist_percentage", 0);
  8334. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8335. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8336. packet->setDataByName("disease_resist_percentage", 0);
  8337. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8338. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8339. packet->setDataByName("poison_resist_percentage", 0);
  8340. packet->setArrayLengthByName("num_chars", 0x01FF);
  8341. string biography = player_to_inspect->GetBiography();
  8342. for (size_t i = 0; i < biography.length(); i++)
  8343. packet->setArrayDataByName("biography_char", biography[i], i);
  8344. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  8345. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  8346. if (pw)
  8347. packet->setItemByName("primary", pw, player_to_inspect, 0);
  8348. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  8349. if (sw)
  8350. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  8351. //DumpPacket(packet->serialize());
  8352. QueuePacket(packet->serialize());
  8353. safe_delete(packet);
  8354. }
  8355. }
  8356. }
  8357. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8358. pending_guild_invite.guild = guild;
  8359. pending_guild_invite.invited_by = invited_by;
  8360. }
  8361. void Client::ShowClaimWindow() {
  8362. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8363. if (packet) {
  8364. map<int32, Item*>* items = &master_item_list.items;
  8365. map<int32, Item*>::iterator itr;
  8366. int32 i = 0;
  8367. if (items->size() > 10)
  8368. packet->setArrayLengthByName("num_claim_items", 10);
  8369. else
  8370. packet->setArrayLengthByName("num_claim_items", items->size());
  8371. for (itr = items->begin(); itr != items->end(); itr++) {
  8372. if (i == 10)
  8373. break;
  8374. Item* item = itr->second;
  8375. packet->setArrayDataByName("id", i, i);
  8376. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8377. packet->setArrayDataByName("num_remaining", 5, i);
  8378. packet->setArrayDataByName("one_per_character", 1, i);
  8379. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8380. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8381. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8382. packet->setArrayDataByName("category", "Scott's Shit", i);
  8383. packet->setArrayDataByName("icon", item->details.icon, i);
  8384. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8385. i++;
  8386. }
  8387. packet->setDataByName("unknown3", 1);
  8388. QueuePacket(packet->serialize());
  8389. safe_delete(packet);
  8390. }
  8391. }
  8392. void Client::ShowGuildSearchWindow() {
  8393. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8394. if (packet) {
  8395. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8396. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8397. packet->setArrayLengthByName("num_guilds", guilds->size());
  8398. int32 i = 0;
  8399. while (itr.Next()) {
  8400. Guild* guild = itr.second;
  8401. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8402. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8403. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8404. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8405. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8406. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8407. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8408. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8409. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8410. packet->setArrayDataByName("unknown7", 0x02, i);
  8411. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8412. i++;
  8413. }
  8414. QueuePacket(packet->serialize());
  8415. safe_delete(packet);
  8416. }
  8417. }
  8418. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8419. PacketStruct* packet;
  8420. vector<int8>* slot_data;
  8421. vector<int8>::iterator itr;
  8422. int32 slots = 0;
  8423. assert(item);
  8424. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8425. return;
  8426. }
  8427. slot_data = &item->slot_data;
  8428. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8429. if (version >= 1188)
  8430. slots = *itr;
  8431. else
  8432. slots += (int8)pow(2.0, *itr);
  8433. }
  8434. packet->setDataByName("slot", slots);
  8435. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8436. if (slots == 2) {
  8437. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8438. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8439. }
  8440. else {
  8441. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8442. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8443. }
  8444. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8445. if (slots == 4) {
  8446. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8447. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8448. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8449. }
  8450. else if (slots == 7) {
  8451. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8452. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8453. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8454. }
  8455. else {
  8456. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8457. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8458. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8459. }
  8460. packet->setDataByName("icon", item->details.icon);
  8461. packet->setDataByName("item_id", item->details.item_id);
  8462. packet->setDataByName("item_crc", crc);
  8463. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8464. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8465. packet->setDataByName("unknown5", 0xFF, 9);
  8466. packet->setDataByName("unknown5", 0xFF, 10);
  8467. QueuePacket(packet->serialize());
  8468. safe_delete(packet);
  8469. }
  8470. void Client::SendCollectionList() {
  8471. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8472. map<int32, Collection*>::iterator itr;
  8473. vector<struct CollectionItem*>* collection_items;
  8474. Collection* collection;
  8475. struct CollectionItem* collection_item;
  8476. PacketStruct* packet = 0;
  8477. int16 i = 0, j;
  8478. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8479. return;
  8480. packet->setArrayLengthByName("num_collections", collections->size());
  8481. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8482. collection = itr->second;
  8483. collection_items = collection->GetCollectionItems();
  8484. packet->setArrayDataByName("unknown", 1, i);
  8485. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8486. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8487. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8488. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8489. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8490. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8491. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8492. for (j = 0; j < collection_items->size(); j++) {
  8493. collection_item = collection_items->at(j);
  8494. Item* item = master_item_list.GetItem(collection_item->item);
  8495. if (item) {
  8496. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8497. if (version < 955)
  8498. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8499. else
  8500. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8501. }
  8502. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8503. }
  8504. i++;
  8505. }
  8506. packet->setDataByName("new_collection_flag", 1);
  8507. QueuePacket(packet->serialize());
  8508. safe_delete(packet);
  8509. }
  8510. bool Client::SendCollectionsForItem(Item* item) {
  8511. map<int32, Collection*> collections_to_send;
  8512. map<int32, Collection*>* collections;
  8513. map<int32, Collection*>::iterator itr;
  8514. vector<struct CollectionItem*>* collection_items;
  8515. Collection* collection;
  8516. struct CollectionItem* collection_item;
  8517. PacketStruct* packet;
  8518. int16 i;
  8519. assert(item);
  8520. /* get any collections required by this item that the player already has */
  8521. collections = player->GetCollectionList()->GetCollections();
  8522. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8523. collection = itr->second;
  8524. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8525. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8526. collections_to_send[collection->GetID()] = collection;
  8527. }
  8528. }
  8529. /* get any collections required by this item that the player does not have and send it to the client */
  8530. collections = master_collection_list.GetCollections();
  8531. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8532. collection = itr->second;
  8533. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8534. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8535. return false;
  8536. }
  8537. packet->setArrayLengthByName("num_collections", 1);
  8538. packet->setArrayDataByName("unknown", 1, 0);
  8539. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8540. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8541. packet->setArrayDataByName("completed", 0, 0);
  8542. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8543. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8544. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8545. packet->setArrayDataByName("unknown3", 0x28, 0);
  8546. collection_items = collection->GetCollectionItems();
  8547. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8548. for (i = 0; i < collection_items->size(); i++) {
  8549. collection_item = collection_items->at(i);
  8550. Item* item2 = master_item_list.GetItem(collection_item->item);
  8551. if (item2) {
  8552. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8553. if (version < 955)
  8554. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8555. else
  8556. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8557. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8558. }
  8559. }
  8560. packet->setDataByName("new_collection_flag", 0);
  8561. QueuePacket(packet->serialize());
  8562. safe_delete(packet);
  8563. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8564. collections_to_send[collection->GetID()] = collection;
  8565. }
  8566. }
  8567. /* send the client a list of collections that should be filtered for this item */
  8568. if (collections_to_send.size() > 0) {
  8569. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8570. return false;
  8571. }
  8572. i = 0;
  8573. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8574. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8575. collection = itr->second;
  8576. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8577. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8578. i++;
  8579. }
  8580. packet->setDataByName("item_icon", item->details.icon);
  8581. packet->setDataByName("item_name", item->name.c_str());
  8582. packet->setDataByName("item_id", item->details.item_id);
  8583. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8584. QueuePacket(packet->serialize());
  8585. safe_delete(packet);
  8586. }
  8587. return collections_to_send.size() > 0;
  8588. }
  8589. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8590. Collection* collection;
  8591. struct CollectionItem* collection_item;
  8592. PacketStruct* packet;
  8593. char tmp[200] = { 0 };
  8594. assert(item);
  8595. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8596. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8597. /* get the item struct that represents the item for this collection */
  8598. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8599. SendCollectionList();
  8600. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8601. return;
  8602. }
  8603. /* sanity check */
  8604. if (collection_item->found) {
  8605. SendCollectionList();
  8606. 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());
  8607. return;
  8608. }
  8609. }
  8610. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8611. collection = new Collection(collection);
  8612. /* get the item struct that represents the item for this collection */
  8613. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8614. SendCollectionList();
  8615. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8616. safe_delete(collection);
  8617. return;
  8618. }
  8619. /* add the new collection to the player's collection list */
  8620. if (!player->GetCollectionList()->AddCollection(collection)) {
  8621. SendCollectionList();
  8622. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8623. safe_delete(collection);
  8624. return;
  8625. }
  8626. }
  8627. else {
  8628. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8629. return;
  8630. }
  8631. collection_item->found = 1;
  8632. collection->SetSaveNeeded(true);
  8633. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8634. SendCollectionList();
  8635. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8636. return;
  8637. }
  8638. packet->setDataByName("collection_id", collection_id);
  8639. packet->setDataByName("collection_item_num", collection_item->index);
  8640. packet->setDataByName("add", 1);
  8641. QueuePacket(packet->serialize());
  8642. Item* item2 = master_item_list.GetItem(collection_item->item);
  8643. if (item2) {
  8644. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8645. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8646. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8647. }
  8648. safe_delete(packet);
  8649. RemoveItem(item, 1);
  8650. SendCollectionList();
  8651. }
  8652. void Client::DisplayCollectionComplete(Collection* collection) {
  8653. vector<struct CollectionRewardItem*>* reward_items;
  8654. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8655. struct CollectionRewardItem* reward_item;
  8656. PacketStruct* packet;
  8657. int32 i;
  8658. assert(collection);
  8659. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8660. return;
  8661. }
  8662. reward_items = collection->GetRewardItems();
  8663. selectable_reward_items = collection->GetSelectableRewardItems();
  8664. packet->setDataByName("title", "Quest Reward!");
  8665. packet->setDataByName("name", collection->GetName());
  8666. packet->setDataByName("description", collection->GetCategory());
  8667. packet->setDataByName("level", collection->GetLevel());
  8668. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8669. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8670. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8671. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8672. for (i = 0; i < reward_items->size(); i++) {
  8673. reward_item = reward_items->at(i);
  8674. if(!reward_item->item)
  8675. {
  8676. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8677. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8678. continue;
  8679. }
  8680. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8681. if (version < 860)
  8682. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8683. else if (version < 1193)
  8684. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8685. else
  8686. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8687. }
  8688. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8689. for (i = 0; i < selectable_reward_items->size(); i++) {
  8690. reward_item = selectable_reward_items->at(i);
  8691. if(!reward_item->item)
  8692. {
  8693. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8694. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8695. continue;
  8696. }
  8697. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8698. if (version < 860)
  8699. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8700. else if (version < 1193)
  8701. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8702. else
  8703. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8704. }
  8705. QueuePacket(packet->serialize());
  8706. safe_delete(packet);
  8707. }
  8708. void Client::HandInCollections() {
  8709. map<int32, Collection*>* collections;
  8710. map<int32, Collection*>::iterator itr;
  8711. Collection* collection;
  8712. /* only show 1 collection reward dialog at a time */
  8713. if (player->GetPendingCollectionReward()) {
  8714. return;
  8715. }
  8716. collections = player->GetCollectionList()->GetCollections();
  8717. /* 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
  8718. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8719. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8720. collection = itr->second;
  8721. if (collection->GetIsReadyToTurnIn()) {
  8722. player->SetPendingCollectionReward(collection);
  8723. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  8724. QuestRewardData* data = new QuestRewardData;
  8725. data->quest_id = 0;
  8726. data->is_temporary = false;
  8727. data->description = std::string("");
  8728. data->is_collection = true;
  8729. data->has_displayed = false;
  8730. data->tmp_coin = 0;
  8731. data->tmp_status = 0;
  8732. data->db_saved = false;
  8733. data->db_index = 0;
  8734. quest_pending_reward.push_back(data);
  8735. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  8736. quest_updates = true;
  8737. break;
  8738. }
  8739. }
  8740. if(quest_updates) {
  8741. SaveQuestRewardData(true);
  8742. }
  8743. }
  8744. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8745. vector<struct CollectionRewardItem*>* reward_items;
  8746. vector<struct CollectionRewardItem*>::iterator itr;
  8747. struct CollectionRewardItem* reward_item;
  8748. int16 num_slots_needed;
  8749. int16 num_slots;
  8750. assert(collection);
  8751. reward_items = collection->GetRewardItems();
  8752. num_slots_needed = (int16)reward_items->size();
  8753. if (selectable_item_id > 0)
  8754. num_slots_needed++;
  8755. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8756. if (num_slots < num_slots_needed) {
  8757. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8758. DisplayCollectionComplete(collection);
  8759. return;
  8760. }
  8761. /* add manditory items */
  8762. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8763. reward_item = *itr;
  8764. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8765. }
  8766. /* find and add the selectable item if there's one */
  8767. if (selectable_item_id > 0) {
  8768. reward_items = collection->GetSelectableRewardItems();
  8769. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8770. reward_item = *itr;
  8771. if (reward_item->item->details.item_id == selectable_item_id) {
  8772. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8773. break;
  8774. }
  8775. }
  8776. }
  8777. if (collection->GetRewardXP() > 0) {
  8778. player->AddXP((int32)collection->GetRewardXP());
  8779. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  8780. }
  8781. if (collection->GetRewardCoin() > 0) {
  8782. player->AddCoins(collection->GetRewardCoin());
  8783. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8784. }
  8785. collection->SetCompleted(true);
  8786. //update achievements for completeing collection here
  8787. collection->SetSaveNeeded(true);
  8788. SendCollectionList();
  8789. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8790. player->SetPendingCollectionReward(0);
  8791. RemoveQueuedQuestReward();
  8792. GetPlayer()->SetActiveReward(false);
  8793. HandInCollections();
  8794. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  8795. }
  8796. void Client::SendRecipeList() {
  8797. PacketStruct* packet = 0;
  8798. if (GetRecipeListSent()) {
  8799. return;
  8800. }
  8801. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8802. return;
  8803. }
  8804. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8805. map<int32, Recipe*>::iterator itr;
  8806. Recipe* recipe;
  8807. int16 i = 0;
  8808. packet->setArrayLengthByName("num_recipes", recipes->size());
  8809. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8810. recipe = itr->second;
  8811. packet->setArrayDataByName("id", recipe->GetID(), i);
  8812. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8813. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8814. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8815. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8816. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8817. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8818. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8819. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8820. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8821. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8822. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8823. i++;
  8824. }
  8825. //packet->PrintPacket();
  8826. //DumpPacket(packet->serialize());
  8827. QueuePacket(packet->serialize());
  8828. safe_delete(packet);
  8829. SetRecipeListSent(true);
  8830. }
  8831. void Client::ShowRecipeBook() {
  8832. PacketStruct* packet = 0;
  8833. Spawn* target = 0;
  8834. if (!(target = player->GetTarget())) {
  8835. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8836. return;
  8837. }
  8838. if (!target->IsObject()) {
  8839. return;
  8840. }
  8841. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8842. return;
  8843. }
  8844. packet->setDataByName("device", target->GetName());
  8845. packet->setDataByName("unknown1", 1);
  8846. if (((Object*)target)->GetDeviceID() > 0) {
  8847. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8848. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8849. packet->setDataByName("unknown2", 8);
  8850. packet->setDataByName("unknown3", deviceID);
  8851. }
  8852. //packet->PrintPacket();
  8853. QueuePacket(packet->serialize());
  8854. safe_delete(packet);
  8855. }
  8856. void Client::SendTitleUpdate() {
  8857. // must call release read lock before leaving function on GetPlayerTitles
  8858. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8859. vector<Title*>::iterator itr;
  8860. Title* title;
  8861. sint32 i = 0;
  8862. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8863. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8864. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8865. if (packet) {
  8866. packet->setArrayLengthByName("num_titles", titles->size());
  8867. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8868. title = *itr;
  8869. packet->setArrayDataByName("title", title->GetName(), i);
  8870. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8871. i++;
  8872. }
  8873. packet->setDataByName("current_prefix", prefix_index);
  8874. packet->setDataByName("current_suffix", suffix_index);
  8875. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8876. #if EQDEBUG >= 9
  8877. packet->PrintPacket();
  8878. #endif
  8879. QueuePacket(packet->serialize());
  8880. safe_delete(packet);
  8881. SendUpdateTitles(prefix_index, suffix_index);
  8882. }
  8883. player->GetPlayerTitles()->ReleaseReadLock();
  8884. }
  8885. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8886. Title* suffix_title = 0;
  8887. Title* prefix_title = 0;
  8888. if (suffix != -1) {
  8889. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8890. if(suffix_title)
  8891. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8892. }
  8893. else
  8894. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8895. if (prefix != -1) {
  8896. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8897. if(prefix_title)
  8898. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8899. }
  8900. else
  8901. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8902. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8903. }
  8904. void Client::SendLanguagesUpdate(int32 id) {
  8905. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8906. list<Language*>::iterator itr;
  8907. Language* language;
  8908. int32 i = 0;
  8909. GetPlayer()->SetCurrentLanguage(id);
  8910. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8911. if (packet) {
  8912. packet->setArrayLengthByName("num_languages", languages->size());
  8913. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8914. language = *itr;
  8915. packet->setArrayDataByName("language_id", language->GetID(), i);
  8916. i++;
  8917. }
  8918. packet->setDataByName("current_language", id);
  8919. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8920. #if EQDEBUG >= 9
  8921. packet->PrintPacket();
  8922. #endif
  8923. QueuePacket(packet->serialize());
  8924. safe_delete(packet);
  8925. }
  8926. }
  8927. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8928. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8929. if (packet) {
  8930. if (pet_name)
  8931. packet->setDataByName("pet_name", pet_name);
  8932. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  8933. packet->setDataByName("protect_master", 1);
  8934. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  8935. packet->setDataByName("protect_self", 1);
  8936. if (player->GetInfoStruct()->get_pet_movement() == 2)
  8937. packet->setDataByName("stay_follow_toggle", 1);
  8938. packet->setDataByName("pet_type", type);
  8939. QueuePacket(packet->serialize());
  8940. }
  8941. safe_delete(packet);
  8942. }
  8943. bool Client::IsCrafting() {
  8944. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8945. }
  8946. void Client::SendBiography() {
  8947. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8948. if (packet) {
  8949. char biography[512];
  8950. if(player->GetInfoStruct()->get_biography().size() < 1)
  8951. {
  8952. safe_delete(packet);
  8953. return;
  8954. }
  8955. else
  8956. {
  8957. int16 size = player->GetInfoStruct()->get_biography().size();
  8958. if(size>511)
  8959. size = 511;
  8960. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  8961. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  8962. }
  8963. packet->setDataByName("biography", biography);
  8964. QueuePacket(packet->serialize());
  8965. }
  8966. safe_delete(packet);
  8967. }
  8968. PendingResurrection* Client::GetCurrentRez() {
  8969. return &current_rez;
  8970. }
  8971. Mutex* Client::GetResurrectMutex() {
  8972. return &m_resurrect;
  8973. }
  8974. void Client::SendResurrectionWindow() {
  8975. Spawn* caster = current_rez.caster;
  8976. if (!caster || !player)
  8977. return;
  8978. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8979. if (!packet)
  8980. return;
  8981. char* tmp = new char[512];
  8982. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8983. packet->setMediumStringByName("text", tmp);
  8984. packet->setMediumStringByName("accept_text", "Yes");
  8985. packet->setMediumStringByName("cancel_text", "No");
  8986. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8987. packet->setMediumStringByName("accept_command", tmp);
  8988. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8989. packet->setMediumStringByName("cancel_command", tmp);
  8990. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8991. QueuePacket(packet->serialize());
  8992. safe_delete(packet);
  8993. safe_delete_array(tmp);
  8994. }
  8995. void Client::AcceptResurrection() {
  8996. Spawn* caster = current_rez.caster;
  8997. if (!player || !caster)
  8998. return;
  8999. if (player->Alive())
  9000. return;
  9001. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9002. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9003. SendResurrectionWindow();
  9004. return;
  9005. }
  9006. player->GetZone()->ResurrectSpawn(player, this);
  9007. current_rez.should_delete = true;
  9008. }
  9009. void Client::SetPendingLastName(string last_name) {
  9010. pending_last_name = new string;
  9011. pending_last_name->assign(last_name);
  9012. }
  9013. string* Client::GetPendingLastName() {
  9014. return pending_last_name;
  9015. }
  9016. void Client::RemovePendingLastName() {
  9017. safe_delete(pending_last_name);
  9018. }
  9019. void Client::SendLastNameConfirmation() {
  9020. if (!pending_last_name)
  9021. return;
  9022. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9023. if (packet) {
  9024. char* text = new char[128];
  9025. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9026. packet->setDataByName("text", text);
  9027. packet->setDataByName("accept_text", "Yes");
  9028. packet->setDataByName("accept_command", "confirmedlastname");
  9029. packet->setDataByName("cancel_text", "No");
  9030. packet->setDataByName("max_length", 50);
  9031. packet->setDataByName("unknown4", 1);
  9032. packet->setDataByName("unknown5", 1);
  9033. QueuePacket(packet->serialize());
  9034. safe_delete(packet);
  9035. safe_delete_array(text);
  9036. }
  9037. }
  9038. void Client::AddQuestTimer(int32 quest_id) {
  9039. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9040. quest_timers.push_back(quest_id);
  9041. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9042. }
  9043. void Client::RemoveQuestTimer(int32 quest_id) {
  9044. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9045. vector<int32>::iterator itr;
  9046. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9047. if ((*itr) == quest_id) {
  9048. quest_timers.erase(itr);
  9049. break;
  9050. }
  9051. }
  9052. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9053. }
  9054. void Client::SavePlayerImages() {
  9055. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9056. // Save the paperdoll image if the server allows it
  9057. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9058. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9059. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9060. // Save the head shot if the server allows it
  9061. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9062. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9063. // Send the head shot to the login server
  9064. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9065. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9066. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9067. memset(packet->pBuffer, 0, size);
  9068. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9069. pic->account_id = GetAccountID();
  9070. pic->char_id = GetCharacterID();
  9071. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9072. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9073. loginserver.SendPacket(packet);
  9074. safe_delete(packet);
  9075. }
  9076. }
  9077. safe_delete_array(incoming_paperdoll.image_bytes);
  9078. incoming_paperdoll.current_size_bytes = 0;
  9079. }
  9080. void Client::EndAutoMount() {
  9081. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9082. if (packet) {
  9083. packet->setDataByName("parameter1", 128);
  9084. packet->setDataByName("parameter2", 64);
  9085. packet->setDataByName("value", 1);
  9086. QueuePacket(packet->serialize());
  9087. safe_delete(packet);
  9088. }
  9089. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9090. if (packet) {
  9091. packet->setDataByName("parameter3", 4);
  9092. packet->setDataByName("parameter5", 2);
  9093. packet->setDataByName("value", 0);
  9094. QueuePacket(packet->serialize());
  9095. safe_delete(packet);
  9096. }
  9097. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9098. if (packet) {
  9099. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  9100. QueuePacket(packet->serialize());
  9101. safe_delete(packet);
  9102. }
  9103. on_auto_mount = false;
  9104. player->SetMount(((Player*)player)->GetTempMount());
  9105. EQ2_Color mount_color = player->GetTempMountColor();
  9106. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  9107. player->SetMountColor(&mount_color);
  9108. player->SetMountSaddleColor(&saddle_color);
  9109. player->SetTempMount(0);
  9110. }
  9111. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  9112. const char* spawn_script = spawn->GetSpawnScript();
  9113. bool should_use_spawn = true;
  9114. if (spawn_script) {
  9115. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  9116. if (state) {
  9117. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  9118. if (state_mutex)
  9119. state_mutex->writelock(__FUNCTION__, __LINE__);
  9120. lua_getglobal(state, "can_use_command");
  9121. if (lua_isfunction(state, -1)) {
  9122. lua_interface->SetSpawnValue(state, spawn);
  9123. lua_interface->SetSpawnValue(state, GetPlayer());
  9124. lua_interface->SetStringValue(state, command ? command : "");
  9125. if (lua_pcall(state, 3, 1, 0) == 0) {
  9126. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  9127. }
  9128. }
  9129. lua_interface->ResetFunctionStack(state);
  9130. if (state_mutex)
  9131. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  9132. }
  9133. }
  9134. return should_use_spawn;
  9135. }
  9136. bool Client::IsCurrentTransmuteID(int32 req_id) {
  9137. return req_id == transmuteID;
  9138. }
  9139. void Client::SetTransmuteID(int32 trans_id) {
  9140. transmuteID = trans_id;
  9141. }
  9142. int32 Client::GetTransmuteID() {
  9143. return transmuteID;
  9144. }
  9145. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  9146. {
  9147. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  9148. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  9149. if (zar)
  9150. {
  9151. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  9152. if (database.IsActiveQuery(charID))
  9153. {
  9154. delayedLogin = true;
  9155. delayedAccountID = account_id;
  9156. delayedAccessKey = access_code;
  9157. delayTimer.Start(500);
  9158. 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);
  9159. return true;
  9160. }
  9161. delayedLogin = false;
  9162. delayTimer.Disable();
  9163. firstlogin = zar->isFirstLogin();
  9164. 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);
  9165. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  9166. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  9167. GetPlayer()->vis_changed = false;
  9168. GetPlayer()->info_changed = false;
  9169. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9170. if (pvp_allowed)
  9171. this->GetPlayer()->SetAttackable(1);
  9172. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  9173. Client* client = zone_list.GetClientByCharName(player->GetName());
  9174. if (client) {
  9175. if (client->getConnection())
  9176. client->getConnection()->SendDisconnect(true);
  9177. if (client->GetCurrentZone() && !client->IsZoning()) {
  9178. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  9179. if (client->GetVersion() == version) {
  9180. client->DisableSave();
  9181. client->ReplaceGroupClient(this);
  9182. Player* current_player = GetPlayer();
  9183. SetPlayer(client->GetPlayer());
  9184. GetPlayer()->SetClient(this);
  9185. GetPlayer()->SetReturningFromLD(true);
  9186. SetCurrentZone(GetPlayer()->GetZone());
  9187. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  9188. client->SetPlayer(current_player);
  9189. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  9190. GetPlayer()->ResetSavedSpawns();
  9191. }
  9192. ZoneServer* tmpZone = client->GetCurrentZone();
  9193. tmpZone->RemoveClientImmediately(client);
  9194. }
  9195. }
  9196. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  9197. if (!GetCurrentZone()) {
  9198. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  9199. ClientPacketFunctions::SendLoginDenied(this);
  9200. }
  9201. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  9202. getConnection()->SetClientVersion(version);
  9203. GetCurrentZone()->SetSpawnStructs(this);
  9204. connected_to_zone = true;
  9205. client_list.Remove(this); //remove from master client list
  9206. GetCurrentZone()->AddClient(this); //add to zones client list
  9207. zone_list.AddClientToMap(player->GetName(), this);
  9208. // 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.
  9209. new_client_login = true;
  9210. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  9211. if (zone_script && lua_interface)
  9212. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  9213. }
  9214. else {
  9215. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  9216. ClientPacketFunctions::SendLoginDenied(this);
  9217. return false;
  9218. }
  9219. }
  9220. else {
  9221. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  9222. ClientPacketFunctions::SendLoginDenied(this);
  9223. }
  9224. zone_auth.RemoveAuth(zar);
  9225. }
  9226. else
  9227. {
  9228. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  9229. Disconnect();
  9230. }
  9231. return true;
  9232. }
  9233. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  9234. if (!IsReadyForUpdates())
  9235. return;
  9236. map<int32, SpawnData> info_changes;
  9237. map<int32, SpawnData> pos_changes;
  9238. map<int32, SpawnData> vis_changes;
  9239. map<int32, SpawnData> empty_changes;
  9240. int32 info_size = 0;
  9241. int32 pos_size = 0;
  9242. int32 vis_size = 0;
  9243. int count = 0;
  9244. for (const auto& spawn : spawns) {
  9245. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  9246. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  9247. continue;
  9248. if (spawn->vis_changed)
  9249. {
  9250. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9251. if (vis_change) {
  9252. SpawnData data;
  9253. data.spawn = spawn;
  9254. data.data = vis_change;
  9255. data.size = spawn->vis_packet_size;
  9256. map<int32, SpawnData> tmp_vis_changes;
  9257. tmp_vis_changes[index] = data;
  9258. map<int32, SpawnData> tmp_info_changes;
  9259. map<int32, SpawnData> tmp_pos_changes;
  9260. int32 tmp_info_size = 0;
  9261. int32 tmp_pos_size = 0;
  9262. if (spawn->info_changed) {
  9263. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9264. if (info_change) {
  9265. SpawnData data;
  9266. data.spawn = spawn;
  9267. data.data = info_change;
  9268. data.size = spawn->info_packet_size;
  9269. tmp_info_size = data.size;
  9270. tmp_info_changes[index] = data;
  9271. }
  9272. }
  9273. if (spawn->position_changed) {
  9274. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9275. if (pos_change) {
  9276. SpawnData data;
  9277. data.spawn = spawn;
  9278. data.data = pos_change;
  9279. data.size = spawn->pos_packet_size;
  9280. tmp_pos_size = data.size;
  9281. tmp_pos_changes[index] = data;
  9282. }
  9283. }
  9284. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  9285. for (auto& kv : tmp_info_changes) {
  9286. safe_delete_array(kv.second.data);
  9287. }
  9288. for (auto& kv : tmp_pos_changes) {
  9289. safe_delete_array(kv.second.data);
  9290. }
  9291. for (auto& kv : tmp_vis_changes) {
  9292. safe_delete_array(kv.second.data);
  9293. }
  9294. continue;
  9295. }
  9296. }
  9297. if (spawn->info_changed) {
  9298. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9299. if (info_change) {
  9300. SpawnData data;
  9301. data.spawn = spawn;
  9302. data.data = info_change;
  9303. data.size = spawn->info_packet_size;
  9304. info_size += spawn->info_packet_size;
  9305. info_changes[index] = data;
  9306. }
  9307. count++;
  9308. }
  9309. if (spawn->position_changed) {
  9310. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9311. if (pos_change) {
  9312. SpawnData data;
  9313. data.spawn = spawn;
  9314. data.data = pos_change;
  9315. data.size = spawn->pos_packet_size;
  9316. pos_size += spawn->pos_packet_size;
  9317. pos_changes[index] = data;
  9318. }
  9319. count++;
  9320. }
  9321. if (spawn->vis_changed) {
  9322. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9323. if (vis_change) {
  9324. SpawnData data;
  9325. data.spawn = spawn;
  9326. data.data = vis_change;
  9327. data.size = spawn->vis_packet_size;
  9328. vis_size += spawn->vis_packet_size;
  9329. vis_changes[index] = data;
  9330. }
  9331. count++;
  9332. }
  9333. }
  9334. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9335. return;
  9336. }
  9337. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9338. for (auto& kv : info_changes) {
  9339. safe_delete_array(kv.second.data);
  9340. }
  9341. for (auto& kv : pos_changes) {
  9342. safe_delete_array(kv.second.data);
  9343. }
  9344. for (auto& kv : vis_changes) {
  9345. safe_delete_array(kv.second.data);
  9346. }
  9347. }
  9348. 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)
  9349. {
  9350. static const int8 oversized = 255;
  9351. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9352. int32 size = info_size + pos_size + vis_size + 8;
  9353. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9354. size += 3;
  9355. size += CheckOverLoadSize(info_size);
  9356. size += CheckOverLoadSize(pos_size);
  9357. size += CheckOverLoadSize(vis_size);
  9358. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9359. size += 2;
  9360. }
  9361. uchar* tmp = new uchar[size];
  9362. uchar* ptr = tmp;
  9363. memset(tmp, 0, size);
  9364. if (version <= 283) {
  9365. if (size >= 255) {
  9366. size -= 3;
  9367. memcpy(ptr, &oversized, sizeof(int8));
  9368. ptr += sizeof(int8);
  9369. memcpy(ptr, &size, sizeof(int16));
  9370. ptr += sizeof(int16);
  9371. size += 3;
  9372. }
  9373. else {
  9374. size -= 1;
  9375. memcpy(ptr, &size, sizeof(int8));
  9376. ptr += sizeof(int8);
  9377. size += 1;
  9378. }
  9379. }
  9380. else {
  9381. size -= 4;
  9382. memcpy(ptr, &size, sizeof(int32));
  9383. ptr += sizeof(int32);
  9384. size += 4;
  9385. }
  9386. memcpy(ptr, &oversized, sizeof(int8));
  9387. ptr += sizeof(int8);
  9388. memcpy(ptr, &opcode_val, sizeof(int16));
  9389. ptr += sizeof(int16);
  9390. int32 current_time = Timer::GetCurrentTime2();
  9391. memcpy(ptr, &current_time, sizeof(int32));
  9392. ptr += sizeof(int32);
  9393. ptr += DoOverLoad(info_size, ptr);
  9394. for (const auto& kv : info_changes) {
  9395. auto info = kv.second;
  9396. memcpy(ptr, info.data, info.size);
  9397. ptr += info.size;
  9398. }
  9399. ptr += DoOverLoad(pos_size, ptr);
  9400. for (const auto& kv : pos_changes) {
  9401. auto pos = kv.second;
  9402. memcpy(ptr, pos.data, pos.size);
  9403. ptr += pos.size;
  9404. }
  9405. ptr += DoOverLoad(vis_size, ptr);
  9406. for (const auto& kv : vis_changes) {
  9407. auto vis = kv.second;
  9408. memcpy(ptr, vis.data, vis.size);
  9409. ptr += vis.size;
  9410. }
  9411. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9412. if (packet) {
  9413. /*char blah[64];
  9414. snprintf(blah, 64, "Sending %i", current_time);
  9415. SimpleMessage(4, blah);*/
  9416. QueuePacket(packet);
  9417. }
  9418. delete[] tmp;
  9419. }
  9420. void Client::SendHailCommand(Spawn* spawn)
  9421. {
  9422. // hardcoded 'hail' entity commands
  9423. switch (spawn->secondary_command_list_id)
  9424. {
  9425. case 9:
  9426. case 1262:
  9427. case 1265:
  9428. case 1267:
  9429. {
  9430. EQ2_16BitString* command = new EQ2_16BitString();
  9431. command->data = "";
  9432. command->size = 0;
  9433. commands.Process(COMMAND_HAIL, command, this, spawn);
  9434. safe_delete(command);
  9435. break;
  9436. }
  9437. }
  9438. }
  9439. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9440. {
  9441. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9442. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9443. if (packet) {
  9444. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9445. packet->setMediumStringByName("command_name", command);
  9446. packet->setDataByName("distance", distance);
  9447. QueuePacket(packet->serialize());
  9448. safe_delete(packet);
  9449. }
  9450. }
  9451. }
  9452. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9453. {
  9454. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9455. return false;
  9456. if (command == "house_spawn_examine")
  9457. {
  9458. uint32 itemID = spawn->GetPickupItemID();
  9459. if (itemID)
  9460. {
  9461. Item* item = master_item_list.GetItem(itemID);
  9462. if (item)
  9463. {
  9464. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9465. //DumpPacket(app);
  9466. QueuePacket(app);
  9467. }
  9468. }
  9469. return true;
  9470. }
  9471. return false;
  9472. }
  9473. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9474. {
  9475. if (GetTempPlacementSpawn())
  9476. {
  9477. Spawn* tmp = GetTempPlacementSpawn();
  9478. int32 spawn_group_id = database.GetNextSpawnLocation();
  9479. tmp->SetSpawnLocationID(spawn_group_id);
  9480. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9481. int32 spawnDBID = 0;
  9482. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9483. {
  9484. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9485. tmp->SetDatabaseID(spawnDBID);
  9486. }
  9487. else
  9488. {
  9489. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9490. if (spawnDBID)
  9491. {
  9492. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9493. tmp->SetDatabaseID(spawnDBID);
  9494. }
  9495. }
  9496. tmp->SetX(place_object->getType_float_ByName("x"));
  9497. tmp->SetY(place_object->getType_float_ByName("y"));
  9498. tmp->SetZ(place_object->getType_float_ByName("z"));
  9499. tmp->SetHeading(newHeading);
  9500. tmp->SetSpawnOrigX(tmp->GetX());
  9501. tmp->SetSpawnOrigY(tmp->GetY());
  9502. tmp->SetSpawnOrigZ(tmp->GetZ());
  9503. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9504. database.SaveSpawnInfo(tmp);
  9505. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9506. if (!spawnDBID)
  9507. {
  9508. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9509. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  9510. }
  9511. return true;
  9512. }
  9513. return false;
  9514. }
  9515. bool Client::PopulateHouseSpawnFinalize()
  9516. {
  9517. if (GetTempPlacementSpawn())
  9518. {
  9519. Spawn* tmp = GetTempPlacementSpawn();
  9520. GetCurrentZone()->AddSpawn(tmp);
  9521. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9522. SetTempPlacementSpawn(nullptr);
  9523. int32 uniqueID = GetPlacementUniqueItemID();
  9524. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9525. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9526. tmp->SetPickupUniqueItemID(uniqueID);
  9527. if (uniqueItem)
  9528. {
  9529. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9530. {
  9531. Query query;
  9532. 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);
  9533. }
  9534. if(lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  9535. {
  9536. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9537. }
  9538. if(uniqueItem) {
  9539. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9540. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9541. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9542. }
  9543. SetPlacementUniqueItemID(0);
  9544. }
  9545. return true;
  9546. }
  9547. return false;
  9548. }
  9549. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9550. {
  9551. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9552. packet->setDataByName("placement_mode", placementMode);
  9553. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9554. packet->setDataByName("model_type", spawn->GetModelType());
  9555. packet->setDataByName("unknown", 1); //size
  9556. packet->setDataByName("unknown2", 1); //size 2
  9557. packet->setDataByName("unknown2", .5, 1); //size 3
  9558. packet->setDataByName("unknown2", 3, 2);
  9559. packet->setDataByName("unknown2", unknown2_3, 3);
  9560. packet->setDataByName("max_distance", 500);
  9561. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9562. QueuePacket(packet->serialize());
  9563. safe_delete(packet);
  9564. }
  9565. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9566. {
  9567. SetPendingFlightPath(path_id);
  9568. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9569. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9570. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9571. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9572. if (packet) {
  9573. QueuePacket(packet->serialize());
  9574. safe_delete(packet);
  9575. }
  9576. if (mount_id)
  9577. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9578. }
  9579. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  9580. {
  9581. if (!sender)
  9582. {
  9583. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9584. return;
  9585. }
  9586. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9587. if (!packet) {
  9588. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9589. return;
  9590. }
  9591. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9592. packet->setDataByName("book_title", title.c_str());
  9593. packet->setDataByName("book_type", "simple");
  9594. packet->setDataByName("unknown2", 1);
  9595. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9596. packet->setDataByName("language", language);
  9597. if (GetVersion() > 546)
  9598. packet->setDataByName("unknown5", 1, 4);
  9599. packet->setArrayLengthByName("num_pages", num_pages);
  9600. va_list args;
  9601. va_start(args, num_pages);
  9602. std::string endString("");
  9603. for (int8 p = 0; p < num_pages; p++)
  9604. {
  9605. std::string page = va_arg(args, string);
  9606. switch (GetVersion())
  9607. {
  9608. // release client
  9609. case 283:
  9610. {
  9611. endString.append(page);
  9612. break;
  9613. }
  9614. // DoF trial
  9615. case 546:
  9616. {
  9617. if (p == 0)
  9618. packet->setDataByName("cover_page", page.c_str());
  9619. else
  9620. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9621. break;
  9622. }
  9623. // all other clients
  9624. default:
  9625. {
  9626. packet->setArrayDataByName("page_text", page.c_str(), p);
  9627. break;
  9628. }
  9629. }
  9630. }
  9631. if (GetVersion() == 283)
  9632. {
  9633. packet->setDataByName("page_text", endString.c_str());
  9634. }
  9635. va_end(args);
  9636. QueuePacket(packet->serialize());
  9637. safe_delete(packet);
  9638. }
  9639. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  9640. {
  9641. if (!sender)
  9642. {
  9643. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9644. return;
  9645. }
  9646. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9647. if (!packet) {
  9648. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9649. return;
  9650. }
  9651. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9652. packet->setDataByName("book_title", title.c_str());
  9653. packet->setDataByName("book_type", "simple");
  9654. packet->setDataByName("unknown2", 1);
  9655. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9656. packet->setDataByName("language", language);
  9657. if (GetVersion() > 546)
  9658. packet->setDataByName("unknown5", 1, 4);
  9659. packet->setArrayLengthByName("num_pages", pages.size());
  9660. std::string endString("");
  9661. for (int8 p = 0; p < pages.size(); p++)
  9662. {
  9663. Item::BookPage* page = pages[p];
  9664. std::string pageText = string(page->page_text.data);
  9665. switch (GetVersion())
  9666. {
  9667. // release client
  9668. case 283:
  9669. {
  9670. endString.append(pageText);
  9671. break;
  9672. }
  9673. // DoF trial
  9674. case 546:
  9675. {
  9676. if (p == 0)
  9677. packet->setDataByName("cover_page", pageText.c_str());
  9678. else
  9679. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9680. break;
  9681. }
  9682. // all other clients
  9683. default:
  9684. {
  9685. int8 valign = int8(page->valign);
  9686. int8 halign = int8(page->halign);
  9687. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9688. packet->setArrayDataByName("page_text_valign", valign, p);
  9689. packet->setArrayDataByName("page_text_halign", halign, p);
  9690. break;
  9691. }
  9692. }
  9693. }
  9694. if (GetVersion() == 283)
  9695. {
  9696. packet->setDataByName("page_text", endString.c_str());
  9697. }
  9698. QueuePacket(packet->serialize());
  9699. safe_delete(packet);
  9700. }
  9701. void Client::ReplaceGroupClient(Client* new_client)
  9702. {
  9703. if (this->GetPlayer()->GetGroupMemberInfo())
  9704. {
  9705. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9706. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9707. if(group)
  9708. {
  9709. group->MGroupMembers.writelock();
  9710. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9711. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9712. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9713. group->MGroupMembers.releasewritelock();
  9714. }
  9715. else
  9716. {
  9717. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9718. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9719. this->GetPlayer()->SetGroupMemberInfo(0);
  9720. }
  9721. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9722. }
  9723. }
  9724. void Client::TempRemoveGroup()
  9725. {
  9726. if (this->GetPlayer()->GetGroupMemberInfo())
  9727. {
  9728. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9729. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9730. if(group)
  9731. {
  9732. group->MGroupMembers.writelock();
  9733. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9734. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9735. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9736. this->GetPlayer()->SetGroupMemberInfo(0);
  9737. group->MGroupMembers.releasewritelock();
  9738. group->RemoveClientReference(this);
  9739. }
  9740. else
  9741. {
  9742. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9743. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9744. this->GetPlayer()->SetGroupMemberInfo(0);
  9745. }
  9746. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9747. }
  9748. }
  9749. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9750. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9751. {
  9752. Mail mail;
  9753. memset(&mail,0,sizeof(Mail));
  9754. mail.player_to_id = charID;
  9755. mail.player_from = fromName;
  9756. mail.subject = subjectName;
  9757. mail.mail_body = mailBody;
  9758. mail.mail_type = mailType;
  9759. mail.coin_copper = copper;
  9760. mail.coin_silver = silver;
  9761. mail.coin_gold = gold;
  9762. mail.coin_plat = platinum;
  9763. mail.char_item_id = item_id;
  9764. mail.stack = stack_size;
  9765. mail.time_sent = time_sent;
  9766. mail.expire_time = expire_time;
  9767. database.SavePlayerMail(&mail);
  9768. }
  9769. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9770. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9771. {
  9772. Mail* mail = new Mail();
  9773. mail->player_to_id = GetCharacterID();
  9774. mail->player_from = fromName;
  9775. mail->subject = subjectName;
  9776. mail->mail_body = mailBody;
  9777. mail->mail_type = mailType;
  9778. mail->coin_copper = copper;
  9779. mail->coin_silver = silver;
  9780. mail->coin_gold = gold;
  9781. mail->coin_plat = platinum;
  9782. mail->char_item_id = item_id;
  9783. mail->stack = stack_size;
  9784. mail->time_sent = time_sent;
  9785. mail->expire_time = expire_time;
  9786. mail->postage_cost = 0;
  9787. mail->save_needed = 1;
  9788. mail->already_read = 0;
  9789. database.SavePlayerMail(mail);
  9790. GetPlayer()->AddMail(mail);
  9791. }
  9792. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9793. {
  9794. if(slot < NUM_SLOTS)
  9795. {
  9796. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9797. if (app)
  9798. QueuePacket(app);
  9799. }
  9800. else
  9801. {
  9802. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9803. if (outapp)
  9804. QueuePacket(outapp);
  9805. }
  9806. }
  9807. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9808. {
  9809. if(spawn_player_id < 1)
  9810. return;
  9811. MQueueStateCmds.writelock();
  9812. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9813. MQueueStateCmds.releasewritelock();
  9814. }
  9815. void Client::ProcessStateCommands()
  9816. {
  9817. if(!IsReadyForUpdates())
  9818. return;
  9819. MQueueStateCmds.writelock();
  9820. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9821. for(; itr != queued_state_commands.end(); itr++)
  9822. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9823. queued_state_commands.clear();
  9824. MQueueStateCmds.releasewritelock();
  9825. }
  9826. void Client::PurgeItem(Item* item)
  9827. {
  9828. MConversation.writelock();
  9829. map<int32, Item*>::iterator itr;
  9830. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9831. {
  9832. if ( itr->second == item )
  9833. {
  9834. conversation_items.erase(itr);
  9835. break;
  9836. }
  9837. }
  9838. MConversation.releasewritelock();
  9839. }
  9840. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9841. {
  9842. if(GetPlayer()->StopSaveSpellEffects())
  9843. return;
  9844. if(item) {
  9845. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9846. if(item->GetItemScript() && lua_interface){
  9847. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9848. if (slot == 22)
  9849. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9850. else
  9851. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9852. }
  9853. if (item->details.count > 1) {
  9854. item->details.count -= 1;
  9855. item->save_needed = true;
  9856. }
  9857. else {
  9858. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9859. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9860. }
  9861. GetPlayer()->SetCharSheetChanged(true);
  9862. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9863. }
  9864. }
  9865. void Client::AwardCoins(int64 total_coins, std::string reason)
  9866. {
  9867. if (total_coins > 0) {
  9868. player->AddCoins(total_coins);
  9869. PlaySound("coin_cha_ching");
  9870. char tmp[64] = { 0 };
  9871. string message = "You receive ";
  9872. int32 val = 0;
  9873. if (total_coins >= 1000000) {
  9874. val = total_coins / 1000000;
  9875. total_coins -= 1000000 * val;
  9876. sprintf(tmp, "%u Platinum ", val);
  9877. message.append(tmp);
  9878. memset(tmp, 0, 64);
  9879. }
  9880. if (total_coins >= 10000) {
  9881. val = total_coins / 10000;
  9882. total_coins -= 10000 * val;
  9883. sprintf(tmp, "%u Gold ", val);
  9884. message.append(tmp);
  9885. memset(tmp, 0, 64);
  9886. }
  9887. if (total_coins >= 100) {
  9888. val = total_coins / 100;
  9889. total_coins -= 100 * val;
  9890. sprintf(tmp, "%u Silver ", val);
  9891. message.append(tmp);
  9892. memset(tmp, 0, 64);
  9893. }
  9894. if (total_coins > 0) {
  9895. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9896. message.append(tmp);
  9897. }
  9898. message.append(reason);
  9899. int8 type = CHANNEL_LOOT;
  9900. SimpleMessage(type, message.c_str());
  9901. }
  9902. }
  9903. void Client::TriggerSpellSave()
  9904. {
  9905. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  9906. // default to not have some bogus value in the rule
  9907. if(interval < 1)
  9908. interval = 100;
  9909. MSaveSpellStateMutex.lock();
  9910. if(!save_spell_state_timer.Enabled())
  9911. {
  9912. save_spell_state_time_bucket = 0;
  9913. save_spell_state_timer.Start(interval, true);
  9914. }
  9915. else
  9916. {
  9917. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  9918. save_spell_state_time_bucket += elapsed_time;
  9919. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  9920. // default to not have some bogus value in the rule
  9921. if(save_wait_cap < interval)
  9922. save_wait_cap = interval+1;
  9923. if(save_spell_state_time_bucket >= save_wait_cap)
  9924. {
  9925. // save immediately and disable timer
  9926. GetPlayer()->SaveSpellEffects();
  9927. save_spell_state_timer.Disable();
  9928. }
  9929. }
  9930. MSaveSpellStateMutex.unlock();
  9931. }
  9932. void Client::UpdateSentSpellList() {
  9933. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  9934. std::map<int32, int32>::iterator itr;
  9935. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  9936. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  9937. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  9938. QueuePacket(app);
  9939. }
  9940. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  9941. }
  9942. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  9943. tempPlacementSpawn = tmp;
  9944. hasSentTempPlacementSpawn = false;
  9945. if(tempPlacementSpawn)
  9946. temp_placement_timer.Start();
  9947. else
  9948. temp_placement_timer.Disable();
  9949. }
  9950. void Client::SetPlayer(Player* new_player) {
  9951. if (player && player != new_player)
  9952. zone_list.RemoveClientFromMap(player->GetName(), this);
  9953. player = new_player;
  9954. player->SetClient(this);
  9955. }
  9956. bool Client::UseItem(Item* item, Spawn* target) {
  9957. if (item && item->GetItemScript()) {
  9958. int16 item_index = item->details.index;
  9959. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  9960. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  9961. }
  9962. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  9963. Message(0, "%s requires an evil race.", item->name.c_str());
  9964. }
  9965. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  9966. Message(0, "%s requires a good race.", item->name.c_str());
  9967. }
  9968. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  9969. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  9970. return true;
  9971. }
  9972. else {
  9973. if (item->details.count > 0) {
  9974. std::string itemName = string(item->name);
  9975. int32 item_id = item->details.item_id;
  9976. sint64 flags = 0;
  9977. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  9978. {
  9979. //reobtain item make sure it wasn't removed
  9980. item = player->item_list.GetItemFromIndex(item_index);
  9981. if(!item) {
  9982. 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);
  9983. return true;
  9984. }
  9985. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  9986. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  9987. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  9988. return true;
  9989. }
  9990. else
  9991. {
  9992. item->details.count--; // charges
  9993. item->save_needed = true;
  9994. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  9995. if(!item->details.count) {
  9996. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  9997. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  9998. }
  9999. return true;
  10000. }
  10001. }
  10002. else {
  10003. 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);
  10004. return true;
  10005. }
  10006. }
  10007. else
  10008. {
  10009. //reobtain item make sure it wasn't removed
  10010. item = player->item_list.GetItemFromIndex(item_index);
  10011. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10012. if(item) {
  10013. 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);
  10014. }
  10015. }
  10016. }
  10017. }
  10018. return false;
  10019. }
  10020. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10021. VoiceOverStruct* garble, bool success, bool garble_success) {
  10022. VoiceOverStruct* resStruct = nullptr;
  10023. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10024. if(success) {
  10025. resStruct = non_garble;
  10026. }
  10027. }
  10028. else if(garble_success) {
  10029. resStruct = garble;
  10030. }
  10031. if(resStruct) {
  10032. 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);
  10033. }
  10034. }
  10035. void Client::SaveQuestRewardData(bool force_refresh) {
  10036. Query query;
  10037. if(force_refresh) {
  10038. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10039. GetCharacterID());
  10040. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10041. GetCharacterID());
  10042. }
  10043. vector<QuestRewardData*>::iterator itr;
  10044. vector<QuestRewardData*> tmp_quest_rewards;
  10045. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10046. int index = 0;
  10047. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10048. int32 questID = (*itr)->quest_id;
  10049. if(!(*itr)->db_saved || force_refresh) {
  10050. 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')",
  10051. 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());
  10052. (*itr)->db_saved = true;
  10053. (*itr)->db_index = index;
  10054. if((*itr)->is_temporary) {
  10055. std::vector<int32> items;
  10056. Quest* quest = GetPlayer()->GetAnyQuest(questID);
  10057. if(quest) {
  10058. quest->GetTmpRewardItemsByID(&items);
  10059. if(!force_refresh && items.size() > 0) {
  10060. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10061. GetCharacterID(), questID);
  10062. }
  10063. for(int i=0;i<items.size();i++) {
  10064. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id) values(%u, %u, %u)",
  10065. GetCharacterID(), questID, items[i]);
  10066. }
  10067. }
  10068. }
  10069. }
  10070. index++;
  10071. }
  10072. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  10073. }
  10074. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  10075. if(!data)
  10076. return;
  10077. if(data->db_saved) {
  10078. Query query;
  10079. 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",
  10080. 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);
  10081. }
  10082. }
  10083. void Client::AddRecipeToPlayer(Recipe* recipe, PacketStruct* packet, int16* i) {
  10084. if(recipe == nullptr)
  10085. return;
  10086. GetPlayer()->GetRecipeList()->AddRecipe(recipe);
  10087. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  10088. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  10089. if (packet && GetRecipeListSent()) {
  10090. packet->setArrayDataByName("id", recipe->GetID(), *i);
  10091. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  10092. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  10093. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  10094. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  10095. packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  10096. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  10097. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  10098. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), *i);
  10099. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  10100. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  10101. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  10102. if(i) {
  10103. (*i)++;
  10104. }
  10105. }
  10106. }