client.cpp 324 KB

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