client.cpp 299 KB

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