client.cpp 447 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "Chat/Chat.h"
  36. #include "SpellProcess.h"
  37. #include "Zone/ChestTrap.h"
  38. #include "../../common/GlobalHeaders.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. #include "VisualStates.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 Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. extern MasterRecipeBookList master_recipebook_list;
  113. extern VisualStates visual_states;
  114. using namespace std;
  115. Client::Client(EQStream* ieqs) : underworld_cooldown_timer(5000), pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  116. eqs = ieqs;
  117. ip = eqs->GetrIP();
  118. port = ntohs(eqs->GetrPort());
  119. merchant_transaction = nullptr;
  120. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  121. ResetSendMail(false);
  122. timestamp_flag = 0;
  123. current_quest_id = 0;
  124. last_update_time = 0;
  125. quest_updates = false;
  126. //autobootup_timeout = new Timer(10000);
  127. //autobootup_timeout->Disable();
  128. CLE_keepalive_timer = new Timer(15000);
  129. connect = new Timer(1000);
  130. connect->Disable();
  131. zoneID = 0;
  132. account_name[0] = 0;
  133. character_id = 0;
  134. account_id = 0;
  135. pwaitingforbootup = 0;
  136. current_zone = 0;
  137. connected_to_zone = false;
  138. connected = false;
  139. camp_timer = 0;
  140. linkdead_timer = 0;
  141. client_zoning = false;
  142. zoning_id = 0;
  143. zoning_x = 0;
  144. zoning_y = 0;
  145. zoning_z = 0;
  146. zoning_instance_id = 0;
  147. player_pos_changed = false;
  148. ++numclients;
  149. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  150. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  151. remove_from_list = false;
  152. new_client_login = NewLoginState::LOGIN_NONE;
  153. UpdateWindowTitle(0);
  154. num_active_failures = 0;
  155. player = new Player();
  156. player->SetClient(this);
  157. combine_spawn = 0;
  158. lua_debug = false;
  159. ready_for_spawns = false;
  160. ready_for_updates = false;
  161. lua_debug_timer.Disable();
  162. transport_spawn = 0;
  163. MBuyBack.SetName("Client::MBuyBack");
  164. MDeletePlayer.SetName("Client::MDeletePlayer");
  165. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  166. search_items = 0;
  167. version = 0;
  168. next_conversation_id = 0;
  169. pending_guild_invite.guild = 0;
  170. pending_guild_invite.invited_by = 0;
  171. m_recipeListSent = false;
  172. m_resurrect.SetName("Client::m_resurrect");
  173. current_rez.expire_timer = 0;
  174. current_rez.should_delete = true;
  175. pending_last_name = 0;
  176. should_target = false;
  177. initial_spawns_sent = false;
  178. MQuestTimers.SetName("Client::quest_timers");
  179. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  180. on_auto_mount = false;
  181. should_load_spells = true;
  182. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  183. delayedLogin = false;
  184. delayedAccountID = 0;
  185. delayedAccessKey = 0;
  186. delayTimer.Disable();
  187. tempPlacementSpawn = nullptr;
  188. placement_unique_item_id = 0;
  189. SetHasOwnerOrEditAccess(false);
  190. temporary_transport_id = 0;
  191. rejoin_group_id = 0;
  192. lastRegionRemapTime = 0;
  193. regionDebugMessaging = false;
  194. client_reloading_zone = false;
  195. last_saved_timestamp = 0;
  196. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  197. save_spell_state_timer.Disable();
  198. save_spell_state_time_bucket = 0;
  199. player_loading_complete = false;
  200. MItemDetails.SetName("Client::MItemDetails");
  201. MSpellDetails.SetName("Client::MSpellDetails");
  202. hasSentTempPlacementSpawn = false;
  203. spawn_removal_timer.Start();
  204. disable_save = false;
  205. SetZoningDestination(nullptr);
  206. underworld_cooldown_timer.Disable();
  207. player_pos_change_count = 0;
  208. pov_ghost_spawn_id = 0;
  209. recipe_orig_packet = nullptr;
  210. recipe_xor_packet = nullptr;
  211. recipe_packet_count = 0;
  212. recipe_orig_packet_size = 0;
  213. }
  214. Client::~Client() {
  215. RemoveClientFromZone();
  216. //let the stream factory know were done with this stream
  217. if (eqs) {
  218. eqs->Close();
  219. try {
  220. eqs->ReleaseFromUse();
  221. }
  222. catch (...) {}
  223. }
  224. eqs = NULL;
  225. //safe_delete(autobootup_timeout);
  226. safe_delete(linkdead_timer);
  227. vector<QueuedQuest*>::iterator itr;
  228. QueuedQuest* queued_quest = 0;
  229. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  230. queued_quest = *itr;
  231. safe_delete(queued_quest);
  232. }
  233. quest_queue.clear();
  234. vector<QuestRewardData*>::iterator rwd_itr;
  235. QuestRewardData* quest_rwd_data = 0;
  236. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  237. quest_rwd_data = *rwd_itr;
  238. safe_delete(quest_rwd_data);
  239. }
  240. quest_pending_reward.clear();
  241. safe_delete(CLE_keepalive_timer);
  242. safe_delete(connect);
  243. --numclients;
  244. UpdateWindowTitle(0);
  245. }
  246. void Client::RemoveClientFromZone() {
  247. if(player && player->GetZone())
  248. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  249. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  250. Spawn* tmp = GetTempPlacementSpawn();
  251. SetTempPlacementSpawn(nullptr);
  252. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  253. }
  254. if (current_zone && player) {
  255. if (player->GetGroupMemberInfo()) {
  256. TempRemoveGroup();
  257. }
  258. world.GetGroupManager()->ClearPendingInvite(player);
  259. }
  260. if (lua_interface)
  261. lua_interface->RemoveDebugClients(this);
  262. if (player)
  263. zone_list.RemoveClientFromMap(player->GetName(), this);
  264. safe_delete(camp_timer);
  265. safe_delete(search_items);
  266. safe_delete(current_rez.expire_timer);
  267. safe_delete(pending_last_name);
  268. safe_delete_array(incoming_paperdoll.image_bytes);
  269. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  270. if (player && !player->GetPendingDeletion())
  271. safe_delete(player);
  272. player = nullptr;
  273. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  274. deque<BuyBackItem*>::iterator itr;
  275. MBuyBack.writelock(__FUNCTION__, __LINE__);
  276. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  277. safe_delete(*itr);
  278. itr = buy_back_items.erase(itr);
  279. }
  280. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  281. }
  282. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  283. if (eqs) {
  284. if (!eqs->CheckActive()) {
  285. client_list.Remove(this);
  286. eqs = 0;
  287. }
  288. }
  289. if (app && eqs && version > 0)
  290. eqs->EQ2QueuePacket(app, attemptedCombine);
  291. else {
  292. safe_delete(app);
  293. }
  294. }
  295. void Client::PopulateSkillMap() {
  296. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  297. if (app)
  298. QueuePacket(app);
  299. else {
  300. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  301. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  302. }
  303. }
  304. void Client::SendLoginInfo() {
  305. if(GetPlayer()->IsReturningFromLD())
  306. firstlogin = true;
  307. if (firstlogin) {
  308. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  309. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  310. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  311. PopulateSkillMap();
  312. // 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!
  313. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  314. }
  315. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  316. database.ToggleCharacterOnline(this, 1);
  317. int32 count = 0;
  318. if(!GetPlayer()->IsReturningFromLD())
  319. {
  320. count = database.LoadCharacterTitles(GetCharacterID(), player);
  321. if (count == 0) {
  322. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  323. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  324. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  325. }
  326. }
  327. if(!GetPlayer()->IsReturningFromLD())
  328. {
  329. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  330. if (count == 0)
  331. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  332. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  333. if (count == 0)
  334. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  335. }
  336. ClientPacketFunctions::SendLoginAccepted(this);
  337. ClientPacketFunctions::SendAbilities ( this );
  338. ClientPacketFunctions::SendCommandNamePacket(this);
  339. ClientPacketFunctions::SendQuickBarInit(this);
  340. // we only need to send the MOTD if it is the first time the person is logging in.
  341. if (firstlogin) {
  342. ClientPacketFunctions::SendMOTD(this);
  343. ClientPacketFunctions::SendCharacterMacros(this);
  344. zone_list.CheckFriendList(this);
  345. }
  346. if(!GetPlayer()->IsReturningFromLD())
  347. {
  348. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  349. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  350. {
  351. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  352. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  353. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  354. }
  355. GetPlayer()->item_list.SetMaxItemIndex();
  356. database.LoadPlayerFactions(this);
  357. database.LoadCharacterQuests(this);
  358. database.LoadCharacterQuestRewards(this);
  359. database.LoadPlayerMail(this);
  360. }
  361. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  362. SendQuestJournal(true, 0, false);
  363. if (version > 546) // right version? possibly not!
  364. master_aa_list.DisplayAA(this, 0, 3);
  365. if (version > 283)
  366. SendCollectionList();
  367. SendBiography();
  368. map<int32, Quest*>::iterator itr;
  369. Quest* quest = 0;
  370. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  371. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  372. quest = itr->second;
  373. if (quest->IsTracked()) {
  374. quest->SetTracked(false);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. quest->SetTracked(true);
  377. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  378. }
  379. }
  380. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  381. // SendAchievementsList();
  382. /*Guild* guild = player->GetGuild();
  383. if (guild) {
  384. guild->UpdateGuildMemberInfo(GetPlayer());
  385. if (firstlogin)
  386. guild->SendGuildMOTD(this);
  387. guild->SendGuildUpdate(this);
  388. guild->SendGuildMember(GetPlayer(), firstlogin);
  389. guild->SendGuildEventList(this);
  390. guild->SendGuildBankEventList(this);
  391. guild->SendAllGuildEvents(this);
  392. guild->SendGuildMemberList(this);
  393. }*/
  394. if (version > 283) {
  395. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  396. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  397. if (outapp) {
  398. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  399. //DumpPacket(outapp);
  400. QueuePacket(outapp);
  401. }
  402. }
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  404. ClientPacketFunctions::SendCommandList(this);
  405. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  406. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  407. ClientPacketFunctions::SendInstanceList(this);
  408. SendZoneInfo();
  409. /*Spell* spell = 0;
  410. vector<QuickBarItem*>::iterator itr;
  411. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  412. if((*itr)->type == 1){
  413. spell = master_spell_list.GetSpell((*itr)->id);
  414. if(spell)
  415. QueuePacket(spell->serialize(this, false, 0x20));
  416. }
  417. }*/
  418. }
  419. void Client::SendPlayerDeathWindow()
  420. {
  421. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  422. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  423. vector<RevivePoint*>::iterator itr;
  424. if (results && results->size() > 0)
  425. {
  426. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  427. if (packet)
  428. {
  429. packet->setArrayLengthByName("location_count", results->size());
  430. RevivePoint* point = 0;
  431. int32 i = 0;
  432. for (itr = results->begin(); itr != results->end(); itr++, i++)
  433. {
  434. point = *itr;
  435. if (point)
  436. {
  437. packet->setArrayDataByName("location_id", point->id, i);
  438. //zone_name = database.GetZoneName(point->zone_id);
  439. string zone_name = database.GetZoneDescription(point->zone_id);
  440. if (zone_name.length() > 0)
  441. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  442. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  443. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  444. }
  445. if (point->id == 0xFFFFFFFF)//tmp location
  446. safe_delete(point);
  447. }
  448. #if EQDEBUG >= 3
  449. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  450. packet->PrintPacket();
  451. #endif
  452. EQ2Packet* outapp = packet->serialize();
  453. QueuePacket(outapp);
  454. safe_delete(packet);
  455. }
  456. // done with the revive points so lets free up the pointer
  457. safe_delete(results);
  458. }
  459. }
  460. void Client::DisplayDeadWindow()
  461. {
  462. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  463. player->SetHP(0);
  464. player->SetPower(0);
  465. GetCurrentZone()->TriggerCharSheetTimer();
  466. if(GetVersion() <= 546) {
  467. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  468. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  469. }
  470. else {
  471. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  472. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  473. }
  474. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  475. if (packet)
  476. {
  477. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  478. QueuePacket(packet->serialize());
  479. safe_delete(packet);
  480. }
  481. SendPlayerDeathWindow();
  482. }
  483. void Client::HandlePlayerRevive(int32 point_id)
  484. {
  485. if(GetVersion() <= 546) {
  486. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  487. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  488. }
  489. else {
  490. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  491. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  492. }
  493. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  494. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  495. if (packet)
  496. {
  497. QueuePacket(packet->serialize());
  498. safe_delete(packet);
  499. }
  500. float origX, origY, origZ, origHeading = 0.0f;
  501. origX = player->GetX();
  502. origY = player->GetY();
  503. origZ = player->GetZ();
  504. origHeading = player->GetHeading();
  505. ZoneServer* originalZone = GetCurrentZone();
  506. int32 origGridID = GetPlayer()->GetLocation();
  507. float x, y, z, heading;
  508. RevivePoint* revive_point = 0;
  509. if (point_id != 0xFFFFFFFF)
  510. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  511. string zone_desc;
  512. const char* location_name = "Unknown";
  513. player->SetAlive(true);
  514. player->SetResurrecting(true);
  515. player->SetHP(player->GetTotalHP());
  516. player->SetPower(player->GetTotalPower());
  517. //revive at zone safe coords
  518. if (!revive_point)
  519. {
  520. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  521. x = GetCurrentZone()->GetSafeX();
  522. y = GetCurrentZone()->GetSafeY();
  523. z = GetCurrentZone()->GetSafeZ();
  524. heading = GetCurrentZone()->GetSafeHeading();
  525. zone_desc = GetCurrentZone()->GetZoneDescription();
  526. location_name = "Zone Safe Point";
  527. Zone(GetCurrentZone()->GetZoneName(), false);
  528. }
  529. else
  530. {
  531. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  532. x = revive_point->x;
  533. y = revive_point->y;
  534. z = revive_point->z;
  535. heading = revive_point->heading;
  536. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  537. location_name = revive_point->location_name.c_str();
  538. Zone(GetCurrentZone()->GetZoneName(), false);
  539. }
  540. player->SetX(x);
  541. player->SetY(y);
  542. player->SetZ(z);
  543. player->SetHeading(heading);
  544. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  545. zone_desc.c_str(),
  546. player->GetX(),
  547. player->GetY(),
  548. player->GetZ(),
  549. player->GetHeading(),
  550. player->GetHP(),
  551. player->GetPower(),
  552. location_name);
  553. //player->ClearEverything();
  554. Save();
  555. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  556. {
  557. string zone_name = database.GetZoneName(revive_point->zone_id);
  558. if (zone_name.length() == 0)
  559. {
  560. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  561. x = GetCurrentZone()->GetSafeX();
  562. y = GetCurrentZone()->GetSafeY();
  563. z = GetCurrentZone()->GetSafeZ();
  564. heading = GetCurrentZone()->GetSafeHeading();
  565. location_name = "Zone Safe Point";
  566. }
  567. else
  568. {
  569. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  570. location_name = revive_point->location_name.c_str();
  571. //player->ClearEverything();
  572. Save();
  573. Zone(zone_name.c_str(), false);
  574. }
  575. }
  576. zone_desc = GetCurrentZone()->GetZoneDescription();
  577. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  578. player->SetSpawnType(4);
  579. if (version > 283) {
  580. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  581. if (packet)
  582. {
  583. QueuePacket(packet->serialize());
  584. safe_delete(packet);
  585. }
  586. }
  587. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  588. if (packet)
  589. {
  590. packet->setDataByName("x", x);
  591. packet->setDataByName("y", y);
  592. packet->setDataByName("z", z);
  593. QueuePacket(packet->serialize());
  594. safe_delete(packet);
  595. }
  596. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  597. if (packet)
  598. {
  599. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  600. packet->setDataByName("speed", 32);
  601. packet->setDataByName("unknown2", 0);
  602. //DoF Merge: old value and speed wasn't included
  603. //packet->setDataByName("unknown2", 255);
  604. QueuePacket(packet->serialize());
  605. safe_delete(packet);
  606. }
  607. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  608. if (packet)
  609. {
  610. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  611. QueuePacket(packet->serialize());
  612. safe_delete(packet);
  613. }
  614. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  615. {
  616. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  617. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  618. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  619. originalZone->RemoveSpawn(player, false, true, true, true, true);
  620. originalZone->AddSpawn(shard);
  621. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  622. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  623. }
  624. m_resurrect.writelock(__FUNCTION__, __LINE__);
  625. if (current_rez.active)
  626. current_rez.should_delete = true;
  627. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  628. }
  629. void Client::SendCharInfo() {
  630. EQ2Packet* app;
  631. player->SetEquippedItemAppearances();
  632. ClientPacketFunctions::SendCharacterData(this);
  633. SendCharPOVGhost();
  634. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  635. if (packet) {
  636. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  637. packet->setDataByName("size", .56);
  638. packet->setDataByName("unknown2", 255);
  639. packet->setDataByName("speed", player->GetSpeed());
  640. packet->setDataByName("air_speed", player->GetAirSpeed());
  641. EQ2Packet* app = packet->serialize();
  642. QueuePacket(app);
  643. safe_delete(packet);
  644. }
  645. if (version <= 283) {
  646. //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
  647. Sleep(2000);
  648. }
  649. //sending bad spawn packet?
  650. //SendAchievementsList();
  651. //if (version > 546)
  652. //ClientPacketFunctions::SendHousingList(this);
  653. ClientPacketFunctions::SendCharacterSheet(this);
  654. ClientPacketFunctions::SendTraitList(this);// moved from below
  655. ClientPacketFunctions::SendAbilities(this);
  656. ClientPacketFunctions::SendSkillBook(this);
  657. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  658. ClientPacketFunctions::SendUpdateSpellBook(this);
  659. }
  660. else {
  661. player->SetResurrecting(false);
  662. }
  663. GetCurrentZone()->AddSpawn(player);
  664. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  665. GetPlayer()->SetX(zoning_x);
  666. GetPlayer()->SetY(zoning_y);
  667. GetPlayer()->SetZ(zoning_z);
  668. GetPlayer()->SetHeading(zoning_h);
  669. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  670. QueuePacket(packet);
  671. }
  672. //SendCollectionList();
  673. Guild* guild = player->GetGuild();
  674. if (guild)
  675. guild->GuildMemberLogin(this, firstlogin);
  676. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  677. if (app) {
  678. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  679. //DumpPacket(app);
  680. QueuePacket(app);
  681. }
  682. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  683. if (app) {
  684. QueuePacket(app);
  685. }
  686. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  687. if (app) {
  688. QueuePacket(app);
  689. }
  690. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  691. if (items && items->size() > 0) {
  692. for (int32 i = 0; i < items->size(); i++) {
  693. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  694. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  695. //DumpPacket(outapp);
  696. QueuePacket(outapp);
  697. }
  698. }
  699. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  700. QueuePacket(app);
  701. safe_delete(items);
  702. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  703. if (items && items->size() > 0) {
  704. for (int32 i = 0; i < items->size(); i++)
  705. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  706. }
  707. safe_delete(items);
  708. if (version > 283) {
  709. SendTitleUpdate();
  710. }
  711. GetPlayer()->UpdateWeapons();
  712. if(!GetPlayer()->IsReturningFromLD()) {
  713. database.LoadBuyBacks(this);
  714. }
  715. if (version > 546)
  716. master_aa_list.DisplayAA(this, 0, 0);
  717. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  718. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  719. string zone_motd_send = "Zone MOTD: " + zone_motd;
  720. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  721. }
  722. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  723. if (zone_script && lua_interface)
  724. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  725. this->client_zoning = false;
  726. this->zoning_id = 0;
  727. this->zoning_instance_id = 0;
  728. SetZoningDestination(nullptr);
  729. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  730. GetCurrentZone()->AddDamagedSpawn(player);
  731. if (firstlogin)
  732. firstlogin = false;
  733. player->ClearProcs();
  734. items = player->GetEquippedItemList();
  735. if (items && items->size() > 0) {
  736. for (int32 i = 0; i < items->size(); i++) {
  737. Item* item = items->at(i);
  738. if (item && item->GetItemScript() && lua_interface)
  739. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  740. }
  741. }
  742. //Allow this player to change their last name if they meet the level requirement
  743. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  744. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  745. safe_delete(items);
  746. if (!player->Alive())
  747. DisplayDeadWindow();
  748. ClientPacketFunctions::SendLocalizedTextMessage(this);
  749. if (GetCurrentZone()->GetInstanceID())
  750. {
  751. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  752. if (ph) {
  753. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  754. string name = string(GetPlayer()->GetName());
  755. if (name.compare(ph->player_name) == 0)
  756. SetHasOwnerOrEditAccess(true);
  757. }
  758. }
  759. bool groupMentor = false;
  760. GetPlayer()->group_id = rejoin_group_id;
  761. if(!world.RejoinGroup(this, rejoin_group_id))
  762. GetPlayer()->group_id = 0;
  763. else
  764. {
  765. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  766. if(ent && ent->IsPlayer())
  767. {
  768. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  769. groupMentor = true;
  770. }
  771. }
  772. if(!groupMentor)
  773. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  774. if(!GetPlayer()->IsReturningFromLD()) {
  775. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  776. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  777. }
  778. else {
  779. Spawn* pet_spawn = nullptr;
  780. if(GetPlayer()->GetPet())
  781. pet_spawn = GetPlayer()->GetPet();
  782. else if(GetPlayer()->GetCharmedPet())
  783. pet_spawn = GetPlayer()->GetCharmedPet();
  784. else if(GetPlayer()->GetCosmeticPet())
  785. pet_spawn = GetPlayer()->GetCosmeticPet();
  786. else if(GetPlayer()->GetDeityPet())
  787. pet_spawn = GetPlayer()->GetDeityPet();
  788. if(pet_spawn) {
  789. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  790. }
  791. }
  792. GetPlayer()->SetSaveSpellEffects(false);
  793. GetPlayer()->SetCharSheetChanged(true);
  794. GetPlayer()->SetReturningFromLD(false);
  795. }
  796. void Client::SendZoneSpawns() {
  797. //Allows us to place spawns almost anywhere
  798. if (version > 283) {
  799. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  800. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  801. QueuePacket(app);
  802. }
  803. ClientPacketFunctions::SendSkillSlotMappings(this);
  804. ClientPacketFunctions::SendGameWorldTime(this);
  805. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  806. }
  807. void Client::SendCharPOVGhost() {
  808. bool use_ghost_pov = false;
  809. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  810. int32 ghost_id = 0;
  811. if (set_pov) {
  812. if(pov_ghost_spawn_id) {
  813. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  814. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  815. if(spawn) {
  816. use_ghost_pov = true;
  817. }
  818. }
  819. if(use_ghost_pov) {
  820. set_pov->setDataByName("spawn_id", ghost_id);
  821. }
  822. else {
  823. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  824. }
  825. EQ2Packet* app_pov = set_pov->serialize();
  826. QueuePacket(app_pov);
  827. safe_delete(set_pov);
  828. }
  829. }
  830. void Client::SendZoneInfo() {
  831. ZoneServer* zone = GetCurrentZone();
  832. if (zone) {
  833. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  834. QueuePacket(packet);
  835. if (version > 283) {
  836. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  837. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  838. #if EQDEBUG >= 9
  839. fog_packet->PrintPacket();
  840. #endif
  841. if (fog_packet) {
  842. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  843. QueuePacket(fog_packet->serialize());
  844. safe_delete(fog_packet);
  845. }
  846. zone->SendFlightPathsPackets(this);
  847. }
  848. }
  849. /*
  850. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  853. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  854. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  865. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  866. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  867. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  868. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  869. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  870. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  871. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  875. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  876. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  877. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  878. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  879. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  880. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  881. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  882. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  883. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  884. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  885. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  886. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  887. QueuePacket(appA);
  888. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  889. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  890. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  891. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  892. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  893. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  894. QueuePacket(appB);
  895. */
  896. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  897. SendFriendList();
  898. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  899. SendIgnoreList();
  900. }
  901. void Client::SendDefaultGroupOptions() {
  902. /*
  903. 0 - loot method
  904. 1 - loot items rarity
  905. 2 - Auto split coin
  906. 4 - default yell method
  907. 6 - group autolock
  908. 7 - solo autolock
  909. */
  910. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  911. if (default_options) {
  912. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  913. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  914. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  915. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  916. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  917. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  918. if(GetVersion() > 561) {
  919. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  920. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  921. }
  922. EQ2Packet* app7 = default_options->serialize();
  923. QueuePacket(app7);
  924. safe_delete(default_options);
  925. }
  926. }
  927. bool Client::HandlePacket(EQApplicationPacket* app) {
  928. bool ret = true;
  929. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  930. //DumpPacket(app);
  931. #if EQDEBUG >= 9
  932. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  933. DumpPacket(app, true);
  934. #endif
  935. EmuOpcode opcode = app->GetOpcode();
  936. #if EQDEBUG >= 9
  937. const char* name = app->GetOpcodeName();
  938. if (name)
  939. cout << name;
  940. else
  941. cout << "Unknown";
  942. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  943. DumpPacket(app);
  944. #endif
  945. //if (opcode != OP_UpdatePositionMsg) {
  946. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  947. //}
  948. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  949. {
  950. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  951. }
  952. switch (opcode) {
  953. case _maxEmuOpcode:
  954. break;
  955. case OP_LoginByNumRequestMsg: {
  956. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  957. PacketStruct* request;
  958. request = configReader.getStruct("LoginByNumRequest", 1);
  959. if (request) {
  960. if(request->LoadPacketData(app->pBuffer, app->size)) {
  961. // test the original location of Version for clients older than 1212
  962. version = request->getType_int16_ByName("version");
  963. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  964. // must be new client data version method, re-fetch the packet
  965. safe_delete(request);
  966. request = configReader.getStruct("LoginByNumRequest", 1208);
  967. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  968. // Xinux suggests using an INT16 here. Our first new version = 57000
  969. version = request->getType_int16_ByName("version");
  970. }
  971. else {
  972. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  973. break;
  974. }
  975. }
  976. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  977. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  978. ClientPacketFunctions::SendLoginDenied(this);
  979. /* reset version and protect server from trying to send packets out to a bad client
  980. ** cause of Dec 6th/Dec 7th 2023 crash
  981. ** Client::MakeSpawnChangePacket
  982. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  983. */
  984. version = 546;
  985. ready_for_updates = false;
  986. ready_for_spawns = false;
  987. return false;
  988. }
  989. int32 account_id = request->getType_int32_ByName("account_id");
  990. int32 access_code = request->getType_int32_ByName("access_code");
  991. if (!HandleNewLogin(account_id, access_code))
  992. return false;
  993. }
  994. }
  995. safe_delete(request);
  996. break;
  997. }
  998. case OP_DefaultGroupOptionsMsg: {
  999. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  1000. if (packet) {
  1001. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1002. packet->PrintPacket();
  1003. int8 loot_method = packet->getType_int8_ByName("loot_method");
  1004. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  1005. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  1006. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  1007. int8 autolock = packet->getType_int8_ByName("group_autolock");
  1008. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  1009. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  1010. int8 auto_loot_method = 0;
  1011. if (GetVersion() > 561) {
  1012. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1013. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1014. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1015. }
  1016. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1017. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1018. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1019. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1020. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1021. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1022. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1023. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1024. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1025. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1026. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1027. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1028. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1029. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1030. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1031. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1032. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1033. {
  1034. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1035. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1036. if (group)
  1037. {
  1038. GroupOptions goptions;
  1039. goptions.loot_method = loot_method;
  1040. goptions.loot_items_rarity = loot_items_rarity;
  1041. goptions.auto_split = auto_split_coin;
  1042. goptions.default_yell = default_yell_method;
  1043. goptions.group_autolock = autolock;
  1044. goptions.solo_autolock = solo_autolock;
  1045. goptions.auto_loot_method = auto_loot_method;
  1046. group->SetDefaultGroupOptions(&goptions);
  1047. }
  1048. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1049. }
  1050. }
  1051. safe_delete(packet);
  1052. }
  1053. break;
  1054. }
  1055. case OP_MapRequest: {
  1056. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1057. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1058. if (packet && app->size > 2 && GetCurrentZone()) {
  1059. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1060. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1061. if (fog_packet) {
  1062. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1063. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1064. fog_packet->setDataByName("unknown1", 1);
  1065. fog_packet->setDataByName("unknown3", 1);
  1066. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1067. //fog_packet->PrintPacket();
  1068. QueuePacket(fog_packet->serialize());
  1069. safe_delete(fog_packet);
  1070. }
  1071. }
  1072. safe_delete(packet);
  1073. }
  1074. break;
  1075. }
  1076. case OP_RequestCampMsg: {
  1077. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1078. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1079. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1080. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1081. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1082. request->getType_int8_ByName("quit"),
  1083. request->getType_int8_ByName("camp_desktop"),
  1084. request->getType_int16_ByName("camp_char_select"),
  1085. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1086. //DumpPacket(app->pBuffer, app->size);
  1087. //request->PrintPacket();
  1088. if (!camp_timer) {
  1089. int16 camp_time = 20; // default if rule cannot be found
  1090. if (GetAdminStatus() >= 100)
  1091. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1092. else
  1093. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1094. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1095. if (response) {
  1096. bool disconnect = false;
  1097. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1098. // Command: /camp desktop
  1099. // Command: /quit
  1100. response->setDataByName("camp_desktop", 1);
  1101. disconnect = true;
  1102. }
  1103. else {
  1104. // Command: /camp
  1105. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1106. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1107. response->setDataByName("seconds", camp_time);
  1108. }
  1109. camp_timer = new Timer(camp_time * 1000);
  1110. camp_timer->Enable();
  1111. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1112. // /camp {char_name}
  1113. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1114. }
  1115. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1116. // /camp (go back to char selection screen)
  1117. response->setDataByName("char_name", " ");
  1118. response->setDataByName("camp_char_select", 1);
  1119. }
  1120. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1121. response->getType_int8_ByName("seconds"),
  1122. response->getType_int8_ByName("camp_desktop"),
  1123. response->getType_int8_ByName("camp_char_select"),
  1124. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1125. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1126. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1127. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1128. //response->PrintPacket();
  1129. QueuePacket(response->serialize());
  1130. safe_delete(response);
  1131. if (disconnect)
  1132. Disconnect();
  1133. }
  1134. }
  1135. }
  1136. safe_delete(request);
  1137. break;
  1138. }
  1139. case OP_StoodMsg: {
  1140. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1141. if (camp_timer)
  1142. {
  1143. // JA: clear camping flag
  1144. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1145. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1146. safe_delete(camp_timer);
  1147. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1148. QueuePacket(outapp);
  1149. }
  1150. player->SetTempVisualState(0);
  1151. break;
  1152. }
  1153. case OP_StandMsg: {
  1154. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1155. if (camp_timer)
  1156. {
  1157. // JA: clear camping flag
  1158. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1159. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1160. safe_delete(camp_timer);
  1161. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1162. QueuePacket(outapp);
  1163. }
  1164. player->SetTempVisualState(539);
  1165. break;
  1166. }
  1167. case OP_SitMsg: {
  1168. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1169. player->SetTempVisualState(538);
  1170. break;
  1171. }
  1172. case OP_SatMsg: {
  1173. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1174. player->SetTempVisualState(540);
  1175. break;
  1176. }
  1177. case OP_QuestJournalOpenMsg:
  1178. case OP_QuestJournalInspectMsg: {
  1179. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1180. if (app->size < sizeof(int32))
  1181. break;
  1182. int32 quest_id = 0;
  1183. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1184. GetPlayer()->SendQuest(quest_id);
  1185. break;
  1186. }
  1187. case OP_QuestJournalSetVisibleMsg: {
  1188. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1189. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1190. if (packet) {
  1191. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1192. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1193. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1194. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1195. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1196. if (player_quests) {
  1197. if (player_quests->count(quest_id) > 0)
  1198. player_quests->at(quest_id)->SetHidden(hidden);
  1199. else
  1200. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1201. }
  1202. else
  1203. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1204. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1205. }
  1206. safe_delete(packet);
  1207. }
  1208. break;
  1209. }
  1210. case OP_MacroUpdateMsg: {
  1211. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1212. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1213. if (macro_update) {
  1214. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1215. vector<string>* update = new vector<string>;
  1216. int8 number = macro_update->getType_int8_ByName("number");
  1217. int16 icon = macro_update->getType_int16_ByName("icon");
  1218. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1219. int8 count = macro_update->getType_int8_ByName("macro_count");
  1220. if (GetVersion() <= 283) {
  1221. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1222. }
  1223. else {
  1224. for (int8 i = 0; i < count; i++) {
  1225. char tmp_command[15] = { 0 };
  1226. sprintf(tmp_command, "command_%i", i);
  1227. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1228. }
  1229. }
  1230. if (name.length() == 0)
  1231. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1232. else
  1233. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1234. safe_delete(update);
  1235. }
  1236. safe_delete(macro_update);
  1237. }
  1238. break;
  1239. }
  1240. case OP_DialogSelectMsg: {
  1241. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1242. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1243. if (packet) {
  1244. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1245. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1246. int32 response_index = packet->getType_int32_ByName("response");
  1247. HandleDialogSelectMsg(conversation_id, response_index);
  1248. }
  1249. }
  1250. safe_delete(packet);
  1251. break;
  1252. }
  1253. case OP_CancelMoveObjectModeMsg: {
  1254. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1255. if (GetTempPlacementSpawn())
  1256. {
  1257. Spawn* tmp = GetTempPlacementSpawn();
  1258. SetTempPlacementSpawn(nullptr);
  1259. SetPlacementUniqueItemID(0);
  1260. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1261. break; // break out early if we are tied to a temp spawn
  1262. }
  1263. // if we are moving some other object? other use-cases not covered
  1264. break;
  1265. }
  1266. case OP_PositionMoveableObject: {
  1267. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1268. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1269. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1270. Spawn* spawn = 0;
  1271. if (GetTempPlacementSpawn())
  1272. spawn = GetTempPlacementSpawn();
  1273. else
  1274. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1275. if (!spawn) {
  1276. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1277. break;
  1278. }
  1279. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1280. {
  1281. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1282. break;
  1283. }
  1284. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1285. if(uniqueID) {
  1286. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1287. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1288. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1289. break;
  1290. }
  1291. }
  1292. // handles instantiation logic + adding to zone of a new house object
  1293. PopulateHouseSpawn(place_object);
  1294. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1295. char query[256];
  1296. switch (GetSpawnPlacementMode())
  1297. {
  1298. case ServerSpawnPlacementMode::OPEN_HEADING:
  1299. {
  1300. if (spawn && spawn->IsWidget())
  1301. {
  1302. Widget* widget = (Widget*)spawn;
  1303. widget->SetOpenHeading(newHeading);
  1304. widget->SetIncludeHeading(true);
  1305. spawn->position_changed = true;
  1306. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1307. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1308. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1309. }
  1310. else
  1311. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1312. break;
  1313. }
  1314. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1315. {
  1316. if (spawn && spawn->IsWidget())
  1317. {
  1318. Widget* widget = (Widget*)spawn;
  1319. widget->SetClosedHeading(newHeading);
  1320. widget->SetIncludeHeading(true);
  1321. spawn->position_changed = true;
  1322. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1323. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1324. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1325. if (spawn->GetSpawnLocationID())
  1326. {
  1327. Query query;
  1328. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1329. }
  1330. }
  1331. else
  1332. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1333. break;
  1334. }
  1335. default:
  1336. {
  1337. spawn->SetX(place_object->getType_float_ByName("x"));
  1338. spawn->SetY(place_object->getType_float_ByName("y"));
  1339. spawn->SetZ(place_object->getType_float_ByName("z"));
  1340. spawn->SetHeading(newHeading);
  1341. spawn->SetSpawnOrigX(spawn->GetX());
  1342. spawn->SetSpawnOrigY(spawn->GetY());
  1343. spawn->SetSpawnOrigZ(spawn->GetZ());
  1344. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1345. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1346. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1347. else if (spawn->GetSpawnLocationID() > 0)
  1348. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1349. }
  1350. }
  1351. PopulateHouseSpawnFinalize();
  1352. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1353. }
  1354. safe_delete(place_object);
  1355. break;
  1356. }
  1357. case OP_CampAbortedMsg: {
  1358. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1359. if (camp_timer)
  1360. {
  1361. // JA: clear camping flag
  1362. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1363. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1364. safe_delete(camp_timer);
  1365. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1366. QueuePacket(outapp);
  1367. }
  1368. break;
  1369. }
  1370. case OP_DoneLoadingUIResourcesMsg: {
  1371. if(GetVersion() < 546) {
  1372. ClientPacketFunctions::SendUpdateSpellBook(this);
  1373. }
  1374. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1375. QueuePacket(app);
  1376. if(!player_loading_complete)
  1377. {
  1378. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1379. if (zone_script && lua_interface)
  1380. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1381. player_loading_complete = true;
  1382. }
  1383. break;
  1384. }
  1385. case OP_DoneLoadingZoneResourcesMsg: {
  1386. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1387. SendZoneSpawns();
  1388. break;
  1389. }
  1390. case OP_DefaultGroupOptionsRequestMsg: {
  1391. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1392. SendDefaultGroupOptions();
  1393. break;
  1394. }
  1395. case OP_DoneLoadingEntityResourcesMsg: {
  1396. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1397. if (!IsReadyForSpawns())
  1398. SetReadyForSpawns(true);
  1399. SendCharInfo();
  1400. pos_update.Start();
  1401. quest_pos_timer.Start();
  1402. break;
  1403. }
  1404. case OP_LootItemsRequestMsg: {
  1405. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1406. HandleLootItemRequestPacket(app);
  1407. break;
  1408. }
  1409. case OP_StoppedLootingMsg: {
  1410. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1411. if (app->size < sizeof(int32))
  1412. break;
  1413. int32 loot_id = 0;
  1414. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1415. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1416. if(spawn) {
  1417. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1418. spawn->SetLooterSpawnID(0);
  1419. }
  1420. break;
  1421. }
  1422. case OP_WaypointSelectMsg: {
  1423. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1424. if (packet) {
  1425. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1426. int32 selection = packet->getType_int32_ByName("selection");
  1427. if (selection > 0) {
  1428. SelectWaypoint(selection);
  1429. }
  1430. }
  1431. }
  1432. safe_delete(packet);
  1433. break;
  1434. }
  1435. case OP_KnowledgeWindowSlotMappingMsg: {
  1436. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1437. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1438. if (packet) {
  1439. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1440. int num_updates = packet->getType_int16_ByName("spell_count");
  1441. int32 spell_id = 0;
  1442. int16 slot_id = 0;
  1443. char tmp_spell_id[15];
  1444. char tmp_slot[15];
  1445. for (int i = 0; i < num_updates; i++) {
  1446. memset(tmp_spell_id, 0, 15);
  1447. memset(tmp_slot, 0, 15);
  1448. sprintf(tmp_spell_id, "spell_id_%i", i);
  1449. sprintf(tmp_slot, "slot_id_%i", i);
  1450. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1451. if (spell_id > 0) {
  1452. slot_id = packet->getType_int16_ByName(tmp_slot);
  1453. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1454. if (spell && spell->slot != slot_id) {
  1455. spell->slot = slot_id;
  1456. spell->save_needed = true;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. safe_delete(packet);
  1462. }
  1463. //SendKnowledgeWindowSlot();
  1464. break;
  1465. }
  1466. case OP_ReadyToZoneMsg: {
  1467. if (!IsReadyForSpawns())
  1468. {
  1469. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1470. }
  1471. else
  1472. {
  1473. if(zoning_destination) {
  1474. SetCurrentZone(zoning_destination);
  1475. }
  1476. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1477. bool succeed_override_zone = true;
  1478. if(!GetCurrentZone()) {
  1479. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1480. if(zoning_instance_id) {
  1481. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1482. if(!zone) {
  1483. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
  1484. succeed_override_zone = false;
  1485. }
  1486. else {
  1487. SetCurrentZone(zone);
  1488. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1489. }
  1490. }
  1491. else if(zoning_id) {
  1492. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1493. if(!zone) {
  1494. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1495. succeed_override_zone = false;
  1496. }
  1497. else {
  1498. SetCurrentZone(zone);
  1499. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1500. }
  1501. }
  1502. }
  1503. if (client_zoning)
  1504. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1505. else
  1506. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1507. Disconnect();
  1508. }
  1509. break;
  1510. }
  1511. case OP_ClientFellMsg: {
  1512. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1513. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1514. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1515. float height = request->getType_float_ByName("height");
  1516. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1517. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1518. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1519. break;
  1520. }*/
  1521. float safe_height = 13.0f;
  1522. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1523. if (safe_skill_with_bonus > 0.0f)
  1524. safe_height += (1 + safe_skill_with_bonus) / 5;
  1525. if (height > safe_height) {
  1526. int16 damage = (int16)ceil((height - safe_height) * 125);
  1527. if (height >= 80)
  1528. damage = 30000;
  1529. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1530. if (damage > 0) {
  1531. GetPlayer()->TakeDamage(damage);
  1532. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1533. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1534. if (!GetPlayer()->GetInvulnerable())
  1535. GetPlayer()->SetCharSheetChanged(true);
  1536. 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);
  1537. if (GetPlayer()->GetHP() == 0) {
  1538. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1539. }
  1540. }
  1541. }
  1542. }
  1543. safe_delete(request);
  1544. break;
  1545. }
  1546. case OP_MapFogDataUpdateMsg: {
  1547. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1548. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1549. break;
  1550. }
  1551. case OP_SelectZoneTeleporterDestinatio: {
  1552. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1553. ProcessTeleportLocation(app);
  1554. break;
  1555. }
  1556. case OP_SendLatestRequestMsg: {
  1557. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1558. if(GetVersion() < 60085) {
  1559. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1560. uchar blah25[] = { 0x01 };
  1561. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1562. QueuePacket(app25);
  1563. }
  1564. break;
  1565. }
  1566. case OP_RequestRecipeDetailsMsg: {
  1567. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1568. if (packet) {
  1569. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1570. vector<int32> recipes;
  1571. int32 recipe_id = 0;
  1572. char recipe_prop_name[30];
  1573. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1574. // WS_RecipeDetails
  1575. for (int32 i = 0; i < num_recipes; i++) {
  1576. memset(recipe_prop_name, 0, 30);
  1577. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1578. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1579. if(recipe_id > 0) {
  1580. recipes.push_back(recipe_id);
  1581. }
  1582. }
  1583. SendRecipeDetails(&recipes);
  1584. }
  1585. safe_delete(packet);
  1586. }
  1587. break;
  1588. }
  1589. case OP_ShowCreateFromRecipeUIMsg: {
  1590. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1591. break;
  1592. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1593. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1594. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1595. QueuePacket(app);
  1596. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1597. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1598. QueuePacket(app);
  1599. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1600. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1601. ,0xff,0xff,0xff};
  1602. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1603. QueuePacket(app);
  1604. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1605. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1606. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1607. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1608. QueuePacket(app);
  1609. uchar blah5[] ={0x00,0x00};
  1610. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1611. QueuePacket(app);
  1612. break;*/
  1613. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1614. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1615. //QueuePacket(app);
  1616. }
  1617. case OP_BeginItemCreationMsg: {
  1618. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1619. //DumpPacket(app->pBuffer, app->size);
  1620. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1621. if (packet) {
  1622. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1623. int32 item = 0;
  1624. int8 qty = 0;
  1625. vector<pair<int32, int16>> items;
  1626. char tmp_item_id[30];
  1627. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1628. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1629. memset(tmp_item_id, 0, 30);
  1630. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1631. item = packet->getType_int32_ByName(tmp_item_id);
  1632. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1633. qty = packet->getType_int16_ByName(tmp_item_id);
  1634. if (item > 0)
  1635. items.push_back(make_pair(item,qty));
  1636. item = 0;
  1637. }
  1638. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1639. for (int8 i = 0; i < build_components; i++) {
  1640. memset(tmp_item_id, 0, 30);
  1641. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1642. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1643. for (int8 j = 0; j < num_selected_items; j++) {
  1644. memset(tmp_item_id, 0, 30);
  1645. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1646. item = packet->getType_int32_ByName(tmp_item_id);
  1647. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1648. qty = packet->getType_int16_ByName(tmp_item_id);
  1649. if (item > 0)
  1650. items.push_back(make_pair(item, qty));
  1651. item = 0;
  1652. }
  1653. }
  1654. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1655. for (int8 i = 0; i < num_fuel_items; i++) {
  1656. memset(tmp_item_id, 0, 30);
  1657. sprintf(tmp_item_id, "fuel_id_%i", i);
  1658. item = packet->getType_int32_ByName(tmp_item_id);
  1659. sprintf(tmp_item_id, "fuel_qty_%i", i);
  1660. qty = packet->getType_int16_ByName(tmp_item_id);
  1661. if (item > 0)
  1662. items.push_back(make_pair(item, qty));
  1663. item = 0;
  1664. }
  1665. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1666. }
  1667. safe_delete(packet);
  1668. }
  1669. break;
  1670. }
  1671. case OP_StopItemCreationMsg: {
  1672. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1673. //DumpPacket(app->pBuffer, app->size);
  1674. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1675. break;
  1676. }
  1677. case OP_SysClient:
  1678. case OP_SignalMsg: {
  1679. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1680. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1681. if (packet) {
  1682. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1683. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1684. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1685. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1686. SetReloadingZone(false);
  1687. if(GetPlayer()->IsDeletedSpawn()) {
  1688. GetPlayer()->SetDeletedSpawn(false);
  1689. }
  1690. ResetZoningCoords();
  1691. SetReadyForUpdates();
  1692. GetPlayer()->SendSpawnChanges(true);
  1693. ProcessStateCommands();
  1694. GetPlayer()->changed = true;
  1695. GetPlayer()->info_changed = true;
  1696. GetPlayer()->vis_changed = true;
  1697. player_pos_changed = true;
  1698. GetPlayer()->AddChangedZoneSpawn();
  1699. ProcessZoneIgnoreWidgets();
  1700. }
  1701. else {
  1702. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1703. }
  1704. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1705. if (zone_script && lua_interface)
  1706. {
  1707. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1708. }
  1709. }
  1710. safe_delete(packet);
  1711. }
  1712. break;
  1713. }
  1714. case OP_EntityVerbsRequestMsg: {
  1715. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1716. HandleVerbRequest(app);
  1717. break;
  1718. }
  1719. case OP_EntityVerbsVerbMsg: {
  1720. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1721. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1722. if (packet) {
  1723. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1724. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1725. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1726. Spawn* spawn = player->GetTarget();
  1727. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1728. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1729. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1730. {
  1731. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1732. if (spawn->IsGroundSpawn())
  1733. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1734. else if (spawn->IsObject())
  1735. ((Object*)spawn)->HandleUse(this, command);
  1736. else if (spawn->IsWidget())
  1737. ((Widget*)spawn)->HandleUse(this, command);
  1738. else if (spawn->IsSign())
  1739. ((Sign*)spawn)->HandleUse(this, command);
  1740. }
  1741. }
  1742. }
  1743. else {
  1744. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1745. if (command.size > 0) {
  1746. string command_name = command.data;
  1747. if (command_name.find(" ") < 0xFFFFFFFF) {
  1748. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1749. string::size_type pos = command_name.find(" ");
  1750. while(pos != string::npos){
  1751. command_name.replace(pos, 1, "_");
  1752. pos = command_name.find(" ");
  1753. }
  1754. }
  1755. else
  1756. command_name = command_name.substr(0, command_name.find(" "));
  1757. }
  1758. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1759. if (handler != 0xFFFFFFFF) {
  1760. if (command.data == command_name) {
  1761. command.data = "";
  1762. command.size = 0;
  1763. }
  1764. else {
  1765. command.data = command.data.substr(command.data.find(" ") + 1);
  1766. command.size = command.data.length();
  1767. }
  1768. commands.Process(handler, &command, this);
  1769. }
  1770. else {
  1771. if (spawn && spawn->IsNPC()) {
  1772. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1773. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1774. command_name = command.data;
  1775. string::size_type pos = command_name.find(" ");
  1776. while (pos != string::npos) {
  1777. command_name.replace(pos, 1, "_");
  1778. pos = command_name.find(" ");
  1779. }
  1780. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1781. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1782. }
  1783. }
  1784. }
  1785. }
  1786. else
  1787. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1788. }
  1789. }
  1790. }
  1791. }
  1792. safe_delete(packet);
  1793. }
  1794. break;
  1795. }
  1796. case OP_SkillInfoRequest: {
  1797. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1798. HandleSkillInfoRequest(app);
  1799. break;
  1800. }
  1801. case OP_UpdateTargetMsg: {
  1802. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1803. int16 index = 0;
  1804. memcpy(&index, app->pBuffer, sizeof(int16));
  1805. if (index == 0xFFFF)
  1806. GetPlayer()->SetTarget(0);
  1807. else {
  1808. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1809. if(spawn)
  1810. GetPlayer()->SetTarget(spawn);
  1811. else {
  1812. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1813. }
  1814. }
  1815. if (GetPlayer()->GetTarget())
  1816. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1817. //player->SetTarget((int16*)app->pBuffer);
  1818. break;
  1819. }
  1820. case OP_ExamineInfoRequestMsg: {
  1821. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1822. HandleExamineInfoRequest(app);
  1823. break;
  1824. }
  1825. case OP_QuickbarUpdateMsg:
  1826. //case OP_QuickbarAddMsg:
  1827. {
  1828. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1829. HandleQuickbarUpdateRequest(app);
  1830. break;
  1831. }
  1832. case OP_PredictionUpdateMsg: {
  1833. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1834. if (version <= 546) {
  1835. int8 offset = 9;
  1836. if (app->pBuffer[0] == 0xFF)
  1837. offset += 2;
  1838. if (app->size > offset) {
  1839. if (player->IsCasting()) {
  1840. float distance = 0;
  1841. float x = player->GetX();
  1842. float y = player->GetY();
  1843. float z = player->GetZ();
  1844. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1845. distance = player->GetDistance(x, y, z, false);
  1846. if (distance > .5)
  1847. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1848. }
  1849. else
  1850. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1851. player_pos_changed = true;
  1852. //DumpPacket(app);
  1853. }
  1854. }
  1855. else {
  1856. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1857. QueuePacket(app);
  1858. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1859. }
  1860. break;
  1861. }
  1862. case OP_RemoteCmdMsg: {
  1863. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1864. if (app->size > 0) {
  1865. EQ2_CommandString remote(app->pBuffer, app->size);
  1866. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1867. #if EQDEBUG >= 9
  1868. DumpPacket(app);
  1869. #endif
  1870. commands.Process(remote.handler, &remote.command, this);
  1871. }
  1872. else //bad client, disconnect
  1873. Disconnect();
  1874. break;
  1875. }
  1876. case OP_CancelSpellCast: {
  1877. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1878. current_zone->Interrupted(player, 0, 0, true);
  1879. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1880. break;
  1881. }
  1882. case OP_UpdatePositionMsg: {
  1883. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1884. int8 offset = 13;
  1885. if (app->pBuffer[0] == 0xFF)
  1886. offset += 2;
  1887. if (app->size > offset) {
  1888. if (player->IsCasting()) {
  1889. float distance = 0;
  1890. float x = player->GetX();
  1891. float y = player->GetY();
  1892. float z = player->GetZ();
  1893. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1894. distance = player->GetDistance(x, y, z, false);
  1895. if (distance > .5)
  1896. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1897. }
  1898. else
  1899. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1900. player_pos_changed = true;
  1901. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1902. //DumpPacket(app);
  1903. }
  1904. break;
  1905. }
  1906. case OP_MailSendMessageMsg: {
  1907. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1908. HandleSentMail(app);
  1909. break;
  1910. }
  1911. case OP_StopTrackingMsg: {
  1912. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1913. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1914. break;
  1915. }
  1916. case OP_BeginTrackingMsg: {
  1917. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1918. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1919. if (packet) {
  1920. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1921. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1922. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1923. if (spawn) {
  1924. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1925. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1926. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1927. }
  1928. }
  1929. safe_delete(packet);
  1930. }
  1931. break;
  1932. }
  1933. case OP_BioUpdateMsg: {
  1934. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1935. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1936. if (packet) {
  1937. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1938. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1939. }
  1940. safe_delete(packet);
  1941. }
  1942. break;
  1943. }
  1944. case OP_RewardPackMsg: {
  1945. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1946. /* 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
  1947. when we come across it (scatman) */
  1948. const char* name = app->GetOpcodeName();
  1949. if (name)
  1950. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1951. else
  1952. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1953. //DumpPacket(app);
  1954. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1955. if (packet) {
  1956. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1957. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1958. /* Player has contacted a guild recruiter */
  1959. if (recruiter_name.length() > 0) {
  1960. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1961. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1962. if (recruiter && guild) {
  1963. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1964. recruiter->Message(CHANNEL_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
  1965. recruiter->PlaySound("ui_guild_page");
  1966. }
  1967. }
  1968. /* New picture taken for guild recruiting */
  1969. else {
  1970. //DumpPacket(app->pBuffer, app->size);
  1971. int32 guild_id = 0;
  1972. int16 picture_data_size = 0;
  1973. unsigned char* recruiter_picture_data = 0;
  1974. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1975. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1976. Guild* guild = guild_list.GetGuild(guild_id);
  1977. if (guild) {
  1978. GuildMember* gm = guild->GetGuildMember(player);
  1979. if (gm) {
  1980. safe_delete_array(gm->recruiter_picture_data);
  1981. recruiter_picture_data = new unsigned char[picture_data_size];
  1982. for (int16 i = 0; i < picture_data_size; i++)
  1983. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1984. gm->recruiter_picture_data = recruiter_picture_data;
  1985. gm->recruiter_picture_data_size = picture_data_size;
  1986. guild->SetMemberSaveNeeded(true);
  1987. }
  1988. }
  1989. }
  1990. }
  1991. safe_delete(packet);
  1992. }
  1993. break;
  1994. }
  1995. case OP_PetOptions: {
  1996. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1997. Spawn* target = player->GetTarget();
  1998. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1999. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  2000. bool change = false;
  2001. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2002. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  2003. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  2004. target->SetName(name.c_str());
  2005. GetCurrentZone()->SendUpdateTitles(target);
  2006. change = true;
  2007. }
  2008. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  2009. // Check protect self setting and update if needed
  2010. if (packet->getType_int8_ByName("protect_self") == 1) {
  2011. if ((pet_behavior & 2) == 0) {
  2012. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2013. change = true;
  2014. }
  2015. }
  2016. else {
  2017. if ((pet_behavior & 2) != 0) {
  2018. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2019. change = true;
  2020. }
  2021. }
  2022. // Check protect master setting and update if needed
  2023. if (packet->getType_int8_ByName("protect_master") == 1) {
  2024. if ((pet_behavior & 1) == 0) {
  2025. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2026. change = true;
  2027. }
  2028. }
  2029. else {
  2030. if ((pet_behavior & 1) != 0) {
  2031. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2032. change = true;
  2033. }
  2034. }
  2035. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2036. // Check stay/follow setting and update if needed
  2037. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2038. if (pet_movement != 2) {
  2039. player->GetInfoStruct()->set_pet_movement(2);
  2040. change = true;
  2041. }
  2042. }
  2043. else {
  2044. if (pet_movement != 1) {
  2045. player->GetInfoStruct()->set_pet_movement(1);
  2046. change = true;
  2047. }
  2048. }
  2049. // Ranged/Melee settings are not implemented yet
  2050. if (change)
  2051. player->SetCharSheetChanged(true);
  2052. }
  2053. safe_delete(packet);
  2054. }
  2055. break;
  2056. }
  2057. case OP_RecipeBook: {
  2058. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2059. SendRecipeList();
  2060. break;
  2061. }
  2062. case OP_BuyPlayerHouseMsg: {
  2063. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2064. //DumpPacket(app);
  2065. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2066. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2067. if (packet) {
  2068. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2069. int64 house_id = 0;
  2070. if(GetVersion() <= 546) {
  2071. house_id = packet->getType_int32_ByName("house_id");
  2072. }
  2073. else {
  2074. house_id = packet->getType_int64_ByName("house_id");
  2075. }
  2076. HouseZone* hz = world.GetHouseZone(house_id);
  2077. if (hz) {
  2078. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2079. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2080. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2081. if (houses.size() > 24)
  2082. {
  2083. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2084. safe_delete(packet);
  2085. break;
  2086. }
  2087. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2088. {
  2089. std::string req = "You must be of ";
  2090. if (hz->alignment == 1)
  2091. req.append("Good");
  2092. else
  2093. req.append("Evil");
  2094. req.append(" alignment to purchase this house");
  2095. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2096. safe_delete(packet);
  2097. break;
  2098. }
  2099. int32 status_req = hz->cost_status;
  2100. int32 available_status = player->GetInfoStruct()->get_status_points();
  2101. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2102. {
  2103. player->GetInfoStruct()->subtract_status_points(status_req);
  2104. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2105. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2106. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2107. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2108. //ClientPacketFunctions::SendHousingList(this);
  2109. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2110. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2111. PlaySound("coin_cha_ching");
  2112. }
  2113. else if (status_req <= available_status && got_bank_money == 1) {
  2114. player->GetInfoStruct()->subtract_status_points(status_req);
  2115. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2116. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2117. if (bankwithdrawl == 0) {
  2118. PlaySound("buy_failed");
  2119. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2120. safe_delete(packet);
  2121. break;
  2122. }
  2123. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2124. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2125. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2126. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2127. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2128. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2129. PlaySound("coin_cha_ching");
  2130. }
  2131. else
  2132. {
  2133. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2134. PlaySound("buy_failed");
  2135. }
  2136. }
  2137. }
  2138. }
  2139. safe_delete(packet);
  2140. break;
  2141. }
  2142. case OP_EnterHouseMsg: {
  2143. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2144. //DumpPacket(app);
  2145. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2146. if (packet) {
  2147. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2148. PlayerHouse* ph = nullptr;
  2149. HouseZone* hz = nullptr;
  2150. int64 house_id = 0;
  2151. int32 spawn_index = 0;
  2152. if(GetVersion() <= 546) {
  2153. spawn_index = packet->getType_int32_ByName("house_id");
  2154. }
  2155. else {
  2156. house_id = packet->getType_int64_ByName("house_id");
  2157. }
  2158. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2159. if (house) {
  2160. Zone(house, true);
  2161. }
  2162. }
  2163. }
  2164. safe_delete(packet);
  2165. break;
  2166. }
  2167. case OP_PayHouseUpkeepMsg: {
  2168. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2169. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2170. if (packet) {
  2171. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2172. int64 house_id = 0;
  2173. if(GetVersion() <= 546) {
  2174. house_id = packet->getType_int32_ByName("house_id");
  2175. }
  2176. else {
  2177. house_id = packet->getType_int64_ByName("house_id");
  2178. }
  2179. HouseZone* hz = nullptr;
  2180. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 546 ? house_id : 0, GetVersion() > 546 ? house_id : 0, &hz);
  2181. if (ph)
  2182. {
  2183. if (!hz)
  2184. {
  2185. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2186. safe_delete(packet);
  2187. break;
  2188. }
  2189. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2190. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2191. {
  2192. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2193. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2194. {
  2195. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2196. PlaySound("buy_failed");
  2197. safe_delete(packet);
  2198. break;
  2199. }
  2200. }
  2201. bool escrowChange = false;
  2202. int64 statusReq = hz->upkeep_status;
  2203. int64 tmpRecoverStatus = 0;
  2204. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2205. {
  2206. escrowChange = true;
  2207. tmpRecoverStatus = ph->escrow_status;
  2208. statusReq -= ph->escrow_status;
  2209. ph->escrow_status = 0;
  2210. }
  2211. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2212. {
  2213. escrowChange = true;
  2214. ph->escrow_status -= statusReq;
  2215. tmpRecoverStatus = statusReq;
  2216. statusReq = 0;
  2217. }
  2218. int64 coinReq = hz->upkeep_coin;
  2219. int64 tmpRecoverCoins = 0;
  2220. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2221. {
  2222. escrowChange = true;
  2223. tmpRecoverCoins = ph->escrow_coins;
  2224. coinReq -= ph->escrow_coins;
  2225. ph->escrow_coins = 0;
  2226. }
  2227. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2228. {
  2229. escrowChange = true;
  2230. // more than enough in escrow, subtract and make our cost 0!
  2231. ph->escrow_coins -= coinReq;
  2232. tmpRecoverCoins = coinReq;
  2233. coinReq = 0;
  2234. }
  2235. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2236. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2237. {
  2238. if(coinReq && player->RemoveCoins(coinReq))
  2239. coinReq = 0;
  2240. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2241. statusReq = 0;
  2242. }
  2243. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2244. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2245. {
  2246. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2247. if (escrowChange)
  2248. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2249. ph->upkeep_due = upkeep_due;
  2250. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2251. //ClientPacketFunctions::SendHousingList(this);
  2252. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2253. PlaySound("coin_cha_ching");
  2254. }
  2255. else if (!statusReq && got_bank_money == 1) {
  2256. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2257. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2258. if (bankwithdrawl == 0) {
  2259. PlaySound("buy_failed");
  2260. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2261. safe_delete(packet);
  2262. break;
  2263. }
  2264. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2265. if (escrowChange)
  2266. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2267. ph->upkeep_due = upkeep_due;
  2268. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2269. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2270. PlaySound("coin_cha_ching");
  2271. }
  2272. else
  2273. {
  2274. // recover the escrow we were going to use but could not spend due to lack of funds
  2275. if (tmpRecoverCoins)
  2276. ph->escrow_coins += tmpRecoverCoins;
  2277. if(tmpRecoverStatus)
  2278. ph->escrow_status += tmpRecoverStatus;
  2279. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2280. PlaySound("buy_failed");
  2281. }
  2282. }
  2283. else
  2284. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2285. }
  2286. }
  2287. safe_delete(packet);
  2288. break;
  2289. }
  2290. case OP_ExitHouseMsg: {
  2291. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2292. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2293. if (instance_id > 0) {
  2294. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2295. if (ph) {
  2296. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2297. if (hz) {
  2298. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2299. // determine if this is an instanced zone that already exists
  2300. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2301. if (instance_zone || new_zone) {
  2302. GetPlayer()->SetX(hz->exit_x);
  2303. GetPlayer()->SetY(hz->exit_y);
  2304. GetPlayer()->SetZ(hz->exit_z);
  2305. GetPlayer()->SetHeading(hz->exit_heading);
  2306. if (instance_zone)
  2307. Zone(instance_zone->GetInstanceID(), false, true);
  2308. else
  2309. Zone(new_zone, false);
  2310. }
  2311. }
  2312. }
  2313. }
  2314. break;
  2315. }
  2316. case OP_QuestJournalWaypointMsg: {
  2317. //DumpPacket(app);
  2318. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2319. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2320. if (packet) {
  2321. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2322. int32 quests = packet->getType_int32_ByName("num_quests");
  2323. if (quests > 100) // just picking a number higher than max allowed
  2324. {
  2325. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2326. break;
  2327. }
  2328. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2329. for (int32 i = 0; i < quests; i++) {
  2330. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2331. if (id == 0)
  2332. continue;
  2333. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2334. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2335. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2336. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2337. player->player_quests[id]->SetTracked(tracked);
  2338. player->player_quests[id]->SetSaveNeeded(true);
  2339. }
  2340. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2341. }
  2342. }
  2343. safe_delete(packet);
  2344. }
  2345. break;
  2346. }
  2347. case OP_PaperdollImage: {
  2348. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2349. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2350. //First check if this is a new image... delete an existing partial image if one exists
  2351. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2352. if (packet_index == 0) {
  2353. safe_delete_array(incoming_paperdoll.image_bytes);
  2354. incoming_paperdoll.last_received_packet_index = 0;
  2355. incoming_paperdoll.current_size_bytes = 0;
  2356. }
  2357. //return if this packet is not the one we are expecting...
  2358. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2359. safe_delete(packet);
  2360. break;
  2361. }
  2362. //Check how many packets we're supposed to be receiving for this/these images
  2363. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2364. //Check the image type, if this is a new type in the same series of packets we have a new image
  2365. int8 img_type = packet->getType_int8_ByName("image_type");
  2366. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2367. //We have a new image. Save the old data and clear before continuing
  2368. SavePlayerImages();
  2369. }
  2370. incoming_paperdoll.image_type = img_type;
  2371. //Get the size of the image data in this packet
  2372. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2373. if (image_size <= 0 || image_size > 1048576) {
  2374. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2375. safe_delete(packet);
  2376. break;
  2377. }
  2378. //Create a new array
  2379. int32 new_image_size = image_size;
  2380. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2381. if (incoming_paperdoll.image_bytes) {
  2382. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2383. safe_delete_array(incoming_paperdoll.image_bytes);
  2384. }
  2385. //variable i should be the index in the packet of the first PNG file byte
  2386. vector<DataStruct*>* d_structs = packet->getStructs();
  2387. vector<DataStruct*>::iterator itr;
  2388. int32 i = 0;
  2389. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2390. DataStruct* ds = (*itr);
  2391. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2392. i += ds->GetDataSizeInBytes();
  2393. else
  2394. break;
  2395. }
  2396. //Return if this packet is bad and we would read out of bounds
  2397. if (app->size - i < new_image_size) {
  2398. safe_delete(packet);
  2399. safe_delete_array(new_image);
  2400. break;
  2401. }
  2402. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2403. memcpy(tmp, app->pBuffer + i, new_image_size);
  2404. incoming_paperdoll.current_size_bytes += new_image_size;
  2405. incoming_paperdoll.image_bytes = new_image;
  2406. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2407. if (incoming_paperdoll.image_num_packets == 1 ||
  2408. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2409. SavePlayerImages();
  2410. }
  2411. incoming_paperdoll.last_received_packet_index = packet_index;
  2412. }
  2413. safe_delete(packet);
  2414. */
  2415. break;
  2416. }
  2417. case OP_ReadyForTakeOffMsg:
  2418. {
  2419. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2420. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2421. if (GetPendingFlightPath() > 0) {
  2422. if (index != -1) {
  2423. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2424. if (packet) {
  2425. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2426. packet->setDataByName("path_id", index);
  2427. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2428. QueuePacket(packet->serialize());
  2429. safe_delete(packet);
  2430. on_auto_mount = true;
  2431. }
  2432. }
  2433. else {
  2434. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2435. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2436. EndAutoMount();
  2437. }
  2438. SetPendingFlightPath(0);
  2439. }
  2440. else
  2441. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2442. break;
  2443. }
  2444. case OP_EarlyLandingRequestMsg:
  2445. {
  2446. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2447. EndAutoMount();
  2448. break;
  2449. }
  2450. case OP_SubmitCharCust:
  2451. {
  2452. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2453. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2454. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 546 ? false : true)) {
  2455. int8 type = packet->getType_int8_ByName("type");
  2456. if (type == 0) {
  2457. /*if (player->custNPC) {
  2458. player->custNPCTarget->CustomizeAppearance(packet);
  2459. current_zone->SendSpawnChanges(player->custNPCTarget);
  2460. }
  2461. else {*/
  2462. player->CustomizeAppearance(packet);
  2463. current_zone->SendSpawnChanges(player);
  2464. //}
  2465. }
  2466. }
  2467. safe_delete(packet);
  2468. /*
  2469. if (player->custNPC) {
  2470. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2471. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2472. if (player->custNPCTarget->IsBot())
  2473. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2474. player->custNPC = false;
  2475. player->custNPCTarget = 0;
  2476. player->changed = true;
  2477. player->info_changed = true;
  2478. current_zone->SendSpawnChanges(player, this);
  2479. }*/
  2480. break;
  2481. }
  2482. default: {
  2483. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2484. const char* name = app->GetOpcodeName();
  2485. if (name)
  2486. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2487. else
  2488. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2489. // keeping this around for debugging purposes
  2490. DumpPacket(app);
  2491. }
  2492. }
  2493. if (!eqs || !eqs->CheckActive()) {
  2494. return false;
  2495. }
  2496. return ret;
  2497. }
  2498. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2499. if (!item) {
  2500. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2501. return false;
  2502. }
  2503. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2504. int16 lore_stack_count = 0;
  2505. Player* lootingPlayer = player;
  2506. Client* lootingClient = this;
  2507. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2508. lootingPlayer = (Player*)target;
  2509. lootingClient = lootingPlayer->GetClient();
  2510. }
  2511. // needs to only be checked before expiration of loot restrictions
  2512. if (entity && !overrideLootRestrictions) {
  2513. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2514. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Group ID from %s did not match Item: %s (%u), expected group id %u.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id, entity->GetLootGroupID());
  2515. return false;
  2516. }
  2517. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2518. switch (entity->GetLootMethod()) {
  2519. case GroupLootMethod::METHOD_LEADER: {
  2520. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2521. LogWrite(LOOT__ERROR, 0, "Loot", "%s: Loot Attempt from %s was not allowed with Item: %s (%u), must be group leader.", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2522. return false;
  2523. }
  2524. break;
  2525. }
  2526. case GroupLootMethod::METHOD_LOTTO:
  2527. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2528. if (entity->IsLootTimerRunning()) {
  2529. LogWrite(LOOT__INFO, 0, "Loot", "%s: Loot Timer is still running, flag player %s to lotto Item: %s (%u).", entity->GetName(), lootingPlayer->GetName(), item->name.c_str(), item->details.item_id);
  2530. return false;
  2531. }
  2532. break;
  2533. }
  2534. }
  2535. }
  2536. }
  2537. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2538. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2539. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2540. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2541. return false;
  2542. }
  2543. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2544. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2545. return false;
  2546. }
  2547. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2548. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2549. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2550. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2551. if (gmi && gmi->group_id)
  2552. {
  2553. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2554. if (group)
  2555. {
  2556. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2557. deque<GroupMemberInfo*>* members = group->GetMembers();
  2558. if (members) {
  2559. for (int8 i = 0; i < members->size(); i++) {
  2560. Entity* member = members->at(i)->member;
  2561. if (!member)
  2562. continue;
  2563. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2564. continue;
  2565. if (member->IsPlayer()) {
  2566. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2567. item->save_needed = true;
  2568. }
  2569. }
  2570. }
  2571. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2572. }
  2573. }
  2574. }
  2575. int8 type = CHANNEL_LOOT;
  2576. if (entity) {
  2577. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2578. }
  2579. else {
  2580. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2581. }
  2582. Guild* guild = lootingPlayer->GetGuild();
  2583. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2584. char adjective[32];
  2585. int8 type;
  2586. memset(adjective, 0, sizeof(adjective));
  2587. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2588. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2589. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2590. }
  2591. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2592. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2593. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2594. }
  2595. else {
  2596. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2597. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2598. }
  2599. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2600. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2601. }
  2602. if (item->GetItemScript() && lua_interface)
  2603. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2604. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2605. if (GetVersion() <= 546) {
  2606. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2607. if (outapp)
  2608. lootingClient->QueuePacket(outapp);
  2609. }
  2610. return true;
  2611. }
  2612. else
  2613. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2614. }
  2615. else
  2616. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2617. return false;
  2618. }
  2619. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2620. if (!entity) {
  2621. return false;
  2622. }
  2623. Item* item = entity->LootItem(item_id);
  2624. bool success = false;
  2625. success = HandleLootItem(entity, item, target);
  2626. if (!success)
  2627. entity->AddLootItem(item);
  2628. return success;
  2629. }
  2630. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2631. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2632. if (packet) {
  2633. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2634. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2635. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2636. int32 target_id = packet->getType_int32_ByName("target_id");
  2637. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2638. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2639. if(!spawn) {
  2640. safe_delete(packet);
  2641. return;
  2642. }
  2643. Item* item = nullptr;
  2644. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2645. if (items) {
  2646. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2647. for (int32 i = 0; i < items->size(); i++) {
  2648. Item* master_item = items->at(i);
  2649. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2650. item = new Item(master_item);
  2651. if (item) {
  2652. loot_all = HandleLootItem(0, item);
  2653. if (loot_all) {
  2654. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2655. if (GetVersion() <= 546) {
  2656. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2657. if (outapp)
  2658. QueuePacket(outapp);
  2659. }
  2660. }
  2661. }
  2662. if (!loot_all)
  2663. break;
  2664. }
  2665. }
  2666. safe_delete(items);
  2667. safe_delete(packet);
  2668. return;
  2669. }
  2670. spawn->LockLoot();
  2671. bool unlockedLoot = false;
  2672. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2673. if (loot_all) {
  2674. switch (spawn->GetLootMethod()) {
  2675. case GroupLootMethod::METHOD_LOTTO: {
  2676. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2677. break;
  2678. }
  2679. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2680. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2681. }
  2682. default: {
  2683. if (!unlockedLoot) {
  2684. spawn->UnlockLoot();
  2685. unlockedLoot = true;
  2686. }
  2687. int32 item_id = 0;
  2688. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2689. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2690. }
  2691. break;
  2692. }
  2693. }
  2694. spawn->UnlockLoot();
  2695. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2696. CloseLoot(loot_id);
  2697. }
  2698. }
  2699. else {
  2700. int8 item_count = packet->getType_int8_ByName("item_count");
  2701. for (int8 cur = 0; cur < item_count; cur++) {
  2702. char item_field_name[64];
  2703. snprintf(item_field_name, 64, "item_id_%u", cur);
  2704. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2705. Spawn* target = this->GetPlayer();
  2706. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2707. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2708. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2709. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2710. safe_delete(packet);
  2711. spawn->UnlockLoot();
  2712. return;
  2713. }
  2714. target = destTarget;
  2715. }
  2716. bool breakLoopAllLooted = false;
  2717. switch (spawn->GetLootMethod()) {
  2718. case GroupLootMethod::METHOD_LOTTO: {
  2719. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2720. break;
  2721. }
  2722. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2723. if (button_clicked == 3) { // decline
  2724. break;
  2725. }
  2726. if (GetVersion() <= 546) {
  2727. button_clicked = 1; // selecting is need
  2728. }
  2729. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2730. break;
  2731. }
  2732. default: {
  2733. if (!unlockedLoot) {
  2734. spawn->UnlockLoot();
  2735. unlockedLoot = true;
  2736. }
  2737. if (!loot_all) {
  2738. HandleLootItemByID(spawn, item_id, target);
  2739. }
  2740. else {
  2741. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2742. loot_all = HandleLootItemByID(spawn, item_id, target);
  2743. }
  2744. breakLoopAllLooted = true;
  2745. }
  2746. break;
  2747. }
  2748. }
  2749. if (breakLoopAllLooted) {
  2750. break;
  2751. }
  2752. }
  2753. if (!unlockedLoot) {
  2754. spawn->UnlockLoot();
  2755. }
  2756. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2757. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2758. CloseLoot(loot_id);
  2759. }
  2760. }
  2761. if (GetVersion() > 546) {
  2762. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2763. if (outapp)
  2764. QueuePacket(outapp);
  2765. }
  2766. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2767. LootSpawnRequest(spawn);
  2768. }
  2769. else {
  2770. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2771. }
  2772. if (!spawn->HasLoot()) {
  2773. CloseLoot(loot_id);
  2774. if (spawn->IsNPC())
  2775. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2776. }
  2777. }
  2778. else {
  2779. spawn->UnlockLoot();
  2780. if (!spawn) {
  2781. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2782. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2783. }
  2784. else
  2785. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2786. }
  2787. }
  2788. safe_delete(packet);
  2789. }
  2790. }
  2791. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2792. PacketStruct* request = 0;
  2793. // cout << "Request: \n";
  2794. // DumpPacket(app);
  2795. switch (app->pBuffer[0]) {
  2796. case 0: { //items
  2797. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2798. if (request) {
  2799. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2800. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2801. if (!item)
  2802. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2803. if (item) {
  2804. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2805. if (response) {
  2806. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2807. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2808. response->setSmallStringByName("name", item->name.c_str());
  2809. EQ2Packet* app2 = response->serialize();
  2810. //DumpPacket(app2);
  2811. QueuePacket(app2);
  2812. safe_delete(response);
  2813. }
  2814. }
  2815. }
  2816. safe_delete(request);
  2817. }
  2818. break;
  2819. }
  2820. case 2: {//spells
  2821. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2822. if (request) {
  2823. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2824. int32 id = request->getType_int32_ByName("id");
  2825. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2826. Spell* spell = master_spell_list.GetSpell(id, tier);
  2827. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2828. if (response) {
  2829. response->setDataByName("request_type", 2);
  2830. response->setDataByName("unique_id", tier);
  2831. response->setDataByName("id", id);
  2832. if (spell)
  2833. response->setSmallStringByName("name", spell->GetName());
  2834. else
  2835. response->setSmallStringByName("name", "Unknown Spell");
  2836. EQ2Packet* app2 = response->serialize();
  2837. // DumpPacket(app2);
  2838. QueuePacket(app2);
  2839. safe_delete(response);
  2840. }
  2841. }
  2842. safe_delete(request);
  2843. }
  2844. break;
  2845. }
  2846. default: {
  2847. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2848. }
  2849. }
  2850. safe_delete(request);
  2851. }
  2852. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2853. PacketStruct* request = 0;
  2854. if (!app || app->size == 0)
  2855. return;
  2856. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2857. //DumpPacket(app);
  2858. int8 type = app->pBuffer[0];
  2859. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2860. if (version <= 283) {
  2861. if (type == 1)
  2862. type = 4;
  2863. else if (type == 2)
  2864. type = 5;
  2865. }
  2866. if (type == 3) {
  2867. Spell* spell = 0;
  2868. bool trait_display;
  2869. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2870. if (!request) {
  2871. return;
  2872. }
  2873. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2874. safe_delete(request);
  2875. return;
  2876. }
  2877. int32 id = request->getType_int32_ByName("id");
  2878. int32 tier = request->getType_int32_ByName("tier");
  2879. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2880. bool display = true;
  2881. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2882. display = false;
  2883. else if (version <= 546)
  2884. display = request->getType_int8_ByName("display");
  2885. else if (version > 546)
  2886. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2887. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2888. if (trait_tier != 0xFFFFFFFF) {
  2889. spell = master_spell_list.GetSpell(id, trait_tier);
  2890. if (!spell) {
  2891. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2892. }
  2893. trait_display = true;
  2894. }
  2895. else {
  2896. spell = master_spell_list.GetSpell(id, tier);
  2897. trait_display = false;
  2898. }
  2899. // if we can't find it on the master spell list, see if it is a custom spell
  2900. if (!spell)
  2901. {
  2902. lua_interface->FindCustomSpellLock();
  2903. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2904. if (tmpSpell)
  2905. spell = tmpSpell->spell;
  2906. lua_interface->FindCustomSpellUnlock();
  2907. }
  2908. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2909. if (!spell->IsCopiedSpell())
  2910. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2911. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2912. //DumpPacket(app);
  2913. QueuePacket(app);
  2914. }
  2915. else if(spell && GetVersion() <=546 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2916. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 546 ? true : false);
  2917. //DumpPacket(app);
  2918. QueuePacket(app);
  2919. }
  2920. }
  2921. else if (type == 0) {
  2922. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2923. if (!request) {
  2924. return;
  2925. }
  2926. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2927. safe_delete(request);
  2928. return;
  2929. }
  2930. int32 id = request->getType_int32_ByName("id");
  2931. Item* item = 0;
  2932. // translate from unique id to spawn id for houses
  2933. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2934. bool wasSpawn = false;
  2935. if (spawn)
  2936. {
  2937. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2938. if (item)
  2939. {
  2940. wasSpawn = true;
  2941. item = new Item(item);
  2942. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2943. }
  2944. }
  2945. if (!item)
  2946. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2947. if (!item)
  2948. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2949. if (!item)
  2950. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2951. if (!item)
  2952. item = master_item_list.GetItem(id);
  2953. if (item) {// && sent_item_details.count(id) == 0){
  2954. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2955. sent_item_details[id] = true;
  2956. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2957. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2958. QueuePacket(app);
  2959. if (wasSpawn)
  2960. delete item;
  2961. }
  2962. else {
  2963. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2964. DumpPacket(app);
  2965. }
  2966. }
  2967. else if (type == 1) {
  2968. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2969. if (!request) {
  2970. return;
  2971. }
  2972. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2973. safe_delete(request);
  2974. return;
  2975. }
  2976. int32 id = request->getType_int32_ByName("id");
  2977. int32 unique_id = request->getType_int32_ByName("unique_id");
  2978. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2979. if (!item)
  2980. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2981. if (!item)
  2982. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2983. if (!item)
  2984. item = master_item_list.GetItem(id);
  2985. if (item) {
  2986. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2987. sent_item_details[id] = true;
  2988. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2989. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2990. QueuePacket(app);
  2991. }
  2992. else {
  2993. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2994. DumpPacket(app);
  2995. }
  2996. }
  2997. else if (type == 2) {
  2998. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2999. if (!request) {
  3000. return;
  3001. }
  3002. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3003. safe_delete(request);
  3004. return;
  3005. }
  3006. int32 id = request->getType_int32_ByName("item_id");
  3007. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  3008. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  3009. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  3010. //int32 unique_id = request->getType_int32_ByName("unique_id");
  3011. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3012. //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);
  3013. Item* item = master_item_list.GetItem(id);
  3014. if (item) {
  3015. //only display popup for non merchant links
  3016. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 546 ? true : false);
  3017. QueuePacket(app);
  3018. }
  3019. else {
  3020. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3021. DumpPacket(app);
  3022. }
  3023. }
  3024. else if (type == 4) { //spell effect
  3025. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3026. if (!request) {
  3027. return;
  3028. }
  3029. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3030. safe_delete(request);
  3031. return;
  3032. }
  3033. int32 id = request->getType_int32_ByName("id");
  3034. int16 display = request->getType_int8_ByName("partial_info");
  3035. SpellEffects* effect = player->GetSpellEffect(id);
  3036. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3037. if (effect) {
  3038. int8 tier = effect->tier;
  3039. Spell* spell = master_spell_list.GetSpell(id, tier);
  3040. // if we can't find it on the master spell list, see if it is a custom spell
  3041. if (!spell)
  3042. {
  3043. lua_interface->FindCustomSpellLock();
  3044. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3045. EQ2Packet* pack = 0;
  3046. if (tmpSpell)
  3047. spell = tmpSpell->spell;
  3048. lua_interface->FindCustomSpellUnlock();
  3049. }
  3050. if (spell && !CountSentSpell(id, tier)) {
  3051. if (!spell->IsCopiedSpell())
  3052. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3053. int8 type = 0;
  3054. if (version <= 283)
  3055. type = 1;
  3056. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3057. //DumpPacket(app);
  3058. QueuePacket(app);
  3059. }
  3060. }
  3061. }
  3062. else if (type == 5) { // recipe info
  3063. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3064. if (!request)
  3065. return;
  3066. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3067. safe_delete(request);
  3068. return;
  3069. }
  3070. int32 id = 0;
  3071. if(GetVersion() < 546) {
  3072. id = request->getType_int32_ByName("id");
  3073. }
  3074. else if(GetVersion() == 546) {
  3075. id = request->getType_int32_ByName("unique_id");
  3076. }
  3077. else {
  3078. id = request->getType_int32_ByName("unknown_id");
  3079. }
  3080. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3081. if (recipe) {
  3082. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3083. //DumpPacket(app);
  3084. QueuePacket(app);
  3085. }
  3086. }
  3087. else if (type == 6) { // AA spell info
  3088. Spell* spell = 0;
  3089. //Spell* spell2 = 0;
  3090. //AltAdvanceData* data = 0;
  3091. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3092. if (!request)
  3093. return;
  3094. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3095. safe_delete(request);
  3096. return;
  3097. }
  3098. int32 id = request->getType_int32_ByName("id");
  3099. int32 tier = GetPlayer()->GetSpellTier(id);
  3100. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3101. //data = master_aa_list.GetAltAdvancement(id);
  3102. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3103. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3104. spell = master_spell_list.GetSpell(id, tier);
  3105. if (!spell)
  3106. spell = master_spell_list.GetSpell(id, 1);
  3107. if (!spell)
  3108. {
  3109. lua_interface->FindCustomSpellLock();
  3110. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3111. if (tmpSpell)
  3112. spell = tmpSpell->spell;
  3113. lua_interface->FindCustomSpellUnlock();
  3114. }
  3115. if (!spell)
  3116. {
  3117. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  3118. return;
  3119. }
  3120. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3121. if (!spell->IsCopiedSpell())
  3122. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3123. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3124. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3125. if(GetVersion() > 546) {
  3126. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3127. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3128. //DumpPacket(app);
  3129. QueuePacket(app);
  3130. }
  3131. //}
  3132. }
  3133. else {
  3134. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  3135. DumpPacket(app);
  3136. }
  3137. safe_delete(request);
  3138. }
  3139. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3140. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3141. if (request) {
  3142. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3143. int32 id = request->getType_int32_ByName("id");
  3144. int32 bar = request->getType_int32_ByName("hotbar_number");
  3145. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3146. int32 type = request->getType_int32_ByName("type");
  3147. int8 tier = request->getType_int32_ByName("unique_id");
  3148. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3149. Spell* spell = 0;
  3150. if (type == 0xFFFFFFFF)
  3151. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3152. else {
  3153. if (type == QUICKBAR_NORMAL)
  3154. spell = master_spell_list.GetSpell(id, tier);
  3155. if (spell)
  3156. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3157. else
  3158. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3159. }
  3160. }
  3161. safe_delete(request);
  3162. }
  3163. }
  3164. bool Client::Process(bool zone_process) {
  3165. bool ret = true;
  3166. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3167. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3168. ResetSendMail();
  3169. if(getConnection())
  3170. getConnection()->SendDisconnect(false);
  3171. safe_delete(camp_timer);
  3172. if(linkdead_timer) {
  3173. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3174. // we remove the linkdead status and force a camp out immediately
  3175. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3176. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3177. }
  3178. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3179. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3180. }
  3181. }
  3182. safe_delete(linkdead_timer);
  3183. ret = false;
  3184. }
  3185. if (!eqs) {
  3186. return false;
  3187. }
  3188. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3189. return true;
  3190. }
  3191. switch(new_client_login) {
  3192. case NewLoginState::LOGIN_SEND: {
  3193. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3194. SendLoginInfo();
  3195. new_client_login = NewLoginState::LOGIN_NONE;
  3196. break;
  3197. }
  3198. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3199. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3200. // wait for starting skills/spells to load and reload from DB.
  3201. if(!isDBActive) {
  3202. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3203. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3204. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3205. }
  3206. new_client_login = NewLoginState::LOGIN_SEND;
  3207. }
  3208. break;
  3209. }
  3210. case NewLoginState::LOGIN_ALLOWED: {
  3211. int32 count = 0;
  3212. if(!GetPlayer()->IsReturningFromLD())
  3213. {
  3214. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3215. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3216. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3217. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3218. }
  3219. else
  3220. {
  3221. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3222. }
  3223. // get the latest character starting skills / spells, may have been updated after character creation
  3224. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3225. world.SyncCharacterAbilities(this);
  3226. Query query;
  3227. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3228. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3229. }
  3230. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3231. break;
  3232. }
  3233. case NewLoginState::LOGIN_DELAYED: {
  3234. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3235. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3236. delay_msg_timer.Start(1000, true);
  3237. }
  3238. if(!GetCurrentZone()->IsLoading()) {
  3239. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3240. }
  3241. return true;
  3242. break;
  3243. }
  3244. }
  3245. delay_msg_timer.Disable();
  3246. sockaddr_in to;
  3247. memset((char*)&to, 0, sizeof(to));
  3248. to.sin_family = AF_INET;
  3249. to.sin_port = port;
  3250. to.sin_addr.s_addr = ip;
  3251. /************ Get all packets from packet manager out queue and process them ************/
  3252. EQApplicationPacket* app = 0;
  3253. if (eqs && !eqs->CheckActive()) {
  3254. num_active_failures++;
  3255. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3256. if (num_active_failures > 100) {
  3257. return false;
  3258. }
  3259. return true;
  3260. }
  3261. while (ret && eqs && (app = eqs->PopPacket())) {
  3262. ret = HandlePacket(app);
  3263. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3264. delete app;
  3265. }
  3266. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3267. //database.LoadCharacterActiveSpells(player);
  3268. player->UnlockAllSpells(true);
  3269. should_load_spells = false;
  3270. }
  3271. if(spawn_removal_timer.Check() && GetPlayer()) {
  3272. GetPlayer()->ProcessSpawnRangeUpdates();
  3273. GetPlayer()->CheckSpawnStateQueue();
  3274. }
  3275. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3276. {
  3277. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3278. return false;
  3279. }
  3280. if (quest_updates) {
  3281. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3282. ProcessQuestUpdates();
  3283. }
  3284. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3285. if(queue_timer_delay < 10) {
  3286. queue_timer_delay = 10;
  3287. }
  3288. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3289. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3290. CheckQuestQueue();
  3291. }
  3292. MSaveSpellStateMutex.lock();
  3293. if(save_spell_state_timer.Check())
  3294. {
  3295. save_spell_state_timer.Disable();
  3296. GetPlayer()->SaveSpellEffects();
  3297. }
  3298. MSaveSpellStateMutex.unlock();
  3299. if (temp_placement_timer.Check()) {
  3300. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3301. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3302. hasSentTempPlacementSpawn = true;
  3303. temp_placement_timer.Disable();
  3304. }
  3305. }
  3306. if (pos_update.Check())
  3307. {
  3308. ProcessStateCommands();
  3309. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3310. if(GetPlayer()->GetRegionMap())
  3311. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3312. if(player_pos_changed && IsReadyForUpdates()) {
  3313. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3314. bool underworld = false;
  3315. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3316. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3317. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3318. underworld = true;
  3319. }
  3320. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3321. underworld = true;
  3322. }
  3323. }
  3324. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3325. underworld = true;
  3326. }
  3327. if(underworld) {
  3328. player->SetX(GetCurrentZone()->GetSafeX());
  3329. player->SetY(GetCurrentZone()->GetSafeY());
  3330. player->SetZ(GetCurrentZone()->GetSafeZ());
  3331. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3332. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3333. if(app){
  3334. QueuePacket(app);
  3335. }
  3336. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3337. }
  3338. underworld_cooldown_timer.Start();
  3339. }
  3340. //GetPlayer()->CalculateLocation();
  3341. client_list.CheckPlayersInvisStatus(this);
  3342. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  3343. player_pos_changed = false;
  3344. GetCurrentZone()->CheckTransporters(this);
  3345. if(GetPlayer()->GetRegionMap())
  3346. {
  3347. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3348. }
  3349. }
  3350. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3351. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3352. }
  3353. }
  3354. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3355. lua_interface->UpdateDebugClients(this);
  3356. if (quest_pos_timer.Check())
  3357. CheckPlayerQuestsLocationUpdate();
  3358. if (player->GetSkills()->HasSkillUpdates()) {
  3359. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3360. if (skills) {
  3361. Skill* skill = 0;
  3362. vector<Skill*>::iterator itr;
  3363. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3364. skill = *itr;
  3365. SkillChanged(skill, skill->previous_val, skill->current_val);
  3366. }
  3367. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3368. if (app) QueuePacket(app);
  3369. safe_delete(skills);
  3370. }
  3371. }
  3372. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3373. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3374. safe_delete(current_rez.expire_timer);
  3375. current_rez.expire_timer = 0;
  3376. current_rez.active = false;
  3377. current_rez.caster = 0;
  3378. current_rez.crit = false;
  3379. current_rez.crit_mod = 0;
  3380. current_rez.expire_timer = 0;
  3381. current_rez.heal_name = "";
  3382. current_rez.hp_perc = 0;
  3383. current_rez.mp_perc = 0;
  3384. current_rez.no_calcs = false;
  3385. current_rez.range = 0;
  3386. current_rez.should_delete = false;
  3387. current_rez.spell_name = "";
  3388. current_rez.spell_visual = 0;
  3389. current_rez.subspell = 0;
  3390. }
  3391. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3392. // Quest timers
  3393. Quest* failed_step = 0;
  3394. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3395. if (quest_timers.size() > 0) {
  3396. vector<int32>::iterator itr;
  3397. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3398. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3399. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3400. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3401. Quest* quest = player_quests->at(*itr);
  3402. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3403. failed_step = quest;
  3404. break;
  3405. }
  3406. }
  3407. else {
  3408. itr = quest_timers.erase(itr);
  3409. break;
  3410. }
  3411. }
  3412. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3413. }
  3414. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3415. if (failed_step)
  3416. failed_step->StepFailed(failed_step->GetTimerStep());
  3417. if (player->ControlFlagsChanged())
  3418. player->SendControlFlagUpdates(this);
  3419. if (!eqs || (eqs && !eqs->CheckActive()))
  3420. ret = false;
  3421. // redundant to client disconnect
  3422. // if(!ret)
  3423. // Save();
  3424. return ret;
  3425. }
  3426. ClientList::ClientList() {
  3427. MClients.SetName("ClientList::MClients");
  3428. }
  3429. ClientList::~ClientList() {
  3430. }
  3431. void ClientList::ReloadQuests() {
  3432. list<Client*>::iterator client_iter;
  3433. Client* client = 0;
  3434. MClients.readlock(__FUNCTION__, __LINE__);
  3435. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3436. client = *client_iter;
  3437. if (client)
  3438. client->ReloadQuests();
  3439. }
  3440. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3441. }
  3442. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3443. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3444. return;
  3445. list<Client*>::iterator client_iter;
  3446. Client* client = 0;
  3447. MClients.readlock(__FUNCTION__, __LINE__);
  3448. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3449. client = *client_iter;
  3450. if (client == owner || client->GetPlayer() == NULL)
  3451. continue;
  3452. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3453. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3454. }
  3455. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3456. }
  3457. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3458. list<Client*>::iterator client_iter;
  3459. Client* client = 0;
  3460. MClients.readlock(__FUNCTION__, __LINE__);
  3461. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3462. client = *client_iter;
  3463. if (!client->GetPlayer())
  3464. continue;
  3465. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3466. }
  3467. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3468. }
  3469. int32 ClientList::Count() {
  3470. return client_list.size();
  3471. }
  3472. void ClientList::Add(Client* client) {
  3473. MClients.writelock(__FUNCTION__, __LINE__);
  3474. client_list.push_back(client);
  3475. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3476. }
  3477. Client* ClientList::FindByAccountID(int32 account_id) {
  3478. list<Client*>::iterator client_iter;
  3479. Client* client = 0;
  3480. Client* ret = 0;
  3481. MClients.readlock(__FUNCTION__, __LINE__);
  3482. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3483. client = *client_iter;
  3484. if (client->GetAccountID() == account_id) {
  3485. ret = client;
  3486. break;
  3487. }
  3488. }
  3489. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3490. return ret;
  3491. }
  3492. Client* ClientList::FindByName(char* charName) {
  3493. list<Client*>::iterator client_iter;
  3494. Client* client = 0;
  3495. Client* ret = 0;
  3496. MClients.readlock(__FUNCTION__, __LINE__);
  3497. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3498. client = *client_iter;
  3499. if (!client || !client->GetPlayer())
  3500. continue;
  3501. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3502. ret = client;
  3503. break;
  3504. }
  3505. }
  3506. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3507. return ret;
  3508. }
  3509. Client* ClientList::Get(int32 ip, int16 port) {
  3510. list<Client*>::iterator client_iter;
  3511. Client* client = 0;
  3512. Client* ret = 0;
  3513. MClients.readlock(__FUNCTION__, __LINE__);
  3514. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3515. client = *client_iter;
  3516. if (client->GetIP() == ip && client->GetPort() == port) {
  3517. ret = client;
  3518. break;
  3519. }
  3520. }
  3521. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3522. return ret;
  3523. }
  3524. void ClientList::Process() {
  3525. list<Client*>::iterator client_iter;
  3526. list<Client*>::iterator erase_iter;
  3527. Client* client = 0;
  3528. MClients.readlock(__FUNCTION__, __LINE__);
  3529. erase_iter = client_list.end();
  3530. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3531. client = *client_iter;
  3532. // have a sanity check because the client list can sometimes obtain null client pointers
  3533. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3534. erase_iter = client_iter;
  3535. break;
  3536. }
  3537. }
  3538. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3539. if (erase_iter != client_list.end()) {
  3540. client = *erase_iter;
  3541. MClients.writelock(__FUNCTION__, __LINE__);
  3542. client_list.erase(erase_iter);
  3543. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3544. if (client && !client->remove_from_list) {
  3545. struct in_addr in;
  3546. in.s_addr = client->GetIP();
  3547. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3548. safe_delete(client);
  3549. }
  3550. }
  3551. }
  3552. void ClientList::RemoveConnection(EQStream* eqs) {
  3553. Client* client;
  3554. if (eqs) {
  3555. list<Client*>::iterator client_iter;
  3556. MClients.readlock(__FUNCTION__, __LINE__);
  3557. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3558. client = *client_iter;
  3559. if (client->getConnection() == eqs)
  3560. client->Disconnect(true);
  3561. }
  3562. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3563. }
  3564. }
  3565. bool ClientList::ContainsStream(EQStream* eqs) {
  3566. if (!eqs) {
  3567. return false;
  3568. }
  3569. list<Client*>::iterator client_iter;
  3570. bool ret = false;
  3571. MClients.readlock(__FUNCTION__, __LINE__);
  3572. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3573. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3574. ret = true;
  3575. break;
  3576. }
  3577. }
  3578. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3579. return ret;
  3580. }
  3581. void ClientList::Remove(Client* client, bool remove_data) {
  3582. client->remove_from_list = true;
  3583. if (remove_data) {
  3584. safe_delete(client);
  3585. }
  3586. }
  3587. void Client::SetCurrentZone(ZoneServer* zone) {
  3588. current_zone = zone;
  3589. if(player) {
  3590. player->SetZone(zone, GetVersion());
  3591. }
  3592. }
  3593. void Client::SetCurrentZone(int32 id) {
  3594. if (current_zone) {
  3595. //current_zone->GetCombat()->RemoveHate(player);
  3596. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3597. }
  3598. SetCurrentZone(zone_list.Get(id));
  3599. }
  3600. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3601. if (current_zone) {
  3602. //current_zone->GetCombat()->RemoveHate(player);
  3603. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3604. }
  3605. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3606. }
  3607. ZoneServer* Client::GetCurrentZone() {
  3608. return current_zone;
  3609. }
  3610. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3611. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3612. if (channel_type == CHANNEL_LOOT)
  3613. return CHANNEL_COLOR_NEW_LOOT;
  3614. }
  3615. else if (GetVersion() >= 973) {
  3616. if (channel_type == CHANNEL_LOOT)
  3617. return CHANNEL_COLOR_NEWEST_LOOT;
  3618. }
  3619. if (GetVersion() <= 283) {
  3620. if (channel_type <=12)
  3621. return channel_type;
  3622. switch (channel_type) {
  3623. case CHANNEL_GROUP_CHAT:
  3624. case CHANNEL_GROUP_SAY:
  3625. case CHANNEL_RAID_SAY:
  3626. case CHANNEL_GUILD_CHAT:
  3627. case CHANNEL_GUILD_SAY:
  3628. case CHANNEL_OFFICER_SAY:
  3629. case CHANNEL_GUILD_MOTD:
  3630. return channel_type - 1;
  3631. case CHANNEL_PRIVATE_CHAT:
  3632. case CHANNEL_NONPLAYER_TELL:
  3633. return channel_type - 5;
  3634. case CHANNEL_PRIVATE_TELL:
  3635. case CHANNEL_TELL_FROM_CS:
  3636. return channel_type - 6;
  3637. case CHANNEL_CHAT_CHANNEL_TEXT:
  3638. case CHANNEL_OUT_OF_CHARACTER:
  3639. case CHANNEL_AUCTION:
  3640. case CHANNEL_CUSTOM_CHANNEL:
  3641. case CHANNEL_CHARACTER_TEXT:
  3642. case CHANNEL_REWARD:
  3643. case CHANNEL_DEATH:
  3644. case CHANNEL_PET_CHAT:
  3645. case CHANNEL_SKILL:
  3646. return channel_type - 7;
  3647. case CHANNEL_SPELLS:
  3648. case CHANNEL_YOU_CAST:
  3649. case CHANNEL_YOU_FAIL:
  3650. return channel_type - 8;
  3651. case CHANNEL_FRIENDLY_CAST:
  3652. case CHANNEL_FRIENDLY_FAIL:
  3653. case CHANNEL_OTHER_CAST:
  3654. case CHANNEL_OTHER_FAIL:
  3655. case CHANNEL_HOSTILE_CAST:
  3656. case CHANNEL_HOSTILE_FAIL:
  3657. case CHANNEL_WORN_OFF:
  3658. case CHANNEL_SPELLS_OTHER:
  3659. return channel_type - 9;
  3660. case CHANNEL_COMBAT:
  3661. return channel_type - 15;
  3662. case CHANNEL_HEROIC_OPPORTUNITY:
  3663. case CHANNEL_NON_MELEE_DAMAGE:
  3664. case CHANNEL_DAMAGE_SHIELD:
  3665. return channel_type - 16;
  3666. case CHANNEL_MELEE_COMBAT:
  3667. case CHANNEL_WARNINGS:
  3668. case CHANNEL_YOU_HIT:
  3669. case CHANNEL_YOU_MISS:
  3670. case CHANNEL_ATTACKER_HITS:
  3671. case CHANNEL_ATTACKER_MISSES:
  3672. return channel_type - 18;
  3673. case CHANNEL_OTHER_HIT:
  3674. case CHANNEL_OTHER_MISSES:
  3675. case CHANNEL_CRITICAL_HIT:
  3676. return channel_type - 22;
  3677. case CHANNEL_OTHER:
  3678. case CHANNEL_MONEY_SPLIT:
  3679. case CHANNEL_LOOT:
  3680. return channel_type - 30;
  3681. case CHANNEL_COMMAND_TEXT:
  3682. case CHANNEL_BROADCAST:
  3683. case CHANNEL_WHO:
  3684. case CHANNEL_COMMANDS:
  3685. case CHANNEL_MERCHANT:
  3686. case CHANNEL_MERCHANT_BUY_SELL:
  3687. case CHANNEL_CONSIDER_MESSAGE:
  3688. case CHANNEL_CON_MINUS_2:
  3689. case CHANNEL_CON_MINUS_1:
  3690. case CHANNEL_CON_0:
  3691. case CHANNEL_CON_1:
  3692. case CHANNEL_CON_2:
  3693. return channel_type - 31;
  3694. default: {
  3695. return CHANNEL_DEFAULT;
  3696. }
  3697. }
  3698. }
  3699. else if (GetVersion() <= 546) {
  3700. if (channel_type < 20)
  3701. return channel_type;
  3702. switch (channel_type) {
  3703. case CHANNEL_GUILD_MOTD:
  3704. case CHANNEL_GUILD_MEMBER_ONLINE:
  3705. case CHANNEL_GUILD_EVENT:
  3706. return channel_type + 1;
  3707. case CHANNEL_PRIVATE_CHAT:
  3708. case CHANNEL_NONPLAYER_TELL:
  3709. return channel_type - 1;
  3710. case CHANNEL_PRIVATE_TELL:
  3711. case CHANNEL_TELL_FROM_CS:
  3712. case CHANNEL_ARENA:
  3713. case CHANNEL_CHAT_CHANNEL_TEXT:
  3714. case CHANNEL_OUT_OF_CHARACTER:
  3715. case CHANNEL_AUCTION:
  3716. case CHANNEL_CUSTOM_CHANNEL:
  3717. case CHANNEL_CHARACTER_TEXT:
  3718. case CHANNEL_REWARD:
  3719. case CHANNEL_DEATH:
  3720. case CHANNEL_PET_CHAT:
  3721. case CHANNEL_SKILL:
  3722. case CHANNEL_FACTION:
  3723. case CHANNEL_SPELLS:
  3724. case CHANNEL_YOU_CAST:
  3725. case CHANNEL_YOU_FAIL:
  3726. return channel_type - 2;
  3727. case CHANNEL_FRIENDLY_CAST:
  3728. case CHANNEL_FRIENDLY_FAIL:
  3729. case CHANNEL_OTHER_CAST:
  3730. case CHANNEL_OTHER_FAIL:
  3731. case CHANNEL_HOSTILE_CAST:
  3732. case CHANNEL_HOSTILE_FAIL:
  3733. case CHANNEL_WORN_OFF:
  3734. case CHANNEL_SPELLS_OTHER:
  3735. case CHANNEL_HEAL_SPELLS:
  3736. case CHANNEL_HEALS:
  3737. case CHANNEL_FRIENDLY_HEALS:
  3738. case CHANNEL_OTHER_HEALS:
  3739. case CHANNEL_HOSTILE_HEALS:
  3740. return channel_type - 3;
  3741. case CHANNEL_COMBAT:
  3742. case CHANNEL_GENERAL_COMBAT:
  3743. case CHANNEL_HEROIC_OPPORTUNITY:
  3744. case CHANNEL_NON_MELEE_DAMAGE:
  3745. case CHANNEL_DAMAGE_SHIELD:
  3746. case CHANNEL_WARD:
  3747. return channel_type - 4;
  3748. case CHANNEL_MELEE_COMBAT:
  3749. case CHANNEL_WARNINGS:
  3750. case CHANNEL_YOU_HIT:
  3751. case CHANNEL_YOU_MISS:
  3752. case CHANNEL_ATTACKER_HITS:
  3753. case CHANNEL_ATTACKER_MISSES:
  3754. case CHANNEL_YOUR_PET_HITS:
  3755. case CHANNEL_YOUR_PET_MISSES:
  3756. case CHANNEL_ATTACKER_HITS_PET:
  3757. case CHANNEL_ATTACKER_MISSES_PET:
  3758. case CHANNEL_OTHER_HIT:
  3759. case CHANNEL_OTHER_MISSES:
  3760. return channel_type - 5;
  3761. case CHANNEL_OTHER:
  3762. case CHANNEL_MONEY_SPLIT:
  3763. case CHANNEL_LOOT:
  3764. return channel_type - 14;
  3765. case CHANNEL_COMMAND_TEXT:
  3766. case CHANNEL_BROADCAST:
  3767. case CHANNEL_WHO:
  3768. case CHANNEL_COMMANDS:
  3769. case CHANNEL_MERCHANT:
  3770. case CHANNEL_MERCHANT_BUY_SELL:
  3771. case CHANNEL_CONSIDER_MESSAGE:
  3772. case CHANNEL_CON_MINUS_2:
  3773. case CHANNEL_CON_MINUS_1:
  3774. case CHANNEL_CON_0:
  3775. case CHANNEL_CON_1:
  3776. case CHANNEL_CON_2:
  3777. case CHANNEL_TRADESKILLS:
  3778. case CHANNEL_HARVESTING:
  3779. case CHANNEL_HARVESTING_WARNINGS:
  3780. return channel_type - 15;
  3781. default: {
  3782. return CHANNEL_DEFAULT;
  3783. }
  3784. }
  3785. }
  3786. else {
  3787. switch (channel_type) {
  3788. default: {
  3789. return channel_type;
  3790. }
  3791. }
  3792. }
  3793. return channel_type;
  3794. }
  3795. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3796. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3797. return;
  3798. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3799. if (packet) {
  3800. packet->setDataByName("from", from->GetPlayer()->GetName());
  3801. packet->setDataByName("to", to);
  3802. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3803. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3804. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3805. packet->setDataByName("unknown2", 1, 1);
  3806. packet->setDataByName("show_bubble", 1);
  3807. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3808. packet->setDataByName("understood", 1);
  3809. }
  3810. packet->setDataByName("time", 2);
  3811. packet->setDataByName("language", current_language_id);
  3812. packet->setMediumStringByName("message", message);
  3813. EQ2Packet* outpacket = packet->serialize();
  3814. QueuePacket(outpacket);
  3815. safe_delete(packet);
  3816. }
  3817. }
  3818. void Client::SimpleMessage(int8 color, const char* message) {
  3819. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3820. if (command_packet) {
  3821. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3822. command_packet->setMediumStringByName("text", message);
  3823. command_packet->setDataByName("unknown02", 0x00ff);
  3824. EQ2Packet* outapp = command_packet->serialize();
  3825. QueuePacket(outapp);
  3826. safe_delete(command_packet);
  3827. }
  3828. }
  3829. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3830. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3831. if (packet) {
  3832. int8 xxx = spell->GetSpellData()->is_aa;
  3833. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3834. packet->setDataByName("spell_id", spell->GetSpellID());
  3835. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3836. packet->setDataByName("spell_name", spell->GetName());
  3837. if(add_silently)
  3838. packet->setDataByName("add_silently", 1);
  3839. if(add_to_hotbar)
  3840. packet->setDataByName("add_to_hotbar", 1);
  3841. packet->setDataByName("unknown", xxx);
  3842. packet->setDataByName("display_spell_tier", 1);
  3843. packet->setDataByName("unknown3", 1);
  3844. packet->setDataByName("tier", spell->GetSpellTier());
  3845. packet->setDataByName("icon", spell->GetSpellIcon());
  3846. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3847. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3848. //packet->PrintPacket();
  3849. EQ2Packet* outapp = packet->serialize();
  3850. //DumpPacket(outapp);
  3851. QueuePacket(outapp);
  3852. safe_delete(packet);
  3853. }
  3854. }
  3855. void Client::Message(int8 type, const char* message, ...) {
  3856. va_list argptr;
  3857. char buffer[4096];
  3858. va_start(argptr, message);
  3859. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3860. va_end(argptr);
  3861. SimpleMessage(type, buffer);
  3862. }
  3863. void Client::Disconnect(bool send_disconnect)
  3864. {
  3865. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3866. this->Save();
  3867. this->GetPlayer()->WritePlayerStatistics();
  3868. SetConnected(false);
  3869. if (send_disconnect && getConnection())
  3870. getConnection()->SendDisconnect(true);
  3871. eqs = 0;
  3872. }
  3873. bool Client::Summon(const char* search_name) {
  3874. Spawn* target = 0;
  3875. if (search_name || GetPlayer()->GetTarget()) {
  3876. Client* search_client = 0;
  3877. if (search_name) {
  3878. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3879. if (target && target->IsPlayer())
  3880. search_client = target->GetClient();
  3881. if (!target) {
  3882. search_client = zone_list.GetClientByCharName(string(search_name));
  3883. if (search_client)
  3884. target = search_client->GetPlayer();
  3885. }
  3886. }
  3887. else
  3888. target = GetPlayer()->GetTarget();
  3889. if (target && target != GetPlayer()) {
  3890. target->SetX(GetPlayer()->GetX());
  3891. target->SetY(GetPlayer()->GetY());
  3892. target->SetZ(GetPlayer()->GetZ());
  3893. target->SetHeading(GetPlayer()->GetHeading());
  3894. if (!target->IsPlayer()) {
  3895. target->SetSpawnOrigX(target->GetX());
  3896. target->SetSpawnOrigY(target->GetY());
  3897. target->SetSpawnOrigZ(target->GetZ());
  3898. target->SetSpawnOrigHeading(target->GetHeading());
  3899. }
  3900. target->SetLocation(GetPlayer()->GetLocation());
  3901. if(target->IsNPC()) {
  3902. ((NPC*)target)->HaltMovement();
  3903. }
  3904. }
  3905. else if (target)
  3906. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3907. if (search_client && search_client != this) {
  3908. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3909. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3910. if (search_client->GetCurrentZone() != GetCurrentZone())
  3911. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3912. else {
  3913. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3914. if (app)
  3915. search_client->QueuePacket(app);
  3916. }
  3917. }
  3918. }
  3919. if (!target)
  3920. return false;
  3921. else
  3922. return true;
  3923. }
  3924. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3925. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3926. if(instanceType < 1)
  3927. return std::string("");
  3928. ZoneServer* instance_zone = nullptr;
  3929. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3930. if (data) {
  3931. // If lockout instances check to see if we are locked out
  3932. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3933. int32 time = 0;
  3934. // Check success timer
  3935. if (data->last_success_timestamp > 0) {
  3936. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3937. // Timer has not expired yet can't re enter
  3938. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3939. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3940. }
  3941. }
  3942. // Check failure timer
  3943. if (data->last_failure_timestamp > 0) {
  3944. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3945. // Timer has not expired yet
  3946. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3947. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3948. }
  3949. }
  3950. // Time > 0 then we are locked out, make the message and send it and return true
  3951. if (time > 0) {
  3952. string time_msg = "";
  3953. int16 hour;
  3954. int8 min;
  3955. int8 sec;
  3956. hour = time / 3600;
  3957. time = time % 3600;
  3958. min = time / 60;
  3959. time = time % 60;
  3960. sec = time;
  3961. if (hour > 0) {
  3962. char temp[10];
  3963. snprintf(temp, 9," %i", hour);
  3964. time_msg.append(temp);
  3965. time_msg.append(" hour");
  3966. time_msg.append((hour > 1) ? "s" : "");
  3967. }
  3968. if (min > 0) {
  3969. char temp[5];
  3970. snprintf(temp, 4," %i", min);
  3971. time_msg.append(temp);
  3972. time_msg.append(" minute");
  3973. time_msg.append((min > 1) ? "s" : "");
  3974. }
  3975. // Only add seconds if minutes and hours are 0
  3976. if (hour == 0 && min == 0 && sec > 0) {
  3977. char temp[5];
  3978. snprintf(temp, 4," %i", sec);
  3979. time_msg.append(temp);
  3980. time_msg.append(" second");
  3981. time_msg.append((sec > 1) ? "s" : "");
  3982. }
  3983. if(displayClient)
  3984. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3985. return time_msg;
  3986. }
  3987. }
  3988. }
  3989. return std::string("");
  3990. }
  3991. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3992. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3993. if(instanceType < 1)
  3994. return nullptr;
  3995. ZoneServer* instance_zone = nullptr;
  3996. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3997. if (data) {
  3998. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3999. // If lockout instances check to see if we are locked out
  4000. if (lockoutTime.length() > 0) {
  4001. return nullptr;
  4002. }
  4003. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  4004. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  4005. // 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
  4006. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  4007. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  4008. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  4009. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  4010. }
  4011. else
  4012. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4013. data->instance_id = instance_zone->GetInstanceID();
  4014. }
  4015. }
  4016. return instance_zone;
  4017. }
  4018. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4019. ZoneServer* instance_zone = NULL;
  4020. int8 instanceType = 0;
  4021. // determine if this is a group instanced zone that already exists
  4022. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4023. if (instance_zone != NULL)
  4024. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4025. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4026. {
  4027. // best to check if we already have our own instance!
  4028. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4029. {
  4030. switch (instanceType)
  4031. {
  4032. case SOLO_LOCKOUT_INSTANCE:
  4033. case GROUP_LOCKOUT_INSTANCE:
  4034. case RAID_LOCKOUT_INSTANCE:
  4035. {
  4036. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4037. if (instance_zone) {
  4038. // 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
  4039. // so delete `instances` entry for the zone when it shuts down.
  4040. 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());
  4041. if (db_id > 0)
  4042. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4043. }
  4044. break;
  4045. }
  4046. case SOLO_PERSIST_INSTANCE:
  4047. case GROUP_PERSIST_INSTANCE:
  4048. case RAID_PERSIST_INSTANCE:
  4049. {
  4050. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4051. if (instance_zone) {
  4052. 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());
  4053. if (db_id > 0)
  4054. 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()));
  4055. }
  4056. break;
  4057. }
  4058. case PUBLIC_INSTANCE:
  4059. case TRADESKILL_INSTANCE:
  4060. {
  4061. // if its public/tradeskill, look for a public already setup
  4062. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4063. if (instance_zone) {
  4064. // Check the current population against the max population, if greater or equal start a new version
  4065. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4066. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4067. }
  4068. else
  4069. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4070. break;
  4071. }
  4072. case PERSONAL_HOUSE_INSTANCE:
  4073. case GUILD_HOUSE_INSTANCE:
  4074. {
  4075. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4076. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4077. // with the OP_EnterHouseMsg opcode
  4078. break;
  4079. }
  4080. case QUEST_INSTANCE:
  4081. {
  4082. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4083. break;
  4084. /*
  4085. 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`;
  4086. */
  4087. }
  4088. default:
  4089. {
  4090. // NONE
  4091. }
  4092. }
  4093. }
  4094. if (instance_zone != NULL)
  4095. Zone(instance_zone, zone_coords_valid);
  4096. }
  4097. if (instance_zone != NULL)
  4098. return true;
  4099. else
  4100. return false;
  4101. }
  4102. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4103. Spawn* target = 0;
  4104. if (search_name || GetPlayer()->GetTarget()) {
  4105. Client* search_client = 0;
  4106. if (search_name) {
  4107. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4108. if (!target) {
  4109. search_client = zone_list.GetClientByCharName(search_name);
  4110. if (search_client)
  4111. target = search_client->GetPlayer();
  4112. }
  4113. if (target)
  4114. GetPlayer()->SetTarget(target);
  4115. }
  4116. else
  4117. target = GetPlayer()->GetTarget();
  4118. if (target && target != GetPlayer()) {
  4119. GetPlayer()->SetX(target->GetX());
  4120. GetPlayer()->SetY(target->GetY());
  4121. GetPlayer()->SetZ(target->GetZ());
  4122. GetPlayer()->SetHeading(target->GetHeading());
  4123. GetPlayer()->SetLocation(target->GetLocation());
  4124. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4125. }
  4126. else if (target)
  4127. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4128. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4129. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4130. else if (target) {
  4131. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4132. if (app)
  4133. QueuePacket(app);
  4134. }
  4135. }
  4136. if (!target)
  4137. return false;
  4138. else
  4139. return true;
  4140. }
  4141. bool Client::CheckZoneAccess(const char* zoneName) {
  4142. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4143. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4144. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4145. if (zone && zone->GetZoneLockState())
  4146. {
  4147. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4148. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4149. return false;
  4150. }
  4151. sint16 zoneMinStatus = 0;
  4152. int16 zoneMinLevel = 0;
  4153. int16 zoneMaxLevel = 0;
  4154. int16 zoneMinVersion = 0;
  4155. if (!zone)
  4156. {
  4157. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4158. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4159. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4160. return true;
  4161. }
  4162. }
  4163. else
  4164. {
  4165. zoneMinStatus = zone->GetMinimumStatus();
  4166. zoneMinLevel = zone->GetMinimumLevel();
  4167. zoneMaxLevel = zone->GetMaximumLevel();
  4168. zoneMinVersion = zone->GetMinimumVersion();
  4169. }
  4170. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4171. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4172. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4173. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4174. {
  4175. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4176. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4177. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4178. return false;
  4179. }
  4180. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4181. {
  4182. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4183. {
  4184. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4185. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4186. return false;
  4187. }
  4188. }
  4189. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4190. {
  4191. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4192. {
  4193. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4194. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4195. return false;
  4196. }
  4197. }
  4198. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4199. {
  4200. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4201. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4202. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4203. {
  4204. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4205. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4206. return false;
  4207. }
  4208. }
  4209. return true;
  4210. }
  4211. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4212. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4213. }
  4214. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4215. if (!new_zone) {
  4216. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4217. return;
  4218. }
  4219. client_zoning = true;
  4220. zoning_id = new_zone->GetZoneID();
  4221. zoning_instance_id = new_zone->GetInstanceID();
  4222. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4223. player->SetResurrecting(true);
  4224. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4225. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4226. SaveSpells();
  4227. ResetSendMail();
  4228. // Remove players pet from zone if there is one
  4229. ((Entity*)player)->DismissAllPets();
  4230. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4231. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4232. GetPlayer()->DeleteSpellEffects(true);
  4233. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4234. SetZoningDestination(new_zone);
  4235. SetCurrentZone(new_zone);
  4236. if (player->GetGroupMemberInfo())
  4237. {
  4238. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4239. player->UpdateGroupMemberInfo();
  4240. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4241. }
  4242. // block out the member info for the group
  4243. TempRemoveGroup();
  4244. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4245. if (set_coords)
  4246. {
  4247. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4248. __FUNCTION__,
  4249. GetCurrentZone()->GetSafeX(),
  4250. GetCurrentZone()->GetSafeY(),
  4251. GetCurrentZone()->GetSafeZ(),
  4252. GetCurrentZone()->GetSafeHeading(),
  4253. new_zone->GetZoneName()
  4254. );
  4255. player->SetX(GetCurrentZone()->GetSafeX());
  4256. player->SetY(GetCurrentZone()->GetSafeY());
  4257. player->SetZ(GetCurrentZone()->GetSafeZ());
  4258. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4259. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4260. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4261. }
  4262. else {
  4263. ResetZoningCoords();
  4264. }
  4265. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4266. Save();
  4267. char* new_zone_ip = 0;
  4268. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4269. new_zone_ip = net.GetInternalWorldAddress();
  4270. else
  4271. new_zone_ip = net.GetWorldAddress();
  4272. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4273. int32 key = Timer::GetUnixTimeStamp();
  4274. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4275. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4276. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4277. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4278. if (version > 283) {
  4279. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4280. if (packet)
  4281. {
  4282. QueuePacket(packet->serialize());
  4283. safe_delete(packet);
  4284. }
  4285. }
  4286. }
  4287. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4288. {
  4289. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4290. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4291. }
  4292. float Client::DistanceFrom(Client* client) {
  4293. float ret = 0;
  4294. if (client && client != this) {
  4295. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4296. ret = sqrt(ret);
  4297. }
  4298. return ret;
  4299. }
  4300. void Client::DetermineCharacterUpdates() {
  4301. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4302. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4303. cdu->account_id = GetAccountID();
  4304. cdu->char_id = GetCharacterID();
  4305. int32 timestamp = Timer::GetUnixTimeStamp();
  4306. int8 flag = GetTimeStampFlag();
  4307. if (flag & LEVEL_UPDATE_FLAG)
  4308. {
  4309. cdu->update_field = LEVEL_UPDATE_FLAG;
  4310. cdu->update_data = player->GetLevel();
  4311. loginserver.SendPacket(outpack);
  4312. }
  4313. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4314. if (flag & CLASS_UPDATE_FLAG)
  4315. {
  4316. cdu->update_field = CLASS_UPDATE_FLAG;
  4317. cdu->update_data = player->GetAdventureClass();
  4318. loginserver.SendPacket(outpack);
  4319. }
  4320. if (flag & GENDER_UPDATE_FLAG)
  4321. {
  4322. cdu->update_field = GENDER_UPDATE_FLAG;
  4323. cdu->update_data = player->GetGender();
  4324. loginserver.SendPacket(outpack);
  4325. }
  4326. if (flag & DELETE_UPDATE_FLAG) {
  4327. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4328. }
  4329. safe_delete(outpack); // Zone, armor and name use a different structure
  4330. if (flag & RACE_UPDATE_FLAG)
  4331. {
  4332. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4333. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4334. ru->account_id = GetAccountID();
  4335. ru->char_id = GetCharacterID();
  4336. ru->race = player->GetRace();
  4337. ru->model_type = player->GetModelType();
  4338. loginserver.SendPacket(outpack);
  4339. safe_delete(outpack);
  4340. }
  4341. if (flag & ZONE_UPDATE_FLAG) {
  4342. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4343. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4344. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4345. czu->account_id = GetAccountID();
  4346. czu->char_id = GetCharacterID();
  4347. czu->zone_id = GetCurrentZone()->GetZoneID();
  4348. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4349. czu->zone_length = strlen(zone_file);
  4350. if (czu->zone_length > 64)
  4351. czu->zone_length = 64;
  4352. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4353. loginserver.SendPacket(outpack);
  4354. safe_delete(outpack);
  4355. }
  4356. if (flag & ARMOR_UPDATE_FLAG) {
  4357. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4358. }
  4359. if (flag & NAME_UPDATE_FLAG) {
  4360. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4361. }
  4362. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4363. }
  4364. void Client::Save() {
  4365. if (GetCharacterID() == 0 || IsSaveDisabled())
  4366. return;
  4367. if (current_zone) {
  4368. DetermineCharacterUpdates();
  4369. UpdateCharacterInstances();
  4370. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4371. database.Save(this);
  4372. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4373. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4374. GetPlayer()->ResetQuickbarNeeded();
  4375. }
  4376. database.SaveItems(this);
  4377. database.SaveBuyBacks(this);
  4378. GetPlayer()->SaveHistory();
  4379. GetPlayer()->SaveLUAHistory();
  4380. MSaveSpellStateMutex.lock();
  4381. GetPlayer()->SaveSpellEffects();
  4382. MSaveSpellStateMutex.unlock();
  4383. }
  4384. }
  4385. void Client::UpdateCharacterInstances() {
  4386. if (GetPlayer() != NULL)
  4387. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4388. /*if ( GetPlayer() != NULL )
  4389. {
  4390. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4391. // to use for applying the update to each instances timer
  4392. int32 lastSaveTS = GetLastSavedTimeStamp();
  4393. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4394. int32 diffTS = newSaveTS - lastSaveTS;
  4395. // update instance timers
  4396. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4397. // update with the new timestamp and save the db
  4398. this->SetLastSavedTimeStamp(newSaveTS);
  4399. }*/
  4400. }
  4401. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4402. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4403. if (packet) {
  4404. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4405. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4406. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4407. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4408. vector<EntityCommand*> commands;
  4409. vector<EntityCommand*> delete_commands;
  4410. if (out && spawn) {
  4411. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4412. {
  4413. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4414. if (!spawn->primary_command_list[i]->default_allow_list)
  4415. {
  4416. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4417. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4418. continue;
  4419. }
  4420. else
  4421. {
  4422. // default is allow list, only deny if added to the list as deny (false itr second)
  4423. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4424. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4425. continue;
  4426. }
  4427. commands.push_back(spawn->primary_command_list[i]);
  4428. }
  4429. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4430. commands.push_back(spawn->secondary_command_list[i]);
  4431. if (spawn->IsPlayer()) {
  4432. if (player->IsFriend(spawn->GetName()))
  4433. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4434. else
  4435. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4436. if (player->IsIgnored(spawn->GetName()))
  4437. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4438. else
  4439. {
  4440. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4441. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4442. }
  4443. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4444. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4445. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4446. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4447. }
  4448. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4449. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4450. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4451. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4452. }
  4453. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4454. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4455. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4456. }
  4457. out->setDataByName("spawn_id", spawn_id);
  4458. out->setArrayLengthByName("num_verbs", commands.size());
  4459. for (int32 i = 0; i < commands.size(); i++) {
  4460. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4461. out->setArrayDataByName("distance", commands[i]->distance, i);
  4462. if (commands[i]->error_text.length() == 0)
  4463. out->setArrayAddToPacketByName("error", false, i);
  4464. else {
  4465. out->setArrayDataByName("display_error", 1, i);
  4466. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4467. }
  4468. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4469. }
  4470. EQ2Packet* outapp = out->serialize();
  4471. //DumpPacket(outapp);
  4472. QueuePacket(outapp);
  4473. safe_delete(out);
  4474. for (int32 i = 0; i < delete_commands.size(); i++) {
  4475. safe_delete(delete_commands[i]);
  4476. }
  4477. }
  4478. }
  4479. safe_delete(packet);
  4480. }
  4481. }
  4482. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4483. if (previous_value != new_value) {
  4484. Message(CHANNEL_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  4485. char tmp[200] = { 0 };
  4486. 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);
  4487. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4488. }
  4489. }
  4490. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4491. {
  4492. /* JA notes on the unknown:
  4493. 2 = ding glimmer
  4494. 16 = Achievement Unlocked
  4495. 6 no longer does anything
  4496. */
  4497. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4498. if (packet) {
  4499. packet->setDataByName("unknown", unknown);
  4500. packet->setMediumStringByName("text", text);
  4501. if (type && strlen(type) > 0)
  4502. packet->setMediumStringByName("message_type", type);
  4503. packet->setDataByName("size", size);
  4504. packet->setDataByName("red", red);
  4505. packet->setDataByName("green", green);
  4506. packet->setDataByName("blue", blue);
  4507. QueuePacket(packet->serialize());
  4508. safe_delete(packet);
  4509. }
  4510. }
  4511. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4512. if (new_level < 1) {
  4513. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4514. return;
  4515. }
  4516. if (player->GetLevel() != new_level) {
  4517. player->SetLevel(new_level);
  4518. if (player->GetGroupMemberInfo()) {
  4519. player->UpdateGroupMemberInfo();
  4520. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4521. }
  4522. }
  4523. if (new_level > old_level) {
  4524. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4525. }
  4526. if (player->GetPet()) {
  4527. NPC* pet = (NPC*)player->GetPet();
  4528. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4529. pet->SetLevel(new_level);
  4530. pet->UpdateWeapons();
  4531. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4532. if (command_packet) {
  4533. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4534. command_packet->setDataByName("anim_type", 1753);
  4535. QueuePacket(command_packet->serialize());
  4536. safe_delete(command_packet);
  4537. }
  4538. }
  4539. }
  4540. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4541. if (level_update) {
  4542. level_update->setDataByName("old_level", old_level);
  4543. level_update->setDataByName("new_level", new_level);
  4544. QueuePacket(level_update->serialize());
  4545. safe_delete(level_update);
  4546. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4547. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4548. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4549. }
  4550. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4551. if (command_packet) {
  4552. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4553. command_packet->setDataByName("anim_type", 1753);
  4554. QueuePacket(command_packet->serialize());
  4555. safe_delete(command_packet);
  4556. }
  4557. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4558. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4559. SendNewAdventureSpells();
  4560. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4561. GetPlayer()->UpdateWeapons();
  4562. // GetPlayer()->SetLevel(new_level);
  4563. 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__);
  4564. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4565. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4566. GetPlayer()->CalculateBonuses();
  4567. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4568. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4569. /*InfoStruct* info = player->GetInfoStruct();
  4570. info->set_agi_base(new_level * 2 + 15);
  4571. info->set_intel_base(new_level * 2 + 15);
  4572. info->set_wis_base(new_level * 2 + 15);
  4573. info->set_str_base(new_level * 2 + 15);
  4574. info->set_sta_base(new_level * 2 + 15);
  4575. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4576. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4577. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4578. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4579. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4580. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4581. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4582. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4583. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4584. GetPlayer()->SetCharSheetChanged(true);
  4585. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4586. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4587. int16 new_skill_cap = 5 * new_level;
  4588. PlayerSkillList* player_skills = player->GetSkills();
  4589. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4590. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4591. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4592. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4593. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4594. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4595. }
  4596. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4597. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4598. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4599. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4600. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4601. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4602. }
  4603. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4604. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4605. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4606. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4607. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4608. if (new_level > player->GetTSLevel())
  4609. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4610. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4611. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4612. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4613. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4614. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4615. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4616. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4617. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4618. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4619. Guild* guild = GetPlayer()->GetGuild();
  4620. if (guild) {
  4621. int8 event_type = 0;
  4622. if (new_level < 10)
  4623. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4624. else if (new_level == 10)
  4625. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4626. else if (new_level >= 11 && new_level < 20)
  4627. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4628. else if (new_level == 20)
  4629. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4630. else if (new_level >= 21 && new_level < 30)
  4631. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4632. else if (new_level == 30)
  4633. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4634. else if (new_level >= 31 && new_level < 40)
  4635. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4636. else if (new_level == 40)
  4637. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4638. else if (new_level >= 41 && new_level < 50)
  4639. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4640. else if (new_level == 50)
  4641. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4642. else if (new_level >= 51 && new_level < 60)
  4643. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4644. else if (new_level == 60)
  4645. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4646. else if (new_level >= 61 && new_level < 70)
  4647. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4648. else if (new_level == 70)
  4649. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4650. else if (new_level >= 71 && new_level < 80)
  4651. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4652. else if (new_level == 80)
  4653. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4654. 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());
  4655. 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());
  4656. guild->UpdateGuildMemberInfo(GetPlayer());
  4657. guild->SendGuildMember(GetPlayer());
  4658. guild->SendGuildMemberList();
  4659. }
  4660. // Need to send the trait list every time the players level changes
  4661. // Also need to force the char sheet update or else there can be a large delay from when you level
  4662. // to when you are actually able to select traits.
  4663. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4664. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4665. if (version > 546)
  4666. master_aa_list.DisplayAA(this, 0, 0);
  4667. if (GetPlayer()->SpawnedBots.size() > 0) {
  4668. map<int32, int32>::iterator itr;
  4669. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4670. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4671. if (bot && bot->IsBot())
  4672. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4673. }
  4674. }
  4675. }
  4676. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4677. if (new_level < 1) {
  4678. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4679. return;
  4680. }
  4681. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4682. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4683. return;
  4684. }
  4685. if (new_level > old_level)
  4686. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4687. if (player->GetTSLevel() != new_level) {
  4688. player->SetTSLevel(new_level);
  4689. if (player->GetGroupMemberInfo()) {
  4690. player->UpdateGroupMemberInfo();
  4691. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4692. }
  4693. }
  4694. // Only tradeskill skills should increace, and then only those related to your class
  4695. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4696. if (level_update) {
  4697. level_update->setDataByName("old_level", old_level);
  4698. level_update->setDataByName("new_level", new_level);
  4699. level_update->setDataByName("type", 1);
  4700. QueuePacket(level_update->serialize());
  4701. safe_delete(level_update);
  4702. }
  4703. // provide new spells upon levelling
  4704. SendNewTradeskillSpells();
  4705. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4706. if (command_packet) {
  4707. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4708. command_packet->setDataByName("anim_type", 1753);
  4709. QueuePacket(command_packet->serialize());
  4710. safe_delete(command_packet);
  4711. }
  4712. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4713. GetPlayer()->SetTSLevel(new_level);
  4714. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4715. GetPlayer()->SetCharSheetChanged(true);
  4716. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4717. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4718. PlayerSkillList* player_skills = player->GetSkills();
  4719. int16 specialize_skill_cap = new_level * 5;
  4720. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4721. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4722. int8 ts_class = player->GetTradeskillClass();
  4723. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4724. int32 skill_id_1, skill_id_2, skill_id_3;
  4725. switch (base_ts_class) {
  4726. case ARTISAN:
  4727. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4728. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4729. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4730. break;
  4731. case OUTFITTER:
  4732. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4733. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4734. skill_id_1 = SKILL_ID_TAILORING;
  4735. skill_id_2 = SKILL_ID_METALSHAPING;
  4736. skill_id_3 = SKILL_ID_METALWORKING;
  4737. if (ts_class == TAILOR) {
  4738. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4739. skill_id_1 = 0;
  4740. }
  4741. else if (ts_class == ARMORER) {
  4742. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4743. skill_id_2 = 0;
  4744. }
  4745. else if (ts_class == WEAPONSMITH) {
  4746. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4747. skill_id_3 = 0;
  4748. }
  4749. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4750. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4751. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4752. break;
  4753. case SCHOLAR:
  4754. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4755. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4756. skill_id_1 = SKILL_ID_SCRIBING;
  4757. skill_id_2 = SKILL_ID_CHEMISTRY;
  4758. skill_id_3 = SKILL_ID_ARTIFICING;
  4759. if (ts_class == SAGE) {
  4760. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4761. skill_id_1 = 0;
  4762. }
  4763. else if (ts_class == ALCHEMIST) {
  4764. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4765. skill_id_2 = 0;
  4766. }
  4767. else if (ts_class == JEWELER) {
  4768. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4769. skill_id_3 = 0;
  4770. }
  4771. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4772. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4773. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4774. break;
  4775. case CRAFTSMAN:
  4776. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4777. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4778. skill_id_1 = SKILL_ID_ARTISTRY;
  4779. skill_id_2 = SKILL_ID_FLETCHING;
  4780. skill_id_3 = SKILL_ID_SCULPTING;
  4781. if (ts_class == PROVISIONER) {
  4782. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4783. skill_id_1 = 0;
  4784. }
  4785. else if (ts_class == WOODWORKER) {
  4786. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4787. skill_id_2 = 0;
  4788. }
  4789. else if (ts_class == CARPENTER) {
  4790. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4791. skill_id_3 = 0;
  4792. }
  4793. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4794. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4795. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4796. break;
  4797. default:
  4798. break;
  4799. }
  4800. if (new_level > player->GetAdventureClass())
  4801. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4802. Guild* guild = GetPlayer()->GetGuild();
  4803. if (guild) {
  4804. int8 event_type = 0;
  4805. if (new_level < 10)
  4806. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4807. else if (new_level == 10)
  4808. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4809. else if (new_level >= 11 && new_level < 20)
  4810. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4811. else if (new_level == 20)
  4812. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4813. else if (new_level >= 21 && new_level < 30)
  4814. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4815. else if (new_level == 30)
  4816. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4817. else if (new_level >= 31 && new_level < 40)
  4818. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4819. else if (new_level == 40)
  4820. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4821. else if (new_level >= 41 && new_level < 50)
  4822. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4823. else if (new_level == 50)
  4824. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4825. else if (new_level >= 51 && new_level < 60)
  4826. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4827. else if (new_level == 60)
  4828. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4829. else if (new_level >= 61 && new_level < 70)
  4830. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4831. else if (new_level == 70)
  4832. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4833. else if (new_level >= 71 && new_level < 80)
  4834. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4835. else if (new_level == 80)
  4836. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4837. 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());
  4838. 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());
  4839. guild->UpdateGuildMemberInfo(GetPlayer());
  4840. guild->SendGuildMember(GetPlayer());
  4841. guild->SendGuildMemberList();
  4842. }
  4843. // Need to send the trait list every time the players level changes
  4844. // Also need to force the char sheet update or else there can be a large delay from when you level
  4845. // to when you are actually able to select traits.
  4846. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4847. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4848. }
  4849. void Client::CloseLoot(int32 spawn_id) {
  4850. if (GetVersion() > 546) {
  4851. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4852. if (packet) {
  4853. packet->setDataByName("window_id", 4);
  4854. EQ2Packet* outapp = packet->serialize();
  4855. if (outapp) {
  4856. //DumpPacket(outapp);
  4857. QueuePacket(outapp);
  4858. }
  4859. safe_delete(packet);
  4860. }
  4861. }
  4862. if(spawn_id > 0){
  4863. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4864. if (packet) {
  4865. packet->setDataByName("spawn_id", spawn_id);
  4866. EQ2Packet* outapp = packet->serialize();
  4867. if (outapp)
  4868. QueuePacket(outapp);
  4869. safe_delete(packet);
  4870. }
  4871. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4872. if(spawn) {
  4873. spawn->CloseLoot(GetPlayer());
  4874. }
  4875. }
  4876. }
  4877. string Client::GetCoinMessage(int32 total_coins) {
  4878. if (total_coins == 0) {
  4879. return " 0 Copper";
  4880. }
  4881. char tmp[64] = { 0 };
  4882. string message = "";
  4883. int32 val = 0;
  4884. if (total_coins >= 1000000) {
  4885. val = total_coins / 1000000;
  4886. total_coins -= 1000000 * val;
  4887. sprintf(tmp, " %u Platinum", val);
  4888. message.append(tmp);
  4889. memset(tmp, 0, 64);
  4890. }
  4891. if (total_coins >= 10000) {
  4892. val = total_coins / 10000;
  4893. total_coins -= 10000 * val;
  4894. sprintf(tmp, " %u Gold", val);
  4895. message.append(tmp);
  4896. memset(tmp, 0, 64);
  4897. }
  4898. if (total_coins >= 100) {
  4899. val = total_coins / 100;
  4900. total_coins -= 100 * val;
  4901. sprintf(tmp, " %u Silver", val);
  4902. message.append(tmp);
  4903. memset(tmp, 0, 64);
  4904. }
  4905. if (total_coins > 0) {
  4906. sprintf(tmp, " %u Copper", (int32)total_coins);
  4907. message.append(tmp);
  4908. }
  4909. return message;
  4910. }
  4911. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  4912. if (!entity) {
  4913. CloseLoot(0);
  4914. return;
  4915. }
  4916. if (total_coins > 0) {
  4917. player->AddCoins(total_coins);
  4918. //PlaySound("coin_cha_ching");
  4919. string message = "";
  4920. if (entity->GetHP() == 0) {
  4921. message = "You loot ";
  4922. entity->SetLootCoins(0, false);
  4923. }
  4924. else
  4925. message = "You receive ";
  4926. message.append(GetCoinMessage(total_coins));
  4927. if (entity->GetHP() == 0)
  4928. message.append(" from the corpse of ").append(entity->GetName());
  4929. int8 type = CHANNEL_LOOT;
  4930. SimpleMessage(type, message.c_str());
  4931. }
  4932. if (!items || items->size() == 0)
  4933. CloseLoot(entity->GetID());
  4934. entity->StartLootTimer(GetPlayer());
  4935. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4936. if (packet) {
  4937. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  4938. vector<Item*>::iterator itr;
  4939. int32 packet_size = 0;
  4940. EQ2Packet* outapp = 0;
  4941. uchar* data = 0;
  4942. vector<Item*> send_items;
  4943. if (items && items->size() > 0) {
  4944. for (int i = 0; i < items->size(); i++) {
  4945. Item* item = (*items)[i];
  4946. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  4947. bool skipItem = entity->IsItemInLootTier(item);
  4948. if (!skipItem) {
  4949. send_items.push_back(item);
  4950. }
  4951. }
  4952. else {
  4953. send_items.push_back(item);
  4954. }
  4955. }
  4956. }
  4957. if (GetVersion() >= 284) {
  4958. if (GetVersion() > 561) {
  4959. if (send_items.size() > 0) {
  4960. packet->setDataByName("loot_count", send_items.size());
  4961. packet->setDataByName("display", 1);
  4962. }
  4963. packet->setDataByName("loot_type", entity->GetLootMethod());
  4964. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  4965. packet->setDataByName("loot_id", entity->GetID());
  4966. EQ2Packet* tmpPacket = packet->serialize();
  4967. packet_size += tmpPacket->size;
  4968. if (send_items.size() > 0) {
  4969. data = new uchar[send_items.size() * 1000 + packet_size];
  4970. memset(data, 0, send_items.size() * 1000 + packet_size);
  4971. }
  4972. else {
  4973. data = new uchar[packet_size];
  4974. memset(data, 0, packet_size);
  4975. }
  4976. uchar* ptr = data;
  4977. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4978. ptr += tmpPacket->size;
  4979. safe_delete(tmpPacket);
  4980. Item* item = 0;
  4981. if (send_items.size() > 0) {
  4982. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  4983. item = *itr;
  4984. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4985. ptr += sizeof(int32);
  4986. packet_size += sizeof(int32);
  4987. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4988. int8 offset = 0;
  4989. if (GetVersion() >= 1188) {
  4990. offset = 13;
  4991. }
  4992. else if (GetVersion() >= 860) {
  4993. offset = 11;
  4994. }
  4995. else if (GetVersion() <= 561) {
  4996. offset = 19;
  4997. }
  4998. else {
  4999. offset = 10;
  5000. }
  5001. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  5002. ptr += tmpPacket->size - offset;
  5003. packet_size += tmpPacket->size - offset;
  5004. safe_delete(tmpPacket);
  5005. }
  5006. }
  5007. packet_size -= sizeof(int32);
  5008. memcpy(data, &packet_size, sizeof(int32));
  5009. packet_size += sizeof(int32);
  5010. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  5011. }
  5012. else {
  5013. if (send_items.size() > 0) {
  5014. packet->setArrayLengthByName("loot_count", send_items.size());
  5015. Item* item = 0;
  5016. if (send_items.size() > 0) {
  5017. int i = 0;
  5018. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5019. item = *itr;
  5020. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5021. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5022. i++;
  5023. }
  5024. }
  5025. packet->setDataByName("display", 1);
  5026. }
  5027. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5028. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5029. packet->setDataByName("spawn_id", entity->GetID());
  5030. outapp = packet->serialize();
  5031. }
  5032. }
  5033. else {
  5034. if (send_items.size() > 0) {
  5035. packet->setArrayLengthByName("loot_count", send_items.size());
  5036. for (int i = 0; i < send_items.size(); i++) {
  5037. Item* item = (send_items)[i];
  5038. packet->setArrayDataByName("name", item->name.c_str(), i);
  5039. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5040. packet->setArrayDataByName("count", item->details.count, i);
  5041. packet->setArrayDataByName("icon", item->details.icon, i);
  5042. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5043. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5044. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5045. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5046. else
  5047. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5048. }
  5049. }
  5050. packet->setDataByName("object_id", entity->GetID());
  5051. packet->setDataByName("unknown3", 1);
  5052. packet->setDataByName("unknown4", 1);
  5053. packet->setDataByName("unknown5", 60);
  5054. outapp = packet->serialize();
  5055. }
  5056. if (outapp) {
  5057. QueuePacket(outapp);
  5058. }
  5059. safe_delete_array(data);
  5060. safe_delete(packet);
  5061. }
  5062. }
  5063. bool Client::LootSpawnByMethod(Spawn* entity) {
  5064. bool sentLoot = false;
  5065. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5066. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5067. if (gmi && gmi->group_id)
  5068. {
  5069. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5070. if (group)
  5071. {
  5072. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5073. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5074. deque<GroupMemberInfo*>* members = group->GetMembers();
  5075. int32 split_coin_per_player = 0;
  5076. int32 coins_remain_after_split = entity->GetLootCoins();
  5077. int32 total_coins = entity->GetLootCoins();
  5078. if (auto_split_coin) {
  5079. int8 members_in_zone = 0;
  5080. for (int8 i = 0; i < members->size(); i++) {
  5081. Entity* member = members->at(i)->member;
  5082. if (!member || !member->IsPlayer())
  5083. continue;
  5084. if (member->GetZone() != GetPlayer()->GetZone())
  5085. continue;
  5086. members_in_zone++;
  5087. }
  5088. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5089. members_in_zone = 0;
  5090. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5091. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5092. entity->SetLootCoins(0, false);
  5093. }
  5094. LogWrite(LOOT__INFO, 0, "Loot", "%s: Group LootSpawnByMethod %u, auto coin split %u, split coin per player %u, remaining coin after split %u", entity->GetName(), entity->GetLootMethod(), auto_split_coin, split_coin_per_player, coins_remain_after_split);
  5095. bool startWithLooter = true;
  5096. for (int8 i = 0; i < members->size(); i++) {
  5097. Entity* member = members->at(i)->member;
  5098. if (!member || !member->IsPlayer())
  5099. continue;
  5100. if (member->GetZone() != GetPlayer()->GetZone())
  5101. continue;
  5102. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5103. if (startWithLooter && member != GetPlayer())
  5104. continue;
  5105. else if (!startWithLooter && member == GetPlayer())
  5106. continue;
  5107. else if (startWithLooter) {
  5108. i = 0;
  5109. startWithLooter = false;
  5110. }
  5111. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5112. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5113. if (((Player*)member)->GetClient()) {
  5114. ((Player*)member)->GetClient()->Message(CHANNEL_MONEY_SPLIT, "Your share of %s from the corpse of %s is %s.", GetCoinMessage(total_coins).c_str(), entity->GetLootName(), GetCoinMessage(split_coin_per_player + coins_remain_after_split).c_str());
  5115. }
  5116. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5117. coins_remain_after_split = 0;
  5118. }
  5119. switch (entity->GetLootMethod()) {
  5120. case GroupLootMethod::METHOD_LOTTO:
  5121. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5122. if (((Player*)member)->GetClient()) {
  5123. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5124. case 1: { // lotto, need
  5125. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5126. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5127. }
  5128. else { // *need* before greed
  5129. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5130. }
  5131. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5132. // if it already exists we have to override the setting
  5133. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5134. break;
  5135. }
  5136. case 2: { // decline
  5137. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5138. // if it already exists we have to override the setting
  5139. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5140. break;
  5141. }
  5142. default: { // presume 0 or higher than 2
  5143. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5144. break;
  5145. }
  5146. }
  5147. sentLoot = true;
  5148. }
  5149. break;
  5150. }
  5151. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5152. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5153. sentLoot = true;
  5154. break;
  5155. }
  5156. case GroupLootMethod::METHOD_LEADER: {
  5157. if (member->GetGroupMemberInfo()->leader)
  5158. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5159. break;
  5160. }
  5161. case GroupLootMethod::METHOD_FFA: {
  5162. if(member == GetPlayer()) {
  5163. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5164. }
  5165. break;
  5166. }
  5167. }
  5168. }
  5169. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5170. }
  5171. }
  5172. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5173. return sentLoot;
  5174. }
  5175. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5176. bool lootAllowed = false;
  5177. bool sentLoot = false;
  5178. std::vector<int32> item_list;
  5179. if (entity->IsNPC()) {
  5180. entity->LockLoot();
  5181. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5182. entity->UnlockLoot();
  5183. if (lootAllowed) {
  5184. OpenChest(entity, attemptDisarm);
  5185. }
  5186. else {
  5187. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5188. return;
  5189. }
  5190. entity->LockLoot();
  5191. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5192. lootAllowed = true;
  5193. if ((sentLoot = LootSpawnByMethod(entity))) {
  5194. entity->GetLootItemsList(&item_list);
  5195. }
  5196. else {
  5197. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5198. }
  5199. }
  5200. entity->UnlockLoot();
  5201. if (lootAllowed) {
  5202. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5203. }
  5204. }
  5205. }
  5206. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5207. {
  5208. if (!entity)
  5209. return;
  5210. int8 chest_difficulty = 0;
  5211. int32 state = 0;
  5212. // Check for the chest and set the action state
  5213. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5214. string modelName;
  5215. if (entity->GetModelType() == 4034) {
  5216. // small chest, open with copper coins
  5217. // does not include traps, however can be disarmed
  5218. chest_difficulty = 1;
  5219. state = 11899;
  5220. modelName.append("Small Chest");
  5221. }
  5222. else if (entity->GetModelType() == 5864) {
  5223. // treasure chest, open with silver coins
  5224. chest_difficulty = 2;
  5225. state = 11901;
  5226. modelName.append("Treasure Chest");
  5227. }
  5228. else if (entity->GetModelType() == 5865) {
  5229. // ornate chest, open with gold coins
  5230. chest_difficulty = 3;
  5231. state = 11900;
  5232. modelName.append("Ornate Chest");
  5233. }
  5234. else if (entity->GetModelType() == 4015) {
  5235. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5236. chest_difficulty = 5;
  5237. state = 11898;
  5238. modelName.append("Exquisite Chest");
  5239. }
  5240. bool firstChestOpen = false;
  5241. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5242. {
  5243. ChestTrap::ChestTrapInfo nextTrap;
  5244. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5245. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5246. firstChestOpen = true;
  5247. entity->SetTrapTriggered(true, state);
  5248. if (ret)
  5249. {
  5250. if (disarmSkill && attemptDisarm)
  5251. {
  5252. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5253. {
  5254. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5255. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5256. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5257. }
  5258. else
  5259. {
  5260. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5261. }
  5262. // despite fail/succeed we should always try to increase skill if disarm is available
  5263. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5264. }
  5265. else // no disarm skill, always fail
  5266. {
  5267. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5268. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5269. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5270. }
  5271. }
  5272. }
  5273. else if (!entity->HasTrapTriggered())
  5274. {
  5275. firstChestOpen = true;
  5276. entity->SetTrapTriggered(true, state);
  5277. }
  5278. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5279. // for those in range the SendStateCommand will cause it to animate open.
  5280. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5281. if (firstChestOpen)
  5282. GetCurrentZone()->SendStateCommand(entity, state);
  5283. }
  5284. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5285. {
  5286. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5287. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5288. if (source == NULL)
  5289. source = (Entity*)GetPlayer();
  5290. if (spell)
  5291. {
  5292. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5293. if (gmi && gmi->group_id)
  5294. {
  5295. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5296. if (group)
  5297. {
  5298. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5299. deque<GroupMemberInfo*>* members = group->GetMembers();
  5300. for (int8 i = 0; i < members->size(); i++) {
  5301. Entity* member = members->at(i)->member;
  5302. if(!member)
  5303. continue;
  5304. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5305. continue;
  5306. // if we have a radius provided then check if the group member is outside the radius or not
  5307. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5308. continue;
  5309. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5310. }
  5311. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5312. }
  5313. }
  5314. else
  5315. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5316. }
  5317. }
  5318. Spawn* Client::GetBanker() {
  5319. return banker;
  5320. }
  5321. void Client::SetBanker(Spawn* in_banker) {
  5322. banker = in_banker;
  5323. }
  5324. void Client::Bank(Spawn* banker, bool cancel) {
  5325. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5326. if (!cancel)
  5327. SetBanker(banker);
  5328. else
  5329. SetBanker(0);
  5330. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5331. if (packet) {
  5332. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5333. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5334. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5335. int32 coins1, coins2;
  5336. coins1 = ((int32*)&coins)[0];
  5337. coins2 = ((int32*)&coins)[1];
  5338. packet->setDataByName("bank_coins", coins1);
  5339. packet->setDataByName("bank_coins2", coins2);
  5340. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5341. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5342. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5343. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5344. if (!cancel)
  5345. packet->setDataByName("display", 1);
  5346. QueuePacket(packet->serialize());
  5347. safe_delete(packet);
  5348. }
  5349. }
  5350. }
  5351. bool Client::BankHasCoin(int64 amount){
  5352. int32 tmp = 0;
  5353. if(amount <= 0)
  5354. return 0;
  5355. //plat
  5356. if (amount >= 1000000) {
  5357. tmp = amount / 1000000;
  5358. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5359. if(bank_coins_plat >= tmp)
  5360. return 1;
  5361. }
  5362. //gold
  5363. if (amount >= 10000) {
  5364. tmp = amount / 10000;
  5365. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5366. if(bank_coins_gold >= tmp)
  5367. return 1;
  5368. }
  5369. //silver
  5370. if (amount >= 100) {
  5371. tmp = amount / 100;
  5372. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5373. if(bank_coins_silver >= tmp)
  5374. return 1;
  5375. }
  5376. //copper
  5377. if (amount > 0) {
  5378. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5379. if(bank_coins_copper >= amount)
  5380. return 1;
  5381. }
  5382. return 0;
  5383. }
  5384. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5385. bool cheater = false;
  5386. if (amount > 0) {
  5387. string withdrawal = "";
  5388. char withdrawal_data[512] = { 0 };
  5389. int32 tmp = 0;
  5390. if (amount >= 1000000) {
  5391. tmp = amount / 1000000;
  5392. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5393. if (tmp > bank_coins_plat)
  5394. cheater = true;
  5395. else {
  5396. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5397. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5398. amount -= (int64)tmp * 1000000;
  5399. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5400. withdrawal.append(withdrawal_data);
  5401. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5402. }
  5403. }
  5404. if (!cheater && amount >= 10000) {
  5405. tmp = amount / 10000;
  5406. if (tmp > GetPlayer()->GetBankCoinsGold())
  5407. cheater = true;
  5408. else {
  5409. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5410. bank_coins_gold -= tmp;
  5411. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5412. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5413. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5414. }
  5415. else
  5416. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5417. amount -= tmp * 10000;
  5418. sprintf(withdrawal_data, "%u Gold ", tmp);
  5419. withdrawal.append(withdrawal_data);
  5420. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5421. }
  5422. }
  5423. if (!cheater && amount >= 100) {
  5424. tmp = amount / 100;
  5425. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5426. if (tmp > bank_coins_silver)
  5427. cheater = true;
  5428. else {
  5429. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5430. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5431. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5432. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5433. }
  5434. else
  5435. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5436. amount -= tmp * 100;
  5437. sprintf(withdrawal_data, "%u Silver ", tmp);
  5438. withdrawal.append(withdrawal_data);
  5439. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5440. }
  5441. }
  5442. if (!cheater) {
  5443. if (amount > 0) {
  5444. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5445. withdrawal.append(withdrawal_data);
  5446. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5447. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5448. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5449. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5450. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5451. }
  5452. else
  5453. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5454. }
  5455. if (withdrawal.length() > 0) {
  5456. withdrawal.append("withdrawn ");
  5457. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5458. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5459. withdrawal.append(withdrawal_data);
  5460. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5461. return 1;
  5462. }
  5463. }
  5464. else
  5465. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5466. return 0;
  5467. }
  5468. return 0;
  5469. }
  5470. void Client::BankWithdrawal(int64 amount) {
  5471. bool cheater = false;
  5472. if (GetBanker() && amount > 0) {
  5473. string withdrawal = "";
  5474. char withdrawal_data[512] = { 0 };
  5475. int32 tmp = 0;
  5476. if (amount >= 1000000) {
  5477. tmp = amount / 1000000;
  5478. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5479. if (tmp > bank_coins_plat)
  5480. cheater = true;
  5481. else {
  5482. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5483. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5484. amount -= (int64)tmp * 1000000;
  5485. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5486. withdrawal.append(withdrawal_data);
  5487. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5488. }
  5489. }
  5490. if (!cheater && amount >= 10000) {
  5491. tmp = amount / 10000;
  5492. if (tmp > GetPlayer()->GetBankCoinsGold())
  5493. cheater = true;
  5494. else {
  5495. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5496. bank_coins_gold -= tmp;
  5497. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5498. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5499. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5500. }
  5501. else
  5502. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5503. amount -= tmp * 10000;
  5504. sprintf(withdrawal_data, "%u Gold ", tmp);
  5505. withdrawal.append(withdrawal_data);
  5506. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5507. }
  5508. }
  5509. if (!cheater && amount >= 100) {
  5510. tmp = amount / 100;
  5511. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5512. if (tmp > bank_coins_silver)
  5513. cheater = true;
  5514. else {
  5515. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5516. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5517. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5518. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5519. }
  5520. else
  5521. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5522. amount -= tmp * 100;
  5523. sprintf(withdrawal_data, "%u Silver ", tmp);
  5524. withdrawal.append(withdrawal_data);
  5525. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5526. }
  5527. }
  5528. if (!cheater) {
  5529. if (amount > 0) {
  5530. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5531. withdrawal.append(withdrawal_data);
  5532. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5533. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5534. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5535. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5536. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5537. }
  5538. else
  5539. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5540. }
  5541. if (withdrawal.length() > 0) {
  5542. withdrawal.append("withdrawn ");
  5543. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5544. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5545. withdrawal.append(withdrawal_data);
  5546. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5547. }
  5548. }
  5549. else
  5550. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5551. player->SetCharSheetChanged(true);
  5552. Bank(banker);
  5553. }
  5554. }
  5555. void Client::BankDeposit(int64 amount) {
  5556. bool cheater = false;
  5557. if (GetBanker() && amount > 0) {
  5558. int32 tmp = 0;
  5559. char deposit_data[512] = { 0 };
  5560. string deposit = "";
  5561. if (amount >= 1000000) {
  5562. tmp = amount / 1000000;
  5563. if (tmp > GetPlayer()->GetCoinsPlat())
  5564. cheater = true;
  5565. else {
  5566. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5567. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5568. amount -= (int64)tmp * 1000000;
  5569. sprintf(deposit_data, "%u Platinum ", tmp);
  5570. deposit.append(deposit_data);
  5571. memset(deposit_data, 0, sizeof(deposit_data));
  5572. }
  5573. }
  5574. if (!cheater && amount >= 10000) {
  5575. tmp = amount / 10000;
  5576. if (tmp > GetPlayer()->GetCoinsGold())
  5577. cheater = true;
  5578. else {
  5579. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5580. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5581. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5582. }
  5583. else
  5584. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5585. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5586. amount -= tmp * 10000;
  5587. sprintf(deposit_data, "%u Gold ", tmp);
  5588. deposit.append(deposit_data);
  5589. memset(deposit_data, 0, sizeof(deposit_data));
  5590. }
  5591. }
  5592. if (!cheater && amount >= 100) {
  5593. tmp = amount / 100;
  5594. if (tmp > GetPlayer()->GetCoinsSilver())
  5595. cheater = true;
  5596. else {
  5597. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5598. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5599. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5600. }
  5601. else
  5602. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5603. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5604. amount -= tmp * 100;
  5605. sprintf(deposit_data, "%u Silver ", tmp);
  5606. deposit.append(deposit_data);
  5607. memset(deposit_data, 0, sizeof(deposit_data));
  5608. }
  5609. }
  5610. if (!cheater) {
  5611. if (amount > 0) {
  5612. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5613. deposit.append(deposit_data);
  5614. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5615. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5616. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5617. }
  5618. else
  5619. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5620. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5621. }
  5622. if (deposit.length() > 0) {
  5623. deposit.append("deposited ");
  5624. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5625. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5626. deposit.append(deposit_data);
  5627. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5628. }
  5629. }
  5630. else
  5631. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5632. player->SetCharSheetChanged(true);
  5633. Bank(banker);
  5634. }
  5635. }
  5636. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5637. {
  5638. std::unique_lock lock(MPendingQuestAccept);
  5639. pending_quest_accept.push_back(quest->GetQuestID());
  5640. }
  5641. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5642. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5643. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5644. quest_updates = update;
  5645. if(quest_updates) {
  5646. SaveQuestRewardData(true);
  5647. }
  5648. }
  5649. void Client::QueueQuestReward(int32 quest_id, bool is_temporary, bool is_collection, bool has_displayed, int64 tmp_coin, int32 tmp_status, std::string description, bool db_saved, int32 index) {
  5650. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5651. return;
  5652. QuestRewardData* data = new QuestRewardData;
  5653. data->quest_id = quest_id;
  5654. data->is_temporary = is_temporary;
  5655. data->is_collection = is_collection;
  5656. data->has_displayed = has_displayed;
  5657. data->tmp_coin = tmp_coin;
  5658. data->tmp_status = tmp_status;
  5659. data->description = std::string(description);
  5660. data->db_saved = db_saved;
  5661. data->db_index = index;
  5662. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5663. quest_pending_reward.push_back(data);
  5664. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5665. }
  5666. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5667. bool success = false;
  5668. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5669. if (quest_pending_reward.size() > 0) {
  5670. vector<QuestRewardData*>::iterator itr;
  5671. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5672. int32 questID = (*itr)->quest_id;
  5673. bool temporary = (*itr)->is_temporary;
  5674. bool collection = (*itr)->is_collection;
  5675. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5676. success = true;
  5677. break;
  5678. }
  5679. }
  5680. }
  5681. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5682. return success;
  5683. }
  5684. void Client::RemoveQueuedQuestReward() {
  5685. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5686. if(quest_pending_reward.size() > 0) {
  5687. QuestRewardData* data = quest_pending_reward.at(0);
  5688. if(data->db_saved) {
  5689. Query query;
  5690. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5691. if(data->is_temporary && data->quest_id) {
  5692. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5693. }
  5694. }
  5695. quest_pending_reward.erase(quest_pending_reward.begin());
  5696. }
  5697. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5698. SaveQuestRewardData(true);
  5699. }
  5700. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5701. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5702. quest_pending_updates[quest_id][step_id] = progress;
  5703. quest_updates = true;
  5704. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5705. }
  5706. void Client::ProcessQuestUpdates() {
  5707. if(!IsReadyForUpdates())
  5708. return;
  5709. if (quest_pending_updates.size() > 0) {
  5710. map<int32, map<int32, int32> > tmp_quest_updates;
  5711. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5712. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5713. quest_pending_updates.clear();
  5714. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5715. map<int32, map<int32, int32> >::iterator quest_itr;
  5716. map<int32, int32>::iterator step_itr;
  5717. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5718. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5719. if (step_itr->second == 0xFFFFFFFF) {
  5720. SetStepComplete(quest_itr->first, step_itr->first);
  5721. player->SendQuestRequiredSpawns(quest_itr->first);
  5722. }
  5723. else
  5724. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5725. }
  5726. }
  5727. }
  5728. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5729. if (quest_pending_reward.size() > 0) {
  5730. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5731. // only able to display one reward at a time
  5732. if(GetPlayer()->IsActiveReward())
  5733. return;
  5734. Query query;
  5735. vector<QuestRewardData*>::iterator itr;
  5736. vector<QuestRewardData*> tmp_quest_rewards;
  5737. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5738. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5739. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5740. bool delete_first = false;
  5741. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5742. int32 questID = (*itr)->quest_id;
  5743. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5744. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5745. GetPlayer()->SetActiveReward(true);
  5746. (*itr)->has_displayed = true;
  5747. UpdateCharacterRewardData((*itr));
  5748. break;
  5749. }
  5750. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5751. (*itr)->has_displayed = true;
  5752. UpdateCharacterRewardData((*itr));
  5753. // only able to display one reward at a time
  5754. break;
  5755. } else {
  5756. delete_first = true;
  5757. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5758. break;
  5759. }
  5760. }
  5761. if(delete_first) {
  5762. RemoveQueuedQuestReward();
  5763. }
  5764. } else {
  5765. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5766. }
  5767. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5768. if (quest_pending_reward.size() > 0) {
  5769. quest_updates = true;
  5770. }
  5771. else {
  5772. quest_updates = false;
  5773. }
  5774. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5775. }
  5776. void Client::CheckQuestQueue() {
  5777. MQuestQueue.writelock();
  5778. last_update_time = 0;
  5779. vector<QueuedQuest*>::iterator itr;
  5780. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5781. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5782. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5783. }
  5784. safe_delete((*itr));
  5785. }
  5786. quest_queue.clear();
  5787. MQuestQueue.releasewritelock();
  5788. }
  5789. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5790. Quest* quest = player->SetStepComplete(quest_id, step);
  5791. if (quest) {
  5792. SendQuestUpdate(quest);
  5793. GetCurrentZone()->SendQuestUpdates(this);
  5794. }
  5795. }
  5796. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5797. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5798. if (quest) {
  5799. SendQuestUpdate(quest);
  5800. GetCurrentZone()->SendQuestUpdates(this);
  5801. }
  5802. }
  5803. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5804. bool hadUpdates = false;
  5805. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5806. if (quest_updates) {
  5807. for (int32 i = 0; i < quest_updates->size(); i++)
  5808. {
  5809. SendQuestUpdate(quest_updates->at(i));
  5810. hadUpdates = true;
  5811. }
  5812. }
  5813. safe_delete(quest_updates);
  5814. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5815. if (quest_failures) {
  5816. for (int32 i = 0; i < quest_failures->size(); i++)
  5817. {
  5818. SendQuestFailure(quest_failures->at(i));
  5819. hadUpdates = true;
  5820. }
  5821. }
  5822. safe_delete(quest_failures);
  5823. if (hadUpdates)
  5824. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5825. }
  5826. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5827. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5828. if (quest_updates) {
  5829. for (int32 i = 0; i < quest_updates->size(); i++)
  5830. SendQuestUpdate(quest_updates->at(i));
  5831. GetCurrentZone()->SendQuestUpdates(this);
  5832. }
  5833. safe_delete(quest_updates);
  5834. }
  5835. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5836. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5837. if (quest_updates) {
  5838. for (int32 i = 0; i < quest_updates->size(); i++)
  5839. SendQuestUpdate(quest_updates->at(i));
  5840. }
  5841. safe_delete(quest_updates);
  5842. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5843. if (quest_failures) {
  5844. for (int32 i = 0; i < quest_failures->size(); i++)
  5845. SendQuestFailure(quest_failures->at(i));
  5846. }
  5847. safe_delete(quest_failures);
  5848. }
  5849. void Client::CheckPlayerQuestsLocationUpdate() {
  5850. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5851. if (quest_updates) {
  5852. for (int32 i = 0; i < quest_updates->size(); i++)
  5853. SendQuestUpdate(quest_updates->at(i));
  5854. }
  5855. safe_delete(quest_updates);
  5856. }
  5857. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5858. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5859. if (quest_updates) {
  5860. for (int32 i = 0; i < quest_updates->size(); i++)
  5861. SendQuestUpdate(quest_updates->at(i));
  5862. }
  5863. safe_delete(quest_updates);
  5864. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5865. if (quest_failures) {
  5866. for (int32 i = 0; i < quest_failures->size(); i++)
  5867. SendQuestFailure(quest_failures->at(i));
  5868. }
  5869. safe_delete(quest_failures);
  5870. }
  5871. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5872. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5873. MPendingQuestAccept.lock();
  5874. player->pending_quests[quest->GetQuestID()] = quest;
  5875. MPendingQuestAccept.unlock();
  5876. AcceptQuest(quest->GetQuestID());
  5877. }
  5878. else {
  5879. MPendingQuestAccept.lock();
  5880. player->pending_quests[quest->GetQuestID()] = quest;
  5881. MPendingQuestAccept.unlock();
  5882. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5883. //DumpPacket(outapp);
  5884. QueuePacket(outapp);
  5885. }
  5886. }
  5887. void Client::AcceptQuest(int32 quest_id) {
  5888. MPendingQuestAccept.lock_shared();
  5889. if (player->pending_quests.count(quest_id) > 0) {
  5890. Quest* quest = player->pending_quests[quest_id];
  5891. if(quest) {
  5892. MPendingQuestAccept.unlock_shared();
  5893. MPendingQuestAccept.lock();
  5894. player->pending_quests.erase(quest->GetQuestID());
  5895. MPendingQuestAccept.unlock();
  5896. AddPlayerQuest(quest);
  5897. GetCurrentZone()->SendQuestUpdates(this);
  5898. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  5899. return; // already unlocked mutex
  5900. }
  5901. }
  5902. MPendingQuestAccept.unlock_shared();
  5903. }
  5904. void Client::RemovePendingQuest(int32 quest_id) {
  5905. bool send_updates = false;
  5906. MPendingQuestAccept.lock_shared();
  5907. if (player->pending_quests.count(quest_id) > 0) {
  5908. Quest* quest = player->pending_quests[quest_id];
  5909. MPendingQuestAccept.unlock_shared();
  5910. MPendingQuestAccept.lock();
  5911. player->pending_quests.erase(quest_id);
  5912. MPendingQuestAccept.unlock();
  5913. if(lua_interface) {
  5914. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  5915. lua_interface->SetLuaUserDataStale(quest);
  5916. }
  5917. safe_delete(quest);
  5918. send_updates = true;
  5919. }
  5920. else {
  5921. MPendingQuestAccept.unlock_shared();
  5922. }
  5923. if(send_updates) {
  5924. GetCurrentZone()->SendQuestUpdates(this);
  5925. }
  5926. }
  5927. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5928. if (!quest || !progress) {
  5929. return;
  5930. }
  5931. map<int32, int32>::iterator itr;
  5932. QuestStep* step = 0;
  5933. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5934. step = quest->GetQuestStep(itr->first);
  5935. if (step && itr->second > 0) {
  5936. step->SetStepProgress(itr->second);
  5937. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5938. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5939. }
  5940. }
  5941. if (lua_interface && step)
  5942. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5943. else if(!step) {
  5944. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5945. }
  5946. }
  5947. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5948. bool lockCleared = false;
  5949. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5950. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  5951. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5952. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5953. int32 questID = quest->GetQuestID();
  5954. lockCleared = true;
  5955. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5956. RemovePlayerQuest(questID, false, false);
  5957. }
  5958. player->player_quests[quest->GetQuestID()] = quest;
  5959. if(!lockCleared)
  5960. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5961. quest->SetPlayer(player);
  5962. quest->SetSaveNeeded(true);
  5963. current_quest_id = quest->GetQuestID();
  5964. if (send_packets && quest->GetQuestGiver() > 0)
  5965. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5966. if (lua_interface && call_accepted)
  5967. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5968. if (send_packets) {
  5969. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5970. //SendQuestJournal();
  5971. SendQuestJournalUpdate(quest);
  5972. // sent twice to match live
  5973. quest->SetTracked(false);
  5974. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5975. quest->SetTracked(true);
  5976. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5977. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5978. }
  5979. //This isn't during a load screen, so update spawns with required quests
  5980. if (call_accepted)
  5981. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5982. }
  5983. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5984. if (current_quest_id == id)
  5985. current_quest_id = 0;
  5986. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5987. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  5988. if (delete_quest) {
  5989. player->player_quests[id]->SetDeleted(true);
  5990. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5991. }
  5992. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5993. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5994. if (send_update && quest_giver > 0)
  5995. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5996. if (send_update) {
  5997. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5998. SendQuestJournal(false, 0, true);
  5999. }
  6000. player->RemoveQuest(id, delete_quest);
  6001. if (send_update) {
  6002. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6003. SendQuestJournal(false, 0, true);
  6004. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  6005. }
  6006. }
  6007. else {
  6008. // if we don't have any quests to count then release the write lock
  6009. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  6010. }
  6011. }
  6012. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6013. if (quest) {
  6014. QuestStep* quest_step = quest->GetQuestStep(step);
  6015. if (quest_step) {
  6016. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6017. quest_step->WasUpdated(false);
  6018. }
  6019. }
  6020. }
  6021. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6022. QueuedQuest* item = new QueuedQuest;
  6023. item->quest_id = quest->GetQuestID();
  6024. item->step = step;
  6025. item->display_quest_helper = display_quest_helper;
  6026. MQuestQueue.writelock();
  6027. quest_queue.push_back(item);
  6028. last_update_time = Timer::GetCurrentTime2();
  6029. MQuestQueue.releasewritelock();
  6030. }
  6031. void Client::SendQuestFailure(Quest* quest) {
  6032. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6033. if (failures) {
  6034. QuestStep* step = 0;
  6035. for (int32 i = 0; i < failures->size(); i++) {
  6036. step = failures->at(i);
  6037. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6038. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6039. SendQuestJournal(false, 0, true);
  6040. }
  6041. failures->clear();
  6042. }
  6043. }
  6044. void Client::SendQuestUpdate(Quest* quest) {
  6045. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6046. if (updates) {
  6047. QuestStep* step = 0;
  6048. bool updated = false;
  6049. for (int32 i = 0; i < updates->size(); i++) {
  6050. step = updates->at(i);
  6051. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6052. {
  6053. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6054. SendQuestUpdateStep(quest, step->GetStepID());
  6055. updated = true;
  6056. }
  6057. if (step->WasUpdated()) {
  6058. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6059. SendQuestJournal(false, 0, true);
  6060. if(!updated)
  6061. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6062. updated = true;
  6063. }
  6064. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6065. }
  6066. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6067. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6068. SendQuestJournalUpdate(quest, true);
  6069. }
  6070. if (quest->GetCompleted()) {
  6071. if (quest->GetQuestReturnNPC() > 0)
  6072. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6073. if (quest->GetCompletedFlag())
  6074. quest->SetCompletedFlag(false);
  6075. }
  6076. updates->clear();
  6077. }
  6078. }
  6079. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6080. if (!client)
  6081. client = this;
  6082. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6083. if (packet) {
  6084. EQ2Packet* outapp = packet->serialize();
  6085. //DumpPacket(outapp);
  6086. client->QueuePacket(outapp);
  6087. safe_delete(packet);
  6088. }
  6089. }
  6090. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6091. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6092. if (packet) {
  6093. QueuePacket(packet->serialize());
  6094. safe_delete(packet);
  6095. }
  6096. }
  6097. void Client::ReloadQuests() {
  6098. vector<int32> ids = player->GetQuestIDs();
  6099. Quest* quest = 0;
  6100. for (int32 i = 0; i < ids.size(); i++) {
  6101. quest = master_quest_list.GetQuest(ids[i]);
  6102. if (quest)
  6103. AddPlayerQuest(quest, false);
  6104. else
  6105. RemovePlayerQuest(ids[i]);
  6106. }
  6107. }
  6108. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6109. std::unique_lock lock(MPendingQuestAccept);
  6110. bool found_quest = false;
  6111. vector<int32>::iterator itr;
  6112. int32 questID = 0;
  6113. Quest* quest = nullptr;
  6114. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6115. questID = *itr;
  6116. bool quest_exists = false;
  6117. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6118. if(!quest_exists) {
  6119. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6120. itr = pending_quest_accept.erase(itr);
  6121. quest = nullptr;
  6122. continue;
  6123. }
  6124. else if (quest) {
  6125. pending_quest_accept.erase(itr);
  6126. break;
  6127. }
  6128. itr++;
  6129. }
  6130. return quest;
  6131. }
  6132. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6133. int8 num_slots_needed = 0;
  6134. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6135. Item* master_item = 0;
  6136. if (item_id > 0) {
  6137. num_slots_needed++;
  6138. master_item = master_item_list.GetItem(item_id);
  6139. }
  6140. int32 totalItems = 0;
  6141. vector<Item*>* items = 0;
  6142. vector<Item*>* tmpItems = 0;
  6143. bool isTempState = quest->GetQuestTemporaryState();
  6144. if(isTempState)
  6145. {
  6146. tmpItems = quest->GetTmpRewardItems();
  6147. if (tmpItems && tmpItems->size() > 0)
  6148. {
  6149. num_slots_needed += tmpItems->size();
  6150. totalItems += tmpItems->size();
  6151. }
  6152. }
  6153. else
  6154. {
  6155. items = quest->GetRewardItems();
  6156. if (items && items->size() > 0)
  6157. {
  6158. num_slots_needed += items->size();
  6159. totalItems += items->size();
  6160. }
  6161. }
  6162. RemoveQueuedQuestReward();
  6163. GetPlayer()->SetActiveReward(false);
  6164. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6165. if (master_item)
  6166. AddItem(item_id);
  6167. if (tmpItems && tmpItems->size() > 0) {
  6168. for (int32 i = 0; i < tmpItems->size(); i++)
  6169. AddItem(new Item(tmpItems->at(i)));
  6170. }
  6171. if (items && items->size() > 0) {
  6172. for (int32 i = 0; i < items->size(); i++)
  6173. AddItem(new Item(items->at(i)));
  6174. }
  6175. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6176. if (outapp)
  6177. QueuePacket(outapp);
  6178. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6179. map<int32, sint32>::iterator itr;
  6180. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6181. int32 faction_id = itr->first;
  6182. sint32 amount = itr->second;
  6183. if (amount > 0)
  6184. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6185. else
  6186. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6187. }
  6188. if(quest->GetQuestTemporaryState())
  6189. {
  6190. int64 total_coins = quest->GetCoinTmpReward();
  6191. if (total_coins > 0)
  6192. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6193. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6194. }
  6195. else {
  6196. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6197. }
  6198. quest->SetQuestTemporaryState(false);
  6199. player->SetCharSheetChanged(true);
  6200. }
  6201. else {
  6202. GetPlayer()->SetActiveReward(true);
  6203. AddPendingQuestAcceptReward(quest);
  6204. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6205. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6206. }
  6207. }
  6208. void Client::DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards, vector<Item*>* selectable_rewards, map<int32, sint32>* factions, const char* header, int32 status_points, const char* text, bool was_displayed) {
  6209. if (coin == 0 && (!rewards || rewards->size() == 0) && (!selectable_rewards || selectable_rewards->size() == 0) && (!factions || factions->size() == 0) && status_points == 0 && text == 0 && (!quest || (quest->GetCoinsReward() == 0 && quest->GetCoinsRewardMax() == 0))) {
  6210. /*if (quest)
  6211. text = quest->GetName();
  6212. else*/
  6213. return;//nothing to give
  6214. }
  6215. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6216. GetPlayer()->ClearPendingItemRewards();
  6217. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6218. if (packet2) {
  6219. int32 source_id = 0;
  6220. if (quest)
  6221. source_id = quest->GetQuestID();
  6222. int64 rewarded_coin = 0;
  6223. if (quest) {
  6224. if (quest->GetCoinsReward() > 0) {
  6225. if (quest->GetCoinsRewardMax() > 0)
  6226. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6227. else
  6228. rewarded_coin = quest->GetCoinsReward();
  6229. }
  6230. quest->SetGeneratedCoin(rewarded_coin);
  6231. }
  6232. if (rewarded_coin > coin)
  6233. coin = rewarded_coin;
  6234. if (!quest && !was_displayed) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6235. if (coin > 0) {
  6236. player->AddCoins(coin);
  6237. PlaySound("coin_cha_ching");
  6238. }
  6239. }
  6240. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6241. packet2->setSubstructDataByName("reward_data", "reward", header);
  6242. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6243. if (player->GetGuild() && !was_displayed) {
  6244. if (!quest) { //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6245. player->GetInfoStruct()->add_status_points(status_points);
  6246. player->SetCharSheetChanged(true);
  6247. }
  6248. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6249. }
  6250. if(text)
  6251. packet2->setSubstructDataByName("reward_data", "text", text);
  6252. std::vector<Item*> items;
  6253. quest->GetTmpRewardItemsByID(&items);
  6254. if(rewards || items.size() > 0){
  6255. int32 item_count = items.size();
  6256. item_count += rewards ? rewards->size() : 0;
  6257. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6258. int i = 0;
  6259. if(rewards) {
  6260. for (i = 0; i < rewards->size(); i++) {
  6261. Item* item = rewards->at(i);
  6262. if (item) {
  6263. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6264. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6265. }
  6266. if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6267. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6268. }
  6269. }
  6270. for (int j = 0; j < items.size(); j++) {
  6271. Item* item = items.at(j);
  6272. if (item) {
  6273. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6274. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6275. }
  6276. if(!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6277. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6278. i++;
  6279. }
  6280. }
  6281. if (selectable_rewards) {
  6282. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6283. for (int i = 0; i < selectable_rewards->size(); i++) {
  6284. Item* item = selectable_rewards->at(i);
  6285. if (item) {
  6286. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6287. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  6288. if (!quest) //this entire function is either for version <=561 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6289. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6290. }
  6291. }
  6292. }
  6293. if (factions) {
  6294. map<int32, sint32>::iterator itr;
  6295. map<Faction*, signed int> factions_map;
  6296. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6297. Faction* faction = master_faction_list.GetFaction(itr->first);
  6298. if (faction)
  6299. factions_map[faction] = itr->second;
  6300. }
  6301. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6302. map<Faction*, signed int>::iterator faction_itr;
  6303. int8 i = 0;
  6304. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6305. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6306. sint32 amount = faction_itr->second;
  6307. packet2->setArrayDataByName("amount", amount, i);
  6308. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6309. if (amount > 0)
  6310. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6311. else
  6312. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6313. }
  6314. i++;
  6315. }
  6316. }
  6317. QueuePacket(packet2->serialize());
  6318. safe_delete(packet2);
  6319. }
  6320. }
  6321. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6322. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6323. if(!items || !packet)
  6324. return;
  6325. if (items) {
  6326. int32 total_item_count = 0;
  6327. for(int s=0;s<items->size();s++) {
  6328. Item* tmpItem = items->at(s);
  6329. if(tmpItem) {
  6330. if(tmpItem->details.count > 1) {
  6331. total_item_count += tmpItem->details.count;
  6332. }
  6333. else {
  6334. total_item_count += 1;
  6335. }
  6336. }
  6337. }
  6338. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6339. int16 count = 0;
  6340. int16 pos = 0;
  6341. for (int32 i = 0; i < items->size();) {
  6342. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6343. if (version < 860)
  6344. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, -1);
  6345. else if (version < 1193)
  6346. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6347. else
  6348. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6349. pos++;
  6350. if(count >= items->at(i)->details.count-1) {
  6351. count = 0;
  6352. }
  6353. else if(items->at(i)->details.count > 1) {
  6354. count++;
  6355. continue;
  6356. }
  6357. i++;
  6358. }
  6359. }
  6360. }
  6361. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6362. if (!quest)
  6363. return;
  6364. if (GetVersion() <= 561) {
  6365. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6366. return;
  6367. }
  6368. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6369. if (packet) {
  6370. packet->setDataByName("title", "Quest Reward!");
  6371. packet->setDataByName("name", quest->GetName());
  6372. if(tempReward)
  6373. {
  6374. packet->setDataByName("description", customDescription.c_str());
  6375. }
  6376. else
  6377. packet->setDataByName("description", quest->GetCompletedDescription());
  6378. packet->setDataByName("level", quest->GetLevel());
  6379. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6380. int8 difficulty = 0;
  6381. if ((string)quest->GetType() == "Tradeskill")
  6382. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6383. else
  6384. difficulty = player->GetArrowColor(quest->GetLevel());
  6385. packet->setDataByName("difficulty", difficulty);
  6386. if(tempReward)
  6387. {
  6388. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6389. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6390. packet->setDataByName("status_points", quest->GetStatusPoints());
  6391. }
  6392. else
  6393. {
  6394. int64 rewarded_coin = 0;
  6395. if (quest->GetCoinsReward() > 0) {
  6396. if (quest->GetCoinsRewardMax() > 0)
  6397. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6398. else
  6399. rewarded_coin = quest->GetCoinsReward();
  6400. }
  6401. quest->SetGeneratedCoin(rewarded_coin);
  6402. packet->setDataByName("max_coin", rewarded_coin);
  6403. packet->setDataByName("min_coin", rewarded_coin);
  6404. packet->setDataByName("status_points", quest->GetStatusPoints());
  6405. }
  6406. if(tempReward) {
  6407. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6408. }
  6409. else
  6410. {
  6411. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6412. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6413. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6414. std::string("select_reward_id"), std::string("select_item"));
  6415. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6416. if (reward_factions && reward_factions->size() > 0) {
  6417. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6418. map<int32, sint32>::iterator itr;
  6419. int16 index = 0;
  6420. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6421. int32 faction_id = itr->first;
  6422. sint32 amount = itr->second;
  6423. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6424. if (faction_name) {
  6425. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6426. packet->setArrayDataByName("amount", amount, index);
  6427. }
  6428. index++;
  6429. }
  6430. }
  6431. }
  6432. EQ2Packet* outapp = packet->serialize();
  6433. // DumpPacket(outapp);
  6434. QueuePacket(outapp);
  6435. safe_delete(packet);
  6436. }
  6437. }
  6438. void Client::DisplayRandomizeFeatures(int32 flags) {
  6439. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6440. if (flags > 0) {
  6441. if (flags & RANDOMIZE_GENDER)
  6442. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6443. if (flags & RANDOMIZE_RACE)
  6444. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6445. if (flags & RANDOMIZE_MODEL_TYPE)
  6446. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6447. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6448. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6449. if (flags & RANDOMIZE_HAIR_TYPE)
  6450. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6451. if (flags & RANDOMIZE_WING_TYPE)
  6452. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6453. if (flags & RANDOMIZE_CHEEK_TYPE)
  6454. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6455. if (flags & RANDOMIZE_CHIN_TYPE)
  6456. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6457. if (flags & RANDOMIZE_EAR_TYPE)
  6458. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6459. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6460. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6461. if (flags & RANDOMIZE_EYE_TYPE)
  6462. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6463. if (flags & RANDOMIZE_LIP_TYPE)
  6464. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6465. if (flags & RANDOMIZE_NOSE_TYPE)
  6466. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6467. if (flags & RANDOMIZE_EYE_COLOR)
  6468. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6469. if (flags & RANDOMIZE_HAIR_COLOR1)
  6470. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6471. if (flags & RANDOMIZE_HAIR_COLOR2)
  6472. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6473. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6474. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6475. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6476. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6477. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6478. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6479. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6480. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6481. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6482. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6483. if (flags & RANDOMIZE_SKIN_COLOR)
  6484. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6485. if (flags & RANDOMIZE_WING_COLOR1)
  6486. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6487. if (flags & RANDOMIZE_WING_COLOR2)
  6488. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6489. }
  6490. else
  6491. {
  6492. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6493. }
  6494. }
  6495. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6496. current_quest_id = 0;
  6497. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6498. {
  6499. quest->IncrementCompleteCount();
  6500. player->AddCompletedQuest(quest);
  6501. }
  6502. AddPendingQuestAcceptReward(quest);
  6503. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6504. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6505. SendQuestJournal();
  6506. if(quest->GetQuestTemporaryState()) {
  6507. return;
  6508. }
  6509. if(!has_displayed) {
  6510. if (quest->GetExpReward() > 0) {
  6511. int32 xp = quest->GetExpReward();
  6512. player->AddXP(xp);
  6513. }
  6514. if (quest->GetTSExpReward() > 0) {
  6515. int8 ts_level = player->GetTSLevel();
  6516. int32 xp = quest->GetTSExpReward();
  6517. if (player->AddTSXP(xp)) {
  6518. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6519. if (player->GetTSLevel() != ts_level)
  6520. ChangeTSLevel(ts_level, player->GetTSLevel());
  6521. player->SetCharSheetChanged(true);
  6522. }
  6523. }
  6524. int64 total_coins = quest->GetGeneratedCoin();
  6525. if (total_coins > 0)
  6526. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6527. player->RemoveQuest(quest->GetQuestID(), false);
  6528. }
  6529. if (quest->GetQuestGiver() > 0)
  6530. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6531. if(!has_displayed) {
  6532. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6533. }
  6534. }
  6535. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6536. std::unique_lock lock(MConversation);
  6537. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6538. if (packet) {
  6539. packet->setDataByName("conversation_id", conversation_id);
  6540. packet->setDataByName("text", text);
  6541. packet->setDataByName("language", language); // default 0
  6542. packet->setDataByName("enable_blue_ui", 0); // default 0
  6543. packet->setDataByName("can_close", can_close); // default 1
  6544. conversation_map[conversation_id].clear();
  6545. if (conversations) {
  6546. packet->setArrayLengthByName("num_responses", conversations->size());
  6547. for (int32 i = 0; i < conversations->size(); i++) {
  6548. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6549. if (conversations->at(i).function.length() > 0)
  6550. conversation_map[conversation_id][i] = conversations->at(i).function;
  6551. }
  6552. }
  6553. packet->setDataByName("spawn_id", spawn_id);
  6554. if (mp3) {
  6555. packet->setDataByName("voice", mp3);
  6556. packet->setDataByName("key1", key1);
  6557. packet->setDataByName("key2", key2);
  6558. }
  6559. QueuePacket(packet->serialize());
  6560. safe_delete(packet);
  6561. }
  6562. }
  6563. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6564. if (!item || !text || !conversations || conversations->size() == 0) {
  6565. return;
  6566. }
  6567. int32 conversation_id = GetConversationID(0, item);
  6568. if (conversation_id == 0) {
  6569. next_conversation_id++;
  6570. conversation_id = next_conversation_id;
  6571. }
  6572. MConversation.lock();
  6573. conversation_items[conversation_id] = item;
  6574. MConversation.unlock();
  6575. if (type == 4)
  6576. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6577. else
  6578. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6579. }
  6580. void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2, int8 language, int8 can_close) {
  6581. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6582. return;
  6583. }
  6584. int32 conversation_id = GetConversationID(src, 0);
  6585. if (conversation_id == 0) {
  6586. next_conversation_id++;
  6587. conversation_id = next_conversation_id;
  6588. }
  6589. MConversation.lock();
  6590. conversation_spawns[conversation_id] = src->GetID();
  6591. MConversation.unlock();
  6592. /* Spawns can start two different types of conversations.
  6593. * Type 1: The chat type with bubbles.
  6594. * Type 2: The dialog type with the blue box. */
  6595. if (type == 1)
  6596. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6597. else if (type == 2)
  6598. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6599. else //if (type == 3)
  6600. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6601. }
  6602. void Client::CloseDialog(int32 conversation_id) {
  6603. std::unique_lock lock(MConversation);
  6604. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6605. if (packet) {
  6606. packet->setDataByName("conversation_id", conversation_id);
  6607. QueuePacket(packet->serialize());
  6608. safe_delete(packet);
  6609. }
  6610. std::map<int32, Item*>::iterator itr;
  6611. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6612. {
  6613. conversation_items.erase(itr);
  6614. }
  6615. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6616. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6617. {
  6618. conversation_spawns.erase(itr2);
  6619. }
  6620. }
  6621. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6622. std::shared_lock lock(MConversation);
  6623. int32 conversation_id = 0;
  6624. if (spawn) {
  6625. map<int32, int32>::iterator itr;
  6626. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6627. if (itr->second == spawn->GetID()) {
  6628. conversation_id = itr->first;
  6629. break;
  6630. }
  6631. }
  6632. }
  6633. else if (item) {
  6634. map<int32, Item*>::iterator itr;
  6635. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6636. if (itr->second == item) {
  6637. conversation_id = itr->first;
  6638. break;
  6639. }
  6640. }
  6641. }
  6642. return conversation_id;
  6643. }
  6644. Spawn* Client::GetCombineSpawn() {
  6645. return combine_spawn;
  6646. }
  6647. bool Client::ShouldTarget() {
  6648. return should_target;
  6649. }
  6650. void Client::TargetSpawn(Spawn* spawn) {
  6651. should_target = false;
  6652. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6653. if (packet) {
  6654. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6655. QueuePacket(packet->serialize());
  6656. safe_delete(packet);
  6657. }
  6658. }
  6659. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6660. combine_spawn = spawn;
  6661. spawn->RemoveSpawnFromGroup(true);
  6662. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6663. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6664. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6665. should_target = true;
  6666. }
  6667. void Client::AddCombineSpawn(Spawn* spawn) {
  6668. if (combine_spawn && combine_spawn != spawn && spawn) {
  6669. combine_spawn->AddSpawnToGroup(spawn);
  6670. spawn->AddSpawnToGroup(combine_spawn);
  6671. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6672. }
  6673. else if (spawn)
  6674. combine_spawn = spawn;
  6675. should_target = true;
  6676. }
  6677. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6678. if (combine_spawn && spawn)
  6679. spawn->RemoveSpawnFromGroup();
  6680. if (combine_spawn == spawn)
  6681. combine_spawn->RemoveSpawnFromGroup(true);
  6682. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6683. if (combine_spawn == spawn)
  6684. combine_spawn = 0;
  6685. }
  6686. void Client::SaveCombineSpawns(const char* name) {
  6687. if (!combine_spawn) {
  6688. return;
  6689. }
  6690. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6691. if (!spawns) {
  6692. return;
  6693. }
  6694. int32 count = spawns->size();
  6695. int32 spawnLocationID = 0;
  6696. if (count == 1)
  6697. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6698. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6699. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6700. // we remove the spawn inside SaveCombinedSpawnLocation
  6701. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6702. }
  6703. else
  6704. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6705. safe_delete(spawns);
  6706. combine_spawn = 0;
  6707. }
  6708. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6709. Item* master_item = master_item_list.GetItem(item_id);
  6710. Item* item = 0;
  6711. if (master_item)
  6712. item = new Item(master_item);
  6713. if (item) {
  6714. if (quantity > 0)
  6715. item->details.count = quantity;
  6716. return AddItem(item, nullptr, type);
  6717. }
  6718. else
  6719. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6720. return false;
  6721. }
  6722. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6723. if (!item) {
  6724. return false;
  6725. }
  6726. if (player->AddItem(item, type)) {
  6727. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6728. if (outapp) {
  6729. //DumpPacket(outapp);
  6730. QueuePacket(outapp);
  6731. //resend bag desc with new item name added
  6732. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6733. if (outapp) {
  6734. //DumpPacket(outapp);
  6735. QueuePacket(outapp);
  6736. }
  6737. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6738. DumpPacket(app);
  6739. client->QueuePacket(app);
  6740. */
  6741. }
  6742. CheckPlayerQuestsItemUpdate(item);
  6743. if (item->GetItemScript() && lua_interface)
  6744. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6745. }
  6746. else {
  6747. lua_interface->SetLuaUserDataStale(item);
  6748. // likely lore conflict
  6749. if(item_deleted)
  6750. *item_deleted = true;
  6751. return false;
  6752. }
  6753. return true;
  6754. }
  6755. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6756. Item* master_item = master_item_list.GetItem(item_id);
  6757. Item* item = 0;
  6758. if (master_item)
  6759. item = new Item(master_item);
  6760. if (item) {
  6761. if (quantity > 0)
  6762. item->details.count = quantity;
  6763. return AddItemToBank(item);
  6764. }
  6765. else
  6766. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6767. return false;
  6768. }
  6769. bool Client::AddItemToBank(Item* item) {
  6770. if (!item) {
  6771. return false;
  6772. }
  6773. if (player->AddItemToBank(item)) {
  6774. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6775. if (outapp) {
  6776. QueuePacket(outapp);
  6777. //resend bag desc with new item name added
  6778. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6779. if (outapp)
  6780. QueuePacket(outapp);
  6781. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6782. DumpPacket(app);
  6783. client->QueuePacket(app);
  6784. */
  6785. }
  6786. CheckPlayerQuestsItemUpdate(item);
  6787. if (item->GetItemScript() && lua_interface)
  6788. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6789. }
  6790. else {
  6791. lua_interface->SetLuaUserDataStale(item);
  6792. // likely lore conflict
  6793. safe_delete(item);
  6794. return false;
  6795. }
  6796. return true;
  6797. }
  6798. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6799. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6800. EQ2Packet* outapp = 0;
  6801. for(int32 i=0;i<packets.size();i++)
  6802. {
  6803. outapp = packets[i];
  6804. if(outapp)
  6805. QueuePacket(outapp);
  6806. }
  6807. GetPlayer()->UpdateWeapons();
  6808. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6809. QueuePacket(characterSheetPackets);
  6810. }
  6811. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6812. EQ2Packet* outapp;
  6813. bool delete_item = false;
  6814. assert(item);
  6815. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6816. item->details.count -= quantity;
  6817. item->save_needed = true;
  6818. }
  6819. else {
  6820. database.DeleteItem(character_id, item, 0);
  6821. player->GetPlayerItemList()->RemoveItem(item, false);
  6822. delete_item = true;
  6823. }
  6824. if(force_override_no_delete)
  6825. delete_item = false;
  6826. if ((outapp = player->SendInventoryUpdate(version))) {
  6827. QueuePacket(outapp);
  6828. if (item->GetItemScript() && lua_interface)
  6829. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6830. if (delete_item)
  6831. {
  6832. PurgeItem(item);
  6833. lua_interface->SetLuaUserDataStale(item);
  6834. safe_delete(item);
  6835. }
  6836. return true;
  6837. }
  6838. return false;
  6839. }
  6840. void Client::SetLuaDebugClient(bool val) {
  6841. if (val)
  6842. lua_debug_timer.Start();
  6843. lua_debug = val;
  6844. if (lua_interface && !val) {
  6845. lua_interface->RemoveDebugClients(this);
  6846. lua_debug_timer.Disable();
  6847. }
  6848. }
  6849. void Client::SetMerchantTransaction(Spawn* spawn) {
  6850. merchant_transaction = spawn;
  6851. }
  6852. Spawn* Client::GetMerchantTransaction() {
  6853. return merchant_transaction;
  6854. }
  6855. void Client::SetMailTransaction(Spawn* spawn) {
  6856. ResetSendMail(spawn ? false : true);
  6857. MMailWindowMutex.lock();
  6858. mail_transaction = spawn;
  6859. MMailWindowMutex.unlock();
  6860. }
  6861. Spawn* Client::GetMailTransaction() {
  6862. return mail_transaction;
  6863. }
  6864. void Client::PlaySound(const char* name) {
  6865. if (name) {
  6866. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6867. if (packet) {
  6868. packet->setMediumStringByName("name", name);
  6869. QueuePacket(packet->serialize());
  6870. safe_delete(packet);
  6871. }
  6872. }
  6873. }
  6874. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6875. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6876. if(multiplier){
  6877. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6878. float diff_low = faction_val - multiplier->faction_min;
  6879. if(diff_low < 0)
  6880. diff_low*=-1;
  6881. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6882. if(total_diff < 0)
  6883. total_diff*=-1;
  6884. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6885. float total1 = (diff_low/total_diff);
  6886. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6887. return final_buy_multiplier;
  6888. }*/
  6889. return 1;
  6890. }
  6891. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6892. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6893. if(multiplier){
  6894. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6895. float diff_low = faction_val - multiplier->faction_min;
  6896. if(diff_low < 0)
  6897. diff_low*=-1;
  6898. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6899. if(total_diff < 0)
  6900. total_diff*=-1;
  6901. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6902. float total1 = (diff_low/total_diff);
  6903. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6904. return final_sell_multiplier;
  6905. }*/
  6906. return 1;
  6907. }
  6908. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6909. Spawn* spawn = GetMerchantTransaction();
  6910. Guild* guild = GetPlayer()->GetGuild();
  6911. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6912. spawn->IsClientInMerchantLevelRange(this)) {
  6913. int32 total_sell_price = 0;
  6914. int32 total_status_sell_price = 0; //for status
  6915. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6916. int32 sell_price = 0;
  6917. int32 status_sell_price = 0; //for status
  6918. Item* master_item = master_item_list.GetItem(item_id);
  6919. Item* item = 0;
  6920. if (unique_id == 0)
  6921. item = player->item_list.GetItemFromID(item_id, quantity);
  6922. else
  6923. item = player->item_list.GetItemFromUniqueID(unique_id);
  6924. if (!item)
  6925. item = player->item_list.GetItemFromID(item_id);
  6926. if (item && master_item) {
  6927. if(item->details.item_locked)
  6928. {
  6929. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6930. return;
  6931. }
  6932. else if(item->CheckFlag(NO_VALUE))
  6933. {
  6934. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6935. return;
  6936. }
  6937. else if (item->IsBag())
  6938. {
  6939. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  6940. if (bagitemcount > 0) {
  6941. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  6942. return;
  6943. }
  6944. }
  6945. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6946. if (sell_price > item->sell_price)
  6947. sell_price = item->sell_price;
  6948. if (quantity > item->details.count)
  6949. quantity = item->details.count;
  6950. total_sell_price = sell_price * quantity;
  6951. //------------------------------For Selling Status Items
  6952. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6953. if (status_sell_price > item->sell_status)
  6954. status_sell_price = item->sell_status;
  6955. if (quantity > item->details.count)
  6956. quantity = item->details.count;
  6957. total_status_sell_price = status_sell_price * quantity;
  6958. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6959. total_status_sell_price = 0;
  6960. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6961. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6962. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6963. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6964. guild->SendGuildMemberList();
  6965. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6966. }
  6967. if (quantity > 1)
  6968. {
  6969. if(total_status_sell_price)
  6970. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s and %u Status Points.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6971. else
  6972. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  6973. }
  6974. else
  6975. {
  6976. if(total_status_sell_price)
  6977. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s and %u Status Points.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str(), status_sell_price);
  6978. else
  6979. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  6980. }
  6981. player->AddCoins(total_sell_price);
  6982. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6983. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6984. if (quantity >= item->details.count) {
  6985. database.DeleteItem(GetCharacterID(), item, 0);
  6986. player->item_list.DestroyItem(item->details.index);
  6987. }
  6988. else {
  6989. item->details.count -= quantity;
  6990. item->save_needed = true;
  6991. }
  6992. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6993. if (outapp)
  6994. QueuePacket(outapp);
  6995. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6996. SendBuyBackList();
  6997. }
  6998. }
  6999. }
  7000. void Client::BuyBack(int32 item_id, int16 quantity) {
  7001. Spawn* spawn = GetMerchantTransaction();
  7002. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  7003. spawn->IsClientInMerchantLevelRange(this)) {
  7004. deque<BuyBackItem*>::iterator itr;
  7005. BuyBackItem* buyback = 0;
  7006. BuyBackItem* closest = 0;
  7007. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7008. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7009. buyback = *itr;
  7010. if (buyback->unique_id == item_id) {
  7011. closest = buyback;
  7012. quantity = buyback->quantity;
  7013. break;
  7014. }
  7015. }
  7016. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7017. if (closest) {
  7018. Item* item = 0;
  7019. Item* master_item = master_item_list.GetItem(closest->item_id);
  7020. if (master_item) {
  7021. item = new Item(master_item);
  7022. if (closest->quantity >= quantity)
  7023. item->details.count = quantity;
  7024. else
  7025. item->details.count = closest->quantity;
  7026. }
  7027. bool itemDeleted = false;
  7028. bool itemAdded = false;
  7029. sint64 dispFlags = 0;
  7030. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7031. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7032. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7033. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7034. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7035. bool removed = false;
  7036. if (closest->quantity == quantity) {
  7037. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7038. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7039. if (*itr == closest) {
  7040. buy_back_items.erase(itr);
  7041. removed = true;
  7042. break;
  7043. }
  7044. }
  7045. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7046. }
  7047. else {
  7048. closest->quantity -= quantity;
  7049. closest->save_needed = true;
  7050. }
  7051. itemAdded = AddItem(item, &itemDeleted);
  7052. if (removed) {
  7053. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7054. safe_delete(closest);
  7055. }
  7056. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7057. SendBuyBackList();
  7058. }
  7059. else
  7060. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7061. if(!itemAdded && !itemDeleted) {
  7062. lua_interface->SetLuaUserDataStale(item);
  7063. safe_delete(item);
  7064. }
  7065. }
  7066. }
  7067. }
  7068. void Client::BuyItem(int32 item_id, int16 quantity) {
  7069. // Get the merchant we are buying from
  7070. Spawn* spawn = GetMerchantTransaction();
  7071. // Make sure the spawn has a merchant list
  7072. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7073. int32 total_buy_price = 0;
  7074. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7075. int32 sell_price = 0;
  7076. Item* master_item = master_item_list.GetItem(item_id);
  7077. Item* item = 0;
  7078. int16 total_available = 0;
  7079. vector<MerchantItemInfo>* temp;
  7080. vector<MerchantItemInfo>::iterator itr;
  7081. MerchantItemInfo* ItemInfo = 0;
  7082. temp = world.GetMerchantList(spawn->GetMerchantID());
  7083. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7084. if ((*itr).item_id == item_id) {
  7085. ItemInfo = &(*itr);
  7086. break;
  7087. }
  7088. }
  7089. if (master_item && ItemInfo) {
  7090. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7091. quantity = 1;
  7092. total_available = 0xFFFF;
  7093. sell_price = master_item->sell_price;
  7094. }
  7095. else {
  7096. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7097. sell_price = (int32)(master_item->sell_price * multiplier);
  7098. if (quantity > total_available)
  7099. quantity = total_available;
  7100. }
  7101. sint64 dispFlags = 0;
  7102. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7103. {
  7104. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7105. return;
  7106. }
  7107. if(quantity < 1)
  7108. {
  7109. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7110. return;
  7111. }
  7112. total_buy_price = sell_price * quantity;
  7113. item = new Item(master_item);
  7114. item->details.count = quantity;
  7115. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7116. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7117. lua_interface->SetLuaUserDataStale(item);
  7118. safe_delete(item);
  7119. }
  7120. else {
  7121. // Price not set in the merchant_inventory table, use the old method
  7122. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7123. if (player->RemoveCoins(total_buy_price)) {
  7124. item->SetMaxSellValue(sell_price);
  7125. if (quantity > 1)
  7126. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  7127. else
  7128. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  7129. bool itemDeleted = false;
  7130. AddItem(item, &itemDeleted);
  7131. if(!itemDeleted) {
  7132. CheckPlayerQuestsItemUpdate(item);
  7133. if (item && total_available < 0xFF) {
  7134. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7135. SendBuyMerchantList();
  7136. }
  7137. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7138. PlayLotto(total_buy_price, item->details.item_id);
  7139. }
  7140. }
  7141. else {
  7142. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7143. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7144. PlaySound("buy_failed");
  7145. }
  7146. }
  7147. else {
  7148. // Price set in merchant_inventory table
  7149. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7150. // TODO: need to add support for station cash
  7151. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7152. // Check items
  7153. int16 item_quantity = 0;
  7154. // Default these to true in case price_item_id or price_item2_id was never set
  7155. bool hasItem1 = true;
  7156. bool hasItem2 = true;
  7157. Item* tempItem1 = 0;
  7158. Item* tempItem2 = 0;
  7159. if (ItemInfo->price_item_id != 0) {
  7160. // Same item for whatever reason lets add the quantities together
  7161. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7162. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7163. else
  7164. item_quantity = ItemInfo->price_item_qty;
  7165. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7166. if (tempItem1) {
  7167. if (tempItem1->details.count < item_quantity)
  7168. hasItem1 = false;
  7169. }
  7170. else {
  7171. hasItem1 = false;
  7172. }
  7173. }
  7174. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7175. // as item1 and we already checked for it so we can skip this check
  7176. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7177. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7178. if (tempItem2) {
  7179. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7180. hasItem2 = false;
  7181. }
  7182. else {
  7183. hasItem2 = false;
  7184. }
  7185. }
  7186. // if we have every thing then remove the price and give the item
  7187. if (hasItem1 && hasItem2) {
  7188. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7189. // TODO: station cash
  7190. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7191. // so there is no need to send it more then that one time
  7192. if (tempItem1) {
  7193. if (tempItem1->details.count > item_quantity) {
  7194. tempItem1->details.count -= item_quantity;
  7195. tempItem1->save_needed = true;
  7196. }
  7197. else {
  7198. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7199. player->item_list.DestroyItem(tempItem1->details.index);
  7200. }
  7201. }
  7202. if (tempItem2) {
  7203. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7204. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7205. tempItem2->save_needed = true;
  7206. }
  7207. else {
  7208. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7209. player->item_list.DestroyItem(tempItem2->details.index);
  7210. }
  7211. }
  7212. // 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
  7213. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7214. item->SetMaxSellValue(sell_price);
  7215. if (quantity > 1)
  7216. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  7217. else
  7218. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  7219. bool itemDeleted = false;
  7220. AddItem(item, &itemDeleted);
  7221. if(!itemDeleted) {
  7222. CheckPlayerQuestsItemUpdate(item);
  7223. if (item && total_available < 0xFF) {
  7224. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7225. SendBuyMerchantList();
  7226. }
  7227. SendSellMerchantList();
  7228. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7229. PlayLotto(total_buy_price, item->details.item_id);
  7230. }
  7231. }
  7232. else {
  7233. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7234. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7235. PlaySound("buy_failed");
  7236. }
  7237. }
  7238. else {
  7239. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7240. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7241. PlaySound("buy_failed");
  7242. }
  7243. }
  7244. }
  7245. }
  7246. }
  7247. }
  7248. void Client::RepairItem(int32 item_id) {
  7249. Spawn* spawn = GetMerchantTransaction();
  7250. if (spawn) {
  7251. Item* item = player->item_list.GetItemFromID(item_id);
  7252. if (!item)
  7253. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7254. if (item) {
  7255. if(item->CheckFlag2(NO_REPAIR)) {
  7256. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7257. PlaySound("buy_failed");
  7258. }
  7259. else {
  7260. int32 repair_cost = item->CalculateRepairCost();
  7261. if (player->RemoveCoins((int32)repair_cost)) {
  7262. item->generic_info.condition = 100;
  7263. item->save_needed = true;
  7264. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7265. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7266. QueuePacket(item->serialize(version, false, player));
  7267. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7268. PlaySound("coin_cha_ching");
  7269. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7270. SendRepairList();
  7271. }
  7272. else {
  7273. string popup_text = "You do not have enough coin to repair ";
  7274. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7275. popup_text.append(popup_item);
  7276. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7277. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7278. PlaySound("buy_failed");
  7279. }
  7280. }
  7281. }
  7282. }
  7283. }
  7284. void Client::RepairAllItems() {
  7285. Spawn* spawn = GetMerchantTransaction();
  7286. if (spawn) {
  7287. vector<Item*>* repairable_items = GetRepairableItems();
  7288. if (repairable_items && repairable_items->size() > 0) {
  7289. vector<Item*>::iterator itr;
  7290. int64 total_cost = 0;
  7291. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7292. total_cost += (*itr)->CalculateRepairCost();
  7293. if (player->RemoveCoins((int32)total_cost)) {
  7294. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7295. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7296. Item* item = *itr;
  7297. if (item) {
  7298. item->generic_info.condition = 100;
  7299. item->save_needed = true;
  7300. QueuePacket(item->serialize(version, false, player));
  7301. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7302. }
  7303. }
  7304. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7305. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7306. PlaySound("coin_cha_ching");
  7307. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7308. SendRepairList();
  7309. }
  7310. else {
  7311. string popup_text = "You do not have enough coin to repair all of your items. ";
  7312. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7313. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7314. PlaySound("buy_failed");
  7315. }
  7316. }
  7317. safe_delete(repairable_items);
  7318. }
  7319. }
  7320. void Client::SendAchievementsList()
  7321. {
  7322. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7323. map<int32, Achievement *>::iterator itr;
  7324. Achievement *achievement;
  7325. vector<AchievementRequirements *> *requirements = 0;
  7326. vector<AchievementRequirements *>::iterator itr2;
  7327. AchievementRequirements *requirement;
  7328. vector<AchievementRewards *> *rewards = 0;
  7329. vector<AchievementRewards *>::iterator itr3;
  7330. AchievementRewards *reward;
  7331. PacketStruct *packet;
  7332. int16 i = 0;
  7333. int16 j = 0;
  7334. int16 k = 0;
  7335. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7336. return;
  7337. }
  7338. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7339. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7340. achievement = itr->second;
  7341. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7342. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7343. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7344. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7345. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7346. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7347. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7348. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7349. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7350. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7351. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7352. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7353. requirements = achievement->GetRequirements();
  7354. rewards = achievement->GetRewards();
  7355. j = 0;
  7356. k = 0;
  7357. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7358. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7359. requirement = *itr2;
  7360. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7361. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7362. j++;
  7363. }
  7364. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7365. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7366. reward = *itr3;
  7367. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7368. k++;
  7369. }
  7370. i++;
  7371. }
  7372. //packet->PrintPacket();
  7373. EQ2Packet* data = packet->serialize();
  7374. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7375. safe_delete(packet);
  7376. safe_delete(data);
  7377. //DumpPacket(app);
  7378. QueuePacket(app);*/
  7379. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7380. SendAchievementUpdate(true);
  7381. }
  7382. void Client::SendAchievementUpdate(bool first_login) {
  7383. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7384. map<int32, AchievementUpdate*>::iterator itr;
  7385. AchievementUpdate* update;
  7386. vector<AchievementUpdateItems*>* update_items = 0;
  7387. vector<AchievementUpdateItems*>::iterator itr2;
  7388. AchievementUpdateItems* update_item;
  7389. int16 i = 0;
  7390. int16 j = 0;
  7391. PacketStruct* packet;
  7392. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7393. return;
  7394. }
  7395. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7396. packet->setArrayLengthByName("num_achievements", updates->size());
  7397. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7398. update = itr->second;
  7399. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7400. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7401. update_items = update->GetUpdateItems();
  7402. j = 0;
  7403. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7404. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7405. update_item = *itr2;
  7406. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7407. j++;
  7408. }
  7409. i++;
  7410. }
  7411. //packet->PrintPacket();
  7412. EQ2Packet* data = packet->serialize();
  7413. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7414. safe_delete(packet);
  7415. safe_delete(data);
  7416. //DumpPacket(app);
  7417. QueuePacket(app);
  7418. }
  7419. void Client::SendBuyMerchantList(bool sell) {
  7420. Spawn* spawn = GetMerchantTransaction();
  7421. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7422. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7423. if (items) {
  7424. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7425. if (packet) {
  7426. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7427. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7428. packet->setArrayLengthByName("num_items", items->size());
  7429. vector<MerchantItemInfo>::iterator itr;
  7430. sint8 item_difficulty = 0;
  7431. int32 sell_price = 0;
  7432. int i = 0;
  7433. int tmp_level = 0;
  7434. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7435. MerchantItemInfo ItemInfo = *itr;
  7436. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7437. if (!item)
  7438. continue;
  7439. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7440. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7441. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7442. packet->setArrayDataByName("icon", item->details.icon, i);
  7443. if (item->generic_info.adventure_default_level > 0)
  7444. tmp_level = item->generic_info.adventure_default_level;
  7445. else
  7446. tmp_level = item->generic_info.tradeskill_default_level;
  7447. packet->setArrayDataByName("level", tmp_level, i);
  7448. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7449. packet->setArrayDataByName("tier", item->details.tier, i);
  7450. }
  7451. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7452. item_difficulty = player->GetArrowColor(tmp_level);
  7453. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7454. item_difficulty = ARROW_COLOR_WHITE;
  7455. sint64 overrideValue = 0;
  7456. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7457. item_difficulty = (sint8)overrideValue;
  7458. item_difficulty -= 6;
  7459. if (item_difficulty < 0)
  7460. item_difficulty *= -1;
  7461. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7462. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7463. packet->setArrayDataByName("unknown5", 255, i);
  7464. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7465. sint64 dispFlags = 0;
  7466. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7467. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7468. std::string overrideValueStr;
  7469. // classic client isn't properly tracking this field, DoF we don't have it identified yet, but no field to cause any issues (can add later if identified)
  7470. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7471. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7472. // If no price set in the merchant_inventory table then use the old method
  7473. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7474. sell_price = (int32)(item->sell_price * multiplier);
  7475. packet->setArrayDataByName("price", sell_price, i);
  7476. }
  7477. else {
  7478. int8 count = 0;
  7479. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7480. count++;
  7481. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7482. count++;
  7483. if (count != 0) {
  7484. packet->setSubArrayLengthByName("num_tokens", count, i);
  7485. int8 index = 0;
  7486. Item* token = 0;
  7487. if (ItemInfo.price_item_id != 0) {
  7488. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7489. if (item) {
  7490. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7491. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7492. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7493. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7494. }
  7495. token = 0;
  7496. index++;
  7497. }
  7498. if (ItemInfo.price_item2_id != 0) {
  7499. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7500. if (item) {
  7501. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7502. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7503. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7504. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7505. }
  7506. }
  7507. }
  7508. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7509. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7510. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7511. }
  7512. }
  7513. if (GetVersion() <= 546) {
  7514. //buy is 0 so dont need to set it
  7515. if (sell)
  7516. packet->setDataByName("type", 1);
  7517. }
  7518. else {
  7519. if (sell)
  7520. packet->setDataByName("type", 130);
  7521. else
  7522. packet->setDataByName("type", 2);
  7523. }
  7524. EQ2Packet* outapp = packet->serialize();
  7525. QueuePacket(outapp);
  7526. safe_delete(packet);
  7527. }
  7528. safe_delete(items);
  7529. }
  7530. else {
  7531. // Need to send an empty packet in the event there is no item list, otherwise the
  7532. // last item list sent to the player will show for this merchant
  7533. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7534. if (packet) {
  7535. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7536. if (GetVersion() <= 546) {
  7537. //buy is 0 so dont need to set it
  7538. if (sell)
  7539. packet->setDataByName("type", 1);
  7540. }
  7541. else {
  7542. if (sell)
  7543. packet->setDataByName("type", 130);
  7544. else
  7545. packet->setDataByName("type", 2);
  7546. }
  7547. EQ2Packet* outapp = packet->serialize();
  7548. QueuePacket(outapp);
  7549. safe_delete(packet);
  7550. }
  7551. }
  7552. }
  7553. }
  7554. void Client::SendSellMerchantList(bool sell) {
  7555. Spawn* spawn = GetMerchantTransaction();
  7556. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7557. return;
  7558. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7559. map<int32, Item*>* items = player->GetItemList();
  7560. if (items) {
  7561. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7562. if (packet) {
  7563. vector<Item*> sellable_items;
  7564. map<int32, Item*>::iterator test_itr;
  7565. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7566. bool isbagwithitems = false;
  7567. if (test_itr->second && test_itr->second->IsBag() && (test_itr->second->details.num_slots - test_itr->second->details.num_free_slots != test_itr->second->details.num_slots))
  7568. isbagwithitems = true;
  7569. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE) && (isbagwithitems == false) && (test_itr->second->details.inv_slot_id != -3) && (test_itr->second->details.inv_slot_id != -4))
  7570. sellable_items.push_back(test_itr->second);
  7571. }
  7572. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7573. packet->setArrayLengthByName("num_items", sellable_items.size());
  7574. vector<Item*>::iterator itr;
  7575. Item* item = 0;
  7576. sint8 item_difficulty = 0;
  7577. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7578. int32 sell_price = 0;
  7579. Item* master_item = 0;
  7580. int i = 0;
  7581. int tmp_level = 0;
  7582. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7583. item = *itr;
  7584. master_item = master_item_list.GetItem(item->details.item_id);
  7585. if (master_item)
  7586. sell_price = (int32)(master_item->sell_price * multiplier);
  7587. else
  7588. sell_price = 0;
  7589. if (sell_price > item->sell_price)
  7590. sell_price = item->sell_price;
  7591. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7592. string thename = item->name;
  7593. packet->setArrayDataByName("price", sell_price, i);
  7594. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7595. int8 dispFlags = 0;
  7596. // only city merchants allow selling for status
  7597. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7598. {
  7599. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7600. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7601. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7602. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7603. }
  7604. }
  7605. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7606. {
  7607. if(GetVersion() < 1188)
  7608. dispFlags += DISPLAY_FLAG_RED_TEXT; // for older clients it isn't "no buy back", you can either have 1 for red text or 255 for 'not for sale' to be checked
  7609. else
  7610. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7611. }
  7612. if(item->no_sale)
  7613. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7614. packet->setArrayDataByName("display_flags", dispFlags, i);
  7615. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7616. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7617. packet->setArrayDataByName("stack_size", item->details.count, i);
  7618. packet->setArrayDataByName("icon", item->details.icon, i);
  7619. if (item->generic_info.adventure_default_level > 0)
  7620. tmp_level = item->generic_info.adventure_default_level;
  7621. else
  7622. tmp_level = item->generic_info.tradeskill_default_level;
  7623. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7624. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7625. packet->setArrayDataByName("tier", item->details.tier, i);
  7626. }
  7627. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7628. item_difficulty = player->GetArrowColor(tmp_level);
  7629. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7630. item_difficulty = ARROW_COLOR_WHITE;
  7631. sint64 overrideValue = 0;
  7632. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7633. item_difficulty = (sint8)overrideValue;
  7634. item_difficulty -= 6;
  7635. if (item_difficulty < 0)
  7636. item_difficulty *= -1;
  7637. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7638. if (item->details.count == 1)
  7639. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7640. else
  7641. packet->setArrayDataByName("quantity", item->details.count, i);
  7642. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7643. if (GetVersion() <= 1096)
  7644. packet->setArrayDataByName("description", item->description.c_str(), i);
  7645. }
  7646. if (GetVersion() <= 546) {
  7647. packet->setDataByName("type", 1);
  7648. }
  7649. else {
  7650. if (sell)
  7651. packet->setDataByName("type", 129);
  7652. else
  7653. packet->setDataByName("type", 1);
  7654. }
  7655. packet->setDataByName("unknown8a", 16256, 6);
  7656. packet->setDataByName("unknown8a", 16256, 10);
  7657. //packet->PrintPacket();
  7658. EQ2Packet* outapp = packet->serialize();
  7659. //DumpPacket(outapp);
  7660. QueuePacket(outapp);
  7661. safe_delete(packet);
  7662. }
  7663. safe_delete(items);
  7664. }
  7665. }
  7666. }
  7667. void Client::SendBuyBackList(bool sell) {
  7668. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7669. return;
  7670. Spawn* spawn = GetMerchantTransaction();
  7671. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7672. deque<BuyBackItem*>::iterator itr;
  7673. int i = 0;
  7674. Item* master_item = 0;
  7675. BuyBackItem* buyback = 0;
  7676. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7677. if (packet) {
  7678. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7679. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7680. sint8 item_difficulty = 0;
  7681. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7682. int tmp_level = 0;
  7683. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7684. buyback = *itr;
  7685. master_item = master_item_list.GetItem(buyback->item_id);
  7686. if (master_item) {
  7687. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7688. packet->setArrayDataByName("price", buyback->price, i);
  7689. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7690. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7691. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7692. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7693. if (master_item->generic_info.adventure_default_level > 0)
  7694. tmp_level = master_item->generic_info.adventure_default_level;
  7695. else
  7696. tmp_level = master_item->generic_info.tradeskill_default_level;
  7697. packet->setArrayDataByName("level", tmp_level, i);
  7698. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7699. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7700. }
  7701. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7702. item_difficulty = player->GetArrowColor(tmp_level);
  7703. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7704. item_difficulty = ARROW_COLOR_WHITE;
  7705. sint64 overrideValue = 0;
  7706. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7707. item_difficulty = (sint8)overrideValue;
  7708. item_difficulty -= 6;
  7709. if (item_difficulty < 0)
  7710. item_difficulty *= -1;
  7711. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7712. sint64 dispFlags = 0;
  7713. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7714. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7715. if (buyback->quantity == 1)
  7716. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7717. else
  7718. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7719. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7720. if (GetVersion() <= 1096)
  7721. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7722. }
  7723. }
  7724. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7725. if (sell)
  7726. packet->setDataByName("type", 640);
  7727. else
  7728. packet->setDataByName("type", 512);
  7729. EQ2Packet* outapp = packet->serialize();
  7730. // DumpPacket(outapp);
  7731. QueuePacket(outapp);
  7732. safe_delete(packet);
  7733. }
  7734. }
  7735. }
  7736. void Client::SendRepairList() {
  7737. Spawn* spawn = GetMerchantTransaction();
  7738. if (spawn) {
  7739. vector<Item*>* repairable_items = GetRepairableItems();
  7740. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7741. if (packet) {
  7742. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7743. packet->setArrayLengthByName("num_items", repairable_items->size());
  7744. Item* item = 0;
  7745. sint8 item_difficulty = 0;
  7746. int32 i = 0;
  7747. vector<Item*>::iterator itr;
  7748. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7749. item = *itr;
  7750. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7751. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7752. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7753. packet->setArrayDataByName("stack_size", item->details.count, i);
  7754. packet->setArrayDataByName("icon", item->details.icon, i);
  7755. /*if (item->generic_info.adventure_default_level > 0)
  7756. tmp_level = item->generic_info.adventure_default_level;
  7757. else
  7758. tmp_level = item->generic_info.tradeskill_default_level;
  7759. packet->setArrayDataByName("level", tmp_level, i);*/
  7760. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7761. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7762. packet->setArrayDataByName("tier", item->details.tier, i);
  7763. }
  7764. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7765. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7766. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7767. item_difficulty = ARROW_COLOR_WHITE;
  7768. item_difficulty -= 6;
  7769. if (item_difficulty < 0)
  7770. item_difficulty *= -1;
  7771. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7772. if (item->details.count == 1)
  7773. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7774. else
  7775. packet->setArrayDataByName("quantity", item->details.count, i);
  7776. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7777. if (GetVersion() <= 1096)
  7778. packet->setArrayDataByName("description", item->description.c_str(), i);
  7779. }
  7780. if (GetVersion() <= 546) {
  7781. packet->setDataByName("type", 112);
  7782. }
  7783. else {
  7784. packet->setDataByName("type", 96);
  7785. }
  7786. EQ2Packet* outapp = packet->serialize();
  7787. //DumpPacket(outapp);
  7788. QueuePacket(outapp);
  7789. /*if (GetVersion() <= 546) {
  7790. packet->setDataByName("type", 16);
  7791. EQ2Packet* outapp2 = packet->serialize();
  7792. QueuePacket(outapp2);
  7793. }*/
  7794. safe_delete(packet);
  7795. }
  7796. safe_delete(repairable_items);
  7797. }
  7798. }
  7799. void Client::ShowLottoWindow() {
  7800. Spawn* spawn = GetMerchantTransaction();
  7801. if (spawn) {
  7802. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7803. if (!item_id)
  7804. {
  7805. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7806. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7807. return;
  7808. }
  7809. else if (item_id == 0)
  7810. {
  7811. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7812. return;
  7813. }
  7814. Item* item = master_item_list.GetItem(item_id);
  7815. if (!item) {
  7816. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7817. return;
  7818. }
  7819. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7820. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7821. if (packet) {
  7822. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7823. packet->setArrayLengthByName("num_items", 1);
  7824. packet->setArrayDataByName("item_name", item->name.c_str());
  7825. packet->setArrayDataByName("price", item->sell_price);
  7826. packet->setArrayDataByName("item_id", item->details.item_id);
  7827. packet->setArrayDataByName("stack_size", item->details.count);
  7828. packet->setArrayDataByName("icon", item->details.icon);
  7829. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7830. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7831. packet->setArrayDataByName("tier", item->details.tier);
  7832. }
  7833. packet->setArrayDataByName("item_id2", item->details.item_id);
  7834. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7835. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7836. item_difficulty = ARROW_COLOR_WHITE;
  7837. item_difficulty -= 6;
  7838. if (item_difficulty < 0)
  7839. item_difficulty *= -1;
  7840. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7841. //if(item->details.count == 1)
  7842. packet->setArrayDataByName("quantity", 0xFFFF);
  7843. //else
  7844. // packet->setArrayDataByName("quantity", item->details.count);
  7845. packet->setArrayDataByName("stack_size2", item->details.count);
  7846. packet->setArrayDataByName("description", item->description.c_str());
  7847. if (GetVersion() <= 546) {
  7848. packet->setDataByName("type", 128);
  7849. }
  7850. else {
  7851. packet->setDataByName("type", 0x00000102);
  7852. }
  7853. QueuePacket(packet->serialize());
  7854. safe_delete(packet);
  7855. }
  7856. }
  7857. }
  7858. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7859. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7860. if (packet) {
  7861. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7862. int32 rolls[6] = { 0 };
  7863. int32 lottery_digits[6] = { 0 };
  7864. int8 num_matches = 0;
  7865. int64 jackpot = 0;
  7866. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7867. if (!item) {
  7868. return;
  7869. }
  7870. database.DeleteItem(GetCharacterID(), item, 0);
  7871. GetPlayer()->item_list.RemoveItem(item, true);
  7872. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7873. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7874. if (!winning_numbers) {
  7875. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7876. variables.AddVariable(winning_numbers);
  7877. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7878. }
  7879. if (strlen(winning_numbers->GetValue()) != 12) {
  7880. winning_numbers->SetValue("231205182236");
  7881. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7882. }
  7883. try {
  7884. for (int32 i = 0; i < 12; i += 2) {
  7885. char num[4];
  7886. strncpy(num, winning_numbers->GetValue() + i, 2);
  7887. lottery_digits[i / 2] = atoi(num);
  7888. }
  7889. }
  7890. catch (...) {
  7891. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7892. return;
  7893. }
  7894. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7895. if (!jackpot_var) {
  7896. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7897. variables.AddVariable(jackpot_var);
  7898. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7899. }
  7900. try {
  7901. jackpot = atoul(jackpot_var->GetValue());
  7902. if (jackpot < 10000)
  7903. jackpot = 10000;
  7904. }
  7905. catch (...) {
  7906. jackpot = 10000;
  7907. }
  7908. char new_jackpot[128] = { 0 };
  7909. sprintf(new_jackpot, "%llu", jackpot + price);
  7910. jackpot_var->SetValue(new_jackpot);
  7911. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7912. world.PickRandomLottoDigits(rolls);
  7913. packet->setDataByName("roll_digit1", rolls[0]);
  7914. packet->setDataByName("roll_digit2", rolls[1]);
  7915. packet->setDataByName("roll_digit3", rolls[2]);
  7916. packet->setDataByName("roll_digit4", rolls[3]);
  7917. packet->setDataByName("roll_digit5", rolls[4]);
  7918. packet->setDataByName("roll_digit6", rolls[5]);
  7919. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7920. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7921. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7922. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7923. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7924. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7925. QueuePacket(packet->serialize());
  7926. safe_delete(packet);
  7927. for (int32 i = 0; i < 6; i++) {
  7928. for (int32 j = 0; j < 6; j++) {
  7929. if (rolls[i] == lottery_digits[j]) {
  7930. num_matches++;
  7931. break;
  7932. }
  7933. }
  7934. }
  7935. char new_jackpot_str[16];
  7936. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7937. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7938. if (num_matches == 6) {
  7939. world.PickRandomLottoDigits(lottery_digits);
  7940. for (int32 i = 0; i < 12; i += 2)
  7941. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7942. winning_numbers->SetValue(new_jackpot_str);
  7943. jackpot_var->SetValue("10000");
  7944. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7945. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7946. }
  7947. }
  7948. }
  7949. void Client::SendGuildCreateWindow() {
  7950. if (GetVersion() <= 546) {
  7951. SimpleMessage(0, "Not implemented on this client...yet?");
  7952. }
  7953. else {
  7954. Spawn* spawn = GetPlayer()->GetTarget();
  7955. if (spawn) {
  7956. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7957. if (packet) {
  7958. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7959. packet->setArrayLengthByName("num_items", 0);
  7960. packet->setDataByName("type", 0x00008000);
  7961. QueuePacket(packet->serialize());
  7962. safe_delete(packet);
  7963. }
  7964. }
  7965. }
  7966. }
  7967. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7968. BuyBackItem* item = new BuyBackItem;
  7969. item->item_id = item_id;
  7970. item->unique_id = unique_id;
  7971. item->price = price;
  7972. item->quantity = quantity;
  7973. item->save_needed = save_needed;
  7974. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7975. buy_back_items.push_back(item);
  7976. if (buy_back_items.size() > 10) {
  7977. safe_delete(buy_back_items.front());
  7978. buy_back_items.pop_front();
  7979. }
  7980. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7981. }
  7982. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7983. return &buy_back_items;
  7984. }
  7985. vector<Item*>* Client::GetRepairableItems() {
  7986. vector<Item*>* repairable_items = new vector<Item*>;
  7987. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7988. map<int32, Item*>* items = player->GetItemList();
  7989. if (equipped_items && equipped_items->size() > 0) {
  7990. for (int32 i = 0; i < equipped_items->size(); i++) {
  7991. Item* item = equipped_items->at(i);
  7992. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  7993. repairable_items->push_back(item);
  7994. }
  7995. }
  7996. if (items && items->size() > 0) {
  7997. map<int32, Item*>::iterator itr;
  7998. for (itr = items->begin(); itr != items->end(); itr++) {
  7999. Item* item = itr->second;
  8000. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  8001. repairable_items->push_back(item);
  8002. }
  8003. }
  8004. safe_delete(equipped_items);
  8005. safe_delete(items);
  8006. return repairable_items;
  8007. }
  8008. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  8009. if(type == NO_EFFECT_TYPE)
  8010. return nullptr;
  8011. vector<Item*>* return_items = new vector<Item*>;
  8012. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8013. map<int32, Item*>* items = player->GetItemList();
  8014. if (equipped_items && equipped_items->size() > 0) {
  8015. for (int32 i = 0; i < equipped_items->size(); i++) {
  8016. Item* item = equipped_items->at(i);
  8017. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8018. return_items->push_back(item);
  8019. }
  8020. }
  8021. if (items && items->size() > 0) {
  8022. map<int32, Item*>::iterator itr;
  8023. for (itr = items->begin(); itr != items->end(); itr++) {
  8024. Item* item = itr->second;
  8025. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8026. return_items->push_back(item);
  8027. }
  8028. }
  8029. safe_delete(equipped_items);
  8030. safe_delete(items);
  8031. return return_items;
  8032. }
  8033. void Client::SendMailList() {
  8034. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8035. if (kiosk_id > 0) {
  8036. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8037. if (p) {
  8038. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8039. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8040. int32 i = 0;
  8041. p->setDataByName("kiosk_id", kiosk_id);
  8042. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8043. while (itr.Next()) {
  8044. Mail* mail = itr->second;
  8045. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8046. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8047. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8048. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8049. p->setArrayDataByName("already_read", mail->already_read, i);
  8050. if(mail->expire_time)
  8051. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8052. else
  8053. p->setArrayDataByName("mail_deletion", 0, i);
  8054. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8055. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8056. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8057. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8058. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8059. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8060. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8061. //p->setArrayDataByName("unknown2", 0, i);
  8062. bool successItemAdd = false;
  8063. if(mail->stack || mail->char_item_id)
  8064. {
  8065. Item* item = master_item_list.GetItem(mail->char_item_id);
  8066. if(item)
  8067. {
  8068. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8069. if (version < 860)
  8070. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  8071. else if (version < 1193)
  8072. p->setItemArrayDataByName("item", item, player, i);
  8073. else
  8074. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8075. successItemAdd = true;
  8076. }
  8077. }
  8078. if(!successItemAdd)
  8079. {
  8080. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8081. p->setArrayDataByName("end_tag3", 0xFF, i);
  8082. }
  8083. i++;
  8084. }
  8085. // GMs send mail for free!
  8086. if (GetAdminStatus() > 0)
  8087. {
  8088. p->setDataByName("postage_cost", 0);
  8089. p->setDataByName("attachment_cost", 0);
  8090. }
  8091. else
  8092. {
  8093. p->setDataByName("postage_cost", 10);
  8094. p->setDataByName("attachment_cost", 50);
  8095. }
  8096. p->setDataByName("unknown3", 0x01F4);
  8097. p->setDataByName("unknown4", 0x01000000);
  8098. EQ2Packet* pack = p->serialize();
  8099. //DumpPacket(pack);
  8100. //p->PrintPacket();
  8101. QueuePacket(pack);
  8102. safe_delete(p);
  8103. }
  8104. }
  8105. else
  8106. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8107. }
  8108. void Client::DisplayMailMessage(int32 mail_id) {
  8109. Mail* mail = player->GetMail(mail_id);
  8110. if (mail) {
  8111. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8112. if (kiosk_id > 0) {
  8113. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8114. if (update) {
  8115. update->setDataByName("action", 0x03);
  8116. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8117. update->setDataByName("packetsubtype", 0xFF);
  8118. QueuePacket(update->serialize());
  8119. safe_delete(update);
  8120. }
  8121. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8122. if (packet) {
  8123. packet->setDataByName("kiosk_id", kiosk_id);
  8124. packet->setDataByName("mail_id", mail->mail_id);
  8125. packet->setDataByName("player_to_id", mail->player_to_id);
  8126. packet->setDataByName("player_from", mail->player_from.c_str());
  8127. packet->setDataByName("subject", mail->subject.c_str());
  8128. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8129. packet->setDataByName("unknown1", 1);
  8130. packet->setDataByName("unknown2", 0);
  8131. packet->setDataByName("lock_report_button", 1);
  8132. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8133. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8134. packet->setDataByName("coin_copper", mail->coin_copper);
  8135. packet->setDataByName("coin_silver", mail->coin_silver);
  8136. packet->setDataByName("coin_gold", mail->coin_gold);
  8137. packet->setDataByName("coin_plat", mail->coin_plat);
  8138. if(mail->stack || mail->char_item_id)
  8139. {
  8140. Item* item = master_item_list.GetItem(mail->char_item_id);
  8141. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8142. if (version < 860)
  8143. packet->setItemByName("item", item, player, 0, -1);
  8144. else if (version < 1193)
  8145. packet->setItemByName("item", item, player, 0, 0);
  8146. else
  8147. packet->setItemByName("item", item, player, 0, 2);
  8148. }
  8149. else
  8150. {
  8151. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8152. packet->setDataByName("end_tag3", 0xFF);
  8153. }
  8154. mail->already_read = true;
  8155. mail->save_needed = true;
  8156. EQ2Packet* pack = packet->serialize();
  8157. QueuePacket(pack);
  8158. safe_delete(packet);
  8159. // trying to update this causes the window not to open
  8160. //SendMailList();
  8161. }
  8162. }
  8163. else
  8164. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8165. }
  8166. }
  8167. /* 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
  8168. packet back to the client before the mail actually sent. */
  8169. void Client::HandleSentMail(EQApplicationPacket* app) {
  8170. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8171. if (packet) {
  8172. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8173. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8174. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8175. vector<int32>* ids = 0;
  8176. MMailWindowMutex.lock();
  8177. if (reply_packet) {
  8178. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8179. if (player_to.length() == 0)
  8180. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8181. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8182. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8183. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8184. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8185. else {
  8186. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8187. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8188. ids = database.GetAllPlayerIDs();
  8189. else
  8190. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8191. }
  8192. else {
  8193. ids = new vector<int32>;
  8194. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8195. }
  8196. if (ids) {
  8197. for (int32 i = 0; i < ids->size(); i++) {
  8198. int32 player_to_id = ids->at(i);
  8199. if (player_to_id > 0) {
  8200. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8201. Mail* mail = new Mail;
  8202. mail->mail_id = 0;
  8203. mail->player_to_id = player_to_id;
  8204. mail->player_from = string(GetPlayer()->GetName());
  8205. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8206. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8207. mail->already_read = 0;
  8208. mail->mail_type = MAIL_TYPE_REGULAR;
  8209. mail->coin_copper = mail_window.coin_copper;
  8210. mail->coin_silver = mail_window.coin_silver;
  8211. mail->coin_gold = mail_window.coin_gold;
  8212. mail->coin_plat = mail_window.coin_plat;
  8213. mail->char_item_id = mail_window.char_item_id;
  8214. mail->stack = mail_window.stack;
  8215. // GM's send mail for free!
  8216. if (GetAdminStatus() > 0)
  8217. {
  8218. mail->postage_cost = 0;
  8219. mail->attachment_cost = 0;
  8220. }
  8221. else
  8222. {
  8223. mail->postage_cost = 10;
  8224. mail->attachment_cost = 50;
  8225. }
  8226. mail->time_sent = Timer::GetUnixTimeStamp();
  8227. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8228. mail->save_needed = false;
  8229. database.SavePlayerMail(mail);
  8230. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8231. if (to_client) {
  8232. to_client->GetPlayer()->AddMail(mail);
  8233. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8234. string popup_text = "You have unread mail!";
  8235. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8236. }
  8237. else {
  8238. // don't need the pointer the client doesn't exist currently
  8239. safe_delete(mail);
  8240. }
  8241. ResetSendMail(false, false);
  8242. }
  8243. else
  8244. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8245. }
  8246. }
  8247. }
  8248. string players_to = "";
  8249. if (ids) {
  8250. for (int32 i = 0; i < ids->size(); i++) {
  8251. if (ids->at(i) != 0)
  8252. players_to.append(database.GetCharacterName(ids->at(i)));
  8253. if (i < (ids->size() - 1))
  8254. players_to.append(", ");
  8255. }
  8256. }
  8257. reply_packet->setDataByName("player_to", players_to.c_str());
  8258. reply_packet->setDataByName("reply_type", reply_type);
  8259. QueuePacket(reply_packet->serialize());
  8260. safe_delete(reply_packet);
  8261. safe_delete(ids);
  8262. }
  8263. MMailWindowMutex.unlock();
  8264. }
  8265. safe_delete(packet);
  8266. }
  8267. }
  8268. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8269. player->DeleteMail(mail_id, from_database);
  8270. }
  8271. bool Client::AddMailItem(Item* item)
  8272. {
  8273. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8274. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8275. return false;
  8276. }
  8277. bool ret = false;
  8278. if (GetMailTransaction()) {
  8279. MMailWindowMutex.lock();
  8280. if(mail_window.char_item_id == 0)
  8281. {
  8282. mail_window.item = item;
  8283. mail_window.char_item_id = item->details.item_id;
  8284. mail_window.stack = item->details.count;
  8285. ret = true;
  8286. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8287. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8288. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8289. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8290. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8291. if(item)
  8292. {
  8293. packet->setDataByName("stack", mail_window.stack);
  8294. item->stack_count = mail_window.stack;
  8295. if (version < 860)
  8296. packet->setItemByName("item", item, player, 0, -1);
  8297. else if (version < 1193)
  8298. packet->setItemByName("item", item, player, 0, 0);
  8299. else
  8300. packet->setItemByName("item", item, player, 0, 2);
  8301. }
  8302. else
  8303. {
  8304. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8305. packet->setDataByName("end_tag3", 0xFF);
  8306. }
  8307. QueuePacket(packet->serialize());
  8308. }
  8309. MMailWindowMutex.unlock();
  8310. }
  8311. return ret;
  8312. }
  8313. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8314. bool ret = false;
  8315. if (GetMailTransaction()) {
  8316. MMailWindowMutex.lock();
  8317. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8318. if (packet) {
  8319. if (copper > 0) {
  8320. if (player->RemoveCoins(copper)) {
  8321. mail_window.coin_copper += copper;
  8322. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8323. ret = true;
  8324. }
  8325. }
  8326. else if (silver > 0) {
  8327. if (player->RemoveCoins(silver * 100)) {
  8328. mail_window.coin_silver += silver;
  8329. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8330. ret = true;
  8331. }
  8332. }
  8333. else if (gold > 0) {
  8334. if (player->RemoveCoins(gold * 10000)) {
  8335. mail_window.coin_gold += gold;
  8336. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8337. ret = true;
  8338. }
  8339. }
  8340. else if (plat > 0) {
  8341. if (player->RemoveCoins(plat * 1000000)) {
  8342. mail_window.coin_plat += plat;
  8343. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8344. ret = true;
  8345. }
  8346. }
  8347. if (ret) {
  8348. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8349. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8350. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8351. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8352. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8353. if(item)
  8354. {
  8355. packet->setDataByName("stack", mail_window.stack);
  8356. item->stack_count = mail_window.stack;
  8357. if (version < 860)
  8358. packet->setItemByName("item", item, player, 0, -1);
  8359. else if (version < 1193)
  8360. packet->setItemByName("item", item, player, 0, 0);
  8361. else
  8362. packet->setItemByName("item", item, player, 0, 2);
  8363. }
  8364. else
  8365. {
  8366. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8367. packet->setDataByName("end_tag3", 0xFF);
  8368. }
  8369. //packet->PrintPacket();
  8370. QueuePacket(packet->serialize());
  8371. }
  8372. else
  8373. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8374. safe_delete(packet);
  8375. }
  8376. MMailWindowMutex.unlock();
  8377. }
  8378. else
  8379. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8380. return ret;
  8381. }
  8382. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8383. bool ret = false;
  8384. if (GetMailTransaction()) {
  8385. MMailWindowMutex.lock();
  8386. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8387. if (packet) {
  8388. if (copper > 0) {
  8389. player->AddCoins(copper);
  8390. mail_window.coin_copper -= copper;
  8391. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8392. ret = true;
  8393. }
  8394. else if (silver > 0) {
  8395. player->AddCoins(silver * 100);
  8396. mail_window.coin_silver -= silver;
  8397. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8398. ret = true;
  8399. }
  8400. else if (gold > 0) {
  8401. player->AddCoins(gold * 10000);
  8402. mail_window.coin_gold -= gold;
  8403. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8404. ret = true;
  8405. }
  8406. else if (plat > 0) {
  8407. player->AddCoins(plat * 1000000);
  8408. mail_window.coin_plat -= plat;
  8409. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8410. ret = true;
  8411. }
  8412. if (ret) {
  8413. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8414. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8415. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8416. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8417. packet->setDataByName("stack", 0);
  8418. packet->setDataByName("packettype", 0x2BFE);
  8419. packet->setDataByName("packetsubtype", 0xFF);
  8420. packet->setDataByName("unknown2", 0);
  8421. QueuePacket(packet->serialize());
  8422. }
  8423. safe_delete(packet);
  8424. }
  8425. MMailWindowMutex.unlock();
  8426. }
  8427. else
  8428. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8429. return ret;
  8430. }
  8431. void Client::TakeMailAttachments(int32 mail_id) {
  8432. if (GetMailTransaction()) {
  8433. Mail* mail = player->GetMail(mail_id);
  8434. if (mail) {
  8435. int64 amount = 0;
  8436. if (mail->coin_copper > 0) {
  8437. amount += mail->coin_copper;
  8438. mail->coin_copper = 0;
  8439. }
  8440. if (mail->coin_silver > 0) {
  8441. amount += mail->coin_silver * 100;
  8442. mail->coin_silver = 0;
  8443. }
  8444. if (mail->coin_gold > 0) {
  8445. amount += mail->coin_gold * 10000;
  8446. mail->coin_gold = 0;
  8447. }
  8448. if (mail->coin_plat > 0) {
  8449. amount += mail->coin_plat * 1000000;
  8450. mail->coin_plat = 0;
  8451. }
  8452. if (mail->char_item_id > 0) {
  8453. AddItem(mail->char_item_id, mail->stack);
  8454. mail->char_item_id = 0;
  8455. mail->stack = 0;
  8456. }
  8457. /* 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
  8458. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8459. find it in any packet logs.*/
  8460. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8461. if (packet) {
  8462. packet->setDataByName("unknown", 0x03);
  8463. packet->setDataByName("coin_copper", mail->coin_copper);
  8464. packet->setDataByName("coin_silver", mail->coin_silver);
  8465. packet->setDataByName("coin_gold", mail->coin_gold);
  8466. packet->setDataByName("coin_plat", mail->coin_plat);
  8467. packet->setDataByName("stack", 0);
  8468. packet->setDataByName("packettype", 0x2BFE);
  8469. packet->setDataByName("packetsubtype", 0xFF);
  8470. packet->setDataByName("unknown2", 0);
  8471. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8472. DumpPacket(packet->serialize());
  8473. QueuePacket(packet->serialize());
  8474. safe_delete(packet);
  8475. }*/
  8476. database.SavePlayerMail(mail);
  8477. if (amount > 0)
  8478. player->AddCoins(amount);
  8479. SendMailList();
  8480. }
  8481. }
  8482. else
  8483. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8484. }
  8485. void Client::ResetSendMail(bool cancel, bool needslock) {
  8486. if(cancel && mail_transaction)
  8487. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8488. if(needslock)
  8489. MMailWindowMutex.lock();
  8490. if(cancel)
  8491. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8492. if(!cancel)
  8493. mail_transaction = 0;
  8494. mail_window.coin_copper = 0;
  8495. mail_window.coin_silver = 0;
  8496. mail_window.coin_gold = 0;
  8497. mail_window.coin_plat = 0;
  8498. mail_window.char_item_id = 0;
  8499. mail_window.stack = 0;
  8500. if(mail_window.item){
  8501. if(cancel)
  8502. AddItem(mail_window.item);
  8503. else
  8504. safe_delete(mail_window.item);
  8505. }
  8506. mail_window.item = nullptr;
  8507. if(needslock)
  8508. MMailWindowMutex.unlock();
  8509. }
  8510. bool Client::GateAllowed() {
  8511. ZoneServer* zone = GetCurrentZone();
  8512. if (zone){
  8513. bool cangate = zone->GetCanGate();
  8514. return cangate;
  8515. }
  8516. return false;
  8517. }
  8518. bool Client::BindAllowed() {
  8519. ZoneServer* zone = GetCurrentZone();
  8520. if (zone){
  8521. bool canbind = zone->GetCanBind();
  8522. return canbind;
  8523. }
  8524. return false;
  8525. }
  8526. bool Client::Bind() {
  8527. int canbind = BindAllowed();
  8528. if(canbind == 0) {
  8529. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8530. return false;
  8531. }
  8532. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8533. player->GetPlayerInfo()->SetBindX(player->GetX());
  8534. player->GetPlayerInfo()->SetBindY(player->GetY());
  8535. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8536. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8537. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8538. return true;
  8539. }
  8540. bool Client::Gate(bool is_spell) {
  8541. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8542. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8543. return false;
  8544. }
  8545. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8546. if (zone) {
  8547. int cangate = GateAllowed();
  8548. if(cangate == 0) {
  8549. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8550. return false;
  8551. }
  8552. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8553. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8554. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8555. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8556. Zone(zone, false, is_spell);
  8557. return true;
  8558. }
  8559. return false;
  8560. }
  8561. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8562. if (!destinations || !spawn) {
  8563. return;
  8564. }
  8565. bool has_map = false;
  8566. if (transport_id > 0)
  8567. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8568. transport_spawn = spawn;
  8569. vector<TransportDestination*> transport_list;
  8570. vector<TransportDestination*>::iterator itr;
  8571. TransportDestination* destination = 0;
  8572. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8573. destination = *itr;
  8574. 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)))
  8575. transport_list.push_back(destination);
  8576. }
  8577. if (transport_list.size() == 0 && destination) {
  8578. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8579. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8580. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8581. else
  8582. {
  8583. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8584. if (app)
  8585. QueuePacket(app);
  8586. }
  8587. }
  8588. else {
  8589. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8590. // determine if this is an instanced zone that already exists
  8591. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8592. if (instance_zone || new_zone) {
  8593. GetPlayer()->SetX(destination->destination_x);
  8594. GetPlayer()->SetY(destination->destination_y);
  8595. GetPlayer()->SetZ(destination->destination_z);
  8596. GetPlayer()->SetHeading(destination->destination_heading);
  8597. if (instance_zone)
  8598. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8599. else
  8600. Zone(new_zone, false, is_spell);
  8601. }
  8602. }
  8603. if (destination->message.length() > 0)
  8604. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8605. }
  8606. else if (transport_list.size() > 0) {
  8607. if (!spawn->IsSoundsDisabled())
  8608. PlaySound("mariner_bell");
  8609. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8610. if (packet) {
  8611. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8612. // Put all the destinations the player can go in a new vector
  8613. vector<TransportDestination*> destinations;
  8614. for (int32 i = 0; i < transport_list.size(); i++) {
  8615. destination = transport_list.at(i);
  8616. // Check min level
  8617. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8618. continue;
  8619. // Check max level
  8620. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8621. continue;
  8622. // Check quest complete
  8623. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8624. continue;
  8625. // Check req quest and step
  8626. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8627. continue;
  8628. // 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
  8629. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8630. packet->setDataByName("current_zone", destination->display_name.c_str());
  8631. packet->setDataByName("current_map_x", destination->map_x);
  8632. packet->setDataByName("current_map_y", destination->map_y);
  8633. }
  8634. else {
  8635. destinations.push_back(destination);
  8636. }
  8637. }
  8638. // Use the new vector to create the packet
  8639. destination = 0;
  8640. packet->setArrayLengthByName("num_destinations", destinations.size());
  8641. for (int32 i = 0; i < destinations.size(); i++) {
  8642. destination = destinations.at(i);
  8643. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8644. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8645. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8646. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8647. packet->setArrayDataByName("cost", destination->cost, i);
  8648. if (has_map) {
  8649. packet->setArrayDataByName("map_x", destination->map_x, i);
  8650. packet->setArrayDataByName("map_y", destination->map_y, i);
  8651. }
  8652. }
  8653. if (has_map)
  8654. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8655. EQ2Packet* app = packet->serialize();
  8656. //DumpPacket(app);
  8657. if (destinations.size() > 0)
  8658. QueuePacket(app);
  8659. safe_delete(packet);
  8660. }
  8661. }
  8662. }
  8663. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8664. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8665. if (packet) {
  8666. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8667. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8668. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8669. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8670. int32 cost = packet->getType_int32_ByName("cost");
  8671. vector<TransportDestination*> destinations;
  8672. TransportDestination* destination = 0;
  8673. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8674. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8675. vector<TransportDestination*>::iterator itr;
  8676. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8677. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8678. destination = *itr;
  8679. break;
  8680. }
  8681. }
  8682. SetTemporaryTransportID(0);
  8683. if (!destination)
  8684. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8685. else {
  8686. if (cost == 0 || player->RemoveCoins(cost)) {
  8687. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8688. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8689. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8690. else
  8691. {
  8692. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8693. if (outapp)
  8694. QueuePacket(outapp);
  8695. }
  8696. }
  8697. else {
  8698. GetPlayer()->SetX(destination->destination_x);
  8699. GetPlayer()->SetY(destination->destination_y);
  8700. GetPlayer()->SetZ(destination->destination_z);
  8701. GetPlayer()->SetHeading(destination->destination_heading);
  8702. // Test if where we're going is an Instanced zone
  8703. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8704. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8705. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8706. Zone(new_zone, false);
  8707. }
  8708. }
  8709. if (destination->message.length() > 0)
  8710. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8711. }
  8712. else
  8713. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8714. }
  8715. }
  8716. safe_delete(packet);
  8717. }
  8718. }
  8719. void Client::SendNewSpells(int8 class_id) {
  8720. if (class_id > 0) {
  8721. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8722. AddSendNewSpells(spells);
  8723. safe_delete(spells);
  8724. }
  8725. }
  8726. void Client::SendNewTSSpells(int8 class_id) {
  8727. if (class_id > 0) {
  8728. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8729. AddSendNewSpells(spells);
  8730. safe_delete(spells);
  8731. }
  8732. }
  8733. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8734. Spell* spell = 0;
  8735. bool send_updates = false;
  8736. vector<Spell*>::iterator itr;
  8737. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8738. spell = *itr;
  8739. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8740. send_updates = true;
  8741. SendSpellUpdate(spell);
  8742. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8743. player->UnlockSpell(spell);
  8744. }
  8745. }
  8746. if (send_updates) {
  8747. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8748. if (outapp)
  8749. QueuePacket(outapp);
  8750. }
  8751. }
  8752. void Client::SetItemSearch(vector<Item*>* items) {
  8753. if (items) {
  8754. safe_delete(search_items);
  8755. search_items = items;
  8756. }
  8757. }
  8758. vector<Item*>* Client::GetSearchItems() {
  8759. return search_items;
  8760. }
  8761. void Client::SearchStore(int32 page) {
  8762. if (search_items) {
  8763. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8764. if (packet) {
  8765. int32 x = page * 8;
  8766. if (search_items->size() > 8) {
  8767. if ((search_items->size() - x) > 8)
  8768. packet->setArrayLengthByName("num_items", 8);
  8769. else
  8770. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8771. }
  8772. else
  8773. packet->setArrayLengthByName("num_items", search_items->size());
  8774. if (search_items->size() > 0) {
  8775. packet->setArrayLengthByName("num_sellers", 1);
  8776. packet->setArrayDataByName("seller_seller_id", 1);
  8777. packet->setDataByName("per_page", 8);
  8778. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8779. packet->setDataByName("page", page);
  8780. Item* item = 0;
  8781. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8782. for (int32 i = 0; i < limit; i++, x++) {
  8783. if (x >= search_items->size())
  8784. break;
  8785. item = search_items->at(x);
  8786. std::string teststr("test ");
  8787. teststr.append(std::to_string(i));
  8788. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  8789. packet->setArrayDataByName("string_two", "testtwo", i);
  8790. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  8791. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8792. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8793. packet->setArrayDataByName("icon", item->details.icon, i);
  8794. //packet->setArrayDataByName("unknown2b", i, i);
  8795. packet->setArrayDataByName("item_seller_id", 1, i);
  8796. if (item->stack_count == 0)
  8797. packet->setArrayDataByName("quantity", 1, i);
  8798. else
  8799. packet->setArrayDataByName("quantity", item->stack_count, i);
  8800. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8801. packet->setArrayDataByName("sell_price", item->sell_price, i);
  8802. std::string tmpStr("");
  8803. tmpStr.append(item->name.c_str());
  8804. tmpStr.append(" (");
  8805. tmpStr.append(std::to_string(item->details.item_id));
  8806. tmpStr.append(")");
  8807. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8808. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8809. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8810. }
  8811. }
  8812. EQ2Packet* outapp = packet->serialize();
  8813. DumpPacket(outapp);
  8814. QueuePacket(outapp);
  8815. safe_delete(packet);
  8816. }
  8817. }
  8818. }
  8819. void Client::SetReadyForUpdates() {
  8820. if (!ready_for_updates) {
  8821. database.loadCharacterProperties(this);
  8822. SendDefaultGroupOptions();
  8823. }
  8824. ready_for_updates = true;
  8825. if(GetVersion() <= 546) {
  8826. SendRecipeList();
  8827. }
  8828. }
  8829. void Client::SetReadyForSpawns(bool val) {
  8830. ready_for_spawns = val;
  8831. if (GetPlayer()->GetActivityStatus() > 0) {
  8832. GetPlayer()->SetActivityStatus(0);
  8833. if (GetPlayer()->GetGroupMemberInfo()) {
  8834. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8835. }
  8836. }
  8837. GetPlayer()->SetActiveReward(false);
  8838. zone_list.CheckFriendZoned(this);
  8839. }
  8840. void Client::SendChatRelationship(int8 type, const char* name) {
  8841. if (!name) {
  8842. return;
  8843. }
  8844. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8845. if (packet) {
  8846. packet->setDataByName("account_id", GetAccountID());
  8847. packet->setDataByName("type", type);
  8848. packet->setArrayLengthByName("num_names", 1);
  8849. packet->setArrayDataByName("name", name);
  8850. if (type == 0) {
  8851. Client* client = zone_list.GetClientByCharName(name);
  8852. if (client) {
  8853. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8854. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8855. }
  8856. }
  8857. QueuePacket(packet->serialize());
  8858. safe_delete(packet);
  8859. }
  8860. }
  8861. void Client::SendFriendList() {
  8862. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8863. if (packet) {
  8864. packet->setDataByName("account_id", GetAccountID());
  8865. map<string, int8>::iterator itr;
  8866. map<string, int8>* friends = player->GetFriends();
  8867. if (friends && friends->size() > 0) {
  8868. Client* client = 0;
  8869. vector<string> names;
  8870. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8871. if (itr->second == 2)
  8872. continue;
  8873. names.push_back(itr->first);
  8874. }
  8875. packet->setArrayLengthByName("num_names", names.size());
  8876. for (int32 i = 0; i < names.size(); i++) {
  8877. client = zone_list.GetClientByCharName(names[i]);
  8878. packet->setArrayDataByName("name", names[i].c_str(), i);
  8879. if (client) {
  8880. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8881. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8882. }
  8883. }
  8884. }
  8885. QueuePacket(packet->serialize());
  8886. safe_delete(packet);
  8887. }
  8888. }
  8889. void Client::SendIgnoreList() {
  8890. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8891. if (packet) {
  8892. packet->setDataByName("account_id", GetAccountID());
  8893. packet->setDataByName("type", 2);
  8894. map<string, int8>::iterator itr;
  8895. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8896. if (ignored && ignored->size() > 0) {
  8897. vector<string> names;
  8898. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8899. if (itr->second == 2)
  8900. continue;
  8901. names.push_back(itr->first);
  8902. }
  8903. packet->setArrayLengthByName("num_names", names.size());
  8904. for (int32 i = 0; i < names.size(); i++)
  8905. packet->setArrayDataByName("name", names[i].c_str(), i);
  8906. }
  8907. QueuePacket(packet->serialize());
  8908. safe_delete(packet);
  8909. }
  8910. }
  8911. void Client::AddWaypoint(string name, int8 type) {
  8912. waypoint_id++;
  8913. WaypointInfo info;
  8914. info.id = waypoint_id;
  8915. info.type = type;
  8916. waypoints[name] = info;
  8917. }
  8918. void Client::SendWaypoints() {
  8919. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8920. if (packet) {
  8921. packet->setArrayLengthByName("num_updates", waypoints.size());
  8922. map<string, WaypointInfo>::iterator itr;
  8923. int16 i = 0;
  8924. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8925. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8926. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8927. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8928. i++;
  8929. }
  8930. packet->setDataByName("unknown", 0xFFFFFFFF);
  8931. QueuePacket(packet->serialize());
  8932. safe_delete(packet);
  8933. }
  8934. }
  8935. void Client::SelectWaypoint(int32 id) {
  8936. string found_name = "";
  8937. map<string, WaypointInfo>::iterator itr;
  8938. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8939. if (itr->second.id == id) {
  8940. found_name = itr->first;
  8941. break;
  8942. }
  8943. }
  8944. if (found_name.length() > 0) {
  8945. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8946. ShowPathToTarget(spawn);
  8947. }
  8948. }
  8949. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8950. if (waypoint_name) {
  8951. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8952. if (packet) {
  8953. packet->setArrayLengthByName("num_updates", 1);
  8954. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8955. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8956. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8957. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8958. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8959. packet->setDataByName("unknown", 0xFFFFFFFF);
  8960. QueuePacket(packet->serialize());
  8961. safe_delete(packet);
  8962. }
  8963. }
  8964. }
  8965. void Client::ClearWaypoint() {
  8966. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8967. if (packet) {
  8968. QueuePacket(packet->serialize());
  8969. safe_delete(packet);
  8970. }
  8971. }
  8972. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8973. if (current_zone->pathing) {
  8974. if (GetPlayer()->GetMap()) {
  8975. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8976. return false;
  8977. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8978. return false;
  8979. auto loc = glm::vec3(x, z, y);
  8980. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  8981. if (new_z != BEST_Z_INVALID) //this is actually y
  8982. y = new_z;
  8983. }
  8984. bool partial = false;
  8985. bool stuck = false;
  8986. PathfinderOptions opts;
  8987. opts.smooth_path = true;
  8988. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8989. opts.offset = y_offset + 1.0f;
  8990. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8991. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8992. if (packet) {
  8993. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8994. packet->setArrayLengthByName("num_points", path.size());
  8995. int i = 0;
  8996. for (auto& node : path)
  8997. {
  8998. packet->setArrayDataByName("x", node.pos.x, i);
  8999. packet->setArrayDataByName("y", node.pos.z, i);
  9000. packet->setArrayDataByName("z", node.pos.y, i);
  9001. packet->setDataByName("waypoint_x", x);
  9002. packet->setDataByName("waypoint_y", y);
  9003. packet->setDataByName("waypoint_z", z);
  9004. i++;
  9005. }
  9006. if (i > 0)
  9007. QueuePacket(packet->serialize());
  9008. safe_delete(packet);
  9009. return (i > 0);
  9010. }
  9011. }
  9012. return false;
  9013. }
  9014. bool Client::ShowPathToTarget(Spawn* spawn) {
  9015. if (spawn) {
  9016. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9017. }
  9018. return false;
  9019. }
  9020. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9021. if (waypoint_name) {
  9022. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9023. if (packet) {
  9024. packet->setArrayLengthByName("num_points", 1);
  9025. packet->setArrayDataByName("x", x, 0);
  9026. packet->setArrayDataByName("y", y, 0);
  9027. packet->setArrayDataByName("z", z, 0);
  9028. packet->setDataByName("waypoint_x", x);
  9029. packet->setDataByName("waypoint_y", y);
  9030. packet->setDataByName("waypoint_z", z);
  9031. packet->setDataByName("waypoint_name", waypoint_name);
  9032. packet->setDataByName("unknown", 0);
  9033. QueuePacket(packet->serialize());
  9034. safe_delete(packet);
  9035. }
  9036. }
  9037. }
  9038. void Client::InspectPlayer(Player* player_to_inspect) {
  9039. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9040. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9041. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9042. if(pvp_allowed == true){
  9043. if(source_pvp_alignment != target_pvp_alignment){
  9044. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9045. return;
  9046. }
  9047. }
  9048. if (player_to_inspect && player_to_inspect->GetClient()) {
  9049. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9050. if (packet) {
  9051. packet->setDataByName("unknown", 0);
  9052. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9053. packet->setDataByName("race", player_to_inspect->GetRace());
  9054. packet->setDataByName("gender", player_to_inspect->GetGender());
  9055. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9056. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9057. packet->setDataByName("adventure_level_effective", effective_level);
  9058. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9059. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9060. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9061. packet->setDataByName("health", player_to_inspect->GetHP());
  9062. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9063. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9064. packet->setDataByName("power", player_to_inspect->GetPower());
  9065. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9066. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9067. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9068. packet->setDataByName("unknown1", 0);
  9069. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9070. packet->setDataByName("unknown2", 0);
  9071. packet->setDataByName("mitigation_percentage", 0);
  9072. packet->setDataByName("strength", player_to_inspect->GetStr());
  9073. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9074. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9075. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9076. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9077. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9078. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9079. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9080. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9081. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9082. packet->setDataByName("unknown4", 0);
  9083. packet->setDataByName("unknown5", 0);
  9084. packet->setDataByName("unknown6", 0);
  9085. packet->setDataByName("unknown7", 0);
  9086. packet->setDataByName("unknown8", 0);
  9087. packet->setDataByName("unknown9", 0);
  9088. packet->setDataByName("unknown10", 0);
  9089. packet->setDataByName("unknown11", 0);
  9090. packet->setDataByName("unknown12", 0);
  9091. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9092. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9093. packet->setDataByName("heat_resist_percentage", 0);
  9094. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9095. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9096. packet->setDataByName("cold_resist_percentage", 0);
  9097. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9098. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9099. packet->setDataByName("magic_resist_percentage", 0);
  9100. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9101. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9102. packet->setDataByName("mental_resist_percentage", 0);
  9103. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9104. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9105. packet->setDataByName("divine_resist_percentage", 0);
  9106. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9107. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9108. packet->setDataByName("disease_resist_percentage", 0);
  9109. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9110. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9111. packet->setDataByName("poison_resist_percentage", 0);
  9112. packet->setArrayLengthByName("num_chars", 0x01FF);
  9113. string biography = player_to_inspect->GetBiography();
  9114. for (size_t i = 0; i < biography.length(); i++)
  9115. packet->setArrayDataByName("biography_char", biography[i], i);
  9116. if(GetVersion() <= 546) {
  9117. for(int32 s=0;s<22;s++) {
  9118. int32 slot = s;
  9119. char item_slot_name[64], item_slot_name_appearance[64];
  9120. _snprintf(item_slot_name,64,"slot_%u",slot);
  9121. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9122. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9123. }
  9124. }
  9125. else {
  9126. for(int32 s=0;s<NUM_SLOTS;s++) {
  9127. int32 slot = s*2;
  9128. char item_slot_name[64], item_slot_name_appearance[64];
  9129. _snprintf(item_slot_name,64,"slot_%u",slot);
  9130. int32 slot_appearance = (s*2)+1;
  9131. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9132. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9133. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9134. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9135. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9136. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9137. }
  9138. else {
  9139. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9140. }
  9141. }
  9142. }
  9143. QueuePacket(packet->serialize());
  9144. safe_delete(packet);
  9145. }
  9146. }
  9147. }
  9148. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9149. pending_guild_invite.guild = guild;
  9150. pending_guild_invite.invited_by = invited_by;
  9151. }
  9152. void Client::ShowClaimWindow() {
  9153. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9154. if (packet) {
  9155. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9156. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9157. int32 account_age = database.GetAccountAge(GetAccountID());
  9158. //not sure if there is a message or not, but adding this and a return, so if we have nothing do nothing rather than display an empty window.
  9159. if (loaded == 0 || claim.empty()) {
  9160. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9161. return;
  9162. }
  9163. packet->setArrayLengthByName("num_claim_items", loaded);
  9164. int j = 0; //use this to track skipped vet items.
  9165. for (int i = 0; i < claim.size(); i++)
  9166. {
  9167. if (j == claim.size()) {
  9168. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9169. return;
  9170. }
  9171. Item* item = master_item_list.GetItem(claim[i].item_id);
  9172. int16 claimed = 0;
  9173. if (claim[i].curr_claim < claim[i].max_claim) {
  9174. claimed = claim[i].max_claim - claim[i].curr_claim;
  9175. }
  9176. else {
  9177. claimed = 0;
  9178. }
  9179. //dont display vet rewards until they reach the age required
  9180. if (account_age < claim[i].vet_reward_time) {
  9181. j++;
  9182. continue;
  9183. }
  9184. packet->setArrayDataByName("id", i, i);
  9185. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9186. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9187. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9188. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9189. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9190. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9191. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9192. packet->setArrayDataByName("icon", item->details.icon, i);
  9193. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9194. j++;
  9195. }
  9196. }
  9197. packet->setDataByName("unknown3", 1);
  9198. QueuePacket(packet->serialize());
  9199. safe_delete(packet);
  9200. }
  9201. void Client::ShowGuildSearchWindow() {
  9202. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9203. if (packet) {
  9204. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9205. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9206. packet->setArrayLengthByName("num_guilds", guilds->size());
  9207. int32 i = 0;
  9208. while (itr.Next()) {
  9209. Guild* guild = itr.second;
  9210. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9211. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9212. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9213. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9214. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9215. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9216. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9217. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9218. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9219. packet->setArrayDataByName("unknown7", 0x02, i);
  9220. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9221. i++;
  9222. }
  9223. QueuePacket(packet->serialize());
  9224. safe_delete(packet);
  9225. }
  9226. }
  9227. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9228. PacketStruct* packet;
  9229. vector<int8>* slot_data;
  9230. vector<int8>::iterator itr;
  9231. int32 slots = 0;
  9232. assert(item);
  9233. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9234. return;
  9235. }
  9236. slot_data = &item->slot_data;
  9237. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9238. if (version >= 1188)
  9239. slots = *itr;
  9240. else
  9241. slots += (int8)pow(2.0, *itr);
  9242. }
  9243. packet->setDataByName("slot", slots);
  9244. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9245. if (slots == 2) {
  9246. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9247. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9248. }
  9249. else {
  9250. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9251. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9252. }
  9253. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9254. if (slots == 4) {
  9255. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9256. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9257. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9258. }
  9259. else if (slots == 7) {
  9260. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9261. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9262. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9263. }
  9264. else {
  9265. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9266. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9267. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9268. }
  9269. packet->setDataByName("icon", item->details.icon);
  9270. packet->setDataByName("item_id", item->details.item_id);
  9271. packet->setDataByName("item_crc", crc);
  9272. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9273. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9274. packet->setDataByName("unknown5", 0xFF, 9);
  9275. packet->setDataByName("unknown5", 0xFF, 10);
  9276. QueuePacket(packet->serialize());
  9277. safe_delete(packet);
  9278. }
  9279. void Client::SendCollectionList() {
  9280. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9281. map<int32, Collection*>::iterator itr;
  9282. vector<struct CollectionItem*>* collection_items;
  9283. Collection* collection;
  9284. struct CollectionItem* collection_item;
  9285. PacketStruct* packet = 0;
  9286. int16 i = 0, j;
  9287. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9288. return;
  9289. packet->setArrayLengthByName("num_collections", collections->size());
  9290. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9291. collection = itr->second;
  9292. collection_items = collection->GetCollectionItems();
  9293. packet->setArrayDataByName("unknown", 1, i);
  9294. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9295. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9296. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9297. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9298. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9299. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9300. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9301. for (j = 0; j < collection_items->size(); j++) {
  9302. collection_item = collection_items->at(j);
  9303. Item* item = master_item_list.GetItem(collection_item->item);
  9304. if (item) {
  9305. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  9306. if (version < 955)
  9307. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9308. else
  9309. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9310. }
  9311. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9312. }
  9313. i++;
  9314. }
  9315. packet->setDataByName("new_collection_flag", 1);
  9316. QueuePacket(packet->serialize());
  9317. safe_delete(packet);
  9318. }
  9319. bool Client::SendCollectionsForItem(Item* item) {
  9320. map<int32, Collection*> collections_to_send;
  9321. map<int32, Collection*>* collections;
  9322. map<int32, Collection*>::iterator itr;
  9323. vector<struct CollectionItem*>* collection_items;
  9324. Collection* collection;
  9325. struct CollectionItem* collection_item;
  9326. PacketStruct* packet;
  9327. int16 i;
  9328. assert(item);
  9329. /* get any collections required by this item that the player already has */
  9330. collections = player->GetCollectionList()->GetCollections();
  9331. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9332. collection = itr->second;
  9333. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9334. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9335. collections_to_send[collection->GetID()] = collection;
  9336. }
  9337. }
  9338. /* get any collections required by this item that the player does not have and send it to the client */
  9339. collections = master_collection_list.GetCollections();
  9340. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9341. collection = itr->second;
  9342. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9343. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9344. return false;
  9345. }
  9346. packet->setArrayLengthByName("num_collections", 1);
  9347. packet->setArrayDataByName("unknown", 1, 0);
  9348. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9349. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9350. packet->setArrayDataByName("completed", 0, 0);
  9351. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9352. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9353. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9354. packet->setArrayDataByName("unknown3", 0x28, 0);
  9355. collection_items = collection->GetCollectionItems();
  9356. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9357. for (i = 0; i < collection_items->size(); i++) {
  9358. collection_item = collection_items->at(i);
  9359. Item* item2 = master_item_list.GetItem(collection_item->item);
  9360. if (item2) {
  9361. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  9362. if (version < 955)
  9363. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9364. else
  9365. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9366. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9367. }
  9368. }
  9369. packet->setDataByName("new_collection_flag", 0);
  9370. QueuePacket(packet->serialize());
  9371. safe_delete(packet);
  9372. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9373. collections_to_send[collection->GetID()] = collection;
  9374. }
  9375. }
  9376. /* send the client a list of collections that should be filtered for this item */
  9377. if (collections_to_send.size() > 0) {
  9378. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9379. return false;
  9380. }
  9381. i = 0;
  9382. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9383. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9384. collection = itr->second;
  9385. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9386. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9387. i++;
  9388. }
  9389. packet->setDataByName("item_icon", item->details.icon);
  9390. packet->setDataByName("item_name", item->name.c_str());
  9391. packet->setDataByName("item_id", item->details.item_id);
  9392. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9393. QueuePacket(packet->serialize());
  9394. safe_delete(packet);
  9395. }
  9396. return collections_to_send.size() > 0;
  9397. }
  9398. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9399. Collection* collection;
  9400. struct CollectionItem* collection_item;
  9401. PacketStruct* packet;
  9402. char tmp[200] = { 0 };
  9403. assert(item);
  9404. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9405. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9406. /* get the item struct that represents the item for this collection */
  9407. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9408. SendCollectionList();
  9409. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9410. return;
  9411. }
  9412. /* sanity check */
  9413. if (collection_item->found) {
  9414. SendCollectionList();
  9415. 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());
  9416. return;
  9417. }
  9418. }
  9419. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9420. collection = new Collection(collection);
  9421. /* get the item struct that represents the item for this collection */
  9422. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9423. SendCollectionList();
  9424. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9425. safe_delete(collection);
  9426. return;
  9427. }
  9428. /* add the new collection to the player's collection list */
  9429. if (!player->GetCollectionList()->AddCollection(collection)) {
  9430. SendCollectionList();
  9431. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9432. safe_delete(collection);
  9433. return;
  9434. }
  9435. }
  9436. else {
  9437. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9438. return;
  9439. }
  9440. collection_item->found = 1;
  9441. collection->SetSaveNeeded(true);
  9442. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9443. SendCollectionList();
  9444. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9445. return;
  9446. }
  9447. packet->setDataByName("collection_id", collection_id);
  9448. packet->setDataByName("collection_item_num", collection_item->index);
  9449. packet->setDataByName("add", 1);
  9450. QueuePacket(packet->serialize());
  9451. Item* item2 = master_item_list.GetItem(collection_item->item);
  9452. if (item2) {
  9453. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9454. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9455. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9456. }
  9457. safe_delete(packet);
  9458. RemoveItem(item, 1);
  9459. SendCollectionList();
  9460. }
  9461. void Client::DisplayCollectionComplete(Collection* collection) {
  9462. vector<struct CollectionRewardItem*>* reward_items;
  9463. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9464. struct CollectionRewardItem* reward_item;
  9465. PacketStruct* packet;
  9466. int32 i;
  9467. assert(collection);
  9468. reward_items = collection->GetRewardItems();
  9469. selectable_reward_items = collection->GetSelectableRewardItems();
  9470. if (GetVersion() <= 546) {
  9471. int32 source_id = collection->GetID();
  9472. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9473. if (packet2) {
  9474. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9475. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9476. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9477. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9478. if(reward_items){
  9479. int32 item_count = reward_items->size();
  9480. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9481. i = 0;
  9482. if(reward_items) {
  9483. for (i = 0; i < reward_items->size(); i++) {
  9484. Item* item = reward_items->at(i)->item;
  9485. if (item) {
  9486. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9487. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  9488. }
  9489. }
  9490. }
  9491. }
  9492. if (selectable_reward_items) {
  9493. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9494. for (i = 0; i < selectable_reward_items->size(); i++) {
  9495. Item* item = selectable_reward_items->at(i)->item;
  9496. if (item) {
  9497. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9498. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  9499. }
  9500. }
  9501. }
  9502. }
  9503. EQ2Packet* app = packet2->serialize();
  9504. QueuePacket(app);
  9505. safe_delete(packet2);
  9506. return;
  9507. }
  9508. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9509. return;
  9510. }
  9511. packet->setDataByName("title", "Quest Reward!");
  9512. packet->setDataByName("name", collection->GetName());
  9513. packet->setDataByName("description", collection->GetCategory());
  9514. packet->setDataByName("level", collection->GetLevel());
  9515. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9516. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9517. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9518. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9519. for (i = 0; i < reward_items->size(); i++) {
  9520. reward_item = reward_items->at(i);
  9521. if(!reward_item->item)
  9522. {
  9523. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9524. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9525. continue;
  9526. }
  9527. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9528. if (version < 860)
  9529. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  9530. else if (version < 1193)
  9531. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9532. else
  9533. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9534. }
  9535. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9536. for (i = 0; i < selectable_reward_items->size(); i++) {
  9537. reward_item = selectable_reward_items->at(i);
  9538. if(!reward_item->item)
  9539. {
  9540. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9541. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9542. continue;
  9543. }
  9544. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9545. if (version < 860)
  9546. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  9547. else if (version < 1193)
  9548. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9549. else
  9550. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9551. }
  9552. QueuePacket(packet->serialize());
  9553. safe_delete(packet);
  9554. }
  9555. void Client::HandInCollections() {
  9556. map<int32, Collection*>* collections;
  9557. map<int32, Collection*>::iterator itr;
  9558. Collection* collection;
  9559. /* only show 1 collection reward dialog at a time */
  9560. if (player->GetPendingCollectionReward()) {
  9561. return;
  9562. }
  9563. collections = player->GetCollectionList()->GetCollections();
  9564. /* 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
  9565. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9566. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9567. collection = itr->second;
  9568. if (collection->GetIsReadyToTurnIn()) {
  9569. player->SetPendingCollectionReward(collection);
  9570. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9571. QuestRewardData* data = new QuestRewardData;
  9572. data->quest_id = 0;
  9573. data->is_temporary = false;
  9574. data->description = std::string("");
  9575. data->is_collection = true;
  9576. data->has_displayed = false;
  9577. data->tmp_coin = 0;
  9578. data->tmp_status = 0;
  9579. data->db_saved = false;
  9580. data->db_index = 0;
  9581. quest_pending_reward.push_back(data);
  9582. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9583. quest_updates = true;
  9584. break;
  9585. }
  9586. }
  9587. if(quest_updates) {
  9588. SaveQuestRewardData(true);
  9589. }
  9590. }
  9591. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9592. vector<struct CollectionRewardItem*>* reward_items;
  9593. vector<struct CollectionRewardItem*>::iterator itr;
  9594. struct CollectionRewardItem* reward_item;
  9595. int16 num_slots_needed;
  9596. int16 num_slots;
  9597. assert(collection);
  9598. reward_items = collection->GetRewardItems();
  9599. num_slots_needed = (int16)reward_items->size();
  9600. if (selectable_item_id > 0)
  9601. num_slots_needed++;
  9602. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9603. if (num_slots < num_slots_needed) {
  9604. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9605. DisplayCollectionComplete(collection);
  9606. return;
  9607. }
  9608. /* add manditory items */
  9609. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9610. reward_item = *itr;
  9611. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9612. }
  9613. /* find and add the selectable item if there's one */
  9614. if (selectable_item_id > 0) {
  9615. reward_items = collection->GetSelectableRewardItems();
  9616. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9617. reward_item = *itr;
  9618. if (reward_item->item->details.item_id == selectable_item_id) {
  9619. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9620. break;
  9621. }
  9622. }
  9623. }
  9624. if (collection->GetRewardXP() > 0) {
  9625. player->AddXP((int32)collection->GetRewardXP());
  9626. }
  9627. if (collection->GetRewardCoin() > 0) {
  9628. player->AddCoins(collection->GetRewardCoin());
  9629. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9630. }
  9631. collection->SetCompleted(true);
  9632. //update achievements for completeing collection here
  9633. collection->SetSaveNeeded(true);
  9634. SendCollectionList();
  9635. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9636. player->SetPendingCollectionReward(0);
  9637. RemoveQueuedQuestReward();
  9638. GetPlayer()->SetActiveReward(false);
  9639. HandInCollections();
  9640. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9641. }
  9642. void Client::SendRecipeList() {
  9643. if(GetRecipeListSent()) {
  9644. return;
  9645. }
  9646. PacketStruct* packet = 0;
  9647. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9648. map<int32, Recipe*>::iterator itr;
  9649. int16 i = 0;
  9650. Recipe* recipe;
  9651. if(version <= 546) {
  9652. PacketStruct* packet = 0;
  9653. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9654. return;
  9655. }
  9656. packet->setArrayLengthByName("recipe_count", recipes->size());
  9657. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9658. recipe = itr->second;
  9659. int32 recipe_id = recipe->GetID();
  9660. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9661. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9662. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9663. i++;
  9664. }
  9665. //packet->PrintPacket();
  9666. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9667. QueuePacket(ret);
  9668. safe_delete(packet);
  9669. SetRecipeListSent(true);
  9670. return;
  9671. }
  9672. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9673. return;
  9674. }
  9675. int8 level = player->GetTSLevel();
  9676. int index = 0;
  9677. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9678. recipe = itr->second;
  9679. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9680. if (res != devices.end())
  9681. index = res - devices.begin();
  9682. else
  9683. devices.push_back(recipe->GetDevice());
  9684. }
  9685. packet->setDataByName("command_type", 0);
  9686. packet->setArrayLengthByName("num_recipes", recipes->size());
  9687. int stringsize = 0;
  9688. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9689. recipe = itr->second;
  9690. int32 myid = recipe->GetID();
  9691. int8 rlevel = recipe->GetLevel();
  9692. int8 even = level - level * .05 + .5;
  9693. int8 easymin = level - level * .25 + .5;
  9694. int8 veasymin = level - level * .35 + .5;
  9695. if (rlevel > level )
  9696. packet->setArrayDataByName("tier", 4, i);
  9697. else if ((rlevel <= level) & (rlevel >= even))
  9698. packet->setArrayDataByName("tier", 3, i);
  9699. else if ((rlevel <= even) & (rlevel >= easymin))
  9700. packet->setArrayDataByName("tier", 2, i);
  9701. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9702. packet->setArrayDataByName("tier", 1, i);
  9703. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9704. packet->setArrayDataByName("tier", 0, i);
  9705. if (rlevel == 2)
  9706. int xxx = 1;
  9707. packet->setArrayDataByName("recipe_id", myid, i);
  9708. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9709. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9710. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9711. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9712. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9713. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9714. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9715. if (recipe_device != devices.end())
  9716. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9717. else
  9718. {//TODO error should never get here
  9719. }
  9720. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9721. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9722. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9723. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9724. i++;
  9725. }
  9726. //packet->PrintPacket();
  9727. EQ2Packet* pack = packet->serialize();
  9728. QueuePacket(pack);
  9729. safe_delete(packet);
  9730. SetRecipeListSent(true);
  9731. }
  9732. void Client::ShowRecipeBook() {
  9733. PacketStruct* packet = 0;
  9734. Spawn* target = 0;
  9735. int index = 0;
  9736. if (!(target = player->GetTarget())) {
  9737. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9738. return;
  9739. }
  9740. if (!target->IsObject()) {
  9741. return;
  9742. }
  9743. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9744. return;
  9745. }
  9746. packet->setDataByName("device", target->GetName());
  9747. packet->setDataByName("unknown1", 1);
  9748. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9749. if (res != devices.end()){
  9750. index = res - devices.begin();
  9751. int32 deviceID = 0;
  9752. deviceID |= 1UL << index;
  9753. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9754. packet->setDataByName("unknown2", devices.size());
  9755. packet->setDataByName("unknown3", deviceID);
  9756. }
  9757. else
  9758. packet->setDataByName("unknown2", devices.size());
  9759. QueuePacket(packet->serialize());
  9760. safe_delete(packet);
  9761. }
  9762. void Client::SendTitleUpdate() {
  9763. // must call release read lock before leaving function on GetPlayerTitles
  9764. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9765. vector<Title*>::iterator itr;
  9766. Title* title;
  9767. sint32 i = 0;
  9768. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  9769. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  9770. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  9771. if (packet) {
  9772. packet->setArrayLengthByName("num_titles", titles->size());
  9773. for (itr = titles->begin(); itr != titles->end(); itr++) {
  9774. title = *itr;
  9775. packet->setArrayDataByName("title", title->GetName(), i);
  9776. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  9777. i++;
  9778. }
  9779. packet->setDataByName("current_prefix", prefix_index);
  9780. packet->setDataByName("current_suffix", suffix_index);
  9781. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9782. #if EQDEBUG >= 9
  9783. packet->PrintPacket();
  9784. #endif
  9785. QueuePacket(packet->serialize());
  9786. safe_delete(packet);
  9787. SendUpdateTitles(prefix_index, suffix_index);
  9788. }
  9789. player->GetPlayerTitles()->ReleaseReadLock();
  9790. }
  9791. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  9792. Title* suffix_title = 0;
  9793. Title* prefix_title = 0;
  9794. if (suffix != -1) {
  9795. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  9796. if(suffix_title)
  9797. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  9798. }
  9799. else
  9800. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  9801. if (prefix != -1) {
  9802. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  9803. if(prefix_title)
  9804. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  9805. }
  9806. else
  9807. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  9808. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  9809. }
  9810. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  9811. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  9812. list<Language*>::iterator itr;
  9813. Language* language;
  9814. int32 i = 0;
  9815. if(setlang==1){
  9816. GetPlayer()->SetCurrentLanguage(id);
  9817. }
  9818. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  9819. if (packet) {
  9820. packet->setArrayLengthByName("num_languages", languages->size());
  9821. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9822. language = *itr;
  9823. packet->setArrayDataByName("language_id", language->GetID(), i);
  9824. i++;
  9825. }
  9826. packet->setDataByName("current_language", id);
  9827. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9828. #if EQDEBUG >= 9
  9829. packet->PrintPacket();
  9830. #endif
  9831. QueuePacket(packet->serialize());
  9832. safe_delete(packet);
  9833. }
  9834. }
  9835. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  9836. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  9837. if (packet) {
  9838. if (pet_name)
  9839. packet->setDataByName("pet_name", pet_name);
  9840. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  9841. packet->setDataByName("protect_master", 1);
  9842. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  9843. packet->setDataByName("protect_self", 1);
  9844. if (player->GetInfoStruct()->get_pet_movement() == 2)
  9845. packet->setDataByName("stay_follow_toggle", 1);
  9846. packet->setDataByName("pet_type", type);
  9847. QueuePacket(packet->serialize());
  9848. }
  9849. safe_delete(packet);
  9850. }
  9851. bool Client::IsCrafting() {
  9852. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  9853. }
  9854. void Client::SendBiography() {
  9855. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  9856. if (packet) {
  9857. char biography[512];
  9858. if(player->GetInfoStruct()->get_biography().size() < 1)
  9859. {
  9860. safe_delete(packet);
  9861. return;
  9862. }
  9863. else
  9864. {
  9865. int16 size = player->GetInfoStruct()->get_biography().size();
  9866. if(size>511)
  9867. size = 511;
  9868. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  9869. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  9870. }
  9871. packet->setDataByName("biography", biography);
  9872. QueuePacket(packet->serialize());
  9873. }
  9874. safe_delete(packet);
  9875. }
  9876. PendingResurrection* Client::GetCurrentRez() {
  9877. return &current_rez;
  9878. }
  9879. Mutex* Client::GetResurrectMutex() {
  9880. return &m_resurrect;
  9881. }
  9882. void Client::SendResurrectionWindow() {
  9883. Spawn* caster = current_rez.caster;
  9884. if (!caster || !player)
  9885. return;
  9886. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9887. if (!packet)
  9888. return;
  9889. char* tmp = new char[512];
  9890. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  9891. packet->setMediumStringByName("text", tmp);
  9892. packet->setMediumStringByName("accept_text", "Yes");
  9893. packet->setMediumStringByName("cancel_text", "No");
  9894. sprintf(tmp, "accept_resurrection %u", player->GetID());
  9895. packet->setMediumStringByName("accept_command", tmp);
  9896. sprintf(tmp, "decline_resurrection %u", player->GetID());
  9897. packet->setMediumStringByName("cancel_command", tmp);
  9898. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  9899. QueuePacket(packet->serialize());
  9900. safe_delete(packet);
  9901. safe_delete_array(tmp);
  9902. }
  9903. void Client::AcceptResurrection() {
  9904. Spawn* caster = current_rez.caster;
  9905. if (!player || !caster)
  9906. return;
  9907. if (player->Alive())
  9908. return;
  9909. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9910. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9911. SendResurrectionWindow();
  9912. return;
  9913. }
  9914. player->GetZone()->ResurrectSpawn(player, this);
  9915. current_rez.should_delete = true;
  9916. }
  9917. void Client::SetPendingLastName(string last_name) {
  9918. pending_last_name = new string;
  9919. pending_last_name->assign(last_name);
  9920. }
  9921. string* Client::GetPendingLastName() {
  9922. return pending_last_name;
  9923. }
  9924. void Client::RemovePendingLastName() {
  9925. safe_delete(pending_last_name);
  9926. }
  9927. void Client::SendLastNameConfirmation() {
  9928. if (!pending_last_name)
  9929. return;
  9930. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9931. if (packet) {
  9932. char* text = new char[128];
  9933. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9934. packet->setDataByName("text", text);
  9935. packet->setDataByName("accept_text", "Yes");
  9936. packet->setDataByName("accept_command", "confirmedlastname");
  9937. packet->setDataByName("cancel_text", "No");
  9938. packet->setDataByName("max_length", 50);
  9939. packet->setDataByName("unknown4", 1);
  9940. packet->setDataByName("unknown5", 1);
  9941. QueuePacket(packet->serialize());
  9942. safe_delete(packet);
  9943. safe_delete_array(text);
  9944. }
  9945. }
  9946. void Client::AddQuestTimer(int32 quest_id) {
  9947. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9948. quest_timers.push_back(quest_id);
  9949. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9950. }
  9951. void Client::RemoveQuestTimer(int32 quest_id) {
  9952. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9953. vector<int32>::iterator itr;
  9954. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9955. if ((*itr) == quest_id) {
  9956. quest_timers.erase(itr);
  9957. break;
  9958. }
  9959. }
  9960. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9961. }
  9962. void Client::SavePlayerImages() {
  9963. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9964. // Save the paperdoll image if the server allows it
  9965. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9966. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9967. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9968. // Save the head shot if the server allows it
  9969. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9970. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9971. // Send the head shot to the login server
  9972. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9973. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9974. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9975. memset(packet->pBuffer, 0, size);
  9976. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9977. pic->account_id = GetAccountID();
  9978. pic->char_id = GetCharacterID();
  9979. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9980. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9981. loginserver.SendPacket(packet);
  9982. safe_delete(packet);
  9983. }
  9984. }
  9985. safe_delete_array(incoming_paperdoll.image_bytes);
  9986. incoming_paperdoll.current_size_bytes = 0;
  9987. }
  9988. void Client::EndAutoMount() {
  9989. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9990. if (packet) {
  9991. packet->setDataByName("parameter1", 128);
  9992. packet->setDataByName("parameter2", 64);
  9993. packet->setDataByName("value", 1);
  9994. QueuePacket(packet->serialize());
  9995. safe_delete(packet);
  9996. }
  9997. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9998. if (packet) {
  9999. packet->setDataByName("parameter3", 4);
  10000. packet->setDataByName("parameter5", 2);
  10001. packet->setDataByName("value", 0);
  10002. QueuePacket(packet->serialize());
  10003. safe_delete(packet);
  10004. }
  10005. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  10006. if (packet) {
  10007. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  10008. QueuePacket(packet->serialize());
  10009. safe_delete(packet);
  10010. }
  10011. on_auto_mount = false;
  10012. player->SetMount(((Player*)player)->GetTempMount());
  10013. EQ2_Color mount_color = player->GetTempMountColor();
  10014. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10015. player->SetMountColor(&mount_color);
  10016. player->SetMountSaddleColor(&saddle_color);
  10017. player->SetTempMount(0);
  10018. }
  10019. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10020. const char* spawn_script = spawn->GetSpawnScript();
  10021. bool should_use_spawn = true;
  10022. if (spawn_script) {
  10023. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10024. if (state) {
  10025. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10026. if (state_mutex)
  10027. state_mutex->writelock(__FUNCTION__, __LINE__);
  10028. lua_getglobal(state, "can_use_command");
  10029. if (lua_isfunction(state, -1)) {
  10030. lua_interface->SetSpawnValue(state, spawn);
  10031. lua_interface->SetSpawnValue(state, GetPlayer());
  10032. lua_interface->SetStringValue(state, command ? command : "");
  10033. if (lua_pcall(state, 3, 1, 0) == 0) {
  10034. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10035. }
  10036. }
  10037. lua_interface->ResetFunctionStack(state);
  10038. if (state_mutex)
  10039. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10040. }
  10041. }
  10042. return should_use_spawn;
  10043. }
  10044. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10045. return req_id == transmuteID;
  10046. }
  10047. void Client::SetTransmuteID(int32 trans_id) {
  10048. transmuteID = trans_id;
  10049. }
  10050. int32 Client::GetTransmuteID() {
  10051. return transmuteID;
  10052. }
  10053. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10054. {
  10055. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10056. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10057. if (zar)
  10058. {
  10059. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10060. if (database.IsActiveQuery(charID))
  10061. {
  10062. delayedLogin = true;
  10063. delayedAccountID = account_id;
  10064. delayedAccessKey = access_code;
  10065. delayTimer.Start(500);
  10066. 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);
  10067. return true;
  10068. }
  10069. delayedLogin = false;
  10070. delayTimer.Disable();
  10071. firstlogin = zar->isFirstLogin();
  10072. SetReadyForSpawns(false);
  10073. ready_for_updates = false;
  10074. 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);
  10075. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10076. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10077. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10078. GetPlayer()->vis_changed = false;
  10079. GetPlayer()->info_changed = false;
  10080. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10081. if (pvp_allowed)
  10082. this->GetPlayer()->SetAttackable(1);
  10083. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10084. if (client) {
  10085. if (client->getConnection())
  10086. client->getConnection()->SendDisconnect(true);
  10087. bool restore_ld_success = false;
  10088. if (client->GetCurrentZone() && !client->IsZoning()) {
  10089. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10090. if (client->GetVersion() == version) {
  10091. client->DisableSave();
  10092. client->ReplaceGroupClient(this);
  10093. Player* current_player = GetPlayer();
  10094. SetPlayer(client->GetPlayer());
  10095. GetPlayer()->SetClient(this);
  10096. GetPlayer()->SetReturningFromLD(true);
  10097. SetCharacterID(client->GetCharacterID());
  10098. SetAccountID(client->GetAccountID());
  10099. SetAdminStatus(client->GetAdminStatus());
  10100. SetCurrentZone(GetPlayer()->GetZone());
  10101. client->SetPlayer(current_player);
  10102. GetPlayer()->ResetSavedSpawns();
  10103. restore_ld_success = true;
  10104. char tmpldname[128];
  10105. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10106. client->GetPlayer()->SetName(tmpldname, false);
  10107. }
  10108. ZoneServer* tmpZone = client->GetCurrentZone();
  10109. tmpZone->RemoveClientImmediately(client);
  10110. }
  10111. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10112. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10113. ClientPacketFunctions::SendLoginDenied(this);
  10114. Disconnect();
  10115. return false;
  10116. }
  10117. }
  10118. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10119. if (!GetCurrentZone()) {
  10120. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10121. ClientPacketFunctions::SendLoginDenied(this);
  10122. Disconnect();
  10123. return false;
  10124. }
  10125. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10126. getConnection()->SetClientVersion(version);
  10127. GetCurrentZone()->SetSpawnStructs(this);
  10128. connected_to_zone = true;
  10129. client_list.Remove(this); //remove from master client list
  10130. GetCurrentZone()->AddClient(this); //add to zones client list
  10131. zone_list.AddClientToMap(player->GetName(), this);
  10132. // this initiates additional DB loading and client offloading within the Zone the player resides, need the client already added in zone and to the map above.
  10133. if(GetCurrentZone()->IsLoading()) {
  10134. new_client_login = NewLoginState::LOGIN_DELAYED;
  10135. }
  10136. else {
  10137. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10138. }
  10139. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10140. if (zone_script && lua_interface)
  10141. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10142. }
  10143. else {
  10144. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10145. version = 0;
  10146. ClientPacketFunctions::SendLoginDenied(this);
  10147. Disconnect();
  10148. return false;
  10149. }
  10150. }
  10151. else {
  10152. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10153. ClientPacketFunctions::SendLoginDenied(this);
  10154. Disconnect();
  10155. return false;
  10156. }
  10157. zone_auth.RemoveAuth(zar);
  10158. }
  10159. else
  10160. {
  10161. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10162. Disconnect();
  10163. return false;
  10164. }
  10165. return true;
  10166. }
  10167. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10168. if (!IsReadyForUpdates())
  10169. return;
  10170. map<int32, SpawnData> info_changes;
  10171. map<int32, SpawnData> pos_changes;
  10172. map<int32, SpawnData> vis_changes;
  10173. map<int32, SpawnData> empty_changes;
  10174. int32 info_size = 0;
  10175. int32 pos_size = 0;
  10176. int32 vis_size = 0;
  10177. int count = 0;
  10178. for (const auto& spawn : spawns) {
  10179. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10180. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10181. continue;
  10182. int16 tmp_info_size = 0;
  10183. int16 tmp_pos_size = 0;
  10184. int16 tmp_vis_size = 0;
  10185. if (spawn->vis_changed)
  10186. {
  10187. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10188. if (vis_change) {
  10189. SpawnData data;
  10190. data.spawn = spawn;
  10191. data.data = vis_change;
  10192. data.size = tmp_vis_size;
  10193. map<int32, SpawnData> tmp_vis_changes;
  10194. tmp_vis_changes[index] = data;
  10195. map<int32, SpawnData> tmp_info_changes;
  10196. map<int32, SpawnData> tmp_pos_changes;
  10197. if (spawn->info_changed) {
  10198. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10199. if (info_change) {
  10200. SpawnData data;
  10201. data.spawn = spawn;
  10202. data.data = info_change;
  10203. data.size = tmp_info_size;
  10204. tmp_info_changes[index] = data;
  10205. }
  10206. }
  10207. if (spawn->position_changed) {
  10208. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10209. if (pos_change) {
  10210. SpawnData data;
  10211. data.spawn = spawn;
  10212. data.data = pos_change;
  10213. data.size = tmp_pos_size;
  10214. tmp_pos_changes[index] = data;
  10215. }
  10216. }
  10217. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10218. for (auto& kv : tmp_info_changes) {
  10219. safe_delete_array(kv.second.data);
  10220. }
  10221. for (auto& kv : tmp_pos_changes) {
  10222. safe_delete_array(kv.second.data);
  10223. }
  10224. for (auto& kv : tmp_vis_changes) {
  10225. safe_delete_array(kv.second.data);
  10226. }
  10227. continue;
  10228. }
  10229. }
  10230. if (spawn->info_changed) {
  10231. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10232. if (info_change) {
  10233. SpawnData data;
  10234. data.spawn = spawn;
  10235. data.data = info_change;
  10236. data.size = tmp_info_size;
  10237. info_size += tmp_info_size;
  10238. info_changes[index] = data;
  10239. }
  10240. count++;
  10241. }
  10242. if (spawn->position_changed) {
  10243. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10244. if (pos_change) {
  10245. SpawnData data;
  10246. data.spawn = spawn;
  10247. data.data = pos_change;
  10248. data.size = tmp_pos_size;
  10249. pos_size += tmp_pos_size;
  10250. pos_changes[index] = data;
  10251. }
  10252. count++;
  10253. }
  10254. if (spawn->vis_changed) {
  10255. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10256. if (vis_change) {
  10257. SpawnData data;
  10258. data.spawn = spawn;
  10259. data.data = vis_change;
  10260. data.size = tmp_vis_size;
  10261. vis_size += tmp_vis_size;
  10262. vis_changes[index] = data;
  10263. }
  10264. count++;
  10265. }
  10266. }
  10267. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10268. return;
  10269. }
  10270. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10271. for (auto& kv : info_changes) {
  10272. safe_delete_array(kv.second.data);
  10273. }
  10274. for (auto& kv : pos_changes) {
  10275. safe_delete_array(kv.second.data);
  10276. }
  10277. for (auto& kv : vis_changes) {
  10278. safe_delete_array(kv.second.data);
  10279. }
  10280. }
  10281. 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)
  10282. {
  10283. static const int8 oversized = 255;
  10284. int16 opcode_val = 0;
  10285. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10286. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10287. }
  10288. int32 size = info_size + pos_size + vis_size + 8;
  10289. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  10290. size += 3;
  10291. size += CheckOverLoadSize(info_size);
  10292. size += CheckOverLoadSize(pos_size);
  10293. size += CheckOverLoadSize(vis_size);
  10294. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  10295. size += 2;
  10296. }
  10297. uchar* tmp = new uchar[size];
  10298. uchar* ptr = tmp;
  10299. memset(tmp, 0, size);
  10300. if (version <= 283) {
  10301. if (size >= 255) {
  10302. size -= 3;
  10303. memcpy(ptr, &oversized, sizeof(int8));
  10304. ptr += sizeof(int8);
  10305. memcpy(ptr, &size, sizeof(int16));
  10306. ptr += sizeof(int16);
  10307. size += 3;
  10308. }
  10309. else {
  10310. size -= 1;
  10311. memcpy(ptr, &size, sizeof(int8));
  10312. ptr += sizeof(int8);
  10313. size += 1;
  10314. }
  10315. }
  10316. else {
  10317. size -= 4;
  10318. memcpy(ptr, &size, sizeof(int32));
  10319. ptr += sizeof(int32);
  10320. size += 4;
  10321. }
  10322. memcpy(ptr, &oversized, sizeof(int8));
  10323. ptr += sizeof(int8);
  10324. memcpy(ptr, &opcode_val, sizeof(int16));
  10325. ptr += sizeof(int16);
  10326. int32 current_time = Timer::GetCurrentTime2();
  10327. memcpy(ptr, &current_time, sizeof(int32));
  10328. ptr += sizeof(int32);
  10329. ptr += DoOverLoad(info_size, ptr);
  10330. for (const auto& kv : info_changes) {
  10331. auto info = kv.second;
  10332. memcpy(ptr, info.data, info.size);
  10333. ptr += info.size;
  10334. }
  10335. ptr += DoOverLoad(pos_size, ptr);
  10336. for (const auto& kv : pos_changes) {
  10337. auto pos = kv.second;
  10338. memcpy(ptr, pos.data, pos.size);
  10339. ptr += pos.size;
  10340. }
  10341. ptr += DoOverLoad(vis_size, ptr);
  10342. for (const auto& kv : vis_changes) {
  10343. auto vis = kv.second;
  10344. memcpy(ptr, vis.data, vis.size);
  10345. ptr += vis.size;
  10346. }
  10347. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10348. if (packet) {
  10349. /*char blah[64];
  10350. snprintf(blah, 64, "Sending %i", current_time);
  10351. SimpleMessage(4, blah);*/
  10352. QueuePacket(packet);
  10353. }
  10354. delete[] tmp;
  10355. }
  10356. void Client::SendHailCommand(Spawn* spawn)
  10357. {
  10358. // hardcoded 'hail' entity commands
  10359. switch (spawn->secondary_command_list_id)
  10360. {
  10361. case 9:
  10362. case 1262:
  10363. case 1265:
  10364. case 1267:
  10365. {
  10366. EQ2_16BitString* command = new EQ2_16BitString();
  10367. command->data = "";
  10368. command->size = 0;
  10369. commands.Process(COMMAND_HAIL, command, this, spawn);
  10370. safe_delete(command);
  10371. break;
  10372. }
  10373. }
  10374. }
  10375. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10376. {
  10377. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10378. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10379. if (packet) {
  10380. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10381. packet->setMediumStringByName("command_name", command);
  10382. packet->setDataByName("distance", distance);
  10383. QueuePacket(packet->serialize());
  10384. safe_delete(packet);
  10385. }
  10386. }
  10387. }
  10388. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10389. {
  10390. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10391. return false;
  10392. if (command == "house_spawn_examine")
  10393. {
  10394. uint32 itemID = spawn->GetPickupItemID();
  10395. if (itemID)
  10396. {
  10397. Item* item = master_item_list.GetItem(itemID);
  10398. if (item)
  10399. {
  10400. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10401. //DumpPacket(app);
  10402. QueuePacket(app);
  10403. }
  10404. }
  10405. return true;
  10406. }
  10407. return false;
  10408. }
  10409. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10410. {
  10411. if (GetTempPlacementSpawn())
  10412. {
  10413. Spawn* tmp = GetTempPlacementSpawn();
  10414. int32 spawn_group_id = database.GetNextSpawnLocation();
  10415. tmp->SetSpawnLocationID(spawn_group_id);
  10416. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10417. int32 spawnDBID = 0;
  10418. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10419. {
  10420. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10421. tmp->SetDatabaseID(spawnDBID);
  10422. }
  10423. else
  10424. {
  10425. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10426. if (spawnDBID)
  10427. {
  10428. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10429. tmp->SetDatabaseID(spawnDBID);
  10430. }
  10431. }
  10432. tmp->SetX(place_object->getType_float_ByName("x"));
  10433. tmp->SetY(place_object->getType_float_ByName("y"));
  10434. tmp->SetZ(place_object->getType_float_ByName("z"));
  10435. tmp->SetHeading(newHeading);
  10436. tmp->SetSpawnOrigX(tmp->GetX());
  10437. tmp->SetSpawnOrigY(tmp->GetY());
  10438. tmp->SetSpawnOrigZ(tmp->GetZ());
  10439. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10440. database.SaveSpawnInfo(tmp);
  10441. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10442. if (!spawnDBID)
  10443. {
  10444. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10445. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10446. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10447. }
  10448. return true;
  10449. }
  10450. return false;
  10451. }
  10452. bool Client::PopulateHouseSpawnFinalize()
  10453. {
  10454. if (GetTempPlacementSpawn())
  10455. {
  10456. Spawn* tmp = GetTempPlacementSpawn();
  10457. GetCurrentZone()->AddSpawn(tmp);
  10458. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10459. SetTempPlacementSpawn(nullptr);
  10460. int32 uniqueID = GetPlacementUniqueItemID();
  10461. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10462. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10463. tmp->SetPickupUniqueItemID(uniqueID);
  10464. if (uniqueItem)
  10465. {
  10466. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10467. {
  10468. Query query;
  10469. query.RunQuery2(Q_INSERT, "insert into spawn_instance_data set spawn_id = %u, spawn_location_id = %u, pickup_item_id = %u, pickup_unique_item_id = %u", tmp->GetDatabaseID(), tmp->GetSpawnLocationID(), tmp->GetPickupItemID(), uniqueID);
  10470. }
  10471. if(uniqueItem->GetItemScript() &&
  10472. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10473. {
  10474. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10475. }
  10476. if(uniqueItem) {
  10477. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10478. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10479. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10480. }
  10481. SetPlacementUniqueItemID(0);
  10482. }
  10483. return true;
  10484. }
  10485. return false;
  10486. }
  10487. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10488. {
  10489. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10490. packet->setDataByName("placement_mode", placementMode);
  10491. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10492. packet->setDataByName("model_type", spawn->GetModelType());
  10493. packet->setDataByName("unknown", 1); //size
  10494. packet->setDataByName("unknown2", 1); //size 2
  10495. packet->setDataByName("unknown2", .5, 1); //size 3
  10496. packet->setDataByName("unknown2", 3, 2);
  10497. packet->setDataByName("unknown2", unknown2_3, 3);
  10498. packet->setDataByName("max_distance", 500);
  10499. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10500. QueuePacket(packet->serialize());
  10501. safe_delete(packet);
  10502. }
  10503. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10504. {
  10505. SetPendingFlightPath(path_id);
  10506. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10507. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10508. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10509. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10510. if (packet) {
  10511. QueuePacket(packet->serialize());
  10512. safe_delete(packet);
  10513. }
  10514. if (mount_id)
  10515. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10516. }
  10517. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10518. {
  10519. if (!sender)
  10520. {
  10521. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10522. return;
  10523. }
  10524. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10525. if (!packet) {
  10526. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10527. return;
  10528. }
  10529. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10530. packet->setDataByName("book_title", title.c_str());
  10531. packet->setDataByName("book_type", "simple");
  10532. packet->setDataByName("unknown2", 1);
  10533. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10534. packet->setDataByName("language", language);
  10535. if (GetVersion() > 546)
  10536. packet->setDataByName("unknown5", 1, 4);
  10537. packet->setArrayLengthByName("num_pages", num_pages);
  10538. va_list args;
  10539. va_start(args, num_pages);
  10540. std::string endString("");
  10541. for (int8 p = 0; p < num_pages; p++)
  10542. {
  10543. std::string page = va_arg(args, string);
  10544. switch (GetVersion())
  10545. {
  10546. // release client
  10547. case 283:
  10548. {
  10549. endString.append(page);
  10550. break;
  10551. }
  10552. // DoF trial
  10553. case 546:
  10554. {
  10555. if (p == 0)
  10556. packet->setDataByName("cover_page", page.c_str());
  10557. else
  10558. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10559. break;
  10560. }
  10561. // all other clients
  10562. default:
  10563. {
  10564. packet->setArrayDataByName("page_text", page.c_str(), p);
  10565. break;
  10566. }
  10567. }
  10568. }
  10569. if (GetVersion() == 283)
  10570. {
  10571. packet->setDataByName("page_text", endString.c_str());
  10572. }
  10573. va_end(args);
  10574. QueuePacket(packet->serialize());
  10575. safe_delete(packet);
  10576. }
  10577. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10578. {
  10579. if (!sender)
  10580. {
  10581. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10582. return;
  10583. }
  10584. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10585. if (!packet) {
  10586. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10587. return;
  10588. }
  10589. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10590. packet->setDataByName("book_title", title.c_str());
  10591. packet->setDataByName("book_type", "simple");
  10592. packet->setDataByName("unknown2", 1);
  10593. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10594. packet->setDataByName("language", language);
  10595. if (GetVersion() > 546)
  10596. packet->setDataByName("unknown5", 1, 4);
  10597. packet->setArrayLengthByName("num_pages", pages.size());
  10598. std::string endString("");
  10599. for (int8 p = 0; p < pages.size(); p++)
  10600. {
  10601. Item::BookPage* page = pages[p];
  10602. std::string pageText = string(page->page_text.data);
  10603. switch (GetVersion())
  10604. {
  10605. // release client
  10606. case 283:
  10607. {
  10608. endString.append(pageText);
  10609. break;
  10610. }
  10611. // DoF trial
  10612. case 546:
  10613. {
  10614. if (p == 0)
  10615. packet->setDataByName("cover_page", pageText.c_str());
  10616. else
  10617. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10618. break;
  10619. }
  10620. // all other clients
  10621. default:
  10622. {
  10623. int8 valign = int8(page->valign);
  10624. int8 halign = int8(page->halign);
  10625. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10626. packet->setArrayDataByName("page_text_valign", valign, p);
  10627. packet->setArrayDataByName("page_text_halign", halign, p);
  10628. break;
  10629. }
  10630. }
  10631. }
  10632. if (GetVersion() == 283)
  10633. {
  10634. packet->setDataByName("page_text", endString.c_str());
  10635. }
  10636. QueuePacket(packet->serialize());
  10637. safe_delete(packet);
  10638. }
  10639. void Client::ReplaceGroupClient(Client* new_client)
  10640. {
  10641. if (this->GetPlayer()->GetGroupMemberInfo())
  10642. {
  10643. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10644. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10645. if(group)
  10646. {
  10647. group->MGroupMembers.writelock();
  10648. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10649. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10650. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10651. group->MGroupMembers.releasewritelock();
  10652. }
  10653. else
  10654. {
  10655. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10656. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10657. this->GetPlayer()->SetGroupMemberInfo(0);
  10658. }
  10659. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10660. }
  10661. }
  10662. void Client::TempRemoveGroup()
  10663. {
  10664. if (this->GetPlayer()->GetGroupMemberInfo())
  10665. {
  10666. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10667. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10668. if(group)
  10669. {
  10670. group->MGroupMembers.writelock();
  10671. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10672. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10673. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10674. this->GetPlayer()->SetGroupMemberInfo(0);
  10675. group->MGroupMembers.releasewritelock();
  10676. group->RemoveClientReference(this);
  10677. }
  10678. else
  10679. {
  10680. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10681. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10682. this->GetPlayer()->SetGroupMemberInfo(0);
  10683. }
  10684. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10685. }
  10686. }
  10687. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10688. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10689. {
  10690. Mail mail;
  10691. mail.mail_id = 0;
  10692. mail.already_read = 0;
  10693. mail.postage_cost = 0;
  10694. mail.attachment_cost = 0;
  10695. mail.save_needed = 1;
  10696. //uhh...mail has std::strings so
  10697. //memset(&mail,0,sizeof(Mail));
  10698. mail.player_to_id = charID;
  10699. mail.player_from = fromName;
  10700. mail.subject = subjectName;
  10701. mail.mail_body = mailBody;
  10702. mail.mail_type = mailType;
  10703. mail.coin_copper = copper;
  10704. mail.coin_silver = silver;
  10705. mail.coin_gold = gold;
  10706. mail.coin_plat = platinum;
  10707. mail.char_item_id = item_id;
  10708. mail.stack = stack_size;
  10709. mail.time_sent = time_sent;
  10710. mail.expire_time = expire_time;
  10711. database.SavePlayerMail(&mail);
  10712. }
  10713. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10714. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10715. {
  10716. Mail* mail = new Mail();
  10717. mail->player_to_id = GetCharacterID();
  10718. mail->player_from = fromName;
  10719. mail->subject = subjectName;
  10720. mail->mail_body = mailBody;
  10721. mail->mail_type = mailType;
  10722. mail->coin_copper = copper;
  10723. mail->coin_silver = silver;
  10724. mail->coin_gold = gold;
  10725. mail->coin_plat = platinum;
  10726. mail->char_item_id = item_id;
  10727. mail->stack = stack_size;
  10728. mail->time_sent = time_sent;
  10729. mail->expire_time = expire_time;
  10730. mail->postage_cost = 0;
  10731. mail->save_needed = 1;
  10732. mail->already_read = 0;
  10733. database.SavePlayerMail(mail);
  10734. GetPlayer()->AddMail(mail);
  10735. }
  10736. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10737. {
  10738. if(slot < NUM_SLOTS)
  10739. {
  10740. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10741. if (app)
  10742. QueuePacket(app);
  10743. }
  10744. else
  10745. {
  10746. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10747. if (outapp)
  10748. QueuePacket(outapp);
  10749. }
  10750. }
  10751. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10752. {
  10753. if(spawn_player_id < 1)
  10754. return;
  10755. MQueueStateCmds.writelock();
  10756. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10757. MQueueStateCmds.releasewritelock();
  10758. }
  10759. void Client::ProcessStateCommands()
  10760. {
  10761. if(!IsReadyForUpdates())
  10762. return;
  10763. MQueueStateCmds.writelock();
  10764. map<int32, int32>::iterator itr = queued_state_commands.begin();
  10765. for(; itr != queued_state_commands.end(); itr++)
  10766. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  10767. queued_state_commands.clear();
  10768. MQueueStateCmds.releasewritelock();
  10769. }
  10770. void Client::PurgeItem(Item* item)
  10771. {
  10772. std::unique_lock lock(MConversation);
  10773. map<int32, Item*>::iterator itr;
  10774. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  10775. {
  10776. if ( itr->second == item )
  10777. {
  10778. conversation_items.erase(itr);
  10779. break;
  10780. }
  10781. }
  10782. }
  10783. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  10784. {
  10785. if(GetPlayer()->StopSaveSpellEffects())
  10786. return;
  10787. if(item) {
  10788. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  10789. if(item->GetItemScript() && lua_interface){
  10790. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  10791. if (slot == 22)
  10792. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  10793. else
  10794. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  10795. }
  10796. if (item->details.count > 1) {
  10797. item->details.count -= 1;
  10798. item->save_needed = true;
  10799. }
  10800. else {
  10801. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  10802. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  10803. }
  10804. GetPlayer()->SetCharSheetChanged(true);
  10805. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  10806. }
  10807. }
  10808. void Client::AwardCoins(int64 total_coins, std::string reason)
  10809. {
  10810. if (total_coins > 0) {
  10811. player->AddCoins(total_coins);
  10812. PlaySound("coin_cha_ching");
  10813. char tmp[64] = { 0 };
  10814. string message = "You receive ";
  10815. int32 val = 0;
  10816. if (total_coins >= 1000000) {
  10817. val = total_coins / 1000000;
  10818. total_coins -= 1000000 * val;
  10819. sprintf(tmp, "%u Platinum ", val);
  10820. message.append(tmp);
  10821. memset(tmp, 0, 64);
  10822. }
  10823. if (total_coins >= 10000) {
  10824. val = total_coins / 10000;
  10825. total_coins -= 10000 * val;
  10826. sprintf(tmp, "%u Gold ", val);
  10827. message.append(tmp);
  10828. memset(tmp, 0, 64);
  10829. }
  10830. if (total_coins >= 100) {
  10831. val = total_coins / 100;
  10832. total_coins -= 100 * val;
  10833. sprintf(tmp, "%u Silver ", val);
  10834. message.append(tmp);
  10835. memset(tmp, 0, 64);
  10836. }
  10837. if (total_coins > 0) {
  10838. sprintf(tmp, "%u Copper ", (int32)total_coins);
  10839. message.append(tmp);
  10840. }
  10841. message.append(reason);
  10842. int8 type = CHANNEL_LOOT;
  10843. SimpleMessage(type, message.c_str());
  10844. }
  10845. }
  10846. void Client::TriggerSpellSave()
  10847. {
  10848. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  10849. // default to not have some bogus value in the rule
  10850. if(interval < 1)
  10851. interval = 100;
  10852. MSaveSpellStateMutex.lock();
  10853. if(!save_spell_state_timer.Enabled())
  10854. {
  10855. save_spell_state_time_bucket = 0;
  10856. save_spell_state_timer.Start(interval, true);
  10857. }
  10858. else
  10859. {
  10860. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  10861. save_spell_state_time_bucket += elapsed_time;
  10862. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  10863. // default to not have some bogus value in the rule
  10864. if(save_wait_cap < interval)
  10865. save_wait_cap = interval+1;
  10866. if(save_spell_state_time_bucket >= save_wait_cap)
  10867. {
  10868. save_spell_state_timer.Trigger();
  10869. }
  10870. }
  10871. MSaveSpellStateMutex.unlock();
  10872. }
  10873. void Client::UpdateSentSpellList() {
  10874. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  10875. std::map<int32, int32>::iterator itr;
  10876. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  10877. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  10878. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  10879. QueuePacket(app);
  10880. }
  10881. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  10882. }
  10883. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  10884. tempPlacementSpawn = tmp;
  10885. hasSentTempPlacementSpawn = false;
  10886. if(tempPlacementSpawn)
  10887. temp_placement_timer.Start();
  10888. else
  10889. temp_placement_timer.Disable();
  10890. }
  10891. void Client::SetPlayer(Player* new_player) {
  10892. if (player && player != new_player)
  10893. zone_list.RemoveClientFromMap(player->GetName(), this);
  10894. player = new_player;
  10895. player->SetClient(this);
  10896. }
  10897. bool Client::UseItem(Item* item, Spawn* target) {
  10898. if (item && item->GetItemScript()) {
  10899. int16 item_index = item->details.index;
  10900. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  10901. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  10902. }
  10903. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  10904. Message(0, "%s requires an evil race.", item->name.c_str());
  10905. }
  10906. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  10907. Message(0, "%s requires a good race.", item->name.c_str());
  10908. }
  10909. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  10910. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  10911. return true;
  10912. }
  10913. else {
  10914. if (item->details.count > 0) {
  10915. std::string itemName = string(item->name);
  10916. int32 item_id = item->details.item_id;
  10917. sint64 flags = 0;
  10918. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  10919. {
  10920. //reobtain item make sure it wasn't removed
  10921. item = player->item_list.GetItemFromIndex(item_index);
  10922. if(!item) {
  10923. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, however after the item looks to be removed.", GetPlayer()->GetName(), itemName.c_str(), item_id);
  10924. return true;
  10925. }
  10926. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  10927. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10928. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10929. return true;
  10930. }
  10931. else
  10932. {
  10933. item->details.count--; // charges
  10934. item->save_needed = true;
  10935. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  10936. if(!item->details.count) {
  10937. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10938. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10939. }
  10940. return true;
  10941. }
  10942. }
  10943. else {
  10944. LogWrite(PLAYER__WARNING, 0, "Command", "%s: Item %s (%i) was used, after it returned %i, bypassing any removal/update of items.", GetPlayer()->GetName(), itemName.c_str(), item_id, flags);
  10945. return true;
  10946. }
  10947. }
  10948. else
  10949. {
  10950. //reobtain item make sure it wasn't removed
  10951. item = player->item_list.GetItemFromIndex(item_index);
  10952. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10953. if(item) {
  10954. LogWrite(PLAYER__ERROR, 0, "Command", "%s: Item %s (%i) attempted to be used, however details.count is 0.", GetPlayer()->GetName(), item->name.c_str(), item->details.item_id);
  10955. }
  10956. }
  10957. }
  10958. }
  10959. return false;
  10960. }
  10961. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10962. VoiceOverStruct* garble, bool success, bool garble_success) {
  10963. VoiceOverStruct* resStruct = nullptr;
  10964. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10965. if(success) {
  10966. resStruct = non_garble;
  10967. }
  10968. }
  10969. else if(garble_success) {
  10970. resStruct = garble;
  10971. }
  10972. if(resStruct) {
  10973. GetPlayer()->GetZone()->PlayFlavor(this, spawn, resStruct->mp3_string.c_str(), resStruct->text_string.c_str(), resStruct->emote_string.c_str(), resStruct->key1, resStruct->key2, language);
  10974. }
  10975. }
  10976. void Client::SaveQuestRewardData(bool force_refresh) {
  10977. Query query;
  10978. if(force_refresh) {
  10979. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10980. GetCharacterID());
  10981. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10982. GetCharacterID());
  10983. }
  10984. vector<QuestRewardData*>::iterator itr;
  10985. vector<QuestRewardData*> tmp_quest_rewards;
  10986. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10987. int index = 0;
  10988. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10989. int32 questID = (*itr)->quest_id;
  10990. if(!(*itr)->db_saved || force_refresh) {
  10991. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_rewards (char_id, indexed, quest_id, is_temporary, is_collection, has_displayed, tmp_coin, tmp_status, description) values(%u, %u, %u, %u, %u, %u, %llu, %u, '%s')",
  10992. GetCharacterID(), index, questID, (*itr)->is_temporary, (*itr)->is_collection, (*itr)->has_displayed, (*itr)->tmp_coin, (*itr)->tmp_status, database.getSafeEscapeString((*itr)->description.c_str()).c_str());
  10993. (*itr)->db_saved = true;
  10994. (*itr)->db_index = index;
  10995. if(questID && (*itr)->is_temporary) {
  10996. std::vector<Item*> items;
  10997. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  10998. if(!force_refresh && items.size() > 0) {
  10999. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  11000. GetCharacterID(), questID);
  11001. }
  11002. for(int i=0;i<items.size();i++) {
  11003. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  11004. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  11005. }
  11006. }
  11007. }
  11008. index++;
  11009. }
  11010. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11011. }
  11012. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11013. if(!data)
  11014. return;
  11015. if(data->db_saved) {
  11016. Query query;
  11017. query.AddQueryAsync(GetCharacterID(), &database, Q_INSERT, "update character_quest_rewards set is_temporary = %u, is_collection = %u, has_displayed = %u, tmp_coin = %llu, tmp_status = %u, description = '%s' where char_id=%u and indexed=%u and quest_id=%u",
  11018. data->is_temporary, data->is_collection, data->has_displayed, data->tmp_coin, data->tmp_status, database.getSafeEscapeString(data->description.c_str()).c_str(), GetCharacterID(), data->db_index, data->quest_id);
  11019. }
  11020. }
  11021. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11022. int index = 0;
  11023. if(recipe == nullptr)
  11024. return;
  11025. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11026. if (prl->GetRecipe(recipe->GetID())) {
  11027. delete recipe;
  11028. return;
  11029. }
  11030. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11031. if (res != devices.end())
  11032. index = res - devices.begin();
  11033. else
  11034. devices.push_back(recipe->GetDevice());
  11035. prl->AddRecipe(recipe);
  11036. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11037. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11038. if (packet && GetRecipeListSent()) {
  11039. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11040. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11041. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11042. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11043. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11044. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11045. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11046. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11047. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11048. if (recipe_device != devices.end())
  11049. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11050. else
  11051. {//TODO error should never get here
  11052. }
  11053. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11054. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11055. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11056. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11057. if(i) {
  11058. (*i)++;
  11059. }
  11060. }
  11061. }
  11062. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11063. if(!spawn) {
  11064. pov_ghost_spawn_id = 0;
  11065. SendCharPOVGhost();
  11066. return true;
  11067. }
  11068. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11069. if(ghost_id) {
  11070. pov_ghost_spawn_id = spawn->GetID();
  11071. SendCharPOVGhost();
  11072. return true;
  11073. }
  11074. return false;
  11075. }
  11076. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11077. std::string conversation = "";
  11078. bool conv_established = false;
  11079. MConversation.lock_shared();
  11080. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11081. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11082. conv_established = true;
  11083. }
  11084. int32 spawn_id = conversation_spawns[conversation_id];
  11085. Item* item = conversation_items[conversation_id];
  11086. MConversation.unlock_shared();
  11087. if (GetCurrentZone()) {
  11088. Spawn* spawn = nullptr;
  11089. if(spawn_id) {
  11090. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11091. }
  11092. if (conv_established) {
  11093. if (spawn) {
  11094. if(conversation == "CloseItemConversation") {
  11095. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11096. }
  11097. else {
  11098. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11099. }
  11100. }
  11101. else if (item && lua_interface && item->GetItemScript())
  11102. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11103. else
  11104. CloseDialog(conversation_id);
  11105. }
  11106. else
  11107. CloseDialog(conversation_id);
  11108. }
  11109. }
  11110. bool Client::SetPetName(const char* petName) {
  11111. int8 result = database.CheckNameFilter(petName,4,31);
  11112. if (result == BADNAMELENGTH_REPLY) {
  11113. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11114. return false;
  11115. }
  11116. else if (result == NAMEINVALID_REPLY) {
  11117. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11118. return false;
  11119. }
  11120. else if (result == NAMETAKEN_REPLY) {
  11121. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11122. return false;
  11123. }
  11124. else if (result == NAMEFILTER_REPLY) {
  11125. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11126. return false;
  11127. }
  11128. else if (result == UNKNOWNERROR_REPLY) {
  11129. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11130. return false;
  11131. }
  11132. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11133. return true;
  11134. }
  11135. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11136. switch(slot) {
  11137. case EQ2_FOOD_SLOT: {
  11138. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11139. if(send_message) {
  11140. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11141. }
  11142. return false;
  11143. }
  11144. break;
  11145. }
  11146. case EQ2_DRINK_SLOT: {
  11147. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11148. {
  11149. if(send_message) {
  11150. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11151. }
  11152. return false;
  11153. }
  11154. break;
  11155. }
  11156. default: {
  11157. return false;
  11158. break;
  11159. }
  11160. }
  11161. return true;
  11162. }
  11163. void Client::StartLinkdeadTimer() {
  11164. if(!linkdead_timer) {
  11165. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11166. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11167. linkdead_timer = new Timer(LD_Timer);
  11168. linkdead_timer->Enable();
  11169. if(GetPlayer()->GetGroupMemberInfo()) {
  11170. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11171. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11172. }
  11173. }
  11174. }
  11175. bool Client::IsLinkdeadTimerEnabled() {
  11176. if(linkdead_timer) {
  11177. return linkdead_timer->Enabled();
  11178. }
  11179. return false;
  11180. }
  11181. void Client::SendNewAdventureSpells() {
  11182. SendNewSpells(player->GetAdventureClass());
  11183. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11184. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11185. if(base_class != player->GetAdventureClass()) {
  11186. SendNewSpells(base_class);
  11187. }
  11188. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11189. SendNewSpells(secondary_class);
  11190. }
  11191. }
  11192. void Client::SendNewTradeskillSpells() {
  11193. SendNewTSSpells(player->GetTradeskillClass());
  11194. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11195. if(secondary_class != player->GetTradeskillClass()) {
  11196. SendNewTSSpells(secondary_class);
  11197. }
  11198. }
  11199. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11200. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11201. if(master_recipe) {
  11202. Recipe* recipe_book = new Recipe(master_recipe);
  11203. // if valid recipe book and the player doesn't have it
  11204. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11205. if(item) {
  11206. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11207. }
  11208. safe_delete(recipe_book);
  11209. }
  11210. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11211. if(item) {
  11212. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11213. }
  11214. safe_delete(recipe_book);
  11215. }
  11216. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11217. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11218. // Add recipe book to the players list
  11219. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11220. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11221. }
  11222. std::vector<Recipe*> recipes;
  11223. // Get a list of all recipes this book contains
  11224. if (item && item->recipebook_info) {
  11225. //Backup I guess if the recipe book is empty for whatever reason?
  11226. for (auto& itr : item->recipebook_info->recipes) {
  11227. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11228. if (r) {
  11229. recipes.push_back(r);
  11230. }
  11231. }
  11232. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11233. }
  11234. else {
  11235. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11236. }
  11237. //Filter out duplicate recipes the player already has
  11238. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11239. Recipe* recipe = *itr;
  11240. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11241. itr = recipes.erase(itr);
  11242. }
  11243. else itr++;
  11244. }
  11245. int16 i = 0;
  11246. // Create the packet to send to update the players recipe list
  11247. PacketStruct* packet = 0;
  11248. if (!recipes.empty() && GetRecipeListSent()) {
  11249. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11250. if (packet) {
  11251. packet->setArrayLengthByName("num_recipes", recipes.size());
  11252. }
  11253. }
  11254. for (int32 r = 0; r < recipes.size(); r++) {
  11255. Recipe* recipe = recipes[r];
  11256. if (recipe) {
  11257. Recipe* player_recipe = new Recipe(recipe);
  11258. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11259. }
  11260. }
  11261. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11262. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11263. if(item) {
  11264. database.DeleteItem(GetCharacterID(), item, 0);
  11265. GetPlayer()->item_list.RemoveItem(item, true);
  11266. }
  11267. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11268. SetRecipeListSent(false);
  11269. SendRecipeList();
  11270. safe_delete(packet);
  11271. return true;
  11272. }
  11273. else {
  11274. if (recipe_book && item) {
  11275. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11276. }
  11277. safe_delete(recipe_book);
  11278. }
  11279. }
  11280. else {
  11281. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11282. }
  11283. return false;
  11284. }
  11285. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11286. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11287. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11288. Recipe* recipe = prl->GetRecipe(recipe_id);
  11289. int8 level = player->GetTSLevel();
  11290. if(packet && recipe) {
  11291. packet->setDataByName("command_type", 1);
  11292. packet->setArrayLengthByName("num_recipes", 1);
  11293. int32 myid = recipe->GetID();
  11294. int8 rlevel = recipe->GetLevel();
  11295. int8 even = level - level * .05 + .5;
  11296. int8 easymin = level - level * .25 + .5;
  11297. int8 veasymin = level - level * .35 + .5;
  11298. if (rlevel > level )
  11299. packet->setArrayDataByName("tier", 4, 0);
  11300. else if ((rlevel <= level) & (rlevel >= even))
  11301. packet->setArrayDataByName("tier", 3, 0);
  11302. else if ((rlevel <= even) & (rlevel >= easymin))
  11303. packet->setArrayDataByName("tier", 2, 0);
  11304. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11305. packet->setArrayDataByName("tier", 1, 0);
  11306. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11307. packet->setArrayDataByName("tier", 0, 0);
  11308. if (rlevel == 2)
  11309. int xxx = 1;
  11310. packet->setArrayDataByName("recipe_id", myid, 0);
  11311. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11312. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11313. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11314. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11315. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11316. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11317. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11318. if (recipe_device != devices.end())
  11319. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11320. else
  11321. {//TODO error should never get here
  11322. }
  11323. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11324. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11325. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11326. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11327. QueuePacket(packet->serialize());
  11328. }
  11329. safe_delete(packet);
  11330. bool res = prl->RemoveRecipe(recipe_id);
  11331. if(res) {
  11332. Query query;
  11333. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11334. }
  11335. return res;
  11336. }
  11337. void Client::SaveSpells() {
  11338. MSaveSpellStateMutex.lock();
  11339. player->SaveSpellEffects();
  11340. player->SetSaveSpellEffects(true);
  11341. MSaveSpellStateMutex.unlock();
  11342. }
  11343. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11344. Widget* new_spawn = new Widget();
  11345. new_spawn->SetWidgetID(widget_id);
  11346. new_spawn->SetLocation(grid_id);
  11347. new_spawn->SetWidgetX(x);
  11348. new_spawn->SetWidgetY(y);
  11349. new_spawn->SetWidgetZ(z);
  11350. new_spawn->SetX(x);
  11351. new_spawn->SetY(y);
  11352. new_spawn->SetZ(z);
  11353. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11354. QueuePacket(ret);
  11355. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11356. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11357. safe_delete(new_spawn);
  11358. }
  11359. void Client::ProcessZoneIgnoreWidgets() {
  11360. GetPlayer()->MIgnoredWidgets.lock_shared();
  11361. std::map<int32, bool>::iterator itr;
  11362. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11363. SendReplaceWidget(itr->first, true);
  11364. }
  11365. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11366. }
  11367. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11368. if(!recipe || !packet)
  11369. return;
  11370. int8 level = player->GetTSLevel();
  11371. int32 myid = recipe->GetID();
  11372. int8 rlevel = recipe->GetLevel();
  11373. int8 even = level - level * .05 + .5;
  11374. int8 easymin = level - level * .25 + .5;
  11375. int8 veasymin = level - level * .35 + .5;
  11376. if (rlevel > level )
  11377. packet->setArrayDataByName("tier", 4, i);
  11378. else if ((rlevel <= level) & (rlevel >= even))
  11379. packet->setArrayDataByName("tier", 3, i);
  11380. else if ((rlevel <= even) & (rlevel >= easymin))
  11381. packet->setArrayDataByName("tier", 2, i);
  11382. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11383. packet->setArrayDataByName("tier", 1, i);
  11384. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11385. packet->setArrayDataByName("tier", 0, i);
  11386. if (rlevel == 2)
  11387. int xxx = 1;
  11388. packet->setArrayDataByName("recipe_id", myid, i);
  11389. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11390. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11391. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11392. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11393. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11394. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11395. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11396. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11397. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11398. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11399. packet->setArrayDataByName("book_volume", 0x01, i);
  11400. packet->setArrayDataByName("device_id", 0x01, i);
  11401. }
  11402. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11403. PacketStruct* packet = 0;
  11404. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11405. return 0;
  11406. }
  11407. packet->setArrayLengthByName("num_recipes", 1);
  11408. PopulateRecipeData(recipe, packet);
  11409. string* generic_string_data = packet->serializeString();
  11410. int32 size = generic_string_data->length();
  11411. if(size < 5)
  11412. return 0;
  11413. uchar* out_data = new uchar[size+1];
  11414. uchar* out_ptr = out_data;
  11415. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11416. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11417. safe_delete(packet);
  11418. safe_delete_array(out_data);
  11419. return out_crc;
  11420. }
  11421. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11422. if(!recipes || recipes->size() == 0)
  11423. return;
  11424. PacketStruct* packet = 0;
  11425. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11426. return;
  11427. }
  11428. int32 recipe_size = player->GetRecipeList()->Size();
  11429. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11430. int16 i = 0;
  11431. int32 count = 0;
  11432. vector<int32>::iterator recipe_itr;
  11433. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11434. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11435. if(!recipe) {
  11436. continue;
  11437. }
  11438. else if(i > 99) {
  11439. QueuePacket(packet->serialize());
  11440. safe_delete(packet);
  11441. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11442. recipe_size -= i;
  11443. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11444. i = 0;
  11445. }
  11446. count++;
  11447. PopulateRecipeData(recipe, packet, i);
  11448. i++;
  11449. }
  11450. //packet->PrintPacket();
  11451. QueuePacket(packet->serialize());
  11452. safe_delete(packet);
  11453. }
  11454. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11455. PlayerHouse* ph = nullptr;
  11456. HouseZone* hz = nullptr;
  11457. if(spawn_id) {
  11458. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11459. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11460. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11461. if (hz) {
  11462. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11463. } else {
  11464. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11465. }
  11466. }
  11467. }
  11468. if(!ph && house_id) {
  11469. ph = world.GetPlayerHouseByUniqueID(house_id);
  11470. if (ph) {
  11471. hz = world.GetHouseZone(ph->house_id);
  11472. }
  11473. }
  11474. if (ph && hz) {
  11475. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11476. return house;
  11477. }
  11478. return nullptr;
  11479. }
  11480. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11481. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11482. if (packet) {
  11483. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11484. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11485. packet->setDataByName("spawn_id", caster_id);
  11486. packet->setArrayLengthByName("num_targets", 1);
  11487. packet->setArrayDataByName("target", target_id);
  11488. packet->setDataByName("num_targets", 1);
  11489. int32 visual = GetSpellVisualOverride(spell_visual);
  11490. packet->setDataByName("spell_visual", visual); //result
  11491. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11492. packet->setDataByName("spell_id", 1);
  11493. packet->setDataByName("spell_level", 1);
  11494. packet->setDataByName("spell_tier", 1);
  11495. EQ2Packet* outapp = packet->serialize();
  11496. DumpPacket(outapp);
  11497. QueuePacket(outapp);
  11498. safe_delete(packet);
  11499. }
  11500. }
  11501. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11502. int32 visual = spell_visual;
  11503. if(GetVersion() <= 546) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11504. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11505. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11506. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11507. if(spellVisualEmote) {
  11508. visual = (int32)spellVisualEmote->GetVisualState();
  11509. }
  11510. }
  11511. }
  11512. return visual;
  11513. }