9
3

client.cpp 447 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833
  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. player = nullptr;
  271. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  272. deque<BuyBackItem*>::iterator itr;
  273. MBuyBack.writelock(__FUNCTION__, __LINE__);
  274. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  275. safe_delete(*itr);
  276. itr = buy_back_items.erase(itr);
  277. }
  278. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  279. }
  280. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  281. if (eqs) {
  282. if (!eqs->CheckActive()) {
  283. client_list.Remove(this);
  284. eqs = 0;
  285. }
  286. }
  287. if (app && eqs && version > 0)
  288. eqs->EQ2QueuePacket(app, attemptedCombine);
  289. else {
  290. safe_delete(app);
  291. }
  292. }
  293. void Client::PopulateSkillMap() {
  294. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  295. if (app)
  296. QueuePacket(app);
  297. else {
  298. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  299. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  300. }
  301. }
  302. void Client::SendLoginInfo() {
  303. if(GetPlayer()->IsReturningFromLD())
  304. firstlogin = true;
  305. if (firstlogin) {
  306. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  307. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  308. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  309. PopulateSkillMap();
  310. // 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!
  311. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  312. }
  313. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  314. database.ToggleCharacterOnline(this, 1);
  315. int32 count = 0;
  316. if(!GetPlayer()->IsReturningFromLD())
  317. {
  318. count = database.LoadCharacterTitles(GetCharacterID(), player);
  319. if (count == 0) {
  320. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  321. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  322. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  323. }
  324. }
  325. if(!GetPlayer()->IsReturningFromLD())
  326. {
  327. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  328. if (count == 0)
  329. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  330. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  331. if (count == 0)
  332. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  333. }
  334. ClientPacketFunctions::SendLoginAccepted(this);
  335. ClientPacketFunctions::SendAbilities ( this );
  336. ClientPacketFunctions::SendCommandNamePacket(this);
  337. ClientPacketFunctions::SendQuickBarInit(this);
  338. // we only need to send the MOTD if it is the first time the person is logging in.
  339. if (firstlogin) {
  340. ClientPacketFunctions::SendMOTD(this);
  341. ClientPacketFunctions::SendCharacterMacros(this);
  342. zone_list.CheckFriendList(this);
  343. }
  344. if(!GetPlayer()->IsReturningFromLD())
  345. {
  346. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  347. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  348. {
  349. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  350. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  351. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  352. }
  353. GetPlayer()->item_list.SetMaxItemIndex();
  354. database.LoadPlayerFactions(this);
  355. database.LoadCharacterQuests(this);
  356. database.LoadCharacterQuestRewards(this);
  357. database.LoadPlayerMail(this);
  358. }
  359. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  360. SendQuestJournal(true, 0, false);
  361. if (version > 546) // right version? possibly not!
  362. master_aa_list.DisplayAA(this, 0, 3);
  363. if (version > 283)
  364. SendCollectionList();
  365. SendBiography();
  366. map<int32, Quest*>::iterator itr;
  367. Quest* quest = 0;
  368. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  369. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  370. quest = itr->second;
  371. if (quest->IsTracked()) {
  372. quest->SetTracked(false);
  373. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  374. quest->SetTracked(true);
  375. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  376. }
  377. }
  378. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  379. // SendAchievementsList();
  380. /*Guild* guild = player->GetGuild();
  381. if (guild) {
  382. guild->UpdateGuildMemberInfo(GetPlayer());
  383. if (firstlogin)
  384. guild->SendGuildMOTD(this);
  385. guild->SendGuildUpdate(this);
  386. guild->SendGuildMember(GetPlayer(), firstlogin);
  387. guild->SendGuildEventList(this);
  388. guild->SendGuildBankEventList(this);
  389. guild->SendAllGuildEvents(this);
  390. guild->SendGuildMemberList(this);
  391. }*/
  392. if (version > 283) {
  393. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  394. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  395. if (outapp) {
  396. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  397. //DumpPacket(outapp);
  398. QueuePacket(outapp);
  399. }
  400. }
  401. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  402. ClientPacketFunctions::SendCommandList(this);
  403. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  404. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  405. ClientPacketFunctions::SendInstanceList(this);
  406. SendZoneInfo();
  407. /*Spell* spell = 0;
  408. vector<QuickBarItem*>::iterator itr;
  409. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  410. if((*itr)->type == 1){
  411. spell = master_spell_list.GetSpell((*itr)->id);
  412. if(spell)
  413. QueuePacket(spell->serialize(this, false, 0x20));
  414. }
  415. }*/
  416. }
  417. void Client::SendPlayerDeathWindow()
  418. {
  419. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  420. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  421. vector<RevivePoint*>::iterator itr;
  422. if (results && results->size() > 0)
  423. {
  424. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  425. if (packet)
  426. {
  427. packet->setArrayLengthByName("location_count", results->size());
  428. RevivePoint* point = 0;
  429. int32 i = 0;
  430. for (itr = results->begin(); itr != results->end(); itr++, i++)
  431. {
  432. point = *itr;
  433. if (point)
  434. {
  435. packet->setArrayDataByName("location_id", point->id, i);
  436. //zone_name = database.GetZoneName(point->zone_id);
  437. string zone_name = database.GetZoneDescription(point->zone_id);
  438. if (zone_name.length() > 0)
  439. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  440. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  441. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  442. }
  443. if (point->id == 0xFFFFFFFF)//tmp location
  444. safe_delete(point);
  445. }
  446. #if EQDEBUG >= 3
  447. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  448. packet->PrintPacket();
  449. #endif
  450. EQ2Packet* outapp = packet->serialize();
  451. QueuePacket(outapp);
  452. safe_delete(packet);
  453. }
  454. // done with the revive points so lets free up the pointer
  455. safe_delete(results);
  456. }
  457. }
  458. void Client::DisplayDeadWindow()
  459. {
  460. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  461. player->SetHP(0);
  462. player->SetPower(0);
  463. GetCurrentZone()->TriggerCharSheetTimer();
  464. if(GetVersion() <= 546) {
  465. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 1);
  466. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 1);
  467. }
  468. else {
  469. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 1);
  470. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 1);
  471. }
  472. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  473. if (packet)
  474. {
  475. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  476. QueuePacket(packet->serialize());
  477. safe_delete(packet);
  478. }
  479. SendPlayerDeathWindow();
  480. }
  481. void Client::HandlePlayerRevive(int32 point_id)
  482. {
  483. if(GetVersion() <= 546) {
  484. ClientPacketFunctions::SendServerControlFlagsClassic(this, 8, 0);
  485. ClientPacketFunctions::SendServerControlFlagsClassic(this, 16, 0);
  486. }
  487. else {
  488. ClientPacketFunctions::SendServerControlFlags(this, 1, 8, 0);
  489. ClientPacketFunctions::SendServerControlFlags(this, 1, 16, 0);
  490. }
  491. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  492. PacketStruct* packet = configReader.getStruct("WS_Resurrected", GetVersion());
  493. if (packet)
  494. {
  495. QueuePacket(packet->serialize());
  496. safe_delete(packet);
  497. }
  498. float origX, origY, origZ, origHeading = 0.0f;
  499. origX = player->GetX();
  500. origY = player->GetY();
  501. origZ = player->GetZ();
  502. origHeading = player->GetHeading();
  503. ZoneServer* originalZone = GetCurrentZone();
  504. int32 origGridID = GetPlayer()->GetLocation();
  505. float x, y, z, heading;
  506. RevivePoint* revive_point = 0;
  507. if (point_id != 0xFFFFFFFF)
  508. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  509. string zone_desc;
  510. const char* location_name = "Unknown";
  511. player->SetAlive(true);
  512. player->SetResurrecting(true);
  513. player->SetHP(player->GetTotalHP());
  514. player->SetPower(player->GetTotalPower());
  515. //revive at zone safe coords
  516. if (!revive_point)
  517. {
  518. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  519. x = GetCurrentZone()->GetSafeX();
  520. y = GetCurrentZone()->GetSafeY();
  521. z = GetCurrentZone()->GetSafeZ();
  522. heading = GetCurrentZone()->GetSafeHeading();
  523. zone_desc = GetCurrentZone()->GetZoneDescription();
  524. location_name = "Zone Safe Point";
  525. Zone(GetCurrentZone()->GetZoneName(), false);
  526. }
  527. else
  528. {
  529. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  530. x = revive_point->x;
  531. y = revive_point->y;
  532. z = revive_point->z;
  533. heading = revive_point->heading;
  534. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  535. location_name = revive_point->location_name.c_str();
  536. Zone(GetCurrentZone()->GetZoneName(), false);
  537. }
  538. player->SetX(x);
  539. player->SetY(y);
  540. player->SetZ(z);
  541. player->SetHeading(heading);
  542. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  543. zone_desc.c_str(),
  544. player->GetX(),
  545. player->GetY(),
  546. player->GetZ(),
  547. player->GetHeading(),
  548. player->GetHP(),
  549. player->GetPower(),
  550. location_name);
  551. //player->ClearEverything();
  552. Save();
  553. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  554. {
  555. string zone_name = database.GetZoneName(revive_point->zone_id);
  556. if (zone_name.length() == 0)
  557. {
  558. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  559. x = GetCurrentZone()->GetSafeX();
  560. y = GetCurrentZone()->GetSafeY();
  561. z = GetCurrentZone()->GetSafeZ();
  562. heading = GetCurrentZone()->GetSafeHeading();
  563. location_name = "Zone Safe Point";
  564. }
  565. else
  566. {
  567. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  568. location_name = revive_point->location_name.c_str();
  569. //player->ClearEverything();
  570. Save();
  571. Zone(zone_name.c_str(), false);
  572. }
  573. }
  574. zone_desc = GetCurrentZone()->GetZoneDescription();
  575. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  576. player->SetSpawnType(4);
  577. if (version > 283) {
  578. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  579. if (packet)
  580. {
  581. QueuePacket(packet->serialize());
  582. safe_delete(packet);
  583. }
  584. }
  585. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  586. if (packet)
  587. {
  588. packet->setDataByName("x", x);
  589. packet->setDataByName("y", y);
  590. packet->setDataByName("z", z);
  591. QueuePacket(packet->serialize());
  592. safe_delete(packet);
  593. }
  594. SendControlGhost();
  595. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  596. if (packet)
  597. {
  598. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  599. QueuePacket(packet->serialize());
  600. safe_delete(packet);
  601. }
  602. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  603. {
  604. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  605. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  606. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  607. originalZone->RemoveSpawn(player, false, true, true, true, true);
  608. originalZone->AddSpawn(shard);
  609. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  610. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  611. }
  612. m_resurrect.writelock(__FUNCTION__, __LINE__);
  613. if (current_rez.active)
  614. current_rez.should_delete = true;
  615. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  616. }
  617. void Client::SendControlGhost(int32 send_id, int8 unknown2) {
  618. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  619. if (packet) {
  620. packet->setDataByName("spawn_id", send_id);
  621. packet->setDataByName("speed", GetPlayer()->GetSpeed());
  622. packet->setDataByName("size", 0.51);
  623. packet->setDataByName("unknown2", unknown2);
  624. packet->setDataByName("air_speed", player->GetAirSpeed());
  625. EQ2Packet* app = packet->serialize();
  626. QueuePacket(app);
  627. safe_delete(packet);
  628. }
  629. }
  630. void Client::SendCharInfo() {
  631. EQ2Packet* app;
  632. player->SetEquippedItemAppearances();
  633. ClientPacketFunctions::SendCharacterData(this);
  634. SendCharPOVGhost();
  635. SendControlGhost(player->GetIDWithPlayerSpawn(player), 255);
  636. //sending bad spawn packet?
  637. //SendAchievementsList();
  638. //if (version > 546)
  639. //ClientPacketFunctions::SendHousingList(this);
  640. ClientPacketFunctions::SendCharacterSheet(this);
  641. ClientPacketFunctions::SendTraitList(this);// moved from below
  642. ClientPacketFunctions::SendAbilities(this);
  643. ClientPacketFunctions::SendSkillBook(this);
  644. if (!IsReloadingZone() && !player->IsResurrecting() && GetVersion() >= 546) {
  645. ClientPacketFunctions::SendUpdateSpellBook(this);
  646. }
  647. else {
  648. player->SetResurrecting(false);
  649. }
  650. GetCurrentZone()->AddSpawn(player);
  651. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  652. GetPlayer()->SetX(zoning_x);
  653. GetPlayer()->SetY(zoning_y);
  654. GetPlayer()->SetZ(zoning_z);
  655. GetPlayer()->SetHeading(zoning_h);
  656. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  657. QueuePacket(packet);
  658. }
  659. //SendCollectionList();
  660. Guild* guild = player->GetGuild();
  661. if (guild)
  662. guild->GuildMemberLogin(this, firstlogin);
  663. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  664. if (app) {
  665. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  666. //DumpPacket(app);
  667. QueuePacket(app);
  668. }
  669. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  670. if (app) {
  671. QueuePacket(app);
  672. }
  673. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  674. if (app) {
  675. QueuePacket(app);
  676. }
  677. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  678. if (items && items->size() > 0) {
  679. for (int32 i = 0; i < items->size(); i++) {
  680. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  681. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  682. //DumpPacket(outapp);
  683. QueuePacket(outapp);
  684. }
  685. }
  686. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  687. QueuePacket(app);
  688. safe_delete(items);
  689. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  690. if (items && items->size() > 0) {
  691. for (int32 i = 0; i < items->size(); i++)
  692. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  693. }
  694. safe_delete(items);
  695. if (version > 283) {
  696. SendTitleUpdate();
  697. }
  698. GetPlayer()->UpdateWeapons();
  699. if(!GetPlayer()->IsReturningFromLD()) {
  700. database.LoadBuyBacks(this);
  701. }
  702. if (version > 546)
  703. master_aa_list.DisplayAA(this, 0, 0);
  704. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  705. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  706. string zone_motd_send = "Zone MOTD: " + zone_motd;
  707. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  708. }
  709. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  710. if (zone_script && lua_interface)
  711. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  712. this->client_zoning = false;
  713. this->zoning_id = 0;
  714. this->zoning_instance_id = 0;
  715. SetZoningDestination(nullptr);
  716. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  717. GetCurrentZone()->AddDamagedSpawn(player);
  718. if (firstlogin)
  719. firstlogin = false;
  720. player->ClearProcs();
  721. items = player->GetEquippedItemList();
  722. if (items && items->size() > 0) {
  723. for (int32 i = 0; i < items->size(); i++) {
  724. Item* item = items->at(i);
  725. if (item && item->GetItemScript() && lua_interface)
  726. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  727. }
  728. }
  729. //Allow this player to change their last name if they meet the level requirement
  730. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  731. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  732. safe_delete(items);
  733. if (!player->Alive())
  734. DisplayDeadWindow();
  735. ClientPacketFunctions::SendLocalizedTextMessage(this);
  736. if (GetCurrentZone()->GetInstanceID())
  737. {
  738. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  739. if (ph) {
  740. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  741. string name = string(GetPlayer()->GetName());
  742. if (name.compare(ph->player_name) == 0)
  743. SetHasOwnerOrEditAccess(true);
  744. }
  745. }
  746. bool groupMentor = false;
  747. GetPlayer()->group_id = rejoin_group_id;
  748. if(!world.RejoinGroup(this, rejoin_group_id))
  749. GetPlayer()->group_id = 0;
  750. else
  751. {
  752. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  753. if(ent && ent->IsPlayer())
  754. {
  755. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID(), false);
  756. groupMentor = true;
  757. }
  758. }
  759. if(!groupMentor)
  760. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0, false);
  761. if(!GetPlayer()->IsReturningFromLD()) {
  762. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  763. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  764. }
  765. else {
  766. Spawn* pet_spawn = nullptr;
  767. if(GetPlayer()->GetPet())
  768. pet_spawn = GetPlayer()->GetPet();
  769. else if(GetPlayer()->GetCharmedPet())
  770. pet_spawn = GetPlayer()->GetCharmedPet();
  771. else if(GetPlayer()->GetCosmeticPet())
  772. pet_spawn = GetPlayer()->GetCosmeticPet();
  773. else if(GetPlayer()->GetDeityPet())
  774. pet_spawn = GetPlayer()->GetDeityPet();
  775. if(pet_spawn) {
  776. GetPlayer()->GetInfoStruct()->set_pet_id(GetPlayer()->GetIDWithPlayerSpawn(pet_spawn));
  777. }
  778. }
  779. GetPlayer()->SetSaveSpellEffects(false);
  780. GetPlayer()->SetCharSheetChanged(true);
  781. GetPlayer()->SetReturningFromLD(false);
  782. }
  783. void Client::SendZoneSpawns() {
  784. //Allows us to place spawns almost anywhere
  785. if (version > 283) {
  786. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  787. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  788. QueuePacket(app);
  789. }
  790. ClientPacketFunctions::SendSkillSlotMappings(this);
  791. ClientPacketFunctions::SendGameWorldTime(this);
  792. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  793. }
  794. void Client::SendCharPOVGhost() {
  795. bool use_ghost_pov = false;
  796. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  797. int32 ghost_id = 0;
  798. if (set_pov) {
  799. if(pov_ghost_spawn_id) {
  800. Spawn* spawn = GetCurrentZone()->GetSpawnByID(pov_ghost_spawn_id);
  801. ghost_id = player->GetIDWithPlayerSpawn(spawn);
  802. if(spawn) {
  803. use_ghost_pov = true;
  804. }
  805. }
  806. if(use_ghost_pov) {
  807. set_pov->setDataByName("spawn_id", ghost_id);
  808. }
  809. else {
  810. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  811. }
  812. EQ2Packet* app_pov = set_pov->serialize();
  813. QueuePacket(app_pov);
  814. safe_delete(set_pov);
  815. }
  816. }
  817. void Client::SendZoneInfo() {
  818. ZoneServer* zone = GetCurrentZone();
  819. if (zone) {
  820. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  821. QueuePacket(packet);
  822. if (version > 283) {
  823. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  824. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  825. #if EQDEBUG >= 9
  826. fog_packet->PrintPacket();
  827. #endif
  828. if (fog_packet) {
  829. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  830. QueuePacket(fog_packet->serialize());
  831. safe_delete(fog_packet);
  832. }
  833. zone->SendFlightPathsPackets(this);
  834. }
  835. }
  836. /*
  837. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  838. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  839. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  840. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  841. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  843. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  844. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0x00};
  873. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  874. QueuePacket(appA);
  875. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,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,0x01,0x00,0x00
  879. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  880. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  881. QueuePacket(appB);
  882. */
  883. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  884. SendFriendList();
  885. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  886. SendIgnoreList();
  887. }
  888. void Client::SendDefaultGroupOptions() {
  889. /*
  890. 0 - loot method
  891. 1 - loot items rarity
  892. 2 - Auto split coin
  893. 4 - default yell method
  894. 6 - group autolock
  895. 7 - solo autolock
  896. */
  897. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  898. if (default_options) {
  899. default_options->setDataByName("loot_method", GetPlayer()->GetInfoStruct()->get_group_loot_method());
  900. default_options->setDataByName("loot_items_rarity", GetPlayer()->GetInfoStruct()->get_group_loot_items_rarity());
  901. default_options->setDataByName("auto_split_coin", GetPlayer()->GetInfoStruct()->get_group_auto_split());
  902. default_options->setDataByName("default_yell_method", GetPlayer()->GetInfoStruct()->get_group_default_yell());
  903. default_options->setDataByName("group_autolock", GetPlayer()->GetInfoStruct()->get_group_autolock());
  904. default_options->setDataByName("default_group_lock_method", GetPlayer()->GetInfoStruct()->get_group_lock_method());
  905. if(GetVersion() > 561) {
  906. default_options->setDataByName("solo_autolock", GetPlayer()->GetInfoStruct()->get_group_solo_autolock());
  907. default_options->setDataByName("auto_loot_method", GetPlayer()->GetInfoStruct()->get_group_auto_loot_method());
  908. }
  909. EQ2Packet* app7 = default_options->serialize();
  910. QueuePacket(app7);
  911. safe_delete(default_options);
  912. }
  913. }
  914. bool Client::HandlePacket(EQApplicationPacket* app) {
  915. bool ret = true;
  916. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  917. //DumpPacket(app);
  918. #if EQDEBUG >= 9
  919. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  920. DumpPacket(app, true);
  921. #endif
  922. EmuOpcode opcode = app->GetOpcode();
  923. #if EQDEBUG >= 9
  924. const char* name = app->GetOpcodeName();
  925. if (name)
  926. cout << name;
  927. else
  928. cout << "Unknown";
  929. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  930. DumpPacket(app);
  931. #endif
  932. //if (opcode != OP_UpdatePositionMsg) {
  933. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  934. //}
  935. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  936. {
  937. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  938. }
  939. switch (opcode) {
  940. case _maxEmuOpcode:
  941. break;
  942. case OP_LoginByNumRequestMsg: {
  943. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  944. PacketStruct* request;
  945. request = configReader.getStruct("LoginByNumRequest", 1);
  946. if (request) {
  947. if(request->LoadPacketData(app->pBuffer, app->size)) {
  948. // test the original location of Version for clients older than 1212
  949. version = request->getType_int16_ByName("version");
  950. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  951. // must be new client data version method, re-fetch the packet
  952. safe_delete(request);
  953. request = configReader.getStruct("LoginByNumRequest", 1208);
  954. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  955. // Xinux suggests using an INT16 here. Our first new version = 57000
  956. version = request->getType_int16_ByName("version");
  957. }
  958. else {
  959. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  960. break;
  961. }
  962. }
  963. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  964. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  965. ClientPacketFunctions::SendLoginDenied(this);
  966. /* reset version and protect server from trying to send packets out to a bad client
  967. ** cause of Dec 6th/Dec 7th 2023 crash
  968. ** Client::MakeSpawnChangePacket
  969. ** int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd); <-- crashes pulling opcode with bad version
  970. */
  971. version = 546;
  972. ready_for_updates = false;
  973. ready_for_spawns = false;
  974. return false;
  975. }
  976. int32 account_id = request->getType_int32_ByName("account_id");
  977. int32 access_code = request->getType_int32_ByName("access_code");
  978. if (!HandleNewLogin(account_id, access_code))
  979. return false;
  980. }
  981. }
  982. safe_delete(request);
  983. break;
  984. }
  985. case OP_DefaultGroupOptionsMsg: {
  986. PacketStruct* packet = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  987. if (packet) {
  988. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  989. packet->PrintPacket();
  990. int8 loot_method = packet->getType_int8_ByName("loot_method");
  991. int8 loot_items_rarity = packet->getType_int8_ByName("loot_items_rarity");
  992. int8 auto_split_coin = packet->getType_int8_ByName("auto_split_coin");
  993. int8 default_yell_method = packet->getType_int8_ByName("default_yell_method");
  994. int8 autolock = packet->getType_int8_ByName("group_autolock");
  995. int8 group_lock_method = packet->getType_int8_ByName("default_group_lock_method");
  996. int8 solo_autolock = packet->getType_int8_ByName("solo_autolock");
  997. int8 auto_loot_method = 0;
  998. if (GetVersion() > 561) {
  999. auto_loot_method = packet->getType_int8_ByName("auto_loot_method");
  1000. if (auto_loot_method > AutoLootMode::METHOD_DECLINE)
  1001. auto_loot_method = AutoLootMode::METHOD_DECLINE;
  1002. }
  1003. GetPlayer()->GetInfoStruct()->set_group_loot_method(loot_method);
  1004. GetPlayer()->GetInfoStruct()->set_group_loot_items_rarity(loot_items_rarity);
  1005. GetPlayer()->GetInfoStruct()->set_group_auto_split(auto_split_coin);
  1006. GetPlayer()->GetInfoStruct()->set_group_default_yell(default_yell_method);
  1007. GetPlayer()->GetInfoStruct()->set_group_autolock(autolock);
  1008. GetPlayer()->GetInfoStruct()->set_group_lock_method(group_lock_method);
  1009. GetPlayer()->GetInfoStruct()->set_group_solo_autolock(solo_autolock);
  1010. GetPlayer()->GetInfoStruct()->set_group_auto_loot_method(auto_loot_method);
  1011. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTMETHOD, (char*)std::to_string(loot_method).c_str());
  1012. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOOTITEMRARITY, (char*)std::to_string(loot_items_rarity).c_str());
  1013. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOSPLIT, (char*)std::to_string(auto_split_coin).c_str());
  1014. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPDEFAULTYELL, (char*)std::to_string(default_yell_method).c_str());
  1015. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPAUTOLOCK, (char*)std::to_string(autolock).c_str());
  1016. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPLOCKMETHOD, (char*)std::to_string(group_lock_method).c_str());
  1017. database.insertCharacterProperty(this, CHAR_PROPERTY_GROUPSOLOAUTOLOCK, (char*)std::to_string(solo_autolock).c_str());
  1018. database.insertCharacterProperty(this, CHAR_PROPERTY_AUTOLOOTMETHOD, (char*)std::to_string(auto_loot_method).c_str());
  1019. if (this->GetPlayer()->GetGroupMemberInfo() && this->GetPlayer()->GetGroupMemberInfo()->leader)
  1020. {
  1021. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  1022. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  1023. if (group)
  1024. {
  1025. GroupOptions goptions;
  1026. goptions.loot_method = loot_method;
  1027. goptions.loot_items_rarity = loot_items_rarity;
  1028. goptions.auto_split = auto_split_coin;
  1029. goptions.default_yell = default_yell_method;
  1030. goptions.group_autolock = autolock;
  1031. goptions.solo_autolock = solo_autolock;
  1032. goptions.auto_loot_method = auto_loot_method;
  1033. group->SetDefaultGroupOptions(&goptions);
  1034. }
  1035. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  1036. }
  1037. }
  1038. safe_delete(packet);
  1039. }
  1040. break;
  1041. }
  1042. case OP_MapRequest: {
  1043. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  1044. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  1045. if (packet && app->size > 2 && GetCurrentZone()) {
  1046. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1047. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  1048. if (fog_packet) {
  1049. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  1050. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  1051. fog_packet->setDataByName("unknown1", 1);
  1052. fog_packet->setDataByName("unknown3", 1);
  1053. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1054. //fog_packet->PrintPacket();
  1055. QueuePacket(fog_packet->serialize());
  1056. safe_delete(fog_packet);
  1057. }
  1058. }
  1059. safe_delete(packet);
  1060. }
  1061. break;
  1062. }
  1063. case OP_RequestCampMsg: {
  1064. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  1065. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  1066. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1067. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1068. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1069. request->getType_int8_ByName("quit"),
  1070. request->getType_int8_ByName("camp_desktop"),
  1071. request->getType_int16_ByName("camp_char_select"),
  1072. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1073. //DumpPacket(app->pBuffer, app->size);
  1074. //request->PrintPacket();
  1075. if (!camp_timer) {
  1076. int16 camp_time = 20; // default if rule cannot be found
  1077. if (GetAdminStatus() >= 100)
  1078. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1079. else
  1080. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1081. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1082. if (response) {
  1083. bool disconnect = false;
  1084. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1085. // Command: /camp desktop
  1086. // Command: /quit
  1087. response->setDataByName("camp_desktop", 1);
  1088. disconnect = true;
  1089. }
  1090. else {
  1091. // Command: /camp
  1092. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1093. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1094. response->setDataByName("seconds", camp_time);
  1095. }
  1096. camp_timer = new Timer(camp_time * 1000);
  1097. camp_timer->Enable();
  1098. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1099. // /camp {char_name}
  1100. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1101. }
  1102. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1103. // /camp (go back to char selection screen)
  1104. response->setDataByName("char_name", " ");
  1105. response->setDataByName("camp_char_select", 1);
  1106. }
  1107. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1108. response->getType_int8_ByName("seconds"),
  1109. response->getType_int8_ByName("camp_desktop"),
  1110. response->getType_int8_ByName("camp_char_select"),
  1111. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1112. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1113. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1114. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1115. //response->PrintPacket();
  1116. QueuePacket(response->serialize());
  1117. safe_delete(response);
  1118. if (disconnect)
  1119. Disconnect();
  1120. }
  1121. }
  1122. }
  1123. safe_delete(request);
  1124. break;
  1125. }
  1126. case OP_StoodMsg: {
  1127. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1128. if (camp_timer)
  1129. {
  1130. // JA: clear camping flag
  1131. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1132. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1133. safe_delete(camp_timer);
  1134. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1135. QueuePacket(outapp);
  1136. }
  1137. player->SetTempVisualState(0);
  1138. break;
  1139. }
  1140. case OP_StandMsg: {
  1141. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1142. if (camp_timer)
  1143. {
  1144. // JA: clear camping flag
  1145. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1146. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1147. safe_delete(camp_timer);
  1148. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1149. QueuePacket(outapp);
  1150. }
  1151. player->SetTempVisualState(539);
  1152. break;
  1153. }
  1154. case OP_SitMsg: {
  1155. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1156. player->SetTempVisualState(538);
  1157. break;
  1158. }
  1159. case OP_SatMsg: {
  1160. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1161. player->SetTempVisualState(540);
  1162. break;
  1163. }
  1164. case OP_QuestJournalOpenMsg:
  1165. case OP_QuestJournalInspectMsg: {
  1166. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1167. if (app->size < sizeof(int32))
  1168. break;
  1169. int32 quest_id = 0;
  1170. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1171. GetPlayer()->SendQuest(quest_id);
  1172. break;
  1173. }
  1174. case OP_QuestJournalSetVisibleMsg: {
  1175. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1176. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1177. if (packet) {
  1178. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1179. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1180. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1181. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1182. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1183. if (player_quests) {
  1184. if (player_quests->count(quest_id) > 0)
  1185. player_quests->at(quest_id)->SetHidden(hidden);
  1186. else
  1187. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1188. }
  1189. else
  1190. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1191. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1192. }
  1193. safe_delete(packet);
  1194. }
  1195. break;
  1196. }
  1197. case OP_MacroUpdateMsg: {
  1198. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1199. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1200. if (macro_update) {
  1201. if(macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1202. vector<string>* update = new vector<string>;
  1203. int8 number = macro_update->getType_int8_ByName("number");
  1204. int16 icon = macro_update->getType_int16_ByName("icon");
  1205. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1206. int8 count = macro_update->getType_int8_ByName("macro_count");
  1207. if (GetVersion() <= 283) {
  1208. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1209. }
  1210. else {
  1211. for (int8 i = 0; i < count; i++) {
  1212. char tmp_command[15] = { 0 };
  1213. sprintf(tmp_command, "command_%i", i);
  1214. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1215. }
  1216. }
  1217. if (name.length() == 0)
  1218. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1219. else
  1220. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1221. safe_delete(update);
  1222. }
  1223. safe_delete(macro_update);
  1224. }
  1225. break;
  1226. }
  1227. case OP_DialogSelectMsg: {
  1228. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1229. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1230. if (packet) {
  1231. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1232. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1233. int32 response_index = packet->getType_int32_ByName("response");
  1234. HandleDialogSelectMsg(conversation_id, response_index);
  1235. }
  1236. }
  1237. safe_delete(packet);
  1238. break;
  1239. }
  1240. case OP_CancelMoveObjectModeMsg: {
  1241. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1242. if (GetTempPlacementSpawn())
  1243. {
  1244. Spawn* tmp = GetTempPlacementSpawn();
  1245. SetTempPlacementSpawn(nullptr);
  1246. SetPlacementUniqueItemID(0);
  1247. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1248. break; // break out early if we are tied to a temp spawn
  1249. }
  1250. // if we are moving some other object? other use-cases not covered
  1251. break;
  1252. }
  1253. case OP_PositionMoveableObject: {
  1254. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1255. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1256. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1257. Spawn* spawn = 0;
  1258. if (GetTempPlacementSpawn())
  1259. spawn = GetTempPlacementSpawn();
  1260. else
  1261. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1262. if (!spawn) {
  1263. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1264. break;
  1265. }
  1266. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1267. {
  1268. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1269. break;
  1270. }
  1271. int32 uniqueID = spawn->GetPickupUniqueItemID();
  1272. if(uniqueID) {
  1273. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  1274. if(uniqueItem && uniqueItem->CheckFlag2(HOUSE_LORE) && GetCurrentZone()->HouseItemSpawnExists(uniqueItem->details.item_id)) {
  1275. Message(CHANNEL_COLOR_RED, "Item %s is house lore and you cannot place another.", uniqueItem->name.c_str());
  1276. break;
  1277. }
  1278. }
  1279. // handles instantiation logic + adding to zone of a new house object
  1280. PopulateHouseSpawn(place_object);
  1281. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1282. char query[256];
  1283. switch (GetSpawnPlacementMode())
  1284. {
  1285. case ServerSpawnPlacementMode::OPEN_HEADING:
  1286. {
  1287. if (spawn && spawn->IsWidget())
  1288. {
  1289. Widget* widget = (Widget*)spawn;
  1290. widget->SetOpenHeading(newHeading);
  1291. widget->SetIncludeHeading(true);
  1292. spawn->position_changed = true;
  1293. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1294. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1295. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1296. }
  1297. else
  1298. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1299. break;
  1300. }
  1301. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1302. {
  1303. if (spawn && spawn->IsWidget())
  1304. {
  1305. Widget* widget = (Widget*)spawn;
  1306. widget->SetClosedHeading(newHeading);
  1307. widget->SetIncludeHeading(true);
  1308. spawn->position_changed = true;
  1309. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1310. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1311. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1312. if (spawn->GetSpawnLocationID())
  1313. {
  1314. Query query;
  1315. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1316. }
  1317. }
  1318. else
  1319. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1320. break;
  1321. }
  1322. default:
  1323. {
  1324. spawn->SetX(place_object->getType_float_ByName("x"));
  1325. spawn->SetY(place_object->getType_float_ByName("y"));
  1326. spawn->SetZ(place_object->getType_float_ByName("z"));
  1327. spawn->SetHeading(newHeading);
  1328. spawn->SetSpawnOrigX(spawn->GetX());
  1329. spawn->SetSpawnOrigY(spawn->GetY());
  1330. spawn->SetSpawnOrigZ(spawn->GetZ());
  1331. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1332. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1333. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1334. else if (spawn->GetSpawnLocationID() > 0)
  1335. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1336. }
  1337. }
  1338. PopulateHouseSpawnFinalize();
  1339. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1340. }
  1341. safe_delete(place_object);
  1342. break;
  1343. }
  1344. case OP_CampAbortedMsg: {
  1345. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1346. if (camp_timer)
  1347. {
  1348. // JA: clear camping flag
  1349. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1350. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1351. safe_delete(camp_timer);
  1352. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1353. QueuePacket(outapp);
  1354. }
  1355. break;
  1356. }
  1357. case OP_DoneLoadingUIResourcesMsg: {
  1358. if(GetVersion() < 546) {
  1359. ClientPacketFunctions::SendUpdateSpellBook(this);
  1360. }
  1361. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1362. QueuePacket(app);
  1363. if(!player_loading_complete)
  1364. {
  1365. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1366. if (zone_script && lua_interface)
  1367. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1368. player_loading_complete = true;
  1369. }
  1370. break;
  1371. }
  1372. case OP_DoneLoadingZoneResourcesMsg: {
  1373. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1374. SendZoneSpawns();
  1375. break;
  1376. }
  1377. case OP_DefaultGroupOptionsRequestMsg: {
  1378. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1379. SendDefaultGroupOptions();
  1380. break;
  1381. }
  1382. case OP_DoneLoadingEntityResourcesMsg: {
  1383. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1384. if (!IsReadyForSpawns())
  1385. SetReadyForSpawns(true);
  1386. player->CalculateApplyWeight();
  1387. SendCharInfo();
  1388. pos_update.Start();
  1389. quest_pos_timer.Start();
  1390. break;
  1391. }
  1392. case OP_LootItemsRequestMsg: {
  1393. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1394. HandleLootItemRequestPacket(app);
  1395. break;
  1396. }
  1397. case OP_StoppedLootingMsg: {
  1398. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoppedLootingMsg", opcode, opcode);
  1399. if (app->size < sizeof(int32))
  1400. break;
  1401. int32 loot_id = 0;
  1402. memcpy(&loot_id, app->pBuffer, sizeof(int32));
  1403. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  1404. if(spawn) {
  1405. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  1406. spawn->SetLooterSpawnID(0);
  1407. }
  1408. break;
  1409. }
  1410. case OP_WaypointSelectMsg: {
  1411. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1412. if (packet) {
  1413. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1414. int32 selection = packet->getType_int32_ByName("selection");
  1415. if (selection > 0) {
  1416. SelectWaypoint(selection);
  1417. }
  1418. }
  1419. }
  1420. safe_delete(packet);
  1421. break;
  1422. }
  1423. case OP_KnowledgeWindowSlotMappingMsg: {
  1424. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1425. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1426. if (packet) {
  1427. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1428. int num_updates = packet->getType_int16_ByName("spell_count");
  1429. int32 spell_id = 0;
  1430. int16 slot_id = 0;
  1431. char tmp_spell_id[15];
  1432. char tmp_slot[15];
  1433. for (int i = 0; i < num_updates; i++) {
  1434. memset(tmp_spell_id, 0, 15);
  1435. memset(tmp_slot, 0, 15);
  1436. sprintf(tmp_spell_id, "spell_id_%i", i);
  1437. sprintf(tmp_slot, "slot_id_%i", i);
  1438. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1439. if (spell_id > 0) {
  1440. slot_id = packet->getType_int16_ByName(tmp_slot);
  1441. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1442. if (spell && spell->slot != slot_id) {
  1443. spell->slot = slot_id;
  1444. spell->save_needed = true;
  1445. }
  1446. }
  1447. }
  1448. }
  1449. safe_delete(packet);
  1450. }
  1451. //SendKnowledgeWindowSlot();
  1452. break;
  1453. }
  1454. case OP_ReadyToZoneMsg: {
  1455. if (!IsReadyForSpawns())
  1456. {
  1457. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1458. }
  1459. else
  1460. {
  1461. if(zoning_destination) {
  1462. SetCurrentZone(zoning_destination);
  1463. }
  1464. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1465. bool succeed_override_zone = true;
  1466. if(!GetCurrentZone()) {
  1467. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1468. if(zoning_instance_id) {
  1469. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1470. if(!zone) {
  1471. 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);
  1472. succeed_override_zone = false;
  1473. }
  1474. else {
  1475. SetCurrentZone(zone);
  1476. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1477. }
  1478. }
  1479. else if(zoning_id) {
  1480. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1481. if(!zone) {
  1482. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1483. succeed_override_zone = false;
  1484. }
  1485. else {
  1486. SetCurrentZone(zone);
  1487. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1488. }
  1489. }
  1490. }
  1491. if (client_zoning)
  1492. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1493. else
  1494. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1495. Disconnect();
  1496. }
  1497. break;
  1498. }
  1499. case OP_ClientFellMsg: {
  1500. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1501. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1502. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1503. float height = request->getType_float_ByName("height");
  1504. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1505. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1506. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1507. break;
  1508. }*/
  1509. float safe_height = 13.0f;
  1510. float safe_skill_with_bonus = GetPlayer()->CalculateSkillWithBonus("Safe Fall", ITEM_STAT_SAFE_FALL, true);
  1511. if (safe_skill_with_bonus > 0.0f)
  1512. safe_height += (1 + safe_skill_with_bonus) / 5;
  1513. if (height > safe_height) {
  1514. int16 damage = (int16)ceil((height - safe_height) * 125);
  1515. if (height >= 80)
  1516. damage = 30000;
  1517. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1518. if (damage > 0) {
  1519. GetPlayer()->TakeDamage(damage);
  1520. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1521. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1522. if (!GetPlayer()->GetInvulnerable())
  1523. GetPlayer()->SetCharSheetChanged(true);
  1524. 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);
  1525. if (GetPlayer()->GetHP() == 0) {
  1526. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1527. }
  1528. }
  1529. }
  1530. }
  1531. safe_delete(request);
  1532. break;
  1533. }
  1534. case OP_MapFogDataUpdateMsg: {
  1535. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1536. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1537. break;
  1538. }
  1539. case OP_SelectZoneTeleporterDestinatio: {
  1540. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1541. ProcessTeleportLocation(app);
  1542. break;
  1543. }
  1544. case OP_SendLatestRequestMsg: {
  1545. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1546. if(GetVersion() < 60085) {
  1547. // this does not exist in newer clients like AoM, confirmed to exist in DoF, other clients will need review at a later time
  1548. uchar blah25[] = { 0x01 };
  1549. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1550. QueuePacket(app25);
  1551. }
  1552. break;
  1553. }
  1554. case OP_RequestRecipeDetailsMsg: {
  1555. PacketStruct* packet = configReader.getStruct("WS_RequestRecipeDetail", GetVersion());
  1556. if (packet) {
  1557. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1558. vector<int32> recipes;
  1559. int32 recipe_id = 0;
  1560. char recipe_prop_name[30];
  1561. int32 num_recipes = packet->getType_int32_ByName("num_recipes");
  1562. // WS_RecipeDetails
  1563. for (int32 i = 0; i < num_recipes; i++) {
  1564. memset(recipe_prop_name, 0, 30);
  1565. snprintf(recipe_prop_name, 30, "recipe_id_%i", i);
  1566. recipe_id = packet->getType_int32_ByName(recipe_prop_name);
  1567. if(recipe_id > 0) {
  1568. recipes.push_back(recipe_id);
  1569. }
  1570. }
  1571. SendRecipeDetails(&recipes);
  1572. }
  1573. safe_delete(packet);
  1574. }
  1575. break;
  1576. }
  1577. case OP_ShowCreateFromRecipeUIMsg: {
  1578. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1579. break;
  1580. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1581. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1582. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1583. QueuePacket(app);
  1584. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1585. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1586. QueuePacket(app);
  1587. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1588. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1589. ,0xff,0xff,0xff};
  1590. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1591. QueuePacket(app);
  1592. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1593. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1594. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1595. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1596. QueuePacket(app);
  1597. uchar blah5[] ={0x00,0x00};
  1598. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1599. QueuePacket(app);
  1600. break;*/
  1601. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1602. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1603. //QueuePacket(app);
  1604. }
  1605. case OP_BeginItemCreationMsg: {
  1606. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1607. //DumpPacket(app->pBuffer, app->size);
  1608. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1609. if (packet) {
  1610. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1611. int32 item = 0;
  1612. int8 qty = 0;
  1613. vector<pair<int32, int16>> items;
  1614. char tmp_item_id[30];
  1615. int8 num_primary_selected_items = packet->getType_int8_ByName("num_primary_selected_items");
  1616. for (int8 i = 0; i < num_primary_selected_items; i++) {
  1617. memset(tmp_item_id, 0, 30);
  1618. sprintf(tmp_item_id, "primary_selected_item_id_%i", i);
  1619. item = packet->getType_int32_ByName(tmp_item_id);
  1620. sprintf(tmp_item_id, "primary_selected_item_qty_%i", i);
  1621. qty = packet->getType_int16_ByName(tmp_item_id);
  1622. if (item > 0)
  1623. items.push_back(make_pair(item,qty));
  1624. item = 0;
  1625. }
  1626. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1627. for (int8 i = 0; i < build_components; i++) {
  1628. memset(tmp_item_id, 0, 30);
  1629. sprintf(tmp_item_id, "num_selected_items_%i", i);
  1630. int8 num_selected_items = packet->getType_int8_ByName(tmp_item_id);
  1631. for (int8 j = 0; j < num_selected_items; j++) {
  1632. memset(tmp_item_id, 0, 30);
  1633. sprintf(tmp_item_id, "selected_id%i_%i", i,j);
  1634. item = packet->getType_int32_ByName(tmp_item_id);
  1635. sprintf(tmp_item_id, "selected_qty%i_%i", i, j);
  1636. qty = packet->getType_int16_ByName(tmp_item_id);
  1637. if (item > 0)
  1638. items.push_back(make_pair(item, qty));
  1639. item = 0;
  1640. }
  1641. }
  1642. int8 num_fuel_items = packet->getType_int8_ByName("num_fuel_items");
  1643. for (int8 i = 0; i < num_fuel_items; i++) {
  1644. memset(tmp_item_id, 0, 30);
  1645. sprintf(tmp_item_id, "fuel_id_%i", i);
  1646. item = packet->getType_int32_ByName(tmp_item_id);
  1647. sprintf(tmp_item_id, "fuel_qty_%i", i);
  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. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1654. }
  1655. safe_delete(packet);
  1656. }
  1657. break;
  1658. }
  1659. case OP_StopItemCreationMsg: {
  1660. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1661. //DumpPacket(app->pBuffer, app->size);
  1662. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1663. break;
  1664. }
  1665. case OP_SysClient:
  1666. case OP_SignalMsg: {
  1667. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1668. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1669. if (packet) {
  1670. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1671. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1672. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1673. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1674. SetReloadingZone(false);
  1675. if(GetPlayer()->IsDeletedSpawn()) {
  1676. GetPlayer()->SetDeletedSpawn(false);
  1677. }
  1678. ResetZoningCoords();
  1679. SetReadyForUpdates();
  1680. GetPlayer()->SendSpawnChanges(true);
  1681. ProcessStateCommands();
  1682. GetPlayer()->changed = true;
  1683. GetPlayer()->info_changed = true;
  1684. GetPlayer()->vis_changed = true;
  1685. player_pos_changed = true;
  1686. GetPlayer()->AddChangedZoneSpawn();
  1687. ProcessZoneIgnoreWidgets();
  1688. }
  1689. else {
  1690. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1691. }
  1692. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1693. if (zone_script && lua_interface)
  1694. {
  1695. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1696. }
  1697. }
  1698. safe_delete(packet);
  1699. }
  1700. break;
  1701. }
  1702. case OP_EntityVerbsRequestMsg: {
  1703. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1704. HandleVerbRequest(app);
  1705. break;
  1706. }
  1707. case OP_EntityVerbsVerbMsg: {
  1708. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1709. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1710. if (packet) {
  1711. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1712. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1713. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1714. Spawn* spawn = player->GetTarget();
  1715. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1716. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1717. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1718. {
  1719. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1720. if (spawn->IsGroundSpawn())
  1721. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1722. else if (spawn->IsObject())
  1723. ((Object*)spawn)->HandleUse(this, command);
  1724. else if (spawn->IsWidget())
  1725. ((Widget*)spawn)->HandleUse(this, command);
  1726. else if (spawn->IsSign())
  1727. ((Sign*)spawn)->HandleUse(this, command);
  1728. }
  1729. }
  1730. }
  1731. else {
  1732. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1733. if (command.size > 0) {
  1734. string command_name = command.data;
  1735. if (command_name.find(" ") < 0xFFFFFFFF) {
  1736. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1737. string::size_type pos = command_name.find(" ");
  1738. while(pos != string::npos){
  1739. command_name.replace(pos, 1, "_");
  1740. pos = command_name.find(" ");
  1741. }
  1742. }
  1743. else
  1744. command_name = command_name.substr(0, command_name.find(" "));
  1745. }
  1746. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1747. if (handler != 0xFFFFFFFF) {
  1748. if (command.data == command_name) {
  1749. command.data = "";
  1750. command.size = 0;
  1751. }
  1752. else {
  1753. command.data = command.data.substr(command.data.find(" ") + 1);
  1754. command.size = command.data.length();
  1755. }
  1756. commands.Process(handler, &command, this);
  1757. }
  1758. else {
  1759. if (spawn && spawn->IsNPC()) {
  1760. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1761. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1762. command_name = command.data;
  1763. string::size_type pos = command_name.find(" ");
  1764. while (pos != string::npos) {
  1765. command_name.replace(pos, 1, "_");
  1766. pos = command_name.find(" ");
  1767. }
  1768. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1769. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1770. }
  1771. }
  1772. }
  1773. }
  1774. else
  1775. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1776. }
  1777. }
  1778. }
  1779. }
  1780. safe_delete(packet);
  1781. }
  1782. break;
  1783. }
  1784. case OP_SkillInfoRequest: {
  1785. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1786. HandleSkillInfoRequest(app);
  1787. break;
  1788. }
  1789. case OP_UpdateTargetMsg: {
  1790. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1791. int16 index = 0;
  1792. memcpy(&index, app->pBuffer, sizeof(int16));
  1793. if (index == 0xFFFF)
  1794. GetPlayer()->SetTarget(0);
  1795. else {
  1796. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1797. if(spawn)
  1798. GetPlayer()->SetTarget(spawn);
  1799. else {
  1800. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1801. }
  1802. }
  1803. if (GetPlayer()->GetTarget())
  1804. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1805. //player->SetTarget((int16*)app->pBuffer);
  1806. break;
  1807. }
  1808. case OP_ExamineInfoRequestMsg: {
  1809. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1810. HandleExamineInfoRequest(app);
  1811. break;
  1812. }
  1813. case OP_QuickbarUpdateMsg:
  1814. //case OP_QuickbarAddMsg:
  1815. {
  1816. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1817. HandleQuickbarUpdateRequest(app);
  1818. break;
  1819. }
  1820. case OP_PredictionUpdateMsg: {
  1821. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1822. if (version <= 546) {
  1823. int8 offset = 9;
  1824. if (app->pBuffer[0] == 0xFF)
  1825. offset += 2;
  1826. if (app->size > offset) {
  1827. if (player->IsCasting()) {
  1828. float distance = 0;
  1829. float x = player->GetX();
  1830. float y = player->GetY();
  1831. float z = player->GetZ();
  1832. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1833. distance = player->GetDistance(x, y, z, false);
  1834. if (distance > .5)
  1835. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1836. }
  1837. else
  1838. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1839. player_pos_changed = true;
  1840. //DumpPacket(app);
  1841. }
  1842. }
  1843. else {
  1844. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1845. QueuePacket(app);
  1846. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1847. }
  1848. break;
  1849. }
  1850. case OP_RemoteCmdMsg: {
  1851. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1852. if (app->size > 0) {
  1853. EQ2_CommandString remote(app->pBuffer, app->size);
  1854. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1855. #if EQDEBUG >= 9
  1856. DumpPacket(app);
  1857. #endif
  1858. commands.Process(remote.handler, &remote.command, this);
  1859. }
  1860. else //bad client, disconnect
  1861. Disconnect();
  1862. break;
  1863. }
  1864. case OP_CancelSpellCast: {
  1865. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1866. current_zone->Interrupted(player, 0, 0, true);
  1867. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1868. break;
  1869. }
  1870. case OP_UpdatePositionMsg: {
  1871. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1872. int8 offset = 13;
  1873. if (app->pBuffer[0] == 0xFF)
  1874. offset += 2;
  1875. if (app->size > offset) {
  1876. if (player->IsCasting()) {
  1877. float distance = 0;
  1878. float x = player->GetX();
  1879. float y = player->GetY();
  1880. float z = player->GetZ();
  1881. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1882. distance = player->GetDistance(x, y, z, false);
  1883. if (distance > .5)
  1884. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1885. }
  1886. else
  1887. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1888. player_pos_changed = true;
  1889. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1890. //DumpPacket(app);
  1891. }
  1892. break;
  1893. }
  1894. case OP_MailSendMessageMsg: {
  1895. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1896. HandleSentMail(app);
  1897. break;
  1898. }
  1899. case OP_StopTrackingMsg: {
  1900. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1901. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1902. break;
  1903. }
  1904. case OP_BeginTrackingMsg: {
  1905. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1906. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1907. if (packet) {
  1908. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1909. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1910. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1911. if (spawn) {
  1912. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1913. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1914. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1915. }
  1916. }
  1917. safe_delete(packet);
  1918. }
  1919. break;
  1920. }
  1921. case OP_BioUpdateMsg: {
  1922. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1923. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1924. if (packet) {
  1925. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1926. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1927. }
  1928. safe_delete(packet);
  1929. }
  1930. break;
  1931. }
  1932. case OP_RewardPackMsg: {
  1933. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1934. /* 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
  1935. when we come across it (scatman) */
  1936. const char* name = app->GetOpcodeName();
  1937. if (name)
  1938. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1939. else
  1940. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1941. //DumpPacket(app);
  1942. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1943. if (packet) {
  1944. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1945. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1946. /* Player has contacted a guild recruiter */
  1947. if (recruiter_name.length() > 0) {
  1948. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1949. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1950. if (recruiter && guild) {
  1951. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1952. 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()));
  1953. recruiter->PlaySound("ui_guild_page");
  1954. }
  1955. }
  1956. /* New picture taken for guild recruiting */
  1957. else {
  1958. //DumpPacket(app->pBuffer, app->size);
  1959. int32 guild_id = 0;
  1960. int16 picture_data_size = 0;
  1961. unsigned char* recruiter_picture_data = 0;
  1962. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1963. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1964. Guild* guild = guild_list.GetGuild(guild_id);
  1965. if (guild) {
  1966. GuildMember* gm = guild->GetGuildMember(player);
  1967. if (gm) {
  1968. safe_delete_array(gm->recruiter_picture_data);
  1969. recruiter_picture_data = new unsigned char[picture_data_size];
  1970. for (int16 i = 0; i < picture_data_size; i++)
  1971. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1972. gm->recruiter_picture_data = recruiter_picture_data;
  1973. gm->recruiter_picture_data_size = picture_data_size;
  1974. guild->SetMemberSaveNeeded(true);
  1975. }
  1976. }
  1977. }
  1978. }
  1979. safe_delete(packet);
  1980. }
  1981. break;
  1982. }
  1983. case OP_PetOptions: {
  1984. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1985. Spawn* target = player->GetTarget();
  1986. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1987. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1988. bool change = false;
  1989. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  1990. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1991. if (strlen(name.c_str()) != 0 && SetPetName(name.c_str())) {
  1992. target->SetName(name.c_str());
  1993. GetCurrentZone()->SendUpdateTitles(target);
  1994. change = true;
  1995. }
  1996. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1997. // Check protect self setting and update if needed
  1998. if (packet->getType_int8_ByName("protect_self") == 1) {
  1999. if ((pet_behavior & 2) == 0) {
  2000. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  2001. change = true;
  2002. }
  2003. }
  2004. else {
  2005. if ((pet_behavior & 2) != 0) {
  2006. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  2007. change = true;
  2008. }
  2009. }
  2010. // Check protect master setting and update if needed
  2011. if (packet->getType_int8_ByName("protect_master") == 1) {
  2012. if ((pet_behavior & 1) == 0) {
  2013. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  2014. change = true;
  2015. }
  2016. }
  2017. else {
  2018. if ((pet_behavior & 1) != 0) {
  2019. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  2020. change = true;
  2021. }
  2022. }
  2023. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  2024. // Check stay/follow setting and update if needed
  2025. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  2026. if (pet_movement != 2) {
  2027. player->GetInfoStruct()->set_pet_movement(2);
  2028. change = true;
  2029. }
  2030. }
  2031. else {
  2032. if (pet_movement != 1) {
  2033. player->GetInfoStruct()->set_pet_movement(1);
  2034. change = true;
  2035. }
  2036. }
  2037. // Ranged/Melee settings are not implemented yet
  2038. if (change)
  2039. player->SetCharSheetChanged(true);
  2040. }
  2041. safe_delete(packet);
  2042. }
  2043. break;
  2044. }
  2045. case OP_RecipeBook: {
  2046. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  2047. SendRecipeList();
  2048. break;
  2049. }
  2050. case OP_BuyPlayerHouseMsg: {
  2051. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  2052. //DumpPacket(app);
  2053. int64 bank_money = GetPlayer()->GetBankCoinsPlat();
  2054. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  2055. if (packet) {
  2056. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2057. int64 house_id = 0;
  2058. if(GetVersion() <= 546) {
  2059. house_id = packet->getType_int32_ByName("house_id");
  2060. }
  2061. else {
  2062. house_id = packet->getType_int64_ByName("house_id");
  2063. }
  2064. HouseZone* hz = world.GetHouseZone(house_id);
  2065. if (hz) {
  2066. bool got_bank_money = BankHasCoin(hz->cost_coin);
  2067. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  2068. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  2069. if (houses.size() > 24)
  2070. {
  2071. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  2072. safe_delete(packet);
  2073. break;
  2074. }
  2075. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  2076. {
  2077. std::string req = "You must be of ";
  2078. if (hz->alignment == 1)
  2079. req.append("Good");
  2080. else
  2081. req.append("Evil");
  2082. req.append(" alignment to purchase this house");
  2083. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  2084. safe_delete(packet);
  2085. break;
  2086. }
  2087. int32 status_req = hz->cost_status;
  2088. int32 available_status = player->GetInfoStruct()->get_status_points();
  2089. if (status_req <= available_status && (!hz->cost_coin || (hz->cost_coin && player->RemoveCoins(hz->cost_coin))))
  2090. {
  2091. player->GetInfoStruct()->subtract_status_points(status_req);
  2092. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2093. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2094. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2095. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2096. //ClientPacketFunctions::SendHousingList(this);
  2097. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2098. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2099. PlaySound("coin_cha_ching");
  2100. }
  2101. else if (status_req <= available_status && got_bank_money == 1) {
  2102. player->GetInfoStruct()->subtract_status_points(status_req);
  2103. bool bankwithdrawl = BankWithdrawalNoBanker(hz->cost_coin);
  2104. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2105. if (bankwithdrawl == 0) {
  2106. PlaySound("buy_failed");
  2107. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2108. safe_delete(packet);
  2109. break;
  2110. }
  2111. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id, false, false);
  2112. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  2113. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  2114. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  2115. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  2116. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2117. PlaySound("coin_cha_ching");
  2118. }
  2119. else
  2120. {
  2121. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  2122. PlaySound("buy_failed");
  2123. }
  2124. }
  2125. }
  2126. }
  2127. safe_delete(packet);
  2128. break;
  2129. }
  2130. case OP_EnterHouseMsg: {
  2131. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  2132. //DumpPacket(app);
  2133. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  2134. if (packet) {
  2135. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2136. PlayerHouse* ph = nullptr;
  2137. HouseZone* hz = nullptr;
  2138. int64 house_id = 0;
  2139. int32 spawn_index = 0;
  2140. if(GetVersion() <= 546) {
  2141. spawn_index = packet->getType_int32_ByName("house_id");
  2142. }
  2143. else {
  2144. house_id = packet->getType_int64_ByName("house_id");
  2145. }
  2146. ZoneServer* house = GetHouseZoneServer(spawn_index, house_id);
  2147. if (house) {
  2148. Zone(house, true);
  2149. }
  2150. }
  2151. }
  2152. safe_delete(packet);
  2153. break;
  2154. }
  2155. case OP_PayHouseUpkeepMsg: {
  2156. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  2157. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  2158. if (packet) {
  2159. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2160. int64 house_id = 0;
  2161. if(GetVersion() <= 546) {
  2162. house_id = packet->getType_int32_ByName("house_id");
  2163. }
  2164. else {
  2165. house_id = packet->getType_int64_ByName("house_id");
  2166. }
  2167. HouseZone* hz = nullptr;
  2168. PlayerHouse* ph = world.GetPlayerHouse(this, GetVersion() <= 546 ? house_id : 0, GetVersion() > 546 ? house_id : 0, &hz);
  2169. if (ph)
  2170. {
  2171. if (!hz)
  2172. {
  2173. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  2174. safe_delete(packet);
  2175. break;
  2176. }
  2177. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2178. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2179. {
  2180. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2181. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2182. {
  2183. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2184. PlaySound("buy_failed");
  2185. safe_delete(packet);
  2186. break;
  2187. }
  2188. }
  2189. bool escrowChange = false;
  2190. int64 statusReq = hz->upkeep_status;
  2191. int64 tmpRecoverStatus = 0;
  2192. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2193. {
  2194. escrowChange = true;
  2195. tmpRecoverStatus = ph->escrow_status;
  2196. statusReq -= ph->escrow_status;
  2197. ph->escrow_status = 0;
  2198. }
  2199. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2200. {
  2201. escrowChange = true;
  2202. ph->escrow_status -= statusReq;
  2203. tmpRecoverStatus = statusReq;
  2204. statusReq = 0;
  2205. }
  2206. int64 coinReq = hz->upkeep_coin;
  2207. int64 tmpRecoverCoins = 0;
  2208. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2209. {
  2210. escrowChange = true;
  2211. tmpRecoverCoins = ph->escrow_coins;
  2212. coinReq -= ph->escrow_coins;
  2213. ph->escrow_coins = 0;
  2214. }
  2215. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2216. {
  2217. escrowChange = true;
  2218. // more than enough in escrow, subtract and make our cost 0!
  2219. ph->escrow_coins -= coinReq;
  2220. tmpRecoverCoins = coinReq;
  2221. coinReq = 0;
  2222. }
  2223. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2224. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2225. {
  2226. if(coinReq && player->RemoveCoins(coinReq))
  2227. coinReq = 0;
  2228. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2229. statusReq = 0;
  2230. }
  2231. bool got_bank_money = BankHasCoin(hz->upkeep_coin);
  2232. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2233. {
  2234. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2235. if (escrowChange)
  2236. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2237. ph->upkeep_due = upkeep_due;
  2238. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2239. //ClientPacketFunctions::SendHousingList(this);
  2240. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2241. PlaySound("coin_cha_ching");
  2242. }
  2243. else if (!statusReq && got_bank_money == 1) {
  2244. bool bankwithdrawl = BankWithdrawalNoBanker(hz->upkeep_coin);
  2245. //this should NEVER happen since we check with got_bank_money, however adding it here should something go nutty.
  2246. if (bankwithdrawl == 0) {
  2247. PlaySound("buy_failed");
  2248. SimpleMessage(CHANNEL_COLOR_RED, "There was an error in bankwithdrawl function.");
  2249. safe_delete(packet);
  2250. break;
  2251. }
  2252. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2253. if (escrowChange)
  2254. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2255. ph->upkeep_due = upkeep_due;
  2256. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2257. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, GetVersion() <= 546 ? house_id : this->GetPlayer()->GetID());
  2258. PlaySound("coin_cha_ching");
  2259. }
  2260. else
  2261. {
  2262. // recover the escrow we were going to use but could not spend due to lack of funds
  2263. if (tmpRecoverCoins)
  2264. ph->escrow_coins += tmpRecoverCoins;
  2265. if(tmpRecoverStatus)
  2266. ph->escrow_status += tmpRecoverStatus;
  2267. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2268. PlaySound("buy_failed");
  2269. }
  2270. }
  2271. else
  2272. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", house_id);
  2273. }
  2274. }
  2275. safe_delete(packet);
  2276. break;
  2277. }
  2278. case OP_ExitHouseMsg: {
  2279. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2280. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2281. if (instance_id > 0) {
  2282. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2283. if (ph) {
  2284. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2285. if (hz) {
  2286. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2287. // determine if this is an instanced zone that already exists
  2288. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2289. if (instance_zone || new_zone) {
  2290. GetPlayer()->SetX(hz->exit_x);
  2291. GetPlayer()->SetY(hz->exit_y);
  2292. GetPlayer()->SetZ(hz->exit_z);
  2293. GetPlayer()->SetHeading(hz->exit_heading);
  2294. if (instance_zone)
  2295. Zone(instance_zone->GetInstanceID(), false, true);
  2296. else
  2297. Zone(new_zone, false);
  2298. }
  2299. }
  2300. }
  2301. }
  2302. break;
  2303. }
  2304. case OP_QuestJournalWaypointMsg: {
  2305. //DumpPacket(app);
  2306. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2307. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2308. if (packet) {
  2309. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  2310. int32 quests = packet->getType_int32_ByName("num_quests");
  2311. if (quests > 100) // just picking a number higher than max allowed
  2312. {
  2313. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2314. break;
  2315. }
  2316. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2317. for (int32 i = 0; i < quests; i++) {
  2318. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2319. if (id == 0)
  2320. continue;
  2321. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2322. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2323. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2324. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  2325. player->player_quests[id]->SetTracked(tracked);
  2326. player->player_quests[id]->SetSaveNeeded(true);
  2327. }
  2328. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2329. }
  2330. }
  2331. safe_delete(packet);
  2332. }
  2333. break;
  2334. }
  2335. case OP_PaperdollImage: {
  2336. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2337. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2338. //First check if this is a new image... delete an existing partial image if one exists
  2339. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2340. if (packet_index == 0) {
  2341. safe_delete_array(incoming_paperdoll.image_bytes);
  2342. incoming_paperdoll.last_received_packet_index = 0;
  2343. incoming_paperdoll.current_size_bytes = 0;
  2344. }
  2345. //return if this packet is not the one we are expecting...
  2346. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2347. safe_delete(packet);
  2348. break;
  2349. }
  2350. //Check how many packets we're supposed to be receiving for this/these images
  2351. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2352. //Check the image type, if this is a new type in the same series of packets we have a new image
  2353. int8 img_type = packet->getType_int8_ByName("image_type");
  2354. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2355. //We have a new image. Save the old data and clear before continuing
  2356. SavePlayerImages();
  2357. }
  2358. incoming_paperdoll.image_type = img_type;
  2359. //Get the size of the image data in this packet
  2360. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2361. if (image_size <= 0 || image_size > 1048576) {
  2362. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2363. safe_delete(packet);
  2364. break;
  2365. }
  2366. //Create a new array
  2367. int32 new_image_size = image_size;
  2368. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2369. if (incoming_paperdoll.image_bytes) {
  2370. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2371. safe_delete_array(incoming_paperdoll.image_bytes);
  2372. }
  2373. //variable i should be the index in the packet of the first PNG file byte
  2374. vector<DataStruct*>* d_structs = packet->getStructs();
  2375. vector<DataStruct*>::iterator itr;
  2376. int32 i = 0;
  2377. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2378. DataStruct* ds = (*itr);
  2379. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2380. i += ds->GetDataSizeInBytes();
  2381. else
  2382. break;
  2383. }
  2384. //Return if this packet is bad and we would read out of bounds
  2385. if (app->size - i < new_image_size) {
  2386. safe_delete(packet);
  2387. safe_delete_array(new_image);
  2388. break;
  2389. }
  2390. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2391. memcpy(tmp, app->pBuffer + i, new_image_size);
  2392. incoming_paperdoll.current_size_bytes += new_image_size;
  2393. incoming_paperdoll.image_bytes = new_image;
  2394. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2395. if (incoming_paperdoll.image_num_packets == 1 ||
  2396. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2397. SavePlayerImages();
  2398. }
  2399. incoming_paperdoll.last_received_packet_index = packet_index;
  2400. }
  2401. safe_delete(packet);
  2402. */
  2403. break;
  2404. }
  2405. case OP_ReadyForTakeOffMsg:
  2406. {
  2407. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2408. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2409. if (GetPendingFlightPath() > 0) {
  2410. if (index != -1) {
  2411. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2412. if (packet) {
  2413. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2414. packet->setDataByName("path_id", index);
  2415. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2416. QueuePacket(packet->serialize());
  2417. safe_delete(packet);
  2418. on_auto_mount = true;
  2419. }
  2420. }
  2421. else {
  2422. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2423. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2424. EndAutoMount();
  2425. }
  2426. SetPendingFlightPath(0);
  2427. }
  2428. else
  2429. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2430. break;
  2431. }
  2432. case OP_EarlyLandingRequestMsg:
  2433. {
  2434. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2435. EndAutoMount();
  2436. break;
  2437. }
  2438. case OP_SubmitCharCust:
  2439. {
  2440. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2441. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2442. if (packet && packet->LoadPacketData(app->pBuffer, app->size, GetVersion() <= 546 ? false : true)) {
  2443. int8 type = packet->getType_int8_ByName("type");
  2444. if (type == 0) {
  2445. /*if (player->custNPC) {
  2446. player->custNPCTarget->CustomizeAppearance(packet);
  2447. current_zone->SendSpawnChanges(player->custNPCTarget);
  2448. }
  2449. else {*/
  2450. player->CustomizeAppearance(packet);
  2451. current_zone->SendSpawnChanges(player);
  2452. //}
  2453. }
  2454. }
  2455. safe_delete(packet);
  2456. /*
  2457. if (player->custNPC) {
  2458. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2459. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2460. if (player->custNPCTarget->IsBot())
  2461. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2462. player->custNPC = false;
  2463. player->custNPCTarget = 0;
  2464. player->changed = true;
  2465. player->info_changed = true;
  2466. current_zone->SendSpawnChanges(player, this);
  2467. }*/
  2468. break;
  2469. }
  2470. default: {
  2471. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2472. const char* name = app->GetOpcodeName();
  2473. if (name)
  2474. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2475. else
  2476. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2477. // keeping this around for debugging purposes
  2478. DumpPacket(app);
  2479. }
  2480. }
  2481. if (!eqs || !eqs->CheckActive()) {
  2482. return false;
  2483. }
  2484. return ret;
  2485. }
  2486. bool Client::HandleLootItem(Spawn* entity, Item* item, Spawn* target, bool overrideLootRestrictions) {
  2487. if (!item) {
  2488. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2489. return false;
  2490. }
  2491. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2492. int16 lore_stack_count = 0;
  2493. Player* lootingPlayer = player;
  2494. Client* lootingClient = this;
  2495. if (target != nullptr && target != lootingPlayer && target->IsPlayer()) {
  2496. lootingPlayer = (Player*)target;
  2497. lootingClient = lootingPlayer->GetClient();
  2498. }
  2499. // needs to only be checked before expiration of loot restrictions
  2500. if (entity && !overrideLootRestrictions) {
  2501. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID())) {
  2502. 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());
  2503. return false;
  2504. }
  2505. if (entity->GetLootMethod() != GroupLootMethod::METHOD_FFA) {
  2506. switch (entity->GetLootMethod()) {
  2507. case GroupLootMethod::METHOD_LEADER: {
  2508. if (entity->GetLootGroupID() > 0 && (!lootingPlayer->GetGroupMemberInfo() || (lootingPlayer->GetGroupMemberInfo() && (lootingPlayer->GetGroupMemberInfo()->group_id != entity->GetLootGroupID() || !lootingPlayer->GetGroupMemberInfo()->leader)))) {
  2509. 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);
  2510. return false;
  2511. }
  2512. break;
  2513. }
  2514. case GroupLootMethod::METHOD_LOTTO:
  2515. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2516. if (entity->IsLootTimerRunning()) {
  2517. 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);
  2518. return false;
  2519. }
  2520. break;
  2521. }
  2522. }
  2523. }
  2524. }
  2525. if (((conflictItemList = lootingPlayer->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2526. (conflictequipmentList = lootingPlayer->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2527. (conflictAppearanceEquipmentList = lootingPlayer->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2528. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2529. return false;
  2530. }
  2531. else if (conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2532. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2533. return false;
  2534. }
  2535. if (lootingPlayer->item_list.HasFreeSlot() || lootingPlayer->item_list.CanStack(item)) {
  2536. if (lootingPlayer->item_list.AssignItemToFreeSlot(item)) {
  2537. if (item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2538. GroupMemberInfo* gmi = lootingClient->GetPlayer()->GetGroupMemberInfo();
  2539. if (gmi && gmi->group_id)
  2540. {
  2541. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2542. if (group)
  2543. {
  2544. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2545. deque<GroupMemberInfo*>* members = group->GetMembers();
  2546. if (members) {
  2547. for (int8 i = 0; i < members->size(); i++) {
  2548. Entity* member = members->at(i)->member;
  2549. if (!member)
  2550. continue;
  2551. if ((member->GetZone() != lootingClient->GetPlayer()->GetZone()))
  2552. continue;
  2553. if (member->IsPlayer()) {
  2554. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2555. item->save_needed = true;
  2556. }
  2557. }
  2558. }
  2559. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2560. }
  2561. }
  2562. }
  2563. int8 type = CHANNEL_LOOT;
  2564. if (entity) {
  2565. lootingClient->Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2566. }
  2567. else {
  2568. lootingClient->Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2569. }
  2570. Guild* guild = lootingPlayer->GetGuild();
  2571. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2572. char adjective[32];
  2573. int8 type;
  2574. memset(adjective, 0, sizeof(adjective));
  2575. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2576. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2577. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2578. }
  2579. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2580. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2581. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2582. }
  2583. else {
  2584. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2585. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2586. }
  2587. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2588. guild->SendMessageToGuild(type, "%s has looted the %s %s", lootingPlayer->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2589. }
  2590. if (item->GetItemScript() && lua_interface)
  2591. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, lootingPlayer);
  2592. lootingClient->CheckPlayerQuestsItemUpdate(item);
  2593. if (GetVersion() <= 546) {
  2594. EQ2Packet* outapp = lootingPlayer->SendInventoryUpdate(GetVersion());
  2595. if (outapp)
  2596. lootingClient->QueuePacket(outapp);
  2597. }
  2598. return true;
  2599. }
  2600. else
  2601. lootingClient->SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2602. }
  2603. else
  2604. lootingClient->SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2605. return false;
  2606. }
  2607. bool Client::HandleLootItemByID(Spawn* entity, int32 item_id, Spawn* target) {
  2608. if (!entity) {
  2609. return false;
  2610. }
  2611. Item* item = entity->LootItem(item_id);
  2612. bool success = false;
  2613. success = HandleLootItem(entity, item, target);
  2614. if (!success)
  2615. entity->AddLootItem(item);
  2616. return success;
  2617. }
  2618. void Client::HandleLootItemRequestPacket(EQApplicationPacket* app) {
  2619. PacketStruct* packet = configReader.getStruct("WS_LootItem", GetVersion());
  2620. if (packet) {
  2621. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  2622. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2623. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2624. int32 target_id = packet->getType_int32_ByName("target_id");
  2625. int8 button_clicked = packet->getType_int8_ByName("button_clicked");
  2626. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2627. if(!spawn) {
  2628. safe_delete(packet);
  2629. return;
  2630. }
  2631. Item* item = nullptr;
  2632. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2633. if (items) {
  2634. int32 item_id = packet->getType_int32_ByName("item_id_0");
  2635. for (int32 i = 0; i < items->size(); i++) {
  2636. Item* master_item = items->at(i);
  2637. if (master_item && (loot_all || master_item->details.item_id == item_id)) {
  2638. item = new Item(master_item);
  2639. if (item) {
  2640. loot_all = HandleLootItem(0, item);
  2641. if (loot_all) {
  2642. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2643. if (GetVersion() <= 546) {
  2644. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2645. if (outapp)
  2646. QueuePacket(outapp);
  2647. }
  2648. }
  2649. }
  2650. if (!loot_all)
  2651. break;
  2652. }
  2653. }
  2654. safe_delete(items);
  2655. safe_delete(packet);
  2656. return;
  2657. }
  2658. spawn->LockLoot();
  2659. bool unlockedLoot = false;
  2660. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2661. if (loot_all) {
  2662. switch (spawn->GetLootMethod()) {
  2663. case GroupLootMethod::METHOD_LOTTO: {
  2664. spawn->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  2665. break;
  2666. }
  2667. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2668. spawn->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  2669. }
  2670. default: {
  2671. if (!unlockedLoot) {
  2672. spawn->UnlockLoot();
  2673. unlockedLoot = true;
  2674. }
  2675. int32 item_id = 0;
  2676. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2677. loot_all = HandleLootItemByID(spawn, item_id, GetPlayer());
  2678. }
  2679. break;
  2680. }
  2681. }
  2682. spawn->UnlockLoot();
  2683. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  2684. CloseLoot(loot_id);
  2685. }
  2686. }
  2687. else {
  2688. int8 item_count = packet->getType_int8_ByName("item_count");
  2689. for (int8 cur = 0; cur < item_count; cur++) {
  2690. char item_field_name[64];
  2691. snprintf(item_field_name, 64, "item_id_%u", cur);
  2692. int32 item_id = packet->getType_int32_ByName(item_field_name);
  2693. Spawn* target = this->GetPlayer();
  2694. if (target_id != 0xFFFFFFFF && GetPlayer()->GetGroupMemberInfo()) {
  2695. Spawn* destTarget = GetPlayer()->GetSpawnWithPlayerID(target_id);
  2696. if (destTarget && (!destTarget->IsPlayer() || !world.GetGroupManager()->IsInGroup(GetPlayer()->GetGroupMemberInfo()->group_id, ((Player*)destTarget)))) {
  2697. SimpleMessage(CHANNEL_COMMAND_TEXT, "HACKS!!");
  2698. safe_delete(packet);
  2699. spawn->UnlockLoot();
  2700. return;
  2701. }
  2702. target = destTarget;
  2703. }
  2704. bool breakLoopAllLooted = false;
  2705. switch (spawn->GetLootMethod()) {
  2706. case GroupLootMethod::METHOD_LOTTO: {
  2707. spawn->AddLottoItemRequest(item_id, GetPlayer()->GetID());
  2708. break;
  2709. }
  2710. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  2711. if (button_clicked == 3) { // decline
  2712. break;
  2713. }
  2714. if (GetVersion() <= 546) {
  2715. button_clicked = 1; // selecting is need
  2716. }
  2717. spawn->AddNeedGreedItemRequest(item_id, GetPlayer()->GetID(), (button_clicked == 1));
  2718. break;
  2719. }
  2720. default: {
  2721. if (!unlockedLoot) {
  2722. spawn->UnlockLoot();
  2723. unlockedLoot = true;
  2724. }
  2725. if (!loot_all) {
  2726. HandleLootItemByID(spawn, item_id, target);
  2727. }
  2728. else {
  2729. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2730. loot_all = HandleLootItemByID(spawn, item_id, target);
  2731. }
  2732. breakLoopAllLooted = true;
  2733. }
  2734. break;
  2735. }
  2736. }
  2737. if (breakLoopAllLooted) {
  2738. break;
  2739. }
  2740. }
  2741. if (!unlockedLoot) {
  2742. spawn->UnlockLoot();
  2743. }
  2744. if (spawn->GetLootMethod() == GroupLootMethod::METHOD_LOTTO ||
  2745. (spawn->GetLootMethod() == GroupLootMethod::METHOD_NEED_BEFORE_GREED && item_count >= spawn->GetLootCount())) {
  2746. CloseLoot(loot_id);
  2747. }
  2748. }
  2749. if (GetVersion() > 546) {
  2750. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2751. if (outapp)
  2752. QueuePacket(outapp);
  2753. }
  2754. if (spawn->GetLootMethod() != GroupLootMethod::METHOD_LOTTO && spawn->GetLootMethod() != GroupLootMethod::METHOD_NEED_BEFORE_GREED) {
  2755. LootSpawnRequest(spawn);
  2756. }
  2757. else {
  2758. spawn->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  2759. }
  2760. if (!spawn->HasLoot()) {
  2761. CloseLoot(loot_id);
  2762. if (spawn->IsNPC())
  2763. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2764. }
  2765. }
  2766. else {
  2767. spawn->UnlockLoot();
  2768. if (!spawn) {
  2769. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2770. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2771. }
  2772. else
  2773. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2774. }
  2775. }
  2776. safe_delete(packet);
  2777. }
  2778. }
  2779. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2780. PacketStruct* request = 0;
  2781. // cout << "Request: \n";
  2782. // DumpPacket(app);
  2783. switch (app->pBuffer[0]) {
  2784. case 0: { //items
  2785. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2786. if (request) {
  2787. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2788. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2789. if (!item)
  2790. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2791. if (item) {
  2792. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2793. if (response) {
  2794. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2795. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2796. response->setSmallStringByName("name", item->name.c_str());
  2797. EQ2Packet* app2 = response->serialize();
  2798. //DumpPacket(app2);
  2799. QueuePacket(app2);
  2800. safe_delete(response);
  2801. }
  2802. }
  2803. }
  2804. safe_delete(request);
  2805. }
  2806. break;
  2807. }
  2808. case 2: {//spells
  2809. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2810. if (request) {
  2811. if(request->LoadPacketData(app->pBuffer, app->size)) {
  2812. int32 id = request->getType_int32_ByName("id");
  2813. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2814. Spell* spell = master_spell_list.GetSpell(id, tier);
  2815. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2816. if (response) {
  2817. response->setDataByName("request_type", 2);
  2818. response->setDataByName("unique_id", tier);
  2819. response->setDataByName("id", id);
  2820. if (spell)
  2821. response->setSmallStringByName("name", spell->GetName());
  2822. else
  2823. response->setSmallStringByName("name", "Unknown Spell");
  2824. EQ2Packet* app2 = response->serialize();
  2825. // DumpPacket(app2);
  2826. QueuePacket(app2);
  2827. safe_delete(response);
  2828. }
  2829. }
  2830. safe_delete(request);
  2831. }
  2832. break;
  2833. }
  2834. default: {
  2835. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2836. }
  2837. }
  2838. safe_delete(request);
  2839. }
  2840. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2841. PacketStruct* request = 0;
  2842. if (!app || app->size == 0)
  2843. return;
  2844. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2845. //DumpPacket(app);
  2846. int8 type = app->pBuffer[0];
  2847. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2848. if (version <= 283) {
  2849. if (type == 1)
  2850. type = 4;
  2851. else if (type == 2)
  2852. type = 5;
  2853. }
  2854. if (type == 3) {
  2855. Spell* spell = 0;
  2856. bool trait_display;
  2857. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  2858. if (!request) {
  2859. return;
  2860. }
  2861. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2862. safe_delete(request);
  2863. return;
  2864. }
  2865. int32 id = request->getType_int32_ByName("id");
  2866. int32 tier = request->getType_int32_ByName("tier");
  2867. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2868. bool display = true;
  2869. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2870. display = false;
  2871. else if (version <= 546)
  2872. display = request->getType_int8_ByName("display");
  2873. else if (version > 546)
  2874. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2875. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2876. if (trait_tier != 0xFFFFFFFF) {
  2877. spell = master_spell_list.GetSpell(id, trait_tier);
  2878. if (!spell) {
  2879. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2880. }
  2881. trait_display = true;
  2882. }
  2883. else {
  2884. spell = master_spell_list.GetSpell(id, tier);
  2885. trait_display = false;
  2886. }
  2887. // if we can't find it on the master spell list, see if it is a custom spell
  2888. if (!spell)
  2889. {
  2890. lua_interface->FindCustomSpellLock();
  2891. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2892. if (tmpSpell)
  2893. spell = tmpSpell->spell;
  2894. lua_interface->FindCustomSpellUnlock();
  2895. }
  2896. if (spell && !CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2897. if (!spell->IsCopiedSpell())
  2898. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2899. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2900. //DumpPacket(app);
  2901. QueuePacket(app);
  2902. }
  2903. else if(spell && GetVersion() <=546 && CountSentSpell(spell->GetSpellID(), spell->GetSpellTier())) {
  2904. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display, GetVersion() <= 546 ? true : false);
  2905. //DumpPacket(app);
  2906. QueuePacket(app);
  2907. }
  2908. }
  2909. else if (type == 0) {
  2910. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2911. if (!request) {
  2912. return;
  2913. }
  2914. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2915. safe_delete(request);
  2916. return;
  2917. }
  2918. int32 id = request->getType_int32_ByName("id");
  2919. Item* item = 0;
  2920. // translate from unique id to spawn id for houses
  2921. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2922. bool wasSpawn = false;
  2923. if (spawn)
  2924. {
  2925. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2926. if (item)
  2927. {
  2928. wasSpawn = true;
  2929. item = new Item(item);
  2930. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2931. }
  2932. }
  2933. if (!item)
  2934. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2935. if (!item)
  2936. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2937. if (!item)
  2938. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2939. if (!item)
  2940. item = master_item_list.GetItem(id);
  2941. if (item) {// && sent_item_details.count(id) == 0){
  2942. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2943. sent_item_details[id] = true;
  2944. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2945. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2946. QueuePacket(app);
  2947. if (wasSpawn)
  2948. delete item;
  2949. }
  2950. else {
  2951. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2952. DumpPacket(app);
  2953. }
  2954. }
  2955. else if (type == 1) {
  2956. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2957. if (!request) {
  2958. return;
  2959. }
  2960. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2961. safe_delete(request);
  2962. return;
  2963. }
  2964. int32 id = request->getType_int32_ByName("id");
  2965. int32 unique_id = request->getType_int32_ByName("unique_id");
  2966. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2967. if (!item)
  2968. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2969. if (!item)
  2970. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2971. if (!item)
  2972. item = master_item_list.GetItem(id);
  2973. if (item) {
  2974. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2975. sent_item_details[id] = true;
  2976. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2977. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2978. QueuePacket(app);
  2979. }
  2980. else {
  2981. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2982. DumpPacket(app);
  2983. }
  2984. }
  2985. else if (type == 2) {
  2986. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2987. if (!request) {
  2988. return;
  2989. }
  2990. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  2991. safe_delete(request);
  2992. return;
  2993. }
  2994. int32 id = request->getType_int32_ByName("item_id");
  2995. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2996. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2997. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2998. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2999. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  3000. //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);
  3001. Item* item = master_item_list.GetItem(id);
  3002. if (item) {
  3003. //only display popup for non merchant links
  3004. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, GetVersion() > 546 ? true : false);
  3005. QueuePacket(app);
  3006. }
  3007. else {
  3008. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  3009. DumpPacket(app);
  3010. }
  3011. }
  3012. else if (type == 4) { //spell effect
  3013. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  3014. if (!request) {
  3015. return;
  3016. }
  3017. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3018. safe_delete(request);
  3019. return;
  3020. }
  3021. int32 id = request->getType_int32_ByName("id");
  3022. int16 display = request->getType_int8_ByName("partial_info");
  3023. SpellEffects* effect = player->GetSpellEffect(id);
  3024. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  3025. if (effect) {
  3026. int8 tier = effect->tier;
  3027. Spell* spell = master_spell_list.GetSpell(id, tier);
  3028. // if we can't find it on the master spell list, see if it is a custom spell
  3029. if (!spell)
  3030. {
  3031. lua_interface->FindCustomSpellLock();
  3032. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3033. EQ2Packet* pack = 0;
  3034. if (tmpSpell)
  3035. spell = tmpSpell->spell;
  3036. lua_interface->FindCustomSpellUnlock();
  3037. }
  3038. if (spell && !CountSentSpell(id, tier)) {
  3039. if (!spell->IsCopiedSpell())
  3040. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3041. int8 type = 0;
  3042. if (version <= 283)
  3043. type = 1;
  3044. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  3045. //DumpPacket(app);
  3046. QueuePacket(app);
  3047. }
  3048. }
  3049. }
  3050. else if (type == 5) { // recipe info
  3051. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3052. if (!request)
  3053. return;
  3054. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3055. safe_delete(request);
  3056. return;
  3057. }
  3058. int32 id = 0;
  3059. if(GetVersion() < 546) {
  3060. id = request->getType_int32_ByName("id");
  3061. }
  3062. else if(GetVersion() == 546) {
  3063. id = request->getType_int32_ByName("unique_id");
  3064. }
  3065. else {
  3066. id = request->getType_int32_ByName("unknown_id");
  3067. }
  3068. Recipe* recipe = master_recipe_list.GetRecipe(id);
  3069. if (recipe) {
  3070. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  3071. //DumpPacket(app);
  3072. QueuePacket(app);
  3073. }
  3074. }
  3075. else if (type == 6) { // AA spell info
  3076. Spell* spell = 0;
  3077. //Spell* spell2 = 0;
  3078. //AltAdvanceData* data = 0;
  3079. request = configReader.getStruct((GetVersion() <= 283) ? "WS_ExamineInfoRequest" : "WS_ExamineInfoRequestMsg", GetVersion());
  3080. if (!request)
  3081. return;
  3082. if(!request->LoadPacketData(app->pBuffer, app->size)) {
  3083. safe_delete(request);
  3084. return;
  3085. }
  3086. int32 id = request->getType_int32_ByName("id");
  3087. int32 tier = GetPlayer()->GetSpellTier(id);
  3088. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  3089. //data = master_aa_list.GetAltAdvancement(id);
  3090. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  3091. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  3092. spell = master_spell_list.GetSpell(id, tier);
  3093. if (!spell)
  3094. spell = master_spell_list.GetSpell(id, 1);
  3095. if (!spell)
  3096. {
  3097. lua_interface->FindCustomSpellLock();
  3098. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  3099. if (tmpSpell)
  3100. spell = tmpSpell->spell;
  3101. lua_interface->FindCustomSpellUnlock();
  3102. }
  3103. if (!spell)
  3104. {
  3105. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  3106. return;
  3107. }
  3108. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  3109. if (!spell->IsCopiedSpell())
  3110. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  3111. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  3112. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  3113. if(GetVersion() > 546) {
  3114. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  3115. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  3116. //DumpPacket(app);
  3117. QueuePacket(app);
  3118. }
  3119. //}
  3120. }
  3121. else {
  3122. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  3123. DumpPacket(app);
  3124. }
  3125. safe_delete(request);
  3126. }
  3127. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  3128. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  3129. if (request) {
  3130. if(request->LoadPacketData(app->pBuffer, app->size)) {
  3131. int32 id = request->getType_int32_ByName("id");
  3132. int32 bar = request->getType_int32_ByName("hotbar_number");
  3133. int32 slot = request->getType_int32_ByName("hotkey_slot");
  3134. int32 type = request->getType_int32_ByName("type");
  3135. int8 tier = request->getType_int32_ByName("unique_id");
  3136. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  3137. Spell* spell = 0;
  3138. if (type == 0xFFFFFFFF)
  3139. GetPlayer()->RemoveQuickbarItem(bar, slot);
  3140. else {
  3141. if (type == QUICKBAR_NORMAL)
  3142. spell = master_spell_list.GetSpell(id, tier);
  3143. if (spell)
  3144. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  3145. else
  3146. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  3147. }
  3148. }
  3149. safe_delete(request);
  3150. }
  3151. }
  3152. bool Client::Process(bool zone_process) {
  3153. bool ret = true;
  3154. // EQS can become null if player is linkdead, we want to always be able to process the camp/linkdead timers when active
  3155. if ((camp_timer && camp_timer->Check()) || (linkdead_timer && linkdead_timer->Check())) {
  3156. ResetSendMail();
  3157. if(getConnection())
  3158. getConnection()->SendDisconnect(false);
  3159. safe_delete(camp_timer);
  3160. if(linkdead_timer) {
  3161. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player %s triggered linkdead timer, disconnecting", GetPlayer()->GetName());
  3162. // we remove the linkdead status and force a camp out immediately
  3163. if((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0) {
  3164. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() - ACTIVITY_STATUS_LINKDEAD);
  3165. }
  3166. if ((GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0) {
  3167. GetPlayer()->SetActivityStatus(GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  3168. }
  3169. }
  3170. safe_delete(linkdead_timer);
  3171. ret = false;
  3172. }
  3173. if (!eqs) {
  3174. return false;
  3175. }
  3176. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  3177. return true;
  3178. }
  3179. switch(new_client_login) {
  3180. case NewLoginState::LOGIN_SEND: {
  3181. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  3182. SendLoginInfo();
  3183. new_client_login = NewLoginState::LOGIN_NONE;
  3184. break;
  3185. }
  3186. case NewLoginState::LOGIN_INITIAL_LOAD: {
  3187. bool isDBActive = database.IsActiveQuery(GetCharacterID());
  3188. // wait for starting skills/spells to load and reload from DB.
  3189. if(!isDBActive) {
  3190. if (GetPlayer()->GetInfoStruct()->get_reload_player_spells()) {
  3191. database.LoadCharacterSpells(GetCharacterID(), GetPlayer());
  3192. GetPlayer()->GetInfoStruct()->set_reload_player_spells(0);
  3193. }
  3194. new_client_login = NewLoginState::LOGIN_SEND;
  3195. }
  3196. break;
  3197. }
  3198. case NewLoginState::LOGIN_ALLOWED: {
  3199. int32 count = 0;
  3200. if(!GetPlayer()->IsReturningFromLD())
  3201. {
  3202. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  3203. count = database.LoadCharacterSkills(GetCharacterID(), player);
  3204. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  3205. count = database.LoadCharacterSpells(GetCharacterID(), player);
  3206. }
  3207. else
  3208. {
  3209. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  3210. }
  3211. // get the latest character starting skills / spells, may have been updated after character creation
  3212. if(GetPlayer()->GetInfoStruct()->get_first_world_login()) {
  3213. world.SyncCharacterAbilities(this);
  3214. Query query;
  3215. query.AddQueryAsync(GetCharacterID(), &database, Q_UPDATE, "UPDATE characters set first_world_login = 0 where id=%u", GetCharacterID());
  3216. GetPlayer()->GetInfoStruct()->set_first_world_login(0);
  3217. }
  3218. new_client_login = NewLoginState::LOGIN_INITIAL_LOAD;
  3219. break;
  3220. }
  3221. case NewLoginState::LOGIN_DELAYED: {
  3222. if(!delay_msg_timer.Enabled() || delay_msg_timer.Check()) {
  3223. LogWrite(CCLIENT__INFO, 0, "Client", "Wait for zone %s to load for new client %s...", GetCurrentZone()->GetZoneName(), GetPlayer()->GetName());
  3224. delay_msg_timer.Start(1000, true);
  3225. }
  3226. if(!GetCurrentZone()->IsLoading()) {
  3227. new_client_login = NewLoginState::LOGIN_ALLOWED;
  3228. }
  3229. return true;
  3230. break;
  3231. }
  3232. }
  3233. delay_msg_timer.Disable();
  3234. sockaddr_in to;
  3235. memset((char*)&to, 0, sizeof(to));
  3236. to.sin_family = AF_INET;
  3237. to.sin_port = port;
  3238. to.sin_addr.s_addr = ip;
  3239. /************ Get all packets from packet manager out queue and process them ************/
  3240. EQApplicationPacket* app = 0;
  3241. if (eqs && !eqs->CheckActive()) {
  3242. num_active_failures++;
  3243. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  3244. if (num_active_failures > 100) {
  3245. return false;
  3246. }
  3247. return true;
  3248. }
  3249. while (ret && eqs && (app = eqs->PopPacket())) {
  3250. ret = HandlePacket(app);
  3251. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  3252. delete app;
  3253. }
  3254. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  3255. //database.LoadCharacterActiveSpells(player);
  3256. player->UnlockAllSpells(true);
  3257. should_load_spells = false;
  3258. }
  3259. if(spawn_removal_timer.Check() && GetPlayer()) {
  3260. GetPlayer()->ProcessSpawnRangeUpdates();
  3261. GetPlayer()->CheckSpawnStateQueue();
  3262. }
  3263. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  3264. {
  3265. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  3266. return false;
  3267. }
  3268. if (quest_updates) {
  3269. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  3270. ProcessQuestUpdates();
  3271. }
  3272. int32 queue_timer_delay = rule_manager.GetGlobalRule(R_Client, QuestQueueTimer)->GetInt32();
  3273. if(queue_timer_delay < 10) {
  3274. queue_timer_delay = 10;
  3275. }
  3276. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - queue_timer_delay)) {
  3277. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  3278. CheckQuestQueue();
  3279. }
  3280. MSaveSpellStateMutex.lock();
  3281. if(save_spell_state_timer.Check())
  3282. {
  3283. save_spell_state_timer.Disable();
  3284. GetPlayer()->SaveSpellEffects();
  3285. }
  3286. MSaveSpellStateMutex.unlock();
  3287. if (temp_placement_timer.Check()) {
  3288. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  3289. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  3290. hasSentTempPlacementSpawn = true;
  3291. temp_placement_timer.Disable();
  3292. }
  3293. }
  3294. if (pos_update.Check())
  3295. {
  3296. ProcessStateCommands();
  3297. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  3298. if(GetPlayer()->GetRegionMap())
  3299. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3300. if(player_pos_changed && IsReadyForUpdates()) {
  3301. if(!underworld_cooldown_timer.Enabled() || (underworld_cooldown_timer.Enabled() && underworld_cooldown_timer.Check())) {
  3302. bool underworld = false;
  3303. if(rule_manager.GetGlobalRule(R_Zone, UseMapUnderworldCoords)->GetBool()) {
  3304. if(GetCurrentZone()->GetUnderWorld() != -1000000.0f) {
  3305. if(GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld())
  3306. underworld = true;
  3307. }
  3308. else if(GetPlayer()->GetMap() && GetPlayer()->GetMap()->GetMinY() != 9999999.0f && GetPlayer()->GetY() < (GetPlayer()->GetMap()->GetMinY() + rule_manager.GetGlobalRule(R_Zone, MapUnderworldCoordOffset)->GetFloat())) {
  3309. underworld = true;
  3310. }
  3311. }
  3312. else if(GetPlayer()->GetMap() && GetPlayer()->GetY() < GetCurrentZone()->GetUnderWorld()) {
  3313. underworld = true;
  3314. }
  3315. if(underworld) {
  3316. player->SetX(GetCurrentZone()->GetSafeX());
  3317. player->SetY(GetCurrentZone()->GetSafeY());
  3318. player->SetZ(GetCurrentZone()->GetSafeZ());
  3319. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3320. EQ2Packet* app = GetPlayer()->Move(player->GetX(), player->GetY(), player->GetZ(), GetVersion(), player->GetHeading());
  3321. if(app){
  3322. QueuePacket(app);
  3323. }
  3324. SimpleMessage(CHANNEL_COLOR_RED, "You have been teleported to a safe location in the zone, because you appeared to have fallen through the world.");
  3325. }
  3326. underworld_cooldown_timer.Start();
  3327. }
  3328. //GetPlayer()->CalculateLocation();
  3329. client_list.CheckPlayersInvisStatus(this);
  3330. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  3331. player_pos_changed = false;
  3332. GetCurrentZone()->CheckTransporters(this);
  3333. if(GetPlayer()->GetRegionMap())
  3334. {
  3335. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3336. }
  3337. }
  3338. else if (IsReadyForUpdates() && GetPlayer()->GetRegionMap()) {
  3339. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  3340. }
  3341. }
  3342. if (lua_interface && lua_debug && lua_debug_timer.Check())
  3343. lua_interface->UpdateDebugClients(this);
  3344. if (quest_pos_timer.Check())
  3345. CheckPlayerQuestsLocationUpdate();
  3346. if (player->GetSkills()->HasSkillUpdates()) {
  3347. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  3348. if (skills) {
  3349. Skill* skill = 0;
  3350. vector<Skill*>::iterator itr;
  3351. for (itr = skills->begin(); itr != skills->end(); itr++) {
  3352. skill = *itr;
  3353. SkillChanged(skill, skill->previous_val, skill->current_val);
  3354. }
  3355. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  3356. if (app) QueuePacket(app);
  3357. safe_delete(skills);
  3358. }
  3359. }
  3360. m_resurrect.writelock(__FUNCTION__, __LINE__);
  3361. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  3362. safe_delete(current_rez.expire_timer);
  3363. current_rez.expire_timer = 0;
  3364. current_rez.active = false;
  3365. current_rez.caster = 0;
  3366. current_rez.crit = false;
  3367. current_rez.crit_mod = 0;
  3368. current_rez.expire_timer = 0;
  3369. current_rez.heal_name = "";
  3370. current_rez.hp_perc = 0;
  3371. current_rez.mp_perc = 0;
  3372. current_rez.no_calcs = false;
  3373. current_rez.range = 0;
  3374. current_rez.should_delete = false;
  3375. current_rez.spell_name = "";
  3376. current_rez.spell_visual = 0;
  3377. current_rez.subspell = 0;
  3378. }
  3379. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  3380. // Quest timers
  3381. Quest* failed_step = 0;
  3382. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  3383. if (quest_timers.size() > 0) {
  3384. vector<int32>::iterator itr;
  3385. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  3386. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  3387. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  3388. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  3389. Quest* quest = player_quests->at(*itr);
  3390. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  3391. failed_step = quest;
  3392. break;
  3393. }
  3394. }
  3395. else {
  3396. itr = quest_timers.erase(itr);
  3397. break;
  3398. }
  3399. }
  3400. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  3401. }
  3402. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  3403. if (failed_step)
  3404. failed_step->StepFailed(failed_step->GetTimerStep());
  3405. if (player->ControlFlagsChanged())
  3406. player->SendControlFlagUpdates(this);
  3407. if (!eqs || (eqs && !eqs->CheckActive()))
  3408. ret = false;
  3409. // redundant to client disconnect
  3410. // if(!ret)
  3411. // Save();
  3412. return ret;
  3413. }
  3414. ClientList::ClientList() {
  3415. MClients.SetName("ClientList::MClients");
  3416. }
  3417. ClientList::~ClientList() {
  3418. }
  3419. void ClientList::ReloadQuests() {
  3420. list<Client*>::iterator client_iter;
  3421. Client* client = 0;
  3422. MClients.readlock(__FUNCTION__, __LINE__);
  3423. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3424. client = *client_iter;
  3425. if (client)
  3426. client->ReloadQuests();
  3427. }
  3428. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3429. }
  3430. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  3431. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  3432. return;
  3433. list<Client*>::iterator client_iter;
  3434. Client* client = 0;
  3435. MClients.readlock(__FUNCTION__, __LINE__);
  3436. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3437. client = *client_iter;
  3438. if (client == owner || client->GetPlayer() == NULL)
  3439. continue;
  3440. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3441. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3442. }
  3443. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3444. }
  3445. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3446. list<Client*>::iterator client_iter;
  3447. Client* client = 0;
  3448. MClients.readlock(__FUNCTION__, __LINE__);
  3449. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3450. client = *client_iter;
  3451. if (!client->GetPlayer())
  3452. continue;
  3453. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3454. }
  3455. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3456. }
  3457. int32 ClientList::Count() {
  3458. return client_list.size();
  3459. }
  3460. void ClientList::Add(Client* client) {
  3461. MClients.writelock(__FUNCTION__, __LINE__);
  3462. client_list.push_back(client);
  3463. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3464. }
  3465. Client* ClientList::FindByAccountID(int32 account_id) {
  3466. list<Client*>::iterator client_iter;
  3467. Client* client = 0;
  3468. Client* ret = 0;
  3469. MClients.readlock(__FUNCTION__, __LINE__);
  3470. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3471. client = *client_iter;
  3472. if (client->GetAccountID() == account_id) {
  3473. ret = client;
  3474. break;
  3475. }
  3476. }
  3477. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3478. return ret;
  3479. }
  3480. Client* ClientList::FindByName(char* charName) {
  3481. list<Client*>::iterator client_iter;
  3482. Client* client = 0;
  3483. Client* ret = 0;
  3484. MClients.readlock(__FUNCTION__, __LINE__);
  3485. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3486. client = *client_iter;
  3487. if (!client || !client->GetPlayer())
  3488. continue;
  3489. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3490. ret = client;
  3491. break;
  3492. }
  3493. }
  3494. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3495. return ret;
  3496. }
  3497. Client* ClientList::Get(int32 ip, int16 port) {
  3498. list<Client*>::iterator client_iter;
  3499. Client* client = 0;
  3500. Client* ret = 0;
  3501. MClients.readlock(__FUNCTION__, __LINE__);
  3502. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3503. client = *client_iter;
  3504. if (client->GetIP() == ip && client->GetPort() == port) {
  3505. ret = client;
  3506. break;
  3507. }
  3508. }
  3509. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3510. return ret;
  3511. }
  3512. void ClientList::Process() {
  3513. list<Client*>::iterator client_iter;
  3514. list<Client*>::iterator erase_iter;
  3515. Client* client = 0;
  3516. MClients.readlock(__FUNCTION__, __LINE__);
  3517. erase_iter = client_list.end();
  3518. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3519. client = *client_iter;
  3520. // have a sanity check because the client list can sometimes obtain null client pointers
  3521. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3522. erase_iter = client_iter;
  3523. break;
  3524. }
  3525. }
  3526. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3527. if (erase_iter != client_list.end()) {
  3528. client = *erase_iter;
  3529. MClients.writelock(__FUNCTION__, __LINE__);
  3530. client_list.erase(erase_iter);
  3531. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3532. if (client && !client->remove_from_list) {
  3533. struct in_addr in;
  3534. in.s_addr = client->GetIP();
  3535. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3536. safe_delete(client);
  3537. }
  3538. }
  3539. }
  3540. void ClientList::RemoveConnection(EQStream* eqs) {
  3541. Client* client;
  3542. if (eqs) {
  3543. list<Client*>::iterator client_iter;
  3544. MClients.readlock(__FUNCTION__, __LINE__);
  3545. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3546. client = *client_iter;
  3547. if (client->getConnection() == eqs)
  3548. client->Disconnect(true);
  3549. }
  3550. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3551. }
  3552. }
  3553. bool ClientList::ContainsStream(EQStream* eqs) {
  3554. if (!eqs) {
  3555. return false;
  3556. }
  3557. list<Client*>::iterator client_iter;
  3558. bool ret = false;
  3559. MClients.readlock(__FUNCTION__, __LINE__);
  3560. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3561. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3562. ret = true;
  3563. break;
  3564. }
  3565. }
  3566. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3567. return ret;
  3568. }
  3569. void ClientList::Remove(Client* client, bool remove_data) {
  3570. client->remove_from_list = true;
  3571. if (remove_data) {
  3572. safe_delete(client);
  3573. }
  3574. }
  3575. void Client::SetCurrentZone(ZoneServer* zone) {
  3576. current_zone = zone;
  3577. if(player) {
  3578. player->SetZone(zone, GetVersion());
  3579. }
  3580. }
  3581. void Client::SetCurrentZone(int32 id) {
  3582. if (current_zone) {
  3583. //current_zone->GetCombat()->RemoveHate(player);
  3584. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3585. }
  3586. SetCurrentZone(zone_list.Get(id));
  3587. }
  3588. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3589. if (current_zone) {
  3590. //current_zone->GetCombat()->RemoveHate(player);
  3591. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3592. }
  3593. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3594. }
  3595. ZoneServer* Client::GetCurrentZone() {
  3596. return current_zone;
  3597. }
  3598. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3599. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3600. if (channel_type == CHANNEL_LOOT)
  3601. return CHANNEL_COLOR_NEW_LOOT;
  3602. }
  3603. else if (GetVersion() >= 973) {
  3604. if (channel_type == CHANNEL_LOOT)
  3605. return CHANNEL_COLOR_NEWEST_LOOT;
  3606. }
  3607. if (GetVersion() <= 283) {
  3608. if (channel_type <=12)
  3609. return channel_type;
  3610. switch (channel_type) {
  3611. case CHANNEL_GROUP_CHAT:
  3612. case CHANNEL_GROUP_SAY:
  3613. case CHANNEL_RAID_SAY:
  3614. case CHANNEL_GUILD_CHAT:
  3615. case CHANNEL_GUILD_SAY:
  3616. case CHANNEL_OFFICER_SAY:
  3617. case CHANNEL_GUILD_MOTD:
  3618. return channel_type - 1;
  3619. case CHANNEL_PRIVATE_CHAT:
  3620. case CHANNEL_NONPLAYER_TELL:
  3621. return channel_type - 5;
  3622. case CHANNEL_PRIVATE_TELL:
  3623. case CHANNEL_TELL_FROM_CS:
  3624. return channel_type - 6;
  3625. case CHANNEL_CHAT_CHANNEL_TEXT:
  3626. case CHANNEL_OUT_OF_CHARACTER:
  3627. case CHANNEL_AUCTION:
  3628. case CHANNEL_CUSTOM_CHANNEL:
  3629. case CHANNEL_CHARACTER_TEXT:
  3630. case CHANNEL_REWARD:
  3631. case CHANNEL_DEATH:
  3632. case CHANNEL_PET_CHAT:
  3633. case CHANNEL_SKILL:
  3634. return channel_type - 7;
  3635. case CHANNEL_SPELLS:
  3636. case CHANNEL_YOU_CAST:
  3637. case CHANNEL_YOU_FAIL:
  3638. return channel_type - 8;
  3639. case CHANNEL_FRIENDLY_CAST:
  3640. case CHANNEL_FRIENDLY_FAIL:
  3641. case CHANNEL_OTHER_CAST:
  3642. case CHANNEL_OTHER_FAIL:
  3643. case CHANNEL_HOSTILE_CAST:
  3644. case CHANNEL_HOSTILE_FAIL:
  3645. case CHANNEL_WORN_OFF:
  3646. case CHANNEL_SPELLS_OTHER:
  3647. return channel_type - 9;
  3648. case CHANNEL_COMBAT:
  3649. return channel_type - 15;
  3650. case CHANNEL_HEROIC_OPPORTUNITY:
  3651. case CHANNEL_NON_MELEE_DAMAGE:
  3652. case CHANNEL_DAMAGE_SHIELD:
  3653. return channel_type - 16;
  3654. case CHANNEL_MELEE_COMBAT:
  3655. case CHANNEL_WARNINGS:
  3656. case CHANNEL_YOU_HIT:
  3657. case CHANNEL_YOU_MISS:
  3658. case CHANNEL_ATTACKER_HITS:
  3659. case CHANNEL_ATTACKER_MISSES:
  3660. return channel_type - 18;
  3661. case CHANNEL_OTHER_HIT:
  3662. case CHANNEL_OTHER_MISSES:
  3663. case CHANNEL_CRITICAL_HIT:
  3664. return channel_type - 22;
  3665. case CHANNEL_OTHER:
  3666. case CHANNEL_MONEY_SPLIT:
  3667. case CHANNEL_LOOT:
  3668. return channel_type - 30;
  3669. case CHANNEL_COMMAND_TEXT:
  3670. case CHANNEL_BROADCAST:
  3671. case CHANNEL_WHO:
  3672. case CHANNEL_COMMANDS:
  3673. case CHANNEL_MERCHANT:
  3674. case CHANNEL_MERCHANT_BUY_SELL:
  3675. case CHANNEL_CONSIDER_MESSAGE:
  3676. case CHANNEL_CON_MINUS_2:
  3677. case CHANNEL_CON_MINUS_1:
  3678. case CHANNEL_CON_0:
  3679. case CHANNEL_CON_1:
  3680. case CHANNEL_CON_2:
  3681. return channel_type - 31;
  3682. default: {
  3683. return CHANNEL_DEFAULT;
  3684. }
  3685. }
  3686. }
  3687. else if (GetVersion() <= 546) {
  3688. if (channel_type < 20)
  3689. return channel_type;
  3690. switch (channel_type) {
  3691. case CHANNEL_GUILD_MOTD:
  3692. case CHANNEL_GUILD_MEMBER_ONLINE:
  3693. case CHANNEL_GUILD_EVENT:
  3694. return channel_type + 1;
  3695. case CHANNEL_PRIVATE_CHAT:
  3696. case CHANNEL_NONPLAYER_TELL:
  3697. return channel_type - 1;
  3698. case CHANNEL_PRIVATE_TELL:
  3699. case CHANNEL_TELL_FROM_CS:
  3700. case CHANNEL_ARENA:
  3701. case CHANNEL_CHAT_CHANNEL_TEXT:
  3702. case CHANNEL_OUT_OF_CHARACTER:
  3703. case CHANNEL_AUCTION:
  3704. case CHANNEL_CUSTOM_CHANNEL:
  3705. case CHANNEL_CHARACTER_TEXT:
  3706. case CHANNEL_REWARD:
  3707. case CHANNEL_DEATH:
  3708. case CHANNEL_PET_CHAT:
  3709. case CHANNEL_SKILL:
  3710. case CHANNEL_FACTION:
  3711. case CHANNEL_SPELLS:
  3712. case CHANNEL_YOU_CAST:
  3713. case CHANNEL_YOU_FAIL:
  3714. return channel_type - 2;
  3715. case CHANNEL_FRIENDLY_CAST:
  3716. case CHANNEL_FRIENDLY_FAIL:
  3717. case CHANNEL_OTHER_CAST:
  3718. case CHANNEL_OTHER_FAIL:
  3719. case CHANNEL_HOSTILE_CAST:
  3720. case CHANNEL_HOSTILE_FAIL:
  3721. case CHANNEL_WORN_OFF:
  3722. case CHANNEL_SPELLS_OTHER:
  3723. case CHANNEL_HEAL_SPELLS:
  3724. case CHANNEL_HEALS:
  3725. case CHANNEL_FRIENDLY_HEALS:
  3726. case CHANNEL_OTHER_HEALS:
  3727. case CHANNEL_HOSTILE_HEALS:
  3728. return channel_type - 3;
  3729. case CHANNEL_COMBAT:
  3730. case CHANNEL_GENERAL_COMBAT:
  3731. case CHANNEL_HEROIC_OPPORTUNITY:
  3732. case CHANNEL_NON_MELEE_DAMAGE:
  3733. case CHANNEL_DAMAGE_SHIELD:
  3734. case CHANNEL_WARD:
  3735. return channel_type - 4;
  3736. case CHANNEL_MELEE_COMBAT:
  3737. case CHANNEL_WARNINGS:
  3738. case CHANNEL_YOU_HIT:
  3739. case CHANNEL_YOU_MISS:
  3740. case CHANNEL_ATTACKER_HITS:
  3741. case CHANNEL_ATTACKER_MISSES:
  3742. case CHANNEL_YOUR_PET_HITS:
  3743. case CHANNEL_YOUR_PET_MISSES:
  3744. case CHANNEL_ATTACKER_HITS_PET:
  3745. case CHANNEL_ATTACKER_MISSES_PET:
  3746. case CHANNEL_OTHER_HIT:
  3747. case CHANNEL_OTHER_MISSES:
  3748. return channel_type - 5;
  3749. case CHANNEL_OTHER:
  3750. case CHANNEL_MONEY_SPLIT:
  3751. case CHANNEL_LOOT:
  3752. return channel_type - 14;
  3753. case CHANNEL_COMMAND_TEXT:
  3754. case CHANNEL_BROADCAST:
  3755. case CHANNEL_WHO:
  3756. case CHANNEL_COMMANDS:
  3757. case CHANNEL_MERCHANT:
  3758. case CHANNEL_MERCHANT_BUY_SELL:
  3759. case CHANNEL_CONSIDER_MESSAGE:
  3760. case CHANNEL_CON_MINUS_2:
  3761. case CHANNEL_CON_MINUS_1:
  3762. case CHANNEL_CON_0:
  3763. case CHANNEL_CON_1:
  3764. case CHANNEL_CON_2:
  3765. case CHANNEL_TRADESKILLS:
  3766. case CHANNEL_HARVESTING:
  3767. case CHANNEL_HARVESTING_WARNINGS:
  3768. return channel_type - 15;
  3769. default: {
  3770. return CHANNEL_DEFAULT;
  3771. }
  3772. }
  3773. }
  3774. else {
  3775. switch (channel_type) {
  3776. default: {
  3777. return channel_type;
  3778. }
  3779. }
  3780. }
  3781. return channel_type;
  3782. }
  3783. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3784. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3785. return;
  3786. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3787. if (packet) {
  3788. packet->setDataByName("from", from->GetPlayer()->GetName());
  3789. packet->setDataByName("to", to);
  3790. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3791. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3792. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3793. packet->setDataByName("unknown2", 1, 1);
  3794. packet->setDataByName("show_bubble", 1);
  3795. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3796. packet->setDataByName("understood", 1);
  3797. }
  3798. packet->setDataByName("time", 2);
  3799. packet->setDataByName("language", current_language_id);
  3800. packet->setMediumStringByName("message", message);
  3801. EQ2Packet* outpacket = packet->serialize();
  3802. QueuePacket(outpacket);
  3803. safe_delete(packet);
  3804. }
  3805. }
  3806. void Client::SimpleMessage(int8 color, const char* message) {
  3807. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3808. if (command_packet) {
  3809. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3810. command_packet->setMediumStringByName("text", message);
  3811. command_packet->setDataByName("unknown02", 0x00ff);
  3812. EQ2Packet* outapp = command_packet->serialize();
  3813. QueuePacket(outapp);
  3814. safe_delete(command_packet);
  3815. }
  3816. }
  3817. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3818. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3819. if (packet) {
  3820. int8 xxx = spell->GetSpellData()->is_aa;
  3821. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3822. packet->setDataByName("spell_id", spell->GetSpellID());
  3823. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3824. packet->setDataByName("spell_name", spell->GetName());
  3825. if(add_silently)
  3826. packet->setDataByName("add_silently", 1);
  3827. if(add_to_hotbar)
  3828. packet->setDataByName("add_to_hotbar", 1);
  3829. packet->setDataByName("unknown", xxx);
  3830. packet->setDataByName("display_spell_tier", 1);
  3831. packet->setDataByName("unknown3", 1);
  3832. packet->setDataByName("tier", spell->GetSpellTier());
  3833. packet->setDataByName("icon", spell->GetSpellIcon());
  3834. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3835. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3836. //packet->PrintPacket();
  3837. EQ2Packet* outapp = packet->serialize();
  3838. //DumpPacket(outapp);
  3839. QueuePacket(outapp);
  3840. safe_delete(packet);
  3841. }
  3842. }
  3843. void Client::Message(int8 type, const char* message, ...) {
  3844. va_list argptr;
  3845. char buffer[4096];
  3846. va_start(argptr, message);
  3847. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3848. va_end(argptr);
  3849. SimpleMessage(type, buffer);
  3850. }
  3851. void Client::Disconnect(bool send_disconnect)
  3852. {
  3853. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3854. this->Save();
  3855. this->GetPlayer()->WritePlayerStatistics();
  3856. SetConnected(false);
  3857. if (send_disconnect && getConnection())
  3858. getConnection()->SendDisconnect(true);
  3859. eqs = 0;
  3860. }
  3861. bool Client::Summon(const char* search_name) {
  3862. Spawn* target = 0;
  3863. if (search_name || GetPlayer()->GetTarget()) {
  3864. Client* search_client = 0;
  3865. if (search_name) {
  3866. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3867. if (target && target->IsPlayer())
  3868. search_client = target->GetClient();
  3869. if (!target) {
  3870. search_client = zone_list.GetClientByCharName(string(search_name));
  3871. if (search_client)
  3872. target = search_client->GetPlayer();
  3873. }
  3874. }
  3875. else
  3876. target = GetPlayer()->GetTarget();
  3877. if (target && target != GetPlayer()) {
  3878. target->SetX(GetPlayer()->GetX());
  3879. target->SetY(GetPlayer()->GetY());
  3880. target->SetZ(GetPlayer()->GetZ());
  3881. target->SetHeading(GetPlayer()->GetHeading());
  3882. if (!target->IsPlayer()) {
  3883. target->SetSpawnOrigX(target->GetX());
  3884. target->SetSpawnOrigY(target->GetY());
  3885. target->SetSpawnOrigZ(target->GetZ());
  3886. target->SetSpawnOrigHeading(target->GetHeading());
  3887. }
  3888. target->SetLocation(GetPlayer()->GetLocation());
  3889. if(target->IsNPC()) {
  3890. ((NPC*)target)->HaltMovement();
  3891. }
  3892. }
  3893. else if (target)
  3894. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3895. if (search_client && search_client != this) {
  3896. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3897. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3898. if (search_client->GetCurrentZone() != GetCurrentZone())
  3899. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3900. else {
  3901. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3902. if (app)
  3903. search_client->QueuePacket(app);
  3904. }
  3905. }
  3906. }
  3907. if (!target)
  3908. return false;
  3909. else
  3910. return true;
  3911. }
  3912. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3913. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3914. if(instanceType < 1)
  3915. return std::string("");
  3916. ZoneServer* instance_zone = nullptr;
  3917. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3918. if (data) {
  3919. // If lockout instances check to see if we are locked out
  3920. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3921. int32 time = 0;
  3922. // Check success timer
  3923. if (data->last_success_timestamp > 0) {
  3924. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3925. // Timer has not expired yet can't re enter
  3926. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3927. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3928. }
  3929. }
  3930. // Check failure timer
  3931. if (data->last_failure_timestamp > 0) {
  3932. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3933. // Timer has not expired yet
  3934. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3935. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3936. }
  3937. }
  3938. // Time > 0 then we are locked out, make the message and send it and return true
  3939. if (time > 0) {
  3940. string time_msg = "";
  3941. int16 hour;
  3942. int8 min;
  3943. int8 sec;
  3944. hour = time / 3600;
  3945. time = time % 3600;
  3946. min = time / 60;
  3947. time = time % 60;
  3948. sec = time;
  3949. if (hour > 0) {
  3950. char temp[10];
  3951. snprintf(temp, 9," %i", hour);
  3952. time_msg.append(temp);
  3953. time_msg.append(" hour");
  3954. time_msg.append((hour > 1) ? "s" : "");
  3955. }
  3956. if (min > 0) {
  3957. char temp[5];
  3958. snprintf(temp, 4," %i", min);
  3959. time_msg.append(temp);
  3960. time_msg.append(" minute");
  3961. time_msg.append((min > 1) ? "s" : "");
  3962. }
  3963. // Only add seconds if minutes and hours are 0
  3964. if (hour == 0 && min == 0 && sec > 0) {
  3965. char temp[5];
  3966. snprintf(temp, 4," %i", sec);
  3967. time_msg.append(temp);
  3968. time_msg.append(" second");
  3969. time_msg.append((sec > 1) ? "s" : "");
  3970. }
  3971. if(displayClient)
  3972. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3973. return time_msg;
  3974. }
  3975. }
  3976. }
  3977. return std::string("");
  3978. }
  3979. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3980. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3981. if(instanceType < 1)
  3982. return nullptr;
  3983. ZoneServer* instance_zone = nullptr;
  3984. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3985. if (data) {
  3986. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3987. // If lockout instances check to see if we are locked out
  3988. if (lockoutTime.length() > 0) {
  3989. return nullptr;
  3990. }
  3991. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3992. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID, false, false);
  3993. // 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
  3994. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3995. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3996. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3997. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3998. }
  3999. else
  4000. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  4001. data->instance_id = instance_zone->GetInstanceID();
  4002. }
  4003. }
  4004. return instance_zone;
  4005. }
  4006. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  4007. ZoneServer* instance_zone = NULL;
  4008. int8 instanceType = 0;
  4009. // determine if this is a group instanced zone that already exists
  4010. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  4011. if (instance_zone != NULL)
  4012. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  4013. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  4014. {
  4015. // best to check if we already have our own instance!
  4016. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  4017. {
  4018. switch (instanceType)
  4019. {
  4020. case SOLO_LOCKOUT_INSTANCE:
  4021. case GROUP_LOCKOUT_INSTANCE:
  4022. case RAID_LOCKOUT_INSTANCE:
  4023. {
  4024. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4025. if (instance_zone) {
  4026. // 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
  4027. // so delete `instances` entry for the zone when it shuts down.
  4028. 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());
  4029. if (db_id > 0)
  4030. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  4031. }
  4032. break;
  4033. }
  4034. case SOLO_PERSIST_INSTANCE:
  4035. case GROUP_PERSIST_INSTANCE:
  4036. case RAID_PERSIST_INSTANCE:
  4037. {
  4038. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4039. if (instance_zone) {
  4040. 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());
  4041. if (db_id > 0)
  4042. 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()));
  4043. }
  4044. break;
  4045. }
  4046. case PUBLIC_INSTANCE:
  4047. case TRADESKILL_INSTANCE:
  4048. {
  4049. // if its public/tradeskill, look for a public already setup
  4050. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  4051. if (instance_zone) {
  4052. // Check the current population against the max population, if greater or equal start a new version
  4053. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  4054. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4055. }
  4056. else
  4057. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4058. break;
  4059. }
  4060. case PERSONAL_HOUSE_INSTANCE:
  4061. case GUILD_HOUSE_INSTANCE:
  4062. {
  4063. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  4064. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  4065. // with the OP_EnterHouseMsg opcode
  4066. break;
  4067. }
  4068. case QUEST_INSTANCE:
  4069. {
  4070. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  4071. break;
  4072. /*
  4073. 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`;
  4074. */
  4075. }
  4076. default:
  4077. {
  4078. // NONE
  4079. }
  4080. }
  4081. }
  4082. if (instance_zone != NULL)
  4083. Zone(instance_zone, zone_coords_valid);
  4084. }
  4085. if (instance_zone != NULL)
  4086. return true;
  4087. else
  4088. return false;
  4089. }
  4090. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  4091. Spawn* target = 0;
  4092. if (search_name || GetPlayer()->GetTarget()) {
  4093. Client* search_client = 0;
  4094. if (search_name) {
  4095. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  4096. if (!target) {
  4097. search_client = zone_list.GetClientByCharName(search_name);
  4098. if (search_client)
  4099. target = search_client->GetPlayer();
  4100. }
  4101. if (target)
  4102. GetPlayer()->SetTarget(target);
  4103. }
  4104. else
  4105. target = GetPlayer()->GetTarget();
  4106. if (target && target != GetPlayer()) {
  4107. GetPlayer()->SetX(target->GetX());
  4108. GetPlayer()->SetY(target->GetY());
  4109. GetPlayer()->SetZ(target->GetZ());
  4110. GetPlayer()->SetHeading(target->GetHeading());
  4111. GetPlayer()->SetLocation(target->GetLocation());
  4112. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  4113. }
  4114. else if (target)
  4115. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  4116. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  4117. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  4118. else if (target) {
  4119. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion(), (target->GetHeading() + 180.0f));
  4120. if (app)
  4121. QueuePacket(app);
  4122. }
  4123. }
  4124. if (!target)
  4125. return false;
  4126. else
  4127. return true;
  4128. }
  4129. bool Client::CheckZoneAccess(const char* zoneName) {
  4130. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  4131. ZoneServer* zone = zone_list.Get(zoneName, false, false, false);
  4132. // JA: implemented /zone lock|unlock commands (2012.07.28)
  4133. if (zone && zone->GetZoneLockState())
  4134. {
  4135. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  4136. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  4137. return false;
  4138. }
  4139. sint16 zoneMinStatus = 0;
  4140. int16 zoneMinLevel = 0;
  4141. int16 zoneMaxLevel = 0;
  4142. int16 zoneMinVersion = 0;
  4143. if (!zone)
  4144. {
  4145. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  4146. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  4147. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  4148. return true;
  4149. }
  4150. }
  4151. else
  4152. {
  4153. zoneMinStatus = zone->GetMinimumStatus();
  4154. zoneMinLevel = zone->GetMinimumLevel();
  4155. zoneMaxLevel = zone->GetMaximumLevel();
  4156. zoneMinVersion = zone->GetMinimumVersion();
  4157. }
  4158. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  4159. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  4160. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  4161. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  4162. {
  4163. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  4164. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  4165. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  4166. return false;
  4167. }
  4168. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  4169. {
  4170. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4171. {
  4172. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4173. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  4174. return false;
  4175. }
  4176. }
  4177. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  4178. {
  4179. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  4180. {
  4181. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  4182. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  4183. return false;
  4184. }
  4185. }
  4186. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  4187. {
  4188. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  4189. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  4190. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  4191. {
  4192. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  4193. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  4194. return false;
  4195. }
  4196. }
  4197. return true;
  4198. }
  4199. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  4200. Zone(zone_list.GetByInstanceID(instanceid, 0, false, true), set_coords, is_spell);
  4201. }
  4202. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  4203. if (!new_zone) {
  4204. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  4205. return;
  4206. }
  4207. client_zoning = true;
  4208. zoning_id = new_zone->GetZoneID();
  4209. zoning_instance_id = new_zone->GetInstanceID();
  4210. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  4211. player->SetResurrecting(true);
  4212. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  4213. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  4214. SaveSpells();
  4215. ResetSendMail();
  4216. // Remove players pet from zone if there is one
  4217. ((Entity*)player)->DismissAllPets();
  4218. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  4219. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  4220. GetPlayer()->DeleteSpellEffects(true);
  4221. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  4222. SetZoningDestination(new_zone);
  4223. SetCurrentZone(new_zone);
  4224. if (player->GetGroupMemberInfo())
  4225. {
  4226. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  4227. player->UpdateGroupMemberInfo();
  4228. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  4229. }
  4230. // block out the member info for the group
  4231. TempRemoveGroup();
  4232. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  4233. if (set_coords)
  4234. {
  4235. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  4236. __FUNCTION__,
  4237. GetCurrentZone()->GetSafeX(),
  4238. GetCurrentZone()->GetSafeY(),
  4239. GetCurrentZone()->GetSafeZ(),
  4240. GetCurrentZone()->GetSafeHeading(),
  4241. new_zone->GetZoneName()
  4242. );
  4243. player->SetX(GetCurrentZone()->GetSafeX());
  4244. player->SetY(GetCurrentZone()->GetSafeY());
  4245. player->SetZ(GetCurrentZone()->GetSafeZ());
  4246. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  4247. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  4248. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  4249. }
  4250. else {
  4251. ResetZoningCoords();
  4252. }
  4253. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  4254. Save();
  4255. char* new_zone_ip = 0;
  4256. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  4257. new_zone_ip = net.GetInternalWorldAddress();
  4258. else
  4259. new_zone_ip = net.GetWorldAddress();
  4260. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  4261. int32 key = Timer::GetUnixTimeStamp();
  4262. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  4263. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  4264. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  4265. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  4266. if (version > 283) {
  4267. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  4268. if (packet)
  4269. {
  4270. QueuePacket(packet->serialize());
  4271. safe_delete(packet);
  4272. }
  4273. }
  4274. }
  4275. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  4276. {
  4277. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  4278. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  4279. }
  4280. float Client::DistanceFrom(Client* client) {
  4281. float ret = 0;
  4282. if (client && client != this) {
  4283. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  4284. ret = sqrt(ret);
  4285. }
  4286. return ret;
  4287. }
  4288. void Client::DetermineCharacterUpdates() {
  4289. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  4290. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  4291. cdu->account_id = GetAccountID();
  4292. cdu->char_id = GetCharacterID();
  4293. int32 timestamp = Timer::GetUnixTimeStamp();
  4294. int8 flag = GetTimeStampFlag();
  4295. if (flag & LEVEL_UPDATE_FLAG)
  4296. {
  4297. cdu->update_field = LEVEL_UPDATE_FLAG;
  4298. cdu->update_data = player->GetLevel();
  4299. loginserver.SendPacket(outpack);
  4300. }
  4301. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  4302. if (flag & CLASS_UPDATE_FLAG)
  4303. {
  4304. cdu->update_field = CLASS_UPDATE_FLAG;
  4305. cdu->update_data = player->GetAdventureClass();
  4306. loginserver.SendPacket(outpack);
  4307. }
  4308. if (flag & GENDER_UPDATE_FLAG)
  4309. {
  4310. cdu->update_field = GENDER_UPDATE_FLAG;
  4311. cdu->update_data = player->GetGender();
  4312. loginserver.SendPacket(outpack);
  4313. }
  4314. if (flag & DELETE_UPDATE_FLAG) {
  4315. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4316. }
  4317. safe_delete(outpack); // Zone, armor and name use a different structure
  4318. if (flag & RACE_UPDATE_FLAG)
  4319. {
  4320. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  4321. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  4322. ru->account_id = GetAccountID();
  4323. ru->char_id = GetCharacterID();
  4324. ru->race = player->GetRace();
  4325. ru->model_type = player->GetModelType();
  4326. loginserver.SendPacket(outpack);
  4327. safe_delete(outpack);
  4328. }
  4329. if (flag & ZONE_UPDATE_FLAG) {
  4330. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  4331. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  4332. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  4333. czu->account_id = GetAccountID();
  4334. czu->char_id = GetCharacterID();
  4335. czu->zone_id = GetCurrentZone()->GetZoneID();
  4336. const char* zone_file = GetCurrentZone()->GetZoneFile();
  4337. czu->zone_length = strlen(zone_file);
  4338. if (czu->zone_length > 64)
  4339. czu->zone_length = 64;
  4340. strncpy(czu->new_zone, zone_file, czu->zone_length);
  4341. loginserver.SendPacket(outpack);
  4342. safe_delete(outpack);
  4343. }
  4344. if (flag & ARMOR_UPDATE_FLAG) {
  4345. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4346. }
  4347. if (flag & NAME_UPDATE_FLAG) {
  4348. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  4349. }
  4350. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  4351. }
  4352. void Client::Save() {
  4353. if (GetCharacterID() == 0 || IsSaveDisabled())
  4354. return;
  4355. if (current_zone) {
  4356. DetermineCharacterUpdates();
  4357. UpdateCharacterInstances();
  4358. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  4359. database.Save(this);
  4360. if (GetPlayer()->UpdateQuickbarNeeded()) {
  4361. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  4362. GetPlayer()->ResetQuickbarNeeded();
  4363. }
  4364. database.SaveItems(this);
  4365. database.SaveBuyBacks(this);
  4366. GetPlayer()->SaveHistory();
  4367. GetPlayer()->SaveLUAHistory();
  4368. MSaveSpellStateMutex.lock();
  4369. GetPlayer()->SaveSpellEffects();
  4370. MSaveSpellStateMutex.unlock();
  4371. }
  4372. }
  4373. void Client::UpdateCharacterInstances() {
  4374. if (GetPlayer() != NULL)
  4375. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  4376. /*if ( GetPlayer() != NULL )
  4377. {
  4378. // determine the last timestamp then get a new one, determine the difference in the timestamp
  4379. // to use for applying the update to each instances timer
  4380. int32 lastSaveTS = GetLastSavedTimeStamp();
  4381. int32 newSaveTS = Timer::GetUnixTimeStamp();
  4382. int32 diffTS = newSaveTS - lastSaveTS;
  4383. // update instance timers
  4384. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  4385. // update with the new timestamp and save the db
  4386. this->SetLastSavedTimeStamp(newSaveTS);
  4387. }*/
  4388. }
  4389. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  4390. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  4391. if (packet) {
  4392. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  4393. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  4394. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  4395. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4396. vector<EntityCommand*> commands;
  4397. vector<EntityCommand*> delete_commands;
  4398. if (out && spawn) {
  4399. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  4400. {
  4401. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  4402. if (!spawn->primary_command_list[i]->default_allow_list)
  4403. {
  4404. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4405. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  4406. continue;
  4407. }
  4408. else
  4409. {
  4410. // default is allow list, only deny if added to the list as deny (false itr second)
  4411. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  4412. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  4413. continue;
  4414. }
  4415. commands.push_back(spawn->primary_command_list[i]);
  4416. }
  4417. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  4418. commands.push_back(spawn->secondary_command_list[i]);
  4419. if (spawn->IsPlayer()) {
  4420. if (player->IsFriend(spawn->GetName()))
  4421. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  4422. else
  4423. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  4424. if (player->IsIgnored(spawn->GetName()))
  4425. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  4426. else
  4427. {
  4428. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  4429. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  4430. }
  4431. if (((Player*)spawn)->GetGroupMemberInfo()) {
  4432. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  4433. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  4434. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  4435. }
  4436. if(spawn->IsPlayer() && player->GetGroupMemberInfo() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  4437. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  4438. else if(spawn->IsPlayer() && player->GetGroupMemberInfo() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  4439. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4440. }
  4441. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4442. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4443. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4444. }
  4445. out->setDataByName("spawn_id", spawn_id);
  4446. out->setArrayLengthByName("num_verbs", commands.size());
  4447. for (int32 i = 0; i < commands.size(); i++) {
  4448. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4449. out->setArrayDataByName("distance", commands[i]->distance, i);
  4450. if (commands[i]->error_text.length() == 0)
  4451. out->setArrayAddToPacketByName("error", false, i);
  4452. else {
  4453. out->setArrayDataByName("display_error", 1, i);
  4454. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4455. }
  4456. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4457. }
  4458. EQ2Packet* outapp = out->serialize();
  4459. //DumpPacket(outapp);
  4460. QueuePacket(outapp);
  4461. safe_delete(out);
  4462. for (int32 i = 0; i < delete_commands.size(); i++) {
  4463. safe_delete(delete_commands[i]);
  4464. }
  4465. }
  4466. }
  4467. safe_delete(packet);
  4468. }
  4469. }
  4470. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4471. if (previous_value != new_value) {
  4472. 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);
  4473. char tmp[200] = { 0 };
  4474. 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);
  4475. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4476. }
  4477. }
  4478. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4479. {
  4480. /* JA notes on the unknown:
  4481. 2 = ding glimmer
  4482. 16 = Achievement Unlocked
  4483. 6 no longer does anything
  4484. */
  4485. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4486. if (packet) {
  4487. packet->setDataByName("unknown", unknown);
  4488. packet->setMediumStringByName("text", text);
  4489. if (type && strlen(type) > 0)
  4490. packet->setMediumStringByName("message_type", type);
  4491. packet->setDataByName("size", size);
  4492. packet->setDataByName("red", red);
  4493. packet->setDataByName("green", green);
  4494. packet->setDataByName("blue", blue);
  4495. QueuePacket(packet->serialize());
  4496. safe_delete(packet);
  4497. }
  4498. }
  4499. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4500. if (new_level < 1) {
  4501. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4502. return;
  4503. }
  4504. if (player->GetLevel() != new_level) {
  4505. player->SetLevel(new_level);
  4506. if (player->GetGroupMemberInfo()) {
  4507. player->UpdateGroupMemberInfo();
  4508. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4509. }
  4510. }
  4511. if (new_level > old_level) {
  4512. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4513. }
  4514. if (player->GetPet()) {
  4515. NPC* pet = (NPC*)player->GetPet();
  4516. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4517. pet->SetLevel(new_level);
  4518. pet->UpdateWeapons();
  4519. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4520. if (command_packet) {
  4521. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4522. command_packet->setDataByName("anim_type", 1753);
  4523. QueuePacket(command_packet->serialize());
  4524. safe_delete(command_packet);
  4525. }
  4526. }
  4527. }
  4528. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4529. if (level_update) {
  4530. level_update->setDataByName("old_level", old_level);
  4531. level_update->setDataByName("new_level", new_level);
  4532. QueuePacket(level_update->serialize());
  4533. safe_delete(level_update);
  4534. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4535. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4536. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4537. }
  4538. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4539. if (command_packet) {
  4540. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4541. command_packet->setDataByName("anim_type", 1753);
  4542. QueuePacket(command_packet->serialize());
  4543. safe_delete(command_packet);
  4544. }
  4545. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4546. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4547. SendNewAdventureSpells();
  4548. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4549. GetPlayer()->UpdateWeapons();
  4550. // GetPlayer()->SetLevel(new_level);
  4551. 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__);
  4552. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4553. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4554. GetPlayer()->CalculateBonuses();
  4555. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4556. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4557. /*InfoStruct* info = player->GetInfoStruct();
  4558. info->set_agi_base(new_level * 2 + 15);
  4559. info->set_intel_base(new_level * 2 + 15);
  4560. info->set_wis_base(new_level * 2 + 15);
  4561. info->set_str_base(new_level * 2 + 15);
  4562. info->set_sta_base(new_level * 2 + 15);
  4563. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4564. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4565. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4566. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4567. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4568. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4569. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4570. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));*/
  4571. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4572. GetPlayer()->SetCharSheetChanged(true);
  4573. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4574. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4575. int16 new_skill_cap = 5 * new_level;
  4576. PlayerSkillList* player_skills = player->GetSkills();
  4577. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4578. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4579. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4580. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4581. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4582. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4583. }
  4584. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4585. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4586. if(rule_manager.GetGlobalRule(R_Player, AutoSkillUpBaseSkills)->GetBool()) {
  4587. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4588. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4589. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4590. }
  4591. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4592. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4593. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4594. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4595. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPONRY, new_skill_cap);
  4596. if (new_level > player->GetTSLevel())
  4597. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4598. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4599. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4600. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4601. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4602. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4603. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4604. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4605. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4606. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4607. Guild* guild = GetPlayer()->GetGuild();
  4608. if (guild) {
  4609. int8 event_type = 0;
  4610. if (new_level < 10)
  4611. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4612. else if (new_level == 10)
  4613. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4614. else if (new_level >= 11 && new_level < 20)
  4615. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4616. else if (new_level == 20)
  4617. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4618. else if (new_level >= 21 && new_level < 30)
  4619. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4620. else if (new_level == 30)
  4621. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4622. else if (new_level >= 31 && new_level < 40)
  4623. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4624. else if (new_level == 40)
  4625. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4626. else if (new_level >= 41 && new_level < 50)
  4627. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4628. else if (new_level == 50)
  4629. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4630. else if (new_level >= 51 && new_level < 60)
  4631. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4632. else if (new_level == 60)
  4633. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4634. else if (new_level >= 61 && new_level < 70)
  4635. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4636. else if (new_level == 70)
  4637. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4638. else if (new_level >= 71 && new_level < 80)
  4639. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4640. else if (new_level == 80)
  4641. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4642. 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());
  4643. 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());
  4644. guild->UpdateGuildMemberInfo(GetPlayer());
  4645. guild->SendGuildMember(GetPlayer());
  4646. guild->SendGuildMemberList();
  4647. }
  4648. // Need to send the trait list every time the players level changes
  4649. // Also need to force the char sheet update or else there can be a large delay from when you level
  4650. // to when you are actually able to select traits.
  4651. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4652. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4653. if (version > 546)
  4654. master_aa_list.DisplayAA(this, 0, 0);
  4655. if (GetPlayer()->SpawnedBots.size() > 0) {
  4656. map<int32, int32>::iterator itr;
  4657. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4658. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4659. if (bot && bot->IsBot())
  4660. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4661. }
  4662. }
  4663. }
  4664. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4665. if (new_level < 1) {
  4666. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4667. return;
  4668. }
  4669. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4670. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4671. return;
  4672. }
  4673. if (new_level > old_level)
  4674. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4675. if (player->GetTSLevel() != new_level) {
  4676. player->SetTSLevel(new_level);
  4677. if (player->GetGroupMemberInfo()) {
  4678. player->UpdateGroupMemberInfo();
  4679. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4680. }
  4681. }
  4682. // Only tradeskill skills should increace, and then only those related to your class
  4683. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4684. if (level_update) {
  4685. level_update->setDataByName("old_level", old_level);
  4686. level_update->setDataByName("new_level", new_level);
  4687. level_update->setDataByName("type", 1);
  4688. QueuePacket(level_update->serialize());
  4689. safe_delete(level_update);
  4690. }
  4691. // provide new spells upon levelling
  4692. SendNewTradeskillSpells();
  4693. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4694. if (command_packet) {
  4695. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4696. command_packet->setDataByName("anim_type", 1753);
  4697. QueuePacket(command_packet->serialize());
  4698. safe_delete(command_packet);
  4699. }
  4700. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4701. GetPlayer()->SetTSLevel(new_level);
  4702. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4703. GetPlayer()->SetCharSheetChanged(true);
  4704. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4705. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4706. PlayerSkillList* player_skills = player->GetSkills();
  4707. int16 specialize_skill_cap = new_level * 5;
  4708. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4709. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4710. int8 ts_class = player->GetTradeskillClass();
  4711. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4712. int32 skill_id_1, skill_id_2, skill_id_3;
  4713. switch (base_ts_class) {
  4714. case ARTISAN:
  4715. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4716. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4717. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4718. break;
  4719. case OUTFITTER:
  4720. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4721. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4722. skill_id_1 = SKILL_ID_TAILORING;
  4723. skill_id_2 = SKILL_ID_METALSHAPING;
  4724. skill_id_3 = SKILL_ID_METALWORKING;
  4725. if (ts_class == TAILOR) {
  4726. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4727. skill_id_1 = 0;
  4728. }
  4729. else if (ts_class == ARMORER) {
  4730. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4731. skill_id_2 = 0;
  4732. }
  4733. else if (ts_class == WEAPONSMITH) {
  4734. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4735. skill_id_3 = 0;
  4736. }
  4737. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4738. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4739. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4740. break;
  4741. case SCHOLAR:
  4742. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4743. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4744. skill_id_1 = SKILL_ID_SCRIBING;
  4745. skill_id_2 = SKILL_ID_CHEMISTRY;
  4746. skill_id_3 = SKILL_ID_ARTIFICING;
  4747. if (ts_class == SAGE) {
  4748. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4749. skill_id_1 = 0;
  4750. }
  4751. else if (ts_class == ALCHEMIST) {
  4752. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4753. skill_id_2 = 0;
  4754. }
  4755. else if (ts_class == JEWELER) {
  4756. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4757. skill_id_3 = 0;
  4758. }
  4759. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4760. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4761. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4762. break;
  4763. case CRAFTSMAN:
  4764. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4765. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4766. skill_id_1 = SKILL_ID_ARTISTRY;
  4767. skill_id_2 = SKILL_ID_FLETCHING;
  4768. skill_id_3 = SKILL_ID_SCULPTING;
  4769. if (ts_class == PROVISIONER) {
  4770. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4771. skill_id_1 = 0;
  4772. }
  4773. else if (ts_class == WOODWORKER) {
  4774. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4775. skill_id_2 = 0;
  4776. }
  4777. else if (ts_class == CARPENTER) {
  4778. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4779. skill_id_3 = 0;
  4780. }
  4781. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4782. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4783. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4784. break;
  4785. default:
  4786. break;
  4787. }
  4788. if (new_level > player->GetAdventureClass())
  4789. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4790. Guild* guild = GetPlayer()->GetGuild();
  4791. if (guild) {
  4792. int8 event_type = 0;
  4793. if (new_level < 10)
  4794. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4795. else if (new_level == 10)
  4796. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4797. else if (new_level >= 11 && new_level < 20)
  4798. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4799. else if (new_level == 20)
  4800. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4801. else if (new_level >= 21 && new_level < 30)
  4802. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4803. else if (new_level == 30)
  4804. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4805. else if (new_level >= 31 && new_level < 40)
  4806. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4807. else if (new_level == 40)
  4808. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4809. else if (new_level >= 41 && new_level < 50)
  4810. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4811. else if (new_level == 50)
  4812. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4813. else if (new_level >= 51 && new_level < 60)
  4814. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4815. else if (new_level == 60)
  4816. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4817. else if (new_level >= 61 && new_level < 70)
  4818. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4819. else if (new_level == 70)
  4820. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4821. else if (new_level >= 71 && new_level < 80)
  4822. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4823. else if (new_level == 80)
  4824. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4825. 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());
  4826. 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());
  4827. guild->UpdateGuildMemberInfo(GetPlayer());
  4828. guild->SendGuildMember(GetPlayer());
  4829. guild->SendGuildMemberList();
  4830. }
  4831. // Need to send the trait list every time the players level changes
  4832. // Also need to force the char sheet update or else there can be a large delay from when you level
  4833. // to when you are actually able to select traits.
  4834. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4835. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4836. }
  4837. void Client::CloseLoot(int32 spawn_id) {
  4838. if (GetVersion() > 546) {
  4839. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4840. if (packet) {
  4841. packet->setDataByName("window_id", 4);
  4842. EQ2Packet* outapp = packet->serialize();
  4843. if (outapp) {
  4844. //DumpPacket(outapp);
  4845. QueuePacket(outapp);
  4846. }
  4847. safe_delete(packet);
  4848. }
  4849. }
  4850. if(spawn_id > 0){
  4851. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4852. if (packet) {
  4853. packet->setDataByName("spawn_id", spawn_id);
  4854. EQ2Packet* outapp = packet->serialize();
  4855. if (outapp)
  4856. QueuePacket(outapp);
  4857. safe_delete(packet);
  4858. }
  4859. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  4860. if(spawn) {
  4861. spawn->CloseLoot(GetPlayer());
  4862. }
  4863. }
  4864. }
  4865. string Client::GetCoinMessage(int32 total_coins) {
  4866. if (total_coins == 0) {
  4867. return " 0 Copper";
  4868. }
  4869. char tmp[64] = { 0 };
  4870. string message = "";
  4871. int32 val = 0;
  4872. if (total_coins >= 1000000) {
  4873. val = total_coins / 1000000;
  4874. total_coins -= 1000000 * val;
  4875. sprintf(tmp, " %u Platinum", val);
  4876. message.append(tmp);
  4877. memset(tmp, 0, 64);
  4878. }
  4879. if (total_coins >= 10000) {
  4880. val = total_coins / 10000;
  4881. total_coins -= 10000 * val;
  4882. sprintf(tmp, " %u Gold", val);
  4883. message.append(tmp);
  4884. memset(tmp, 0, 64);
  4885. }
  4886. if (total_coins >= 100) {
  4887. val = total_coins / 100;
  4888. total_coins -= 100 * val;
  4889. sprintf(tmp, " %u Silver", val);
  4890. message.append(tmp);
  4891. memset(tmp, 0, 64);
  4892. }
  4893. if (total_coins > 0) {
  4894. sprintf(tmp, " %u Copper", (int32)total_coins);
  4895. message.append(tmp);
  4896. }
  4897. return message;
  4898. }
  4899. void Client::SendLootResponsePacket(int32 total_coins, vector<Item*>* items, Spawn* entity, bool ignore_loot_tier) {
  4900. if (!entity) {
  4901. CloseLoot(0);
  4902. return;
  4903. }
  4904. if (total_coins > 0) {
  4905. player->AddCoins(total_coins);
  4906. //PlaySound("coin_cha_ching");
  4907. string message = "";
  4908. if (entity->GetHP() == 0) {
  4909. message = "You loot ";
  4910. entity->SetLootCoins(0, false);
  4911. }
  4912. else
  4913. message = "You receive ";
  4914. message.append(GetCoinMessage(total_coins));
  4915. if (entity->GetHP() == 0)
  4916. message.append(" from the corpse of ").append(entity->GetName());
  4917. int8 type = CHANNEL_LOOT;
  4918. SimpleMessage(type, message.c_str());
  4919. }
  4920. if (!items || items->size() == 0)
  4921. CloseLoot(entity->GetID());
  4922. entity->StartLootTimer(GetPlayer());
  4923. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4924. if (packet) {
  4925. entity->AddSpawnLootWindowCompleted(GetPlayer()->GetID(), false);
  4926. vector<Item*>::iterator itr;
  4927. int32 packet_size = 0;
  4928. EQ2Packet* outapp = 0;
  4929. uchar* data = 0;
  4930. vector<Item*> send_items;
  4931. if (items && items->size() > 0) {
  4932. for (int i = 0; i < items->size(); i++) {
  4933. Item* item = (*items)[i];
  4934. if (entity->GetLootMethod() > GroupLootMethod::METHOD_FFA && !ignore_loot_tier) {
  4935. bool skipItem = entity->IsItemInLootTier(item);
  4936. if (!skipItem) {
  4937. send_items.push_back(item);
  4938. }
  4939. }
  4940. else {
  4941. send_items.push_back(item);
  4942. }
  4943. }
  4944. }
  4945. if (GetVersion() >= 284) {
  4946. if (GetVersion() > 561) {
  4947. if (send_items.size() > 0) {
  4948. packet->setDataByName("loot_count", send_items.size());
  4949. packet->setDataByName("display", 1);
  4950. }
  4951. packet->setDataByName("loot_type", entity->GetLootMethod());
  4952. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000);
  4953. packet->setDataByName("loot_id", entity->GetID());
  4954. EQ2Packet* tmpPacket = packet->serialize();
  4955. packet_size += tmpPacket->size;
  4956. if (send_items.size() > 0) {
  4957. data = new uchar[send_items.size() * 1000 + packet_size];
  4958. memset(data, 0, send_items.size() * 1000 + packet_size);
  4959. }
  4960. else {
  4961. data = new uchar[packet_size];
  4962. memset(data, 0, packet_size);
  4963. }
  4964. uchar* ptr = data;
  4965. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4966. ptr += tmpPacket->size;
  4967. safe_delete(tmpPacket);
  4968. Item* item = 0;
  4969. if (send_items.size() > 0) {
  4970. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  4971. item = *itr;
  4972. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4973. ptr += sizeof(int32);
  4974. packet_size += sizeof(int32);
  4975. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4976. int8 offset = 0;
  4977. if (GetVersion() >= 1188) {
  4978. offset = 13;
  4979. }
  4980. else if (GetVersion() >= 860) {
  4981. offset = 11;
  4982. }
  4983. else if (GetVersion() <= 561) {
  4984. offset = 19;
  4985. }
  4986. else {
  4987. offset = 10;
  4988. }
  4989. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4990. ptr += tmpPacket->size - offset;
  4991. packet_size += tmpPacket->size - offset;
  4992. safe_delete(tmpPacket);
  4993. }
  4994. }
  4995. packet_size -= sizeof(int32);
  4996. memcpy(data, &packet_size, sizeof(int32));
  4997. packet_size += sizeof(int32);
  4998. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4999. }
  5000. else {
  5001. if (send_items.size() > 0) {
  5002. packet->setArrayLengthByName("loot_count", send_items.size());
  5003. Item* item = 0;
  5004. if (send_items.size() > 0) {
  5005. int i = 0;
  5006. for (itr = send_items.begin(); itr != send_items.end(); itr++) {
  5007. item = *itr;
  5008. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  5009. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  5010. i++;
  5011. }
  5012. }
  5013. packet->setDataByName("display", 1);
  5014. }
  5015. packet->setDataByName("loot_type", entity->GetLootMethod()); // normal
  5016. packet->setDataByName("lotto_timeout", entity->GetLootTimeRemaining() / 1000); // 60 seconds
  5017. packet->setDataByName("spawn_id", entity->GetID());
  5018. outapp = packet->serialize();
  5019. }
  5020. }
  5021. else {
  5022. if (send_items.size() > 0) {
  5023. packet->setArrayLengthByName("loot_count", send_items.size());
  5024. for (int i = 0; i < send_items.size(); i++) {
  5025. Item* item = (send_items)[i];
  5026. packet->setArrayDataByName("name", item->name.c_str(), i);
  5027. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5028. packet->setArrayDataByName("count", item->details.count, i);
  5029. packet->setArrayDataByName("icon", item->details.icon, i);
  5030. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  5031. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  5032. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  5033. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  5034. else
  5035. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  5036. }
  5037. }
  5038. packet->setDataByName("object_id", entity->GetID());
  5039. packet->setDataByName("unknown3", 1);
  5040. packet->setDataByName("unknown4", 1);
  5041. packet->setDataByName("unknown5", 60);
  5042. outapp = packet->serialize();
  5043. }
  5044. if (outapp) {
  5045. QueuePacket(outapp);
  5046. }
  5047. safe_delete_array(data);
  5048. safe_delete(packet);
  5049. }
  5050. }
  5051. bool Client::LootSpawnByMethod(Spawn* entity) {
  5052. bool sentLoot = false;
  5053. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  5054. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5055. if (gmi && gmi->group_id)
  5056. {
  5057. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5058. if (group)
  5059. {
  5060. int8 auto_split_coin = group->GetGroupOptions()->auto_split;
  5061. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5062. deque<GroupMemberInfo*>* members = group->GetMembers();
  5063. int32 split_coin_per_player = 0;
  5064. int32 coins_remain_after_split = entity->GetLootCoins();
  5065. int32 total_coins = entity->GetLootCoins();
  5066. if (auto_split_coin) {
  5067. int8 members_in_zone = 0;
  5068. for (int8 i = 0; i < members->size(); i++) {
  5069. Entity* member = members->at(i)->member;
  5070. if (!member || !member->IsPlayer())
  5071. continue;
  5072. if (member->GetZone() != GetPlayer()->GetZone())
  5073. continue;
  5074. members_in_zone++;
  5075. }
  5076. if (members_in_zone < 1) // this should not happen, but divide by zero checked
  5077. members_in_zone = 0;
  5078. split_coin_per_player = entity->GetLootCoins() / members_in_zone;
  5079. coins_remain_after_split = entity->GetLootCoins() - (split_coin_per_player * members_in_zone);
  5080. entity->SetLootCoins(0, false);
  5081. }
  5082. 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);
  5083. bool startWithLooter = true;
  5084. for (int8 i = 0; i < members->size(); i++) {
  5085. Entity* member = members->at(i)->member;
  5086. if (!member || !member->IsPlayer())
  5087. continue;
  5088. if (member->GetZone() != GetPlayer()->GetZone())
  5089. continue;
  5090. // this will make sure we properly send the loot window to the initial requester if there is no item rarity matches
  5091. if (startWithLooter && member != GetPlayer())
  5092. continue;
  5093. else if (!startWithLooter && member == GetPlayer())
  5094. continue;
  5095. else if (startWithLooter) {
  5096. i = 0;
  5097. startWithLooter = false;
  5098. }
  5099. if (auto_split_coin && (split_coin_per_player + coins_remain_after_split) > 0) {
  5100. player->AddCoins(split_coin_per_player + coins_remain_after_split);
  5101. if (((Player*)member)->GetClient()) {
  5102. ((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());
  5103. }
  5104. if (coins_remain_after_split > 0) // overflow of coin division went to the first player
  5105. coins_remain_after_split = 0;
  5106. }
  5107. switch (entity->GetLootMethod()) {
  5108. case GroupLootMethod::METHOD_LOTTO:
  5109. case GroupLootMethod::METHOD_NEED_BEFORE_GREED: {
  5110. if (((Player*)member)->GetClient()) {
  5111. switch (member->GetInfoStruct()->get_group_auto_loot_method()) {
  5112. case 1: { // lotto, need
  5113. if (entity->GetLootMethod() == GroupLootMethod::METHOD_LOTTO) {
  5114. entity->AddLottoItemRequest(0xFFFFFFFF, GetPlayer()->GetID());
  5115. }
  5116. else { // *need* before greed
  5117. entity->AddNeedGreedItemRequest(0xFFFFFFFF, GetPlayer()->GetID(), true);
  5118. }
  5119. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5120. // if it already exists we have to override the setting
  5121. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5122. break;
  5123. }
  5124. case 2: { // decline
  5125. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5126. // if it already exists we have to override the setting
  5127. entity->SetSpawnLootWindowCompleted(GetPlayer()->GetID());
  5128. break;
  5129. }
  5130. default: { // presume 0 or higher than 2
  5131. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity, true);
  5132. break;
  5133. }
  5134. }
  5135. sentLoot = true;
  5136. }
  5137. break;
  5138. }
  5139. case GroupLootMethod::METHOD_ROUND_ROBIN: {
  5140. entity->AddSpawnLootWindowCompleted(member->GetID(), true);
  5141. sentLoot = true;
  5142. break;
  5143. }
  5144. case GroupLootMethod::METHOD_LEADER: {
  5145. if (member->GetGroupMemberInfo()->leader)
  5146. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5147. break;
  5148. }
  5149. case GroupLootMethod::METHOD_FFA: {
  5150. if(member == GetPlayer()) {
  5151. ((Player*)member)->GetClient()->SendLootResponsePacket((!auto_split_coin && member == GetPlayer()) ? entity->GetLootCoins() : 0, entity->GetLootItems(), entity);
  5152. }
  5153. break;
  5154. }
  5155. }
  5156. }
  5157. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5158. }
  5159. }
  5160. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  5161. return sentLoot;
  5162. }
  5163. void Client::LootSpawnRequest(Spawn* entity, bool attemptDisarm) {
  5164. bool lootAllowed = false;
  5165. bool sentLoot = false;
  5166. std::vector<int32> item_list;
  5167. if (entity->IsNPC()) {
  5168. entity->LockLoot();
  5169. lootAllowed = ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer());
  5170. entity->UnlockLoot();
  5171. if (lootAllowed) {
  5172. OpenChest(entity, attemptDisarm);
  5173. }
  5174. else {
  5175. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  5176. return;
  5177. }
  5178. entity->LockLoot();
  5179. if (((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  5180. lootAllowed = true;
  5181. if ((sentLoot = LootSpawnByMethod(entity))) {
  5182. entity->GetLootItemsList(&item_list);
  5183. }
  5184. else {
  5185. SendLootResponsePacket(entity->GetLootCoins(), entity->GetLootItems(), entity);
  5186. }
  5187. }
  5188. entity->UnlockLoot();
  5189. if (lootAllowed) {
  5190. entity->DistributeGroupLoot_RoundRobin(&item_list, true);
  5191. }
  5192. }
  5193. }
  5194. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  5195. {
  5196. if (!entity)
  5197. return;
  5198. int8 chest_difficulty = 0;
  5199. int32 state = 0;
  5200. // Check for the chest and set the action state
  5201. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  5202. string modelName;
  5203. if (entity->GetModelType() == 4034) {
  5204. // small chest, open with copper coins
  5205. // does not include traps, however can be disarmed
  5206. chest_difficulty = 1;
  5207. state = 11899;
  5208. modelName.append("Small Chest");
  5209. }
  5210. else if (entity->GetModelType() == 5864) {
  5211. // treasure chest, open with silver coins
  5212. chest_difficulty = 2;
  5213. state = 11901;
  5214. modelName.append("Treasure Chest");
  5215. }
  5216. else if (entity->GetModelType() == 5865) {
  5217. // ornate chest, open with gold coins
  5218. chest_difficulty = 3;
  5219. state = 11900;
  5220. modelName.append("Ornate Chest");
  5221. }
  5222. else if (entity->GetModelType() == 4015) {
  5223. // exquisite chest, open with gold coins and jewels as well as a glow effect
  5224. chest_difficulty = 5;
  5225. state = 11898;
  5226. modelName.append("Exquisite Chest");
  5227. }
  5228. bool firstChestOpen = false;
  5229. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  5230. {
  5231. ChestTrap::ChestTrapInfo nextTrap;
  5232. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  5233. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  5234. firstChestOpen = true;
  5235. entity->SetTrapTriggered(true, state);
  5236. if (ret)
  5237. {
  5238. if (disarmSkill && attemptDisarm)
  5239. {
  5240. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  5241. {
  5242. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5243. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5244. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5245. }
  5246. else
  5247. {
  5248. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  5249. }
  5250. // despite fail/succeed we should always try to increase skill if disarm is available
  5251. GetPlayer()->GetSkillByName("Disarm Trap", true);
  5252. }
  5253. else // no disarm skill, always fail
  5254. {
  5255. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  5256. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  5257. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  5258. }
  5259. }
  5260. }
  5261. else if (!entity->HasTrapTriggered())
  5262. {
  5263. firstChestOpen = true;
  5264. entity->SetTrapTriggered(true, state);
  5265. }
  5266. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  5267. // for those in range the SendStateCommand will cause it to animate open.
  5268. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  5269. if (firstChestOpen)
  5270. GetCurrentZone()->SendStateCommand(entity, state);
  5271. }
  5272. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  5273. {
  5274. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  5275. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  5276. if (source == NULL)
  5277. source = (Entity*)GetPlayer();
  5278. if (spell)
  5279. {
  5280. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  5281. if (gmi && gmi->group_id)
  5282. {
  5283. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  5284. if (group)
  5285. {
  5286. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  5287. deque<GroupMemberInfo*>* members = group->GetMembers();
  5288. for (int8 i = 0; i < members->size(); i++) {
  5289. Entity* member = members->at(i)->member;
  5290. if(!member)
  5291. continue;
  5292. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  5293. continue;
  5294. // if we have a radius provided then check if the group member is outside the radius or not
  5295. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  5296. continue;
  5297. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5298. }
  5299. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  5300. }
  5301. }
  5302. else
  5303. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  5304. }
  5305. }
  5306. Spawn* Client::GetBanker() {
  5307. return banker;
  5308. }
  5309. void Client::SetBanker(Spawn* in_banker) {
  5310. banker = in_banker;
  5311. }
  5312. void Client::Bank(Spawn* banker, bool cancel) {
  5313. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  5314. if (!cancel)
  5315. SetBanker(banker);
  5316. else
  5317. SetBanker(0);
  5318. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  5319. if (packet) {
  5320. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  5321. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  5322. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  5323. int32 coins1, coins2;
  5324. coins1 = ((int32*)&coins)[0];
  5325. coins2 = ((int32*)&coins)[1];
  5326. packet->setDataByName("bank_coins", coins1);
  5327. packet->setDataByName("bank_coins2", coins2);
  5328. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  5329. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  5330. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  5331. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  5332. if (!cancel)
  5333. packet->setDataByName("display", 1);
  5334. QueuePacket(packet->serialize());
  5335. safe_delete(packet);
  5336. }
  5337. }
  5338. }
  5339. bool Client::BankHasCoin(int64 amount){
  5340. int32 tmp = 0;
  5341. if(amount <= 0)
  5342. return 0;
  5343. //plat
  5344. if (amount >= 1000000) {
  5345. tmp = amount / 1000000;
  5346. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5347. if(bank_coins_plat >= tmp)
  5348. return 1;
  5349. }
  5350. //gold
  5351. if (amount >= 10000) {
  5352. tmp = amount / 10000;
  5353. int32 bank_coins_gold = GetPlayer()->GetBankCoinsGold();
  5354. if(bank_coins_gold >= tmp)
  5355. return 1;
  5356. }
  5357. //silver
  5358. if (amount >= 100) {
  5359. tmp = amount / 100;
  5360. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5361. if(bank_coins_silver >= tmp)
  5362. return 1;
  5363. }
  5364. //copper
  5365. if (amount > 0) {
  5366. int32 bank_coins_copper = GetPlayer()->GetBankCoinsCopper();
  5367. if(bank_coins_copper >= amount)
  5368. return 1;
  5369. }
  5370. return 0;
  5371. }
  5372. bool Client::BankWithdrawalNoBanker(int64 amount) {
  5373. bool cheater = false;
  5374. if (amount > 0) {
  5375. string withdrawal = "";
  5376. char withdrawal_data[512] = { 0 };
  5377. int32 tmp = 0;
  5378. if (amount >= 1000000) {
  5379. tmp = amount / 1000000;
  5380. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5381. if (tmp > bank_coins_plat)
  5382. cheater = true;
  5383. else {
  5384. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5385. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5386. amount -= (int64)tmp * 1000000;
  5387. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5388. withdrawal.append(withdrawal_data);
  5389. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5390. }
  5391. }
  5392. if (!cheater && amount >= 10000) {
  5393. tmp = amount / 10000;
  5394. if (tmp > GetPlayer()->GetBankCoinsGold())
  5395. cheater = true;
  5396. else {
  5397. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5398. bank_coins_gold -= tmp;
  5399. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5400. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5401. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5402. }
  5403. else
  5404. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5405. amount -= tmp * 10000;
  5406. sprintf(withdrawal_data, "%u Gold ", tmp);
  5407. withdrawal.append(withdrawal_data);
  5408. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5409. }
  5410. }
  5411. if (!cheater && amount >= 100) {
  5412. tmp = amount / 100;
  5413. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5414. if (tmp > bank_coins_silver)
  5415. cheater = true;
  5416. else {
  5417. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5418. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5419. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5420. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5421. }
  5422. else
  5423. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5424. amount -= tmp * 100;
  5425. sprintf(withdrawal_data, "%u Silver ", tmp);
  5426. withdrawal.append(withdrawal_data);
  5427. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5428. }
  5429. }
  5430. if (!cheater) {
  5431. if (amount > 0) {
  5432. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5433. withdrawal.append(withdrawal_data);
  5434. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5435. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5436. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5437. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5438. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5439. }
  5440. else
  5441. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5442. }
  5443. if (withdrawal.length() > 0) {
  5444. withdrawal.append("withdrawn ");
  5445. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5446. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5447. withdrawal.append(withdrawal_data);
  5448. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5449. return 1;
  5450. }
  5451. }
  5452. else
  5453. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5454. return 0;
  5455. }
  5456. return 0;
  5457. }
  5458. void Client::BankWithdrawal(int64 amount) {
  5459. bool cheater = false;
  5460. if (GetBanker() && amount > 0) {
  5461. string withdrawal = "";
  5462. char withdrawal_data[512] = { 0 };
  5463. int32 tmp = 0;
  5464. if (amount >= 1000000) {
  5465. tmp = amount / 1000000;
  5466. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  5467. if (tmp > bank_coins_plat)
  5468. cheater = true;
  5469. else {
  5470. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  5471. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  5472. amount -= (int64)tmp * 1000000;
  5473. sprintf(withdrawal_data, "%u Platinum ", tmp);
  5474. withdrawal.append(withdrawal_data);
  5475. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5476. }
  5477. }
  5478. if (!cheater && amount >= 10000) {
  5479. tmp = amount / 10000;
  5480. if (tmp > GetPlayer()->GetBankCoinsGold())
  5481. cheater = true;
  5482. else {
  5483. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  5484. bank_coins_gold -= tmp;
  5485. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  5486. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  5487. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  5488. }
  5489. else
  5490. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  5491. amount -= tmp * 10000;
  5492. sprintf(withdrawal_data, "%u Gold ", tmp);
  5493. withdrawal.append(withdrawal_data);
  5494. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5495. }
  5496. }
  5497. if (!cheater && amount >= 100) {
  5498. tmp = amount / 100;
  5499. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  5500. if (tmp > bank_coins_silver)
  5501. cheater = true;
  5502. else {
  5503. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  5504. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  5505. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  5506. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  5507. }
  5508. else
  5509. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  5510. amount -= tmp * 100;
  5511. sprintf(withdrawal_data, "%u Silver ", tmp);
  5512. withdrawal.append(withdrawal_data);
  5513. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  5514. }
  5515. }
  5516. if (!cheater) {
  5517. if (amount > 0) {
  5518. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  5519. withdrawal.append(withdrawal_data);
  5520. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  5521. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  5522. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  5523. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  5524. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  5525. }
  5526. else
  5527. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  5528. }
  5529. if (withdrawal.length() > 0) {
  5530. withdrawal.append("withdrawn ");
  5531. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5532. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5533. withdrawal.append(withdrawal_data);
  5534. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  5535. }
  5536. }
  5537. else
  5538. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5539. player->SetCharSheetChanged(true);
  5540. Bank(banker);
  5541. }
  5542. }
  5543. void Client::BankDeposit(int64 amount) {
  5544. bool cheater = false;
  5545. if (GetBanker() && amount > 0) {
  5546. int32 tmp = 0;
  5547. char deposit_data[512] = { 0 };
  5548. string deposit = "";
  5549. if (amount >= 1000000) {
  5550. tmp = amount / 1000000;
  5551. if (tmp > GetPlayer()->GetCoinsPlat())
  5552. cheater = true;
  5553. else {
  5554. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  5555. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  5556. amount -= (int64)tmp * 1000000;
  5557. sprintf(deposit_data, "%u Platinum ", tmp);
  5558. deposit.append(deposit_data);
  5559. memset(deposit_data, 0, sizeof(deposit_data));
  5560. }
  5561. }
  5562. if (!cheater && amount >= 10000) {
  5563. tmp = amount / 10000;
  5564. if (tmp > GetPlayer()->GetCoinsGold())
  5565. cheater = true;
  5566. else {
  5567. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  5568. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  5569. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  5570. }
  5571. else
  5572. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  5573. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  5574. amount -= tmp * 10000;
  5575. sprintf(deposit_data, "%u Gold ", tmp);
  5576. deposit.append(deposit_data);
  5577. memset(deposit_data, 0, sizeof(deposit_data));
  5578. }
  5579. }
  5580. if (!cheater && amount >= 100) {
  5581. tmp = amount / 100;
  5582. if (tmp > GetPlayer()->GetCoinsSilver())
  5583. cheater = true;
  5584. else {
  5585. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  5586. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  5587. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  5588. }
  5589. else
  5590. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  5591. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  5592. amount -= tmp * 100;
  5593. sprintf(deposit_data, "%u Silver ", tmp);
  5594. deposit.append(deposit_data);
  5595. memset(deposit_data, 0, sizeof(deposit_data));
  5596. }
  5597. }
  5598. if (!cheater) {
  5599. if (amount > 0) {
  5600. sprintf(deposit_data, "%u Copper ", (int32)amount);
  5601. deposit.append(deposit_data);
  5602. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  5603. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  5604. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  5605. }
  5606. else
  5607. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  5608. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  5609. }
  5610. if (deposit.length() > 0) {
  5611. deposit.append("deposited ");
  5612. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  5613. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  5614. deposit.append(deposit_data);
  5615. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  5616. }
  5617. }
  5618. else
  5619. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  5620. player->SetCharSheetChanged(true);
  5621. Bank(banker);
  5622. }
  5623. }
  5624. void Client::AddPendingQuestAcceptReward(Quest* quest)
  5625. {
  5626. std::unique_lock lock(MPendingQuestAccept);
  5627. pending_quest_accept.push_back(quest->GetQuestID());
  5628. }
  5629. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  5630. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  5631. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  5632. quest_updates = update;
  5633. if(quest_updates) {
  5634. SaveQuestRewardData(true);
  5635. }
  5636. }
  5637. 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) {
  5638. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  5639. return;
  5640. QuestRewardData* data = new QuestRewardData;
  5641. data->quest_id = quest_id;
  5642. data->is_temporary = is_temporary;
  5643. data->is_collection = is_collection;
  5644. data->has_displayed = has_displayed;
  5645. data->tmp_coin = tmp_coin;
  5646. data->tmp_status = tmp_status;
  5647. data->description = std::string(description);
  5648. data->db_saved = db_saved;
  5649. data->db_index = index;
  5650. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5651. quest_pending_reward.push_back(data);
  5652. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5653. }
  5654. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  5655. bool success = false;
  5656. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5657. if (quest_pending_reward.size() > 0) {
  5658. vector<QuestRewardData*>::iterator itr;
  5659. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  5660. int32 questID = (*itr)->quest_id;
  5661. bool temporary = (*itr)->is_temporary;
  5662. bool collection = (*itr)->is_collection;
  5663. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  5664. success = true;
  5665. break;
  5666. }
  5667. }
  5668. }
  5669. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5670. return success;
  5671. }
  5672. void Client::RemoveQueuedQuestReward() {
  5673. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5674. if(quest_pending_reward.size() > 0) {
  5675. QuestRewardData* data = quest_pending_reward.at(0);
  5676. if(data->db_saved) {
  5677. Query query;
  5678. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  5679. if(data->is_temporary && data->quest_id) {
  5680. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  5681. }
  5682. }
  5683. quest_pending_reward.erase(quest_pending_reward.begin());
  5684. }
  5685. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5686. SaveQuestRewardData(true);
  5687. }
  5688. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  5689. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5690. quest_pending_updates[quest_id][step_id] = progress;
  5691. quest_updates = true;
  5692. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5693. }
  5694. void Client::ProcessQuestUpdates() {
  5695. if(!IsReadyForUpdates())
  5696. return;
  5697. if (quest_pending_updates.size() > 0) {
  5698. map<int32, map<int32, int32> > tmp_quest_updates;
  5699. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5700. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  5701. quest_pending_updates.clear();
  5702. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5703. map<int32, map<int32, int32> >::iterator quest_itr;
  5704. map<int32, int32>::iterator step_itr;
  5705. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5706. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5707. if (step_itr->second == 0xFFFFFFFF) {
  5708. SetStepComplete(quest_itr->first, step_itr->first);
  5709. player->SendQuestRequiredSpawns(quest_itr->first);
  5710. }
  5711. else
  5712. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5713. }
  5714. }
  5715. }
  5716. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5717. if (quest_pending_reward.size() > 0) {
  5718. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5719. // only able to display one reward at a time
  5720. if(GetPlayer()->IsActiveReward())
  5721. return;
  5722. Query query;
  5723. vector<QuestRewardData*>::iterator itr;
  5724. vector<QuestRewardData*> tmp_quest_rewards;
  5725. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5726. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5727. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5728. bool delete_first = false;
  5729. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end();) {
  5730. int32 questID = (*itr)->quest_id;
  5731. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5732. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5733. GetPlayer()->SetActiveReward(true);
  5734. (*itr)->has_displayed = true;
  5735. UpdateCharacterRewardData((*itr));
  5736. break;
  5737. }
  5738. else if(questID > 0 && GetPlayer()->UpdateQuestReward(questID, (*itr))) {
  5739. (*itr)->has_displayed = true;
  5740. UpdateCharacterRewardData((*itr));
  5741. // only able to display one reward at a time
  5742. break;
  5743. } else {
  5744. delete_first = true;
  5745. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, deleting quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5746. break;
  5747. }
  5748. }
  5749. if(delete_first) {
  5750. RemoveQueuedQuestReward();
  5751. }
  5752. } else {
  5753. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5754. }
  5755. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5756. if (quest_pending_reward.size() > 0) {
  5757. quest_updates = true;
  5758. }
  5759. else {
  5760. quest_updates = false;
  5761. }
  5762. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5763. }
  5764. void Client::CheckQuestQueue() {
  5765. MQuestQueue.writelock();
  5766. last_update_time = 0;
  5767. vector<QueuedQuest*>::iterator itr;
  5768. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5769. if(!GetPlayer()->SendQuestStepUpdate((*itr)->quest_id, (*itr)->step, (*itr)->display_quest_helper)) {
  5770. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", (*itr)->quest_id, GetPlayer()->GetName());
  5771. }
  5772. safe_delete((*itr));
  5773. }
  5774. quest_queue.clear();
  5775. MQuestQueue.releasewritelock();
  5776. }
  5777. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5778. Quest* quest = player->SetStepComplete(quest_id, step);
  5779. if (quest) {
  5780. SendQuestUpdate(quest);
  5781. GetCurrentZone()->SendQuestUpdates(this);
  5782. }
  5783. }
  5784. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5785. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5786. if (quest) {
  5787. SendQuestUpdate(quest);
  5788. GetCurrentZone()->SendQuestUpdates(this);
  5789. }
  5790. }
  5791. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5792. bool hadUpdates = false;
  5793. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5794. if (quest_updates) {
  5795. for (int32 i = 0; i < quest_updates->size(); i++)
  5796. {
  5797. SendQuestUpdate(quest_updates->at(i));
  5798. hadUpdates = true;
  5799. }
  5800. }
  5801. safe_delete(quest_updates);
  5802. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5803. if (quest_failures) {
  5804. for (int32 i = 0; i < quest_failures->size(); i++)
  5805. {
  5806. SendQuestFailure(quest_failures->at(i));
  5807. hadUpdates = true;
  5808. }
  5809. }
  5810. safe_delete(quest_failures);
  5811. if (hadUpdates)
  5812. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5813. }
  5814. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5815. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5816. if (quest_updates) {
  5817. for (int32 i = 0; i < quest_updates->size(); i++)
  5818. SendQuestUpdate(quest_updates->at(i));
  5819. GetCurrentZone()->SendQuestUpdates(this);
  5820. }
  5821. safe_delete(quest_updates);
  5822. }
  5823. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5824. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5825. if (quest_updates) {
  5826. for (int32 i = 0; i < quest_updates->size(); i++)
  5827. SendQuestUpdate(quest_updates->at(i));
  5828. }
  5829. safe_delete(quest_updates);
  5830. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5831. if (quest_failures) {
  5832. for (int32 i = 0; i < quest_failures->size(); i++)
  5833. SendQuestFailure(quest_failures->at(i));
  5834. }
  5835. safe_delete(quest_failures);
  5836. }
  5837. void Client::CheckPlayerQuestsLocationUpdate() {
  5838. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5839. if (quest_updates) {
  5840. for (int32 i = 0; i < quest_updates->size(); i++)
  5841. SendQuestUpdate(quest_updates->at(i));
  5842. }
  5843. safe_delete(quest_updates);
  5844. }
  5845. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5846. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5847. if (quest_updates) {
  5848. for (int32 i = 0; i < quest_updates->size(); i++)
  5849. SendQuestUpdate(quest_updates->at(i));
  5850. }
  5851. safe_delete(quest_updates);
  5852. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5853. if (quest_failures) {
  5854. for (int32 i = 0; i < quest_failures->size(); i++)
  5855. SendQuestFailure(quest_failures->at(i));
  5856. }
  5857. safe_delete(quest_failures);
  5858. }
  5859. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5860. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5861. MPendingQuestAccept.lock();
  5862. player->pending_quests[quest->GetQuestID()] = quest;
  5863. MPendingQuestAccept.unlock();
  5864. AcceptQuest(quest->GetQuestID());
  5865. }
  5866. else {
  5867. MPendingQuestAccept.lock();
  5868. player->pending_quests[quest->GetQuestID()] = quest;
  5869. MPendingQuestAccept.unlock();
  5870. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5871. //DumpPacket(outapp);
  5872. QueuePacket(outapp);
  5873. }
  5874. }
  5875. void Client::AcceptQuest(int32 quest_id) {
  5876. MPendingQuestAccept.lock_shared();
  5877. if (player->pending_quests.count(quest_id) > 0) {
  5878. Quest* quest = player->pending_quests[quest_id];
  5879. if(quest) {
  5880. MPendingQuestAccept.unlock_shared();
  5881. MPendingQuestAccept.lock();
  5882. player->pending_quests.erase(quest->GetQuestID());
  5883. MPendingQuestAccept.unlock();
  5884. AddPlayerQuest(quest);
  5885. GetCurrentZone()->SendQuestUpdates(this);
  5886. GetPlayer()->UpdateQuestCompleteCount(quest_id);
  5887. return; // already unlocked mutex
  5888. }
  5889. }
  5890. MPendingQuestAccept.unlock_shared();
  5891. }
  5892. void Client::RemovePendingQuest(int32 quest_id) {
  5893. bool send_updates = false;
  5894. MPendingQuestAccept.lock_shared();
  5895. if (player->pending_quests.count(quest_id) > 0) {
  5896. Quest* quest = player->pending_quests[quest_id];
  5897. MPendingQuestAccept.unlock_shared();
  5898. MPendingQuestAccept.lock();
  5899. player->pending_quests.erase(quest_id);
  5900. MPendingQuestAccept.unlock();
  5901. if(lua_interface) {
  5902. lua_interface->CallQuestFunction(quest, "Declined", GetPlayer());
  5903. lua_interface->SetLuaUserDataStale(quest);
  5904. }
  5905. safe_delete(quest);
  5906. send_updates = true;
  5907. }
  5908. else {
  5909. MPendingQuestAccept.unlock_shared();
  5910. }
  5911. if(send_updates) {
  5912. GetCurrentZone()->SendQuestUpdates(this);
  5913. }
  5914. }
  5915. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5916. if (!quest || !progress) {
  5917. return;
  5918. }
  5919. map<int32, int32>::iterator itr;
  5920. QuestStep* step = 0;
  5921. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5922. step = quest->GetQuestStep(itr->first);
  5923. if (step && itr->second > 0) {
  5924. step->SetStepProgress(itr->second);
  5925. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5926. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5927. }
  5928. }
  5929. if (lua_interface && step)
  5930. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5931. else if(!step) {
  5932. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5933. }
  5934. }
  5935. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5936. bool lockCleared = false;
  5937. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5938. if (player->player_quests.count(quest->GetQuestID()) > 0 && player->player_quests[quest->GetQuestID()]) {
  5939. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5940. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5941. int32 questID = quest->GetQuestID();
  5942. lockCleared = true;
  5943. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5944. RemovePlayerQuest(questID, false, false);
  5945. }
  5946. player->player_quests[quest->GetQuestID()] = quest;
  5947. if(!lockCleared)
  5948. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5949. quest->SetPlayer(player);
  5950. quest->SetSaveNeeded(true);
  5951. current_quest_id = quest->GetQuestID();
  5952. if (send_packets && quest->GetQuestGiver() > 0)
  5953. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5954. if (lua_interface && call_accepted)
  5955. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5956. if (send_packets) {
  5957. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5958. //SendQuestJournal();
  5959. SendQuestJournalUpdate(quest);
  5960. // sent twice to match live
  5961. quest->SetTracked(false);
  5962. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5963. quest->SetTracked(true);
  5964. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5965. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5966. }
  5967. //This isn't during a load screen, so update spawns with required quests
  5968. if (call_accepted)
  5969. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5970. }
  5971. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5972. if (current_quest_id == id)
  5973. current_quest_id = 0;
  5974. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5975. if (player->player_quests.count(id) > 0 && player->player_quests[id]) {
  5976. if (delete_quest) {
  5977. player->player_quests[id]->SetDeleted(true);
  5978. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5979. }
  5980. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5981. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5982. if (send_update && quest_giver > 0)
  5983. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5984. if (send_update) {
  5985. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5986. SendQuestJournal(false, 0, true);
  5987. }
  5988. player->RemoveQuest(id, delete_quest);
  5989. if (send_update) {
  5990. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5991. SendQuestJournal(false, 0, true);
  5992. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5993. }
  5994. }
  5995. else {
  5996. // if we don't have any quests to count then release the write lock
  5997. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5998. }
  5999. }
  6000. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  6001. if (quest) {
  6002. QuestStep* quest_step = quest->GetQuestStep(step);
  6003. if (quest_step) {
  6004. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  6005. quest_step->WasUpdated(false);
  6006. }
  6007. }
  6008. }
  6009. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  6010. QueuedQuest* item = new QueuedQuest;
  6011. item->quest_id = quest->GetQuestID();
  6012. item->step = step;
  6013. item->display_quest_helper = display_quest_helper;
  6014. MQuestQueue.writelock();
  6015. quest_queue.push_back(item);
  6016. last_update_time = Timer::GetCurrentTime2();
  6017. MQuestQueue.releasewritelock();
  6018. }
  6019. void Client::SendQuestFailure(Quest* quest) {
  6020. vector<QuestStep*>* failures = quest->GetQuestFailures();
  6021. if (failures) {
  6022. QuestStep* step = 0;
  6023. for (int32 i = 0; i < failures->size(); i++) {
  6024. step = failures->at(i);
  6025. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  6026. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6027. SendQuestJournal(false, 0, true);
  6028. }
  6029. failures->clear();
  6030. }
  6031. }
  6032. void Client::SendQuestUpdate(Quest* quest) {
  6033. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  6034. if (updates) {
  6035. QuestStep* step = 0;
  6036. bool updated = false;
  6037. for (int32 i = 0; i < updates->size(); i++) {
  6038. step = updates->at(i);
  6039. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  6040. {
  6041. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  6042. SendQuestUpdateStep(quest, step->GetStepID());
  6043. updated = true;
  6044. }
  6045. if (step->WasUpdated()) {
  6046. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  6047. SendQuestJournal(false, 0, true);
  6048. if(!updated)
  6049. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  6050. updated = true;
  6051. }
  6052. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6053. }
  6054. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  6055. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  6056. SendQuestJournalUpdate(quest, true);
  6057. }
  6058. if (quest->GetCompleted()) {
  6059. if (quest->GetQuestReturnNPC() > 0)
  6060. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  6061. if (quest->GetCompletedFlag())
  6062. quest->SetCompletedFlag(false);
  6063. }
  6064. updates->clear();
  6065. }
  6066. }
  6067. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  6068. if (!client)
  6069. client = this;
  6070. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  6071. if (packet) {
  6072. EQ2Packet* outapp = packet->serialize();
  6073. //DumpPacket(outapp);
  6074. client->QueuePacket(outapp);
  6075. safe_delete(packet);
  6076. }
  6077. }
  6078. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  6079. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  6080. if (packet) {
  6081. QueuePacket(packet->serialize());
  6082. safe_delete(packet);
  6083. }
  6084. }
  6085. void Client::ReloadQuests() {
  6086. vector<int32> ids = player->GetQuestIDs();
  6087. Quest* quest = 0;
  6088. for (int32 i = 0; i < ids.size(); i++) {
  6089. quest = master_quest_list.GetQuest(ids[i]);
  6090. if (quest)
  6091. AddPlayerQuest(quest, false);
  6092. else
  6093. RemovePlayerQuest(ids[i]);
  6094. }
  6095. }
  6096. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  6097. std::unique_lock lock(MPendingQuestAccept);
  6098. bool found_quest = false;
  6099. vector<int32>::iterator itr;
  6100. int32 questID = 0;
  6101. Quest* quest = nullptr;
  6102. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end();) {
  6103. questID = *itr;
  6104. bool quest_exists = false;
  6105. quest = GetPlayer()->PendingQuestAcceptance(questID, item_id, &quest_exists);
  6106. if(!quest_exists) {
  6107. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  6108. itr = pending_quest_accept.erase(itr);
  6109. quest = nullptr;
  6110. continue;
  6111. }
  6112. else if (quest) {
  6113. pending_quest_accept.erase(itr);
  6114. break;
  6115. }
  6116. itr++;
  6117. }
  6118. return quest;
  6119. }
  6120. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  6121. int8 num_slots_needed = 0;
  6122. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  6123. Item* master_item = 0;
  6124. if (item_id > 0) {
  6125. num_slots_needed++;
  6126. master_item = master_item_list.GetItem(item_id);
  6127. }
  6128. int32 totalItems = 0;
  6129. vector<Item*>* items = 0;
  6130. vector<Item*>* tmpItems = 0;
  6131. bool isTempState = quest->GetQuestTemporaryState();
  6132. if(isTempState)
  6133. {
  6134. tmpItems = quest->GetTmpRewardItems();
  6135. if (tmpItems && tmpItems->size() > 0)
  6136. {
  6137. num_slots_needed += tmpItems->size();
  6138. totalItems += tmpItems->size();
  6139. }
  6140. }
  6141. else
  6142. {
  6143. items = quest->GetRewardItems();
  6144. if (items && items->size() > 0)
  6145. {
  6146. num_slots_needed += items->size();
  6147. totalItems += items->size();
  6148. }
  6149. }
  6150. RemoveQueuedQuestReward();
  6151. GetPlayer()->SetActiveReward(false);
  6152. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  6153. if (master_item)
  6154. AddItem(item_id);
  6155. if (tmpItems && tmpItems->size() > 0) {
  6156. for (int32 i = 0; i < tmpItems->size(); i++)
  6157. AddItem(new Item(tmpItems->at(i)));
  6158. }
  6159. if (items && items->size() > 0) {
  6160. for (int32 i = 0; i < items->size(); i++)
  6161. AddItem(new Item(items->at(i)));
  6162. }
  6163. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6164. if (outapp)
  6165. QueuePacket(outapp);
  6166. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6167. map<int32, sint32>::iterator itr;
  6168. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6169. int32 faction_id = itr->first;
  6170. sint32 amount = itr->second;
  6171. if (amount > 0)
  6172. player->GetFactions()->IncreaseFaction(faction_id, amount);
  6173. else
  6174. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  6175. }
  6176. if(quest->GetQuestTemporaryState())
  6177. {
  6178. int64 total_coins = quest->GetCoinTmpReward();
  6179. if (total_coins > 0)
  6180. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6181. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  6182. }
  6183. else {
  6184. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  6185. }
  6186. quest->SetQuestTemporaryState(false);
  6187. player->SetCharSheetChanged(true);
  6188. }
  6189. else {
  6190. GetPlayer()->SetActiveReward(true);
  6191. AddPendingQuestAcceptReward(quest);
  6192. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  6193. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6194. }
  6195. }
  6196. 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) {
  6197. 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))) {
  6198. /*if (quest)
  6199. text = quest->GetName();
  6200. else*/
  6201. return;//nothing to give
  6202. }
  6203. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  6204. GetPlayer()->ClearPendingItemRewards();
  6205. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  6206. if (packet2) {
  6207. int32 source_id = 0;
  6208. if (quest)
  6209. source_id = quest->GetQuestID();
  6210. int64 rewarded_coin = 0;
  6211. if (quest) {
  6212. if (quest->GetCoinsReward() > 0) {
  6213. if (quest->GetCoinsRewardMax() > 0)
  6214. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6215. else
  6216. rewarded_coin = quest->GetCoinsReward();
  6217. }
  6218. quest->SetGeneratedCoin(rewarded_coin);
  6219. }
  6220. if (rewarded_coin > coin)
  6221. coin = rewarded_coin;
  6222. 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
  6223. if (coin > 0) {
  6224. player->AddCoins(coin);
  6225. PlaySound("coin_cha_ching");
  6226. }
  6227. }
  6228. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  6229. packet2->setSubstructDataByName("reward_data", "reward", header);
  6230. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  6231. if (player->GetGuild() && !was_displayed) {
  6232. 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
  6233. player->GetInfoStruct()->add_status_points(status_points);
  6234. player->SetCharSheetChanged(true);
  6235. }
  6236. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  6237. }
  6238. if(text)
  6239. packet2->setSubstructDataByName("reward_data", "text", text);
  6240. std::vector<Item*> items;
  6241. quest->GetTmpRewardItemsByID(&items);
  6242. if(rewards || items.size() > 0){
  6243. int32 item_count = items.size();
  6244. item_count += rewards ? rewards->size() : 0;
  6245. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  6246. int i = 0;
  6247. if(rewards) {
  6248. for (i = 0; i < rewards->size(); i++) {
  6249. Item* item = rewards->at(i);
  6250. if (item) {
  6251. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6252. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6253. }
  6254. 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
  6255. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6256. }
  6257. }
  6258. for (int j = 0; j < items.size(); j++) {
  6259. Item* item = items.at(j);
  6260. if (item) {
  6261. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  6262. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  6263. }
  6264. 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
  6265. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  6266. i++;
  6267. }
  6268. }
  6269. if (selectable_rewards) {
  6270. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  6271. for (int i = 0; i < selectable_rewards->size(); i++) {
  6272. Item* item = selectable_rewards->at(i);
  6273. if (item) {
  6274. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  6275. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  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->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  6278. }
  6279. }
  6280. }
  6281. if (factions) {
  6282. map<int32, sint32>::iterator itr;
  6283. map<Faction*, signed int> factions_map;
  6284. for (itr = factions->begin(); itr != factions->end(); itr++) {
  6285. Faction* faction = master_faction_list.GetFaction(itr->first);
  6286. if (faction)
  6287. factions_map[faction] = itr->second;
  6288. }
  6289. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  6290. map<Faction*, signed int>::iterator faction_itr;
  6291. int8 i = 0;
  6292. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  6293. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  6294. sint32 amount = faction_itr->second;
  6295. packet2->setArrayDataByName("amount", amount, i);
  6296. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  6297. if (amount > 0)
  6298. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  6299. else
  6300. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  6301. }
  6302. i++;
  6303. }
  6304. }
  6305. QueuePacket(packet2->serialize());
  6306. safe_delete(packet2);
  6307. }
  6308. }
  6309. void Client::PopulateQuestRewardItems(vector <Item*>* items, PacketStruct* packet,
  6310. std::string num_rewards_str, std::string reward_id_str, std::string item_str) {
  6311. if(!items || !packet)
  6312. return;
  6313. if (items) {
  6314. int32 total_item_count = 0;
  6315. for(int s=0;s<items->size();s++) {
  6316. Item* tmpItem = items->at(s);
  6317. if(tmpItem) {
  6318. if(tmpItem->details.count > 1) {
  6319. total_item_count += tmpItem->details.count;
  6320. }
  6321. else {
  6322. total_item_count += 1;
  6323. }
  6324. }
  6325. }
  6326. packet->setArrayLengthByName(num_rewards_str.c_str(), total_item_count);
  6327. int16 count = 0;
  6328. int16 pos = 0;
  6329. for (int32 i = 0; i < items->size();) {
  6330. packet->setArrayDataByName(reward_id_str.c_str(), items->at(i)->details.item_id, pos);
  6331. if (version < 860)
  6332. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, -1);
  6333. else if (version < 1193)
  6334. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos);
  6335. else
  6336. packet->setItemArrayDataByName(item_str.c_str(), items->at(i), player, pos, 0, 2);
  6337. pos++;
  6338. if(count >= items->at(i)->details.count-1) {
  6339. count = 0;
  6340. }
  6341. else if(items->at(i)->details.count > 1) {
  6342. count++;
  6343. continue;
  6344. }
  6345. i++;
  6346. }
  6347. }
  6348. }
  6349. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  6350. if (!quest)
  6351. return;
  6352. if (GetVersion() <= 561) {
  6353. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), tempReward ? customDescription.c_str() : quest->GetCompletedDescription(), was_displayed);
  6354. return;
  6355. }
  6356. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  6357. if (packet) {
  6358. packet->setDataByName("title", "Quest Reward!");
  6359. packet->setDataByName("name", quest->GetName());
  6360. if(tempReward)
  6361. {
  6362. packet->setDataByName("description", customDescription.c_str());
  6363. }
  6364. else
  6365. packet->setDataByName("description", quest->GetCompletedDescription());
  6366. packet->setDataByName("level", quest->GetLevel());
  6367. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  6368. int8 difficulty = 0;
  6369. if ((string)quest->GetType() == "Tradeskill")
  6370. difficulty = player->GetTSArrowColor(quest->GetLevel());
  6371. else
  6372. difficulty = player->GetArrowColor(quest->GetLevel());
  6373. packet->setDataByName("difficulty", difficulty);
  6374. if(tempReward)
  6375. {
  6376. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  6377. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  6378. packet->setDataByName("status_points", quest->GetStatusPoints());
  6379. }
  6380. else
  6381. {
  6382. int64 rewarded_coin = 0;
  6383. if (quest->GetCoinsReward() > 0) {
  6384. if (quest->GetCoinsRewardMax() > 0)
  6385. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  6386. else
  6387. rewarded_coin = quest->GetCoinsReward();
  6388. }
  6389. quest->SetGeneratedCoin(rewarded_coin);
  6390. packet->setDataByName("max_coin", rewarded_coin);
  6391. packet->setDataByName("min_coin", rewarded_coin);
  6392. packet->setDataByName("status_points", quest->GetStatusPoints());
  6393. }
  6394. if(tempReward) {
  6395. PopulateQuestRewardItems(quest->GetTmpRewardItems(), packet);
  6396. }
  6397. else
  6398. {
  6399. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  6400. PopulateQuestRewardItems(quest->GetRewardItems(), packet);
  6401. PopulateQuestRewardItems(quest->GetSelectableRewardItems(), packet, std::string("num_select_rewards"),
  6402. std::string("select_reward_id"), std::string("select_item"));
  6403. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  6404. if (reward_factions && reward_factions->size() > 0) {
  6405. packet->setArrayLengthByName("num_factions", reward_factions->size());
  6406. map<int32, sint32>::iterator itr;
  6407. int16 index = 0;
  6408. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  6409. int32 faction_id = itr->first;
  6410. sint32 amount = itr->second;
  6411. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  6412. if (faction_name) {
  6413. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  6414. packet->setArrayDataByName("amount", amount, index);
  6415. }
  6416. index++;
  6417. }
  6418. }
  6419. }
  6420. EQ2Packet* outapp = packet->serialize();
  6421. // DumpPacket(outapp);
  6422. QueuePacket(outapp);
  6423. safe_delete(packet);
  6424. }
  6425. }
  6426. void Client::DisplayRandomizeFeatures(int32 flags) {
  6427. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  6428. if (flags > 0) {
  6429. if (flags & RANDOMIZE_GENDER)
  6430. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  6431. if (flags & RANDOMIZE_RACE)
  6432. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  6433. if (flags & RANDOMIZE_MODEL_TYPE)
  6434. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  6435. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  6436. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  6437. if (flags & RANDOMIZE_HAIR_TYPE)
  6438. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  6439. if (flags & RANDOMIZE_WING_TYPE)
  6440. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  6441. if (flags & RANDOMIZE_CHEEK_TYPE)
  6442. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  6443. if (flags & RANDOMIZE_CHIN_TYPE)
  6444. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  6445. if (flags & RANDOMIZE_EAR_TYPE)
  6446. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  6447. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  6448. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  6449. if (flags & RANDOMIZE_EYE_TYPE)
  6450. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  6451. if (flags & RANDOMIZE_LIP_TYPE)
  6452. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  6453. if (flags & RANDOMIZE_NOSE_TYPE)
  6454. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  6455. if (flags & RANDOMIZE_EYE_COLOR)
  6456. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  6457. if (flags & RANDOMIZE_HAIR_COLOR1)
  6458. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  6459. if (flags & RANDOMIZE_HAIR_COLOR2)
  6460. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  6461. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  6462. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  6463. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  6464. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  6465. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  6466. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  6467. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  6468. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  6469. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  6470. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  6471. if (flags & RANDOMIZE_SKIN_COLOR)
  6472. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  6473. if (flags & RANDOMIZE_WING_COLOR1)
  6474. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  6475. if (flags & RANDOMIZE_WING_COLOR2)
  6476. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  6477. }
  6478. else
  6479. {
  6480. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  6481. }
  6482. }
  6483. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  6484. current_quest_id = 0;
  6485. if(!quest->GetQuestTemporaryState() && !has_displayed)
  6486. {
  6487. quest->IncrementCompleteCount();
  6488. player->AddCompletedQuest(quest);
  6489. }
  6490. AddPendingQuestAcceptReward(quest);
  6491. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  6492. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  6493. SendQuestJournal();
  6494. if(quest->GetQuestTemporaryState()) {
  6495. return;
  6496. }
  6497. if(!has_displayed) {
  6498. if (quest->GetExpReward() > 0) {
  6499. int32 xp = quest->GetExpReward();
  6500. player->AddXP(xp);
  6501. }
  6502. if (quest->GetTSExpReward() > 0) {
  6503. int8 ts_level = player->GetTSLevel();
  6504. int32 xp = quest->GetTSExpReward();
  6505. if (player->AddTSXP(xp)) {
  6506. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  6507. if (player->GetTSLevel() != ts_level)
  6508. ChangeTSLevel(ts_level, player->GetTSLevel());
  6509. player->SetCharSheetChanged(true);
  6510. }
  6511. }
  6512. int64 total_coins = quest->GetGeneratedCoin();
  6513. if (total_coins > 0)
  6514. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  6515. player->RemoveQuest(quest->GetQuestID(), false);
  6516. }
  6517. if (quest->GetQuestGiver() > 0)
  6518. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  6519. if(!has_displayed) {
  6520. RemovePlayerQuest(quest->GetQuestID(), true, false);
  6521. }
  6522. }
  6523. 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) {
  6524. std::unique_lock lock(MConversation);
  6525. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  6526. if (packet) {
  6527. packet->setDataByName("conversation_id", conversation_id);
  6528. packet->setDataByName("text", text);
  6529. packet->setDataByName("language", language); // default 0
  6530. packet->setDataByName("enable_blue_ui", 0); // default 0
  6531. packet->setDataByName("can_close", can_close); // default 1
  6532. conversation_map[conversation_id].clear();
  6533. if (conversations) {
  6534. packet->setArrayLengthByName("num_responses", conversations->size());
  6535. for (int32 i = 0; i < conversations->size(); i++) {
  6536. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  6537. if (conversations->at(i).function.length() > 0)
  6538. conversation_map[conversation_id][i] = conversations->at(i).function;
  6539. }
  6540. }
  6541. packet->setDataByName("spawn_id", spawn_id);
  6542. if (mp3) {
  6543. packet->setDataByName("voice", mp3);
  6544. packet->setDataByName("key1", key1);
  6545. packet->setDataByName("key2", key2);
  6546. }
  6547. QueuePacket(packet->serialize());
  6548. safe_delete(packet);
  6549. }
  6550. }
  6551. 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) {
  6552. if (!item || !text || !conversations || conversations->size() == 0) {
  6553. return;
  6554. }
  6555. int32 conversation_id = GetConversationID(0, item);
  6556. if (conversation_id == 0) {
  6557. next_conversation_id++;
  6558. conversation_id = next_conversation_id;
  6559. }
  6560. MConversation.lock();
  6561. conversation_items[conversation_id] = item;
  6562. MConversation.unlock();
  6563. if (type == 4)
  6564. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6565. else
  6566. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6567. }
  6568. 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) {
  6569. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  6570. return;
  6571. }
  6572. int32 conversation_id = GetConversationID(src, 0);
  6573. if (conversation_id == 0) {
  6574. next_conversation_id++;
  6575. conversation_id = next_conversation_id;
  6576. }
  6577. MConversation.lock();
  6578. conversation_spawns[conversation_id] = src->GetID();
  6579. MConversation.unlock();
  6580. /* Spawns can start two different types of conversations.
  6581. * Type 1: The chat type with bubbles.
  6582. * Type 2: The dialog type with the blue box. */
  6583. if (type == 1)
  6584. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  6585. else if (type == 2)
  6586. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  6587. else //if (type == 3)
  6588. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  6589. }
  6590. void Client::CloseDialog(int32 conversation_id) {
  6591. std::unique_lock lock(MConversation);
  6592. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  6593. if (packet) {
  6594. packet->setDataByName("conversation_id", conversation_id);
  6595. QueuePacket(packet->serialize());
  6596. safe_delete(packet);
  6597. }
  6598. std::map<int32, Item*>::iterator itr;
  6599. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  6600. {
  6601. conversation_items.erase(itr);
  6602. }
  6603. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  6604. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  6605. {
  6606. conversation_spawns.erase(itr2);
  6607. }
  6608. }
  6609. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  6610. std::shared_lock lock(MConversation);
  6611. int32 conversation_id = 0;
  6612. if (spawn) {
  6613. map<int32, int32>::iterator itr;
  6614. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  6615. if (itr->second == spawn->GetID()) {
  6616. conversation_id = itr->first;
  6617. break;
  6618. }
  6619. }
  6620. }
  6621. else if (item) {
  6622. map<int32, Item*>::iterator itr;
  6623. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  6624. if (itr->second == item) {
  6625. conversation_id = itr->first;
  6626. break;
  6627. }
  6628. }
  6629. }
  6630. return conversation_id;
  6631. }
  6632. Spawn* Client::GetCombineSpawn() {
  6633. return combine_spawn;
  6634. }
  6635. bool Client::ShouldTarget() {
  6636. return should_target;
  6637. }
  6638. void Client::TargetSpawn(Spawn* spawn) {
  6639. should_target = false;
  6640. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  6641. if (packet) {
  6642. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6643. QueuePacket(packet->serialize());
  6644. safe_delete(packet);
  6645. }
  6646. }
  6647. void Client::CombineSpawns(float radius, Spawn* spawn) {
  6648. combine_spawn = spawn;
  6649. spawn->RemoveSpawnFromGroup(true);
  6650. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  6651. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  6652. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6653. should_target = true;
  6654. }
  6655. void Client::AddCombineSpawn(Spawn* spawn) {
  6656. if (combine_spawn && combine_spawn != spawn && spawn) {
  6657. combine_spawn->AddSpawnToGroup(spawn);
  6658. spawn->AddSpawnToGroup(combine_spawn);
  6659. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6660. }
  6661. else if (spawn)
  6662. combine_spawn = spawn;
  6663. should_target = true;
  6664. }
  6665. void Client::RemoveCombineSpawn(Spawn* spawn) {
  6666. if (combine_spawn && spawn)
  6667. spawn->RemoveSpawnFromGroup();
  6668. if (combine_spawn == spawn)
  6669. combine_spawn->RemoveSpawnFromGroup(true);
  6670. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  6671. if (combine_spawn == spawn)
  6672. combine_spawn = 0;
  6673. }
  6674. void Client::SaveCombineSpawns(const char* name) {
  6675. if (!combine_spawn) {
  6676. return;
  6677. }
  6678. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  6679. if (!spawns) {
  6680. return;
  6681. }
  6682. int32 count = spawns->size();
  6683. int32 spawnLocationID = 0;
  6684. if (count == 1)
  6685. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  6686. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  6687. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  6688. // we remove the spawn inside SaveCombinedSpawnLocation
  6689. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  6690. }
  6691. else
  6692. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  6693. safe_delete(spawns);
  6694. combine_spawn = 0;
  6695. }
  6696. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  6697. Item* master_item = master_item_list.GetItem(item_id);
  6698. Item* item = 0;
  6699. if (master_item)
  6700. item = new Item(master_item);
  6701. if (item) {
  6702. if (quantity > 0)
  6703. item->details.count = quantity;
  6704. return AddItem(item, nullptr, type);
  6705. }
  6706. else
  6707. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6708. return false;
  6709. }
  6710. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6711. if (!item) {
  6712. return false;
  6713. }
  6714. if (player->AddItem(item, type)) {
  6715. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6716. if (outapp) {
  6717. //DumpPacket(outapp);
  6718. QueuePacket(outapp);
  6719. //resend bag desc with new item name added
  6720. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6721. if (outapp) {
  6722. //DumpPacket(outapp);
  6723. QueuePacket(outapp);
  6724. }
  6725. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6726. DumpPacket(app);
  6727. client->QueuePacket(app);
  6728. */
  6729. }
  6730. CheckPlayerQuestsItemUpdate(item);
  6731. if (item->GetItemScript() && lua_interface)
  6732. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6733. }
  6734. else {
  6735. lua_interface->SetLuaUserDataStale(item);
  6736. // likely lore conflict
  6737. if(item_deleted)
  6738. *item_deleted = true;
  6739. return false;
  6740. }
  6741. return true;
  6742. }
  6743. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6744. Item* master_item = master_item_list.GetItem(item_id);
  6745. Item* item = 0;
  6746. if (master_item)
  6747. item = new Item(master_item);
  6748. if (item) {
  6749. if (quantity > 0)
  6750. item->details.count = quantity;
  6751. return AddItemToBank(item);
  6752. }
  6753. else
  6754. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6755. return false;
  6756. }
  6757. bool Client::AddItemToBank(Item* item) {
  6758. if (!item) {
  6759. return false;
  6760. }
  6761. if (player->AddItemToBank(item)) {
  6762. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6763. if (outapp) {
  6764. QueuePacket(outapp);
  6765. //resend bag desc with new item name added
  6766. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6767. if (outapp)
  6768. QueuePacket(outapp);
  6769. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6770. DumpPacket(app);
  6771. client->QueuePacket(app);
  6772. */
  6773. }
  6774. CheckPlayerQuestsItemUpdate(item);
  6775. if (item->GetItemScript() && lua_interface)
  6776. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6777. }
  6778. else {
  6779. lua_interface->SetLuaUserDataStale(item);
  6780. // likely lore conflict
  6781. safe_delete(item);
  6782. return false;
  6783. }
  6784. return true;
  6785. }
  6786. void Client::UnequipItem(int16 index, sint32 bag_id, int8 to_slot, int8 appearance_equip) {
  6787. vector<EQ2Packet*> packets = GetPlayer()->UnequipItem(index, bag_id, to_slot, GetVersion(), appearance_equip);
  6788. EQ2Packet* outapp = 0;
  6789. for(int32 i=0;i<packets.size();i++)
  6790. {
  6791. outapp = packets[i];
  6792. if(outapp)
  6793. QueuePacket(outapp);
  6794. }
  6795. GetPlayer()->UpdateWeapons();
  6796. EQ2Packet* characterSheetPackets = GetPlayer()->GetPlayerInfo()->serialize(GetVersion());
  6797. QueuePacket(characterSheetPackets);
  6798. }
  6799. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6800. EQ2Packet* outapp;
  6801. bool delete_item = false;
  6802. assert(item);
  6803. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6804. item->details.count -= quantity;
  6805. item->save_needed = true;
  6806. }
  6807. else {
  6808. database.DeleteItem(character_id, item, 0);
  6809. player->GetPlayerItemList()->RemoveItem(item, false);
  6810. delete_item = true;
  6811. }
  6812. if(force_override_no_delete)
  6813. delete_item = false;
  6814. if ((outapp = player->SendInventoryUpdate(version))) {
  6815. QueuePacket(outapp);
  6816. if (item->GetItemScript() && lua_interface)
  6817. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6818. if (delete_item)
  6819. {
  6820. PurgeItem(item);
  6821. lua_interface->SetLuaUserDataStale(item);
  6822. safe_delete(item);
  6823. }
  6824. GetPlayer()->CalculateApplyWeight();
  6825. return true;
  6826. }
  6827. return false;
  6828. }
  6829. void Client::SetLuaDebugClient(bool val) {
  6830. if (val)
  6831. lua_debug_timer.Start();
  6832. lua_debug = val;
  6833. if (lua_interface && !val) {
  6834. lua_interface->RemoveDebugClients(this);
  6835. lua_debug_timer.Disable();
  6836. }
  6837. }
  6838. void Client::SetMerchantTransaction(Spawn* spawn) {
  6839. merchant_transaction = spawn;
  6840. }
  6841. Spawn* Client::GetMerchantTransaction() {
  6842. return merchant_transaction;
  6843. }
  6844. void Client::SetMailTransaction(Spawn* spawn) {
  6845. ResetSendMail(spawn ? false : true);
  6846. MMailWindowMutex.lock();
  6847. mail_transaction = spawn;
  6848. MMailWindowMutex.unlock();
  6849. }
  6850. Spawn* Client::GetMailTransaction() {
  6851. return mail_transaction;
  6852. }
  6853. void Client::PlaySound(const char* name) {
  6854. if (name) {
  6855. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6856. if (packet) {
  6857. packet->setMediumStringByName("name", name);
  6858. QueuePacket(packet->serialize());
  6859. safe_delete(packet);
  6860. }
  6861. }
  6862. }
  6863. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6864. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6865. if(multiplier){
  6866. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6867. float diff_low = faction_val - multiplier->faction_min;
  6868. if(diff_low < 0)
  6869. diff_low*=-1;
  6870. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6871. if(total_diff < 0)
  6872. total_diff*=-1;
  6873. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6874. float total1 = (diff_low/total_diff);
  6875. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6876. return final_buy_multiplier;
  6877. }*/
  6878. return 1;
  6879. }
  6880. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6881. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6882. if(multiplier){
  6883. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6884. float diff_low = faction_val - multiplier->faction_min;
  6885. if(diff_low < 0)
  6886. diff_low*=-1;
  6887. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6888. if(total_diff < 0)
  6889. total_diff*=-1;
  6890. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6891. float total1 = (diff_low/total_diff);
  6892. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6893. return final_sell_multiplier;
  6894. }*/
  6895. return 1;
  6896. }
  6897. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6898. Spawn* spawn = GetMerchantTransaction();
  6899. Guild* guild = GetPlayer()->GetGuild();
  6900. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6901. spawn->IsClientInMerchantLevelRange(this)) {
  6902. int32 total_sell_price = 0;
  6903. int32 total_status_sell_price = 0; //for status
  6904. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6905. int32 sell_price = 0;
  6906. int32 status_sell_price = 0; //for status
  6907. Item* master_item = master_item_list.GetItem(item_id);
  6908. Item* item = 0;
  6909. if (unique_id == 0)
  6910. item = player->item_list.GetItemFromID(item_id, quantity);
  6911. else
  6912. item = player->item_list.GetItemFromUniqueID(unique_id);
  6913. if (!item)
  6914. item = player->item_list.GetItemFromID(item_id);
  6915. if (item && master_item) {
  6916. if(item->details.item_locked)
  6917. {
  6918. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6919. return;
  6920. }
  6921. else if(item->CheckFlag(NO_VALUE))
  6922. {
  6923. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6924. return;
  6925. }
  6926. else if (item->IsBag())
  6927. {
  6928. int32 bagitemcount = player->GetPlayerItemList()->GetItemCountInBag(item);
  6929. if (bagitemcount > 0) {
  6930. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell a bag with items inside it.");
  6931. return;
  6932. }
  6933. }
  6934. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6935. if (sell_price > item->sell_price)
  6936. sell_price = item->sell_price;
  6937. if (quantity > item->details.count)
  6938. quantity = item->details.count;
  6939. total_sell_price = sell_price * quantity;
  6940. //------------------------------For Selling Status Items
  6941. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6942. if (status_sell_price > item->sell_status)
  6943. status_sell_price = item->sell_status;
  6944. if (quantity > item->details.count)
  6945. quantity = item->details.count;
  6946. total_status_sell_price = status_sell_price * quantity;
  6947. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6948. total_status_sell_price = 0;
  6949. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6950. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6951. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6952. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6953. guild->SendGuildMemberList();
  6954. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6955. }
  6956. if (quantity > 1)
  6957. {
  6958. if(total_status_sell_price)
  6959. 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);
  6960. else
  6961. 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());
  6962. }
  6963. else
  6964. {
  6965. if(total_status_sell_price)
  6966. 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);
  6967. else
  6968. 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());
  6969. }
  6970. player->AddCoins(total_sell_price);
  6971. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6972. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6973. if (quantity >= item->details.count) {
  6974. database.DeleteItem(GetCharacterID(), item, 0);
  6975. player->item_list.DestroyItem(item->details.index);
  6976. }
  6977. else {
  6978. item->details.count -= quantity;
  6979. item->save_needed = true;
  6980. }
  6981. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6982. if (outapp)
  6983. QueuePacket(outapp);
  6984. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6985. SendBuyBackList();
  6986. }
  6987. }
  6988. }
  6989. void Client::BuyBack(int32 item_id, int16 quantity) {
  6990. Spawn* spawn = GetMerchantTransaction();
  6991. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6992. spawn->IsClientInMerchantLevelRange(this)) {
  6993. deque<BuyBackItem*>::iterator itr;
  6994. BuyBackItem* buyback = 0;
  6995. BuyBackItem* closest = 0;
  6996. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6997. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6998. buyback = *itr;
  6999. if (buyback->unique_id == item_id) {
  7000. closest = buyback;
  7001. quantity = buyback->quantity;
  7002. break;
  7003. }
  7004. }
  7005. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7006. if (closest) {
  7007. Item* item = 0;
  7008. Item* master_item = master_item_list.GetItem(closest->item_id);
  7009. if (master_item) {
  7010. item = new Item(master_item);
  7011. if (closest->quantity >= quantity)
  7012. item->details.count = quantity;
  7013. else
  7014. item->details.count = closest->quantity;
  7015. }
  7016. bool itemDeleted = false;
  7017. bool itemAdded = false;
  7018. sint64 dispFlags = 0;
  7019. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  7020. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7021. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  7022. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7023. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  7024. bool removed = false;
  7025. if (closest->quantity == quantity) {
  7026. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7027. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  7028. if (*itr == closest) {
  7029. buy_back_items.erase(itr);
  7030. removed = true;
  7031. break;
  7032. }
  7033. }
  7034. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7035. }
  7036. else {
  7037. closest->quantity -= quantity;
  7038. closest->save_needed = true;
  7039. }
  7040. itemAdded = AddItem(item, &itemDeleted);
  7041. if (removed) {
  7042. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  7043. safe_delete(closest);
  7044. }
  7045. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  7046. SendBuyBackList();
  7047. }
  7048. else
  7049. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  7050. if(!itemAdded && !itemDeleted) {
  7051. lua_interface->SetLuaUserDataStale(item);
  7052. safe_delete(item);
  7053. }
  7054. }
  7055. }
  7056. }
  7057. void Client::BuyItem(int32 item_id, int16 quantity) {
  7058. // Get the merchant we are buying from
  7059. Spawn* spawn = GetMerchantTransaction();
  7060. // Make sure the spawn has a merchant list
  7061. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7062. int32 total_buy_price = 0;
  7063. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7064. int32 sell_price = 0;
  7065. Item* master_item = master_item_list.GetItem(item_id);
  7066. Item* item = 0;
  7067. int16 total_available = 0;
  7068. vector<MerchantItemInfo>* temp;
  7069. vector<MerchantItemInfo>::iterator itr;
  7070. MerchantItemInfo* ItemInfo = 0;
  7071. temp = world.GetMerchantList(spawn->GetMerchantID());
  7072. for (itr = temp->begin(); itr != temp->end(); itr++) {
  7073. if ((*itr).item_id == item_id) {
  7074. ItemInfo = &(*itr);
  7075. break;
  7076. }
  7077. }
  7078. if (master_item && ItemInfo) {
  7079. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  7080. quantity = 1;
  7081. total_available = 0xFFFF;
  7082. sell_price = master_item->sell_price;
  7083. }
  7084. else {
  7085. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  7086. sell_price = (int32)(master_item->sell_price * multiplier);
  7087. if (quantity > total_available)
  7088. quantity = total_available;
  7089. }
  7090. sint64 dispFlags = 0;
  7091. 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))
  7092. {
  7093. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  7094. return;
  7095. }
  7096. if(quantity < 1)
  7097. {
  7098. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  7099. return;
  7100. }
  7101. total_buy_price = sell_price * quantity;
  7102. item = new Item(master_item);
  7103. item->details.count = quantity;
  7104. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  7105. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  7106. lua_interface->SetLuaUserDataStale(item);
  7107. safe_delete(item);
  7108. }
  7109. else {
  7110. // Price not set in the merchant_inventory table, use the old method
  7111. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  7112. if (player->RemoveCoins(total_buy_price)) {
  7113. item->SetMaxSellValue(sell_price);
  7114. if (quantity > 1)
  7115. 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());
  7116. else
  7117. 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());
  7118. bool itemDeleted = false;
  7119. AddItem(item, &itemDeleted);
  7120. if(!itemDeleted) {
  7121. CheckPlayerQuestsItemUpdate(item);
  7122. if (item && total_available < 0xFF) {
  7123. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7124. SendBuyMerchantList();
  7125. }
  7126. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7127. PlayLotto(total_buy_price, item->details.item_id);
  7128. }
  7129. }
  7130. else {
  7131. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7132. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7133. PlaySound("buy_failed");
  7134. }
  7135. }
  7136. else {
  7137. // Price set in merchant_inventory table
  7138. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  7139. // TODO: need to add support for station cash
  7140. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  7141. // Check items
  7142. int16 item_quantity = 0;
  7143. // Default these to true in case price_item_id or price_item2_id was never set
  7144. bool hasItem1 = true;
  7145. bool hasItem2 = true;
  7146. Item* tempItem1 = 0;
  7147. Item* tempItem2 = 0;
  7148. if (ItemInfo->price_item_id != 0) {
  7149. // Same item for whatever reason lets add the quantities together
  7150. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  7151. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  7152. else
  7153. item_quantity = ItemInfo->price_item_qty;
  7154. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  7155. if (tempItem1) {
  7156. if (tempItem1->details.count < item_quantity)
  7157. hasItem1 = false;
  7158. }
  7159. else {
  7160. hasItem1 = false;
  7161. }
  7162. }
  7163. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  7164. // as item1 and we already checked for it so we can skip this check
  7165. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  7166. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  7167. if (tempItem2) {
  7168. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  7169. hasItem2 = false;
  7170. }
  7171. else {
  7172. hasItem2 = false;
  7173. }
  7174. }
  7175. // if we have every thing then remove the price and give the item
  7176. if (hasItem1 && hasItem2) {
  7177. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  7178. // TODO: station cash
  7179. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  7180. // so there is no need to send it more then that one time
  7181. if (tempItem1) {
  7182. if (tempItem1->details.count > item_quantity) {
  7183. tempItem1->details.count -= item_quantity;
  7184. tempItem1->save_needed = true;
  7185. }
  7186. else {
  7187. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  7188. player->item_list.DestroyItem(tempItem1->details.index);
  7189. }
  7190. }
  7191. if (tempItem2) {
  7192. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  7193. tempItem2->details.count -= ItemInfo->price_item2_qty;
  7194. tempItem2->save_needed = true;
  7195. }
  7196. else {
  7197. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  7198. player->item_list.DestroyItem(tempItem2->details.index);
  7199. }
  7200. }
  7201. // 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
  7202. player->RemoveCoins(ItemInfo->price_coins * quantity);
  7203. item->SetMaxSellValue(sell_price);
  7204. if (quantity > 1)
  7205. 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());
  7206. else
  7207. 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());
  7208. bool itemDeleted = false;
  7209. AddItem(item, &itemDeleted);
  7210. if(!itemDeleted) {
  7211. CheckPlayerQuestsItemUpdate(item);
  7212. if (item && total_available < 0xFF) {
  7213. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  7214. SendBuyMerchantList();
  7215. }
  7216. SendSellMerchantList();
  7217. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  7218. PlayLotto(total_buy_price, item->details.item_id);
  7219. }
  7220. }
  7221. else {
  7222. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7223. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7224. PlaySound("buy_failed");
  7225. }
  7226. }
  7227. else {
  7228. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  7229. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  7230. PlaySound("buy_failed");
  7231. }
  7232. }
  7233. }
  7234. }
  7235. }
  7236. }
  7237. void Client::RepairItem(int32 item_id) {
  7238. Spawn* spawn = GetMerchantTransaction();
  7239. if (spawn) {
  7240. Item* item = player->item_list.GetItemFromID(item_id);
  7241. if (!item)
  7242. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  7243. if (item) {
  7244. if(item->CheckFlag2(NO_REPAIR)) {
  7245. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  7246. PlaySound("buy_failed");
  7247. }
  7248. else {
  7249. int32 repair_cost = item->CalculateRepairCost();
  7250. if (player->RemoveCoins((int32)repair_cost)) {
  7251. item->generic_info.condition = 100;
  7252. item->save_needed = true;
  7253. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7254. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7255. QueuePacket(item->serialize(version, false, player));
  7256. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  7257. PlaySound("coin_cha_ching");
  7258. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7259. SendRepairList();
  7260. }
  7261. else {
  7262. string popup_text = "You do not have enough coin to repair ";
  7263. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  7264. popup_text.append(popup_item);
  7265. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7266. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  7267. PlaySound("buy_failed");
  7268. }
  7269. }
  7270. }
  7271. }
  7272. }
  7273. void Client::RepairAllItems() {
  7274. Spawn* spawn = GetMerchantTransaction();
  7275. if (spawn) {
  7276. vector<Item*>* repairable_items = GetRepairableItems();
  7277. if (repairable_items && repairable_items->size() > 0) {
  7278. vector<Item*>::iterator itr;
  7279. int64 total_cost = 0;
  7280. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  7281. total_cost += (*itr)->CalculateRepairCost();
  7282. if (player->RemoveCoins((int32)total_cost)) {
  7283. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  7284. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  7285. Item* item = *itr;
  7286. if (item) {
  7287. item->generic_info.condition = 100;
  7288. item->save_needed = true;
  7289. QueuePacket(item->serialize(version, false, player));
  7290. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  7291. }
  7292. }
  7293. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  7294. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  7295. PlaySound("coin_cha_ching");
  7296. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  7297. SendRepairList();
  7298. }
  7299. else {
  7300. string popup_text = "You do not have enough coin to repair all of your items. ";
  7301. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7302. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  7303. PlaySound("buy_failed");
  7304. }
  7305. }
  7306. safe_delete(repairable_items);
  7307. }
  7308. }
  7309. void Client::SendAchievementsList()
  7310. {
  7311. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  7312. map<int32, Achievement *>::iterator itr;
  7313. Achievement *achievement;
  7314. vector<AchievementRequirements *> *requirements = 0;
  7315. vector<AchievementRequirements *>::iterator itr2;
  7316. AchievementRequirements *requirement;
  7317. vector<AchievementRewards *> *rewards = 0;
  7318. vector<AchievementRewards *>::iterator itr3;
  7319. AchievementRewards *reward;
  7320. PacketStruct *packet;
  7321. int16 i = 0;
  7322. int16 j = 0;
  7323. int16 k = 0;
  7324. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  7325. return;
  7326. }
  7327. packet->setArrayLengthByName("num_achievements" , achievements->size());
  7328. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  7329. achievement = itr->second;
  7330. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  7331. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  7332. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  7333. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  7334. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  7335. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  7336. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  7337. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  7338. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  7339. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  7340. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  7341. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  7342. requirements = achievement->GetRequirements();
  7343. rewards = achievement->GetRewards();
  7344. j = 0;
  7345. k = 0;
  7346. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  7347. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  7348. requirement = *itr2;
  7349. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  7350. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  7351. j++;
  7352. }
  7353. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  7354. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  7355. reward = *itr3;
  7356. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  7357. k++;
  7358. }
  7359. i++;
  7360. }
  7361. //packet->PrintPacket();
  7362. EQ2Packet* data = packet->serialize();
  7363. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7364. safe_delete(packet);
  7365. safe_delete(data);
  7366. //DumpPacket(app);
  7367. QueuePacket(app);*/
  7368. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  7369. SendAchievementUpdate(true);
  7370. }
  7371. void Client::SendAchievementUpdate(bool first_login) {
  7372. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  7373. map<int32, AchievementUpdate*>::iterator itr;
  7374. AchievementUpdate* update;
  7375. vector<AchievementUpdateItems*>* update_items = 0;
  7376. vector<AchievementUpdateItems*>::iterator itr2;
  7377. AchievementUpdateItems* update_item;
  7378. int16 i = 0;
  7379. int16 j = 0;
  7380. PacketStruct* packet;
  7381. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  7382. return;
  7383. }
  7384. packet->setDataByName("unknown1", first_login ? 1 : 0);
  7385. packet->setArrayLengthByName("num_achievements", updates->size());
  7386. for (itr = updates->begin(); itr != updates->end(); itr++) {
  7387. update = itr->second;
  7388. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  7389. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  7390. update_items = update->GetUpdateItems();
  7391. j = 0;
  7392. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  7393. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  7394. update_item = *itr2;
  7395. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  7396. j++;
  7397. }
  7398. i++;
  7399. }
  7400. //packet->PrintPacket();
  7401. EQ2Packet* data = packet->serialize();
  7402. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  7403. safe_delete(packet);
  7404. safe_delete(data);
  7405. //DumpPacket(app);
  7406. QueuePacket(app);
  7407. }
  7408. void Client::SendBuyMerchantList(bool sell) {
  7409. Spawn* spawn = GetMerchantTransaction();
  7410. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7411. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  7412. if (items) {
  7413. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7414. if (packet) {
  7415. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  7416. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7417. packet->setArrayLengthByName("num_items", items->size());
  7418. vector<MerchantItemInfo>::iterator itr;
  7419. sint8 item_difficulty = 0;
  7420. int32 sell_price = 0;
  7421. int i = 0;
  7422. int tmp_level = 0;
  7423. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  7424. MerchantItemInfo ItemInfo = *itr;
  7425. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  7426. if (!item)
  7427. continue;
  7428. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7429. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7430. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7431. packet->setArrayDataByName("icon", item->details.icon, i);
  7432. if (item->generic_info.adventure_default_level > 0)
  7433. tmp_level = item->generic_info.adventure_default_level;
  7434. else
  7435. tmp_level = item->generic_info.tradeskill_default_level;
  7436. packet->setArrayDataByName("level", tmp_level, i);
  7437. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7438. packet->setArrayDataByName("tier", item->details.tier, i);
  7439. }
  7440. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7441. item_difficulty = player->GetArrowColor(tmp_level);
  7442. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7443. item_difficulty = ARROW_COLOR_WHITE;
  7444. sint64 overrideValue = 0;
  7445. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7446. item_difficulty = (sint8)overrideValue;
  7447. item_difficulty -= 6;
  7448. if (item_difficulty < 0)
  7449. item_difficulty *= -1;
  7450. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7451. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  7452. packet->setArrayDataByName("unknown5", 255, i);
  7453. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  7454. sint64 dispFlags = 0;
  7455. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  7456. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7457. std::string overrideValueStr;
  7458. // 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)
  7459. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  7460. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  7461. // If no price set in the merchant_inventory table then use the old method
  7462. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  7463. sell_price = (int32)(item->sell_price * multiplier);
  7464. packet->setArrayDataByName("price", sell_price, i);
  7465. }
  7466. else {
  7467. int8 count = 0;
  7468. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  7469. count++;
  7470. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  7471. count++;
  7472. if (count != 0) {
  7473. packet->setSubArrayLengthByName("num_tokens", count, i);
  7474. int8 index = 0;
  7475. Item* token = 0;
  7476. if (ItemInfo.price_item_id != 0) {
  7477. token = master_item_list.GetItem(ItemInfo.price_item_id);
  7478. if (item) {
  7479. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7480. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  7481. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  7482. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7483. }
  7484. token = 0;
  7485. index++;
  7486. }
  7487. if (ItemInfo.price_item2_id != 0) {
  7488. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  7489. if (item) {
  7490. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  7491. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  7492. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  7493. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  7494. }
  7495. }
  7496. }
  7497. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  7498. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  7499. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  7500. }
  7501. }
  7502. if (GetVersion() <= 546) {
  7503. //buy is 0 so dont need to set it
  7504. if (sell)
  7505. packet->setDataByName("type", 1);
  7506. }
  7507. else {
  7508. if (sell)
  7509. packet->setDataByName("type", 130);
  7510. else
  7511. packet->setDataByName("type", 2);
  7512. }
  7513. EQ2Packet* outapp = packet->serialize();
  7514. QueuePacket(outapp);
  7515. safe_delete(packet);
  7516. }
  7517. safe_delete(items);
  7518. }
  7519. else {
  7520. // Need to send an empty packet in the event there is no item list, otherwise the
  7521. // last item list sent to the player will show for this merchant
  7522. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7523. if (packet) {
  7524. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7525. if (GetVersion() <= 546) {
  7526. //buy is 0 so dont need to set it
  7527. if (sell)
  7528. packet->setDataByName("type", 1);
  7529. }
  7530. else {
  7531. if (sell)
  7532. packet->setDataByName("type", 130);
  7533. else
  7534. packet->setDataByName("type", 2);
  7535. }
  7536. EQ2Packet* outapp = packet->serialize();
  7537. QueuePacket(outapp);
  7538. safe_delete(packet);
  7539. }
  7540. }
  7541. }
  7542. }
  7543. void Client::SendSellMerchantList(bool sell) {
  7544. Spawn* spawn = GetMerchantTransaction();
  7545. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  7546. return;
  7547. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7548. map<int32, Item*>* items = player->GetItemList();
  7549. if (items) {
  7550. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7551. if (packet) {
  7552. vector<Item*> sellable_items;
  7553. map<int32, Item*>::iterator test_itr;
  7554. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  7555. bool isbagwithitems = false;
  7556. 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))
  7557. isbagwithitems = true;
  7558. 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))
  7559. sellable_items.push_back(test_itr->second);
  7560. }
  7561. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7562. packet->setArrayLengthByName("num_items", sellable_items.size());
  7563. vector<Item*>::iterator itr;
  7564. Item* item = 0;
  7565. sint8 item_difficulty = 0;
  7566. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  7567. int32 sell_price = 0;
  7568. Item* master_item = 0;
  7569. int i = 0;
  7570. int tmp_level = 0;
  7571. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  7572. item = *itr;
  7573. master_item = master_item_list.GetItem(item->details.item_id);
  7574. if (master_item)
  7575. sell_price = (int32)(master_item->sell_price * multiplier);
  7576. else
  7577. sell_price = 0;
  7578. if (sell_price > item->sell_price)
  7579. sell_price = item->sell_price;
  7580. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7581. string thename = item->name;
  7582. packet->setArrayDataByName("price", sell_price, i);
  7583. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  7584. int8 dispFlags = 0;
  7585. // only city merchants allow selling for status
  7586. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  7587. {
  7588. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  7589. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  7590. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  7591. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  7592. }
  7593. }
  7594. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  7595. {
  7596. if(GetVersion() < 1188)
  7597. 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
  7598. else
  7599. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  7600. }
  7601. if(item->no_sale)
  7602. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  7603. packet->setArrayDataByName("display_flags", dispFlags, i);
  7604. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7605. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  7606. packet->setArrayDataByName("stack_size", item->details.count, i);
  7607. packet->setArrayDataByName("icon", item->details.icon, i);
  7608. if (item->generic_info.adventure_default_level > 0)
  7609. tmp_level = item->generic_info.adventure_default_level;
  7610. else
  7611. tmp_level = item->generic_info.tradeskill_default_level;
  7612. packet->setArrayDataByName("level", item->details.recommended_level, i);
  7613. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7614. packet->setArrayDataByName("tier", item->details.tier, i);
  7615. }
  7616. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7617. item_difficulty = player->GetArrowColor(tmp_level);
  7618. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7619. item_difficulty = ARROW_COLOR_WHITE;
  7620. sint64 overrideValue = 0;
  7621. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  7622. item_difficulty = (sint8)overrideValue;
  7623. item_difficulty -= 6;
  7624. if (item_difficulty < 0)
  7625. item_difficulty *= -1;
  7626. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7627. if (item->details.count == 1)
  7628. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7629. else
  7630. packet->setArrayDataByName("quantity", item->details.count, i);
  7631. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7632. if (GetVersion() <= 1096)
  7633. packet->setArrayDataByName("description", item->description.c_str(), i);
  7634. }
  7635. if (GetVersion() <= 546) {
  7636. packet->setDataByName("type", 1);
  7637. }
  7638. else {
  7639. if (sell)
  7640. packet->setDataByName("type", 129);
  7641. else
  7642. packet->setDataByName("type", 1);
  7643. }
  7644. packet->setDataByName("unknown8a", 16256, 6);
  7645. packet->setDataByName("unknown8a", 16256, 10);
  7646. //packet->PrintPacket();
  7647. EQ2Packet* outapp = packet->serialize();
  7648. //DumpPacket(outapp);
  7649. QueuePacket(outapp);
  7650. safe_delete(packet);
  7651. }
  7652. safe_delete(items);
  7653. }
  7654. }
  7655. }
  7656. void Client::SendBuyBackList(bool sell) {
  7657. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  7658. return;
  7659. Spawn* spawn = GetMerchantTransaction();
  7660. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  7661. deque<BuyBackItem*>::iterator itr;
  7662. int i = 0;
  7663. Item* master_item = 0;
  7664. BuyBackItem* buyback = 0;
  7665. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7666. if (packet) {
  7667. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7668. packet->setArrayLengthByName("num_items", buy_back_items.size());
  7669. sint8 item_difficulty = 0;
  7670. MBuyBack.readlock(__FUNCTION__, __LINE__);
  7671. int tmp_level = 0;
  7672. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  7673. buyback = *itr;
  7674. master_item = master_item_list.GetItem(buyback->item_id);
  7675. if (master_item) {
  7676. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  7677. packet->setArrayDataByName("price", buyback->price, i);
  7678. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  7679. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  7680. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  7681. packet->setArrayDataByName("icon", master_item->details.icon, i);
  7682. if (master_item->generic_info.adventure_default_level > 0)
  7683. tmp_level = master_item->generic_info.adventure_default_level;
  7684. else
  7685. tmp_level = master_item->generic_info.tradeskill_default_level;
  7686. packet->setArrayDataByName("level", tmp_level, i);
  7687. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7688. packet->setArrayDataByName("tier", master_item->details.tier, i);
  7689. }
  7690. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  7691. item_difficulty = player->GetArrowColor(tmp_level);
  7692. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7693. item_difficulty = ARROW_COLOR_WHITE;
  7694. sint64 overrideValue = 0;
  7695. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  7696. item_difficulty = (sint8)overrideValue;
  7697. item_difficulty -= 6;
  7698. if (item_difficulty < 0)
  7699. item_difficulty *= -1;
  7700. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7701. sint64 dispFlags = 0;
  7702. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  7703. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  7704. if (buyback->quantity == 1)
  7705. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7706. else
  7707. packet->setArrayDataByName("quantity", buyback->quantity, i);
  7708. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  7709. if (GetVersion() <= 1096)
  7710. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  7711. }
  7712. }
  7713. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  7714. if (sell)
  7715. packet->setDataByName("type", 640);
  7716. else
  7717. packet->setDataByName("type", 512);
  7718. EQ2Packet* outapp = packet->serialize();
  7719. // DumpPacket(outapp);
  7720. QueuePacket(outapp);
  7721. safe_delete(packet);
  7722. }
  7723. }
  7724. }
  7725. void Client::SendRepairList() {
  7726. Spawn* spawn = GetMerchantTransaction();
  7727. if (spawn) {
  7728. vector<Item*>* repairable_items = GetRepairableItems();
  7729. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7730. if (packet) {
  7731. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7732. packet->setArrayLengthByName("num_items", repairable_items->size());
  7733. Item* item = 0;
  7734. sint8 item_difficulty = 0;
  7735. int32 i = 0;
  7736. vector<Item*>::iterator itr;
  7737. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7738. item = *itr;
  7739. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7740. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7741. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7742. packet->setArrayDataByName("stack_size", item->details.count, i);
  7743. packet->setArrayDataByName("icon", item->details.icon, i);
  7744. /*if (item->generic_info.adventure_default_level > 0)
  7745. tmp_level = item->generic_info.adventure_default_level;
  7746. else
  7747. tmp_level = item->generic_info.tradeskill_default_level;
  7748. packet->setArrayDataByName("level", tmp_level, i);*/
  7749. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7750. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7751. packet->setArrayDataByName("tier", item->details.tier, i);
  7752. }
  7753. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7754. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7755. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7756. item_difficulty = ARROW_COLOR_WHITE;
  7757. item_difficulty -= 6;
  7758. if (item_difficulty < 0)
  7759. item_difficulty *= -1;
  7760. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7761. if (item->details.count == 1)
  7762. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7763. else
  7764. packet->setArrayDataByName("quantity", item->details.count, i);
  7765. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7766. if (GetVersion() <= 1096)
  7767. packet->setArrayDataByName("description", item->description.c_str(), i);
  7768. }
  7769. if (GetVersion() <= 546) {
  7770. packet->setDataByName("type", 112);
  7771. }
  7772. else {
  7773. packet->setDataByName("type", 96);
  7774. }
  7775. EQ2Packet* outapp = packet->serialize();
  7776. //DumpPacket(outapp);
  7777. QueuePacket(outapp);
  7778. /*if (GetVersion() <= 546) {
  7779. packet->setDataByName("type", 16);
  7780. EQ2Packet* outapp2 = packet->serialize();
  7781. QueuePacket(outapp2);
  7782. }*/
  7783. safe_delete(packet);
  7784. }
  7785. safe_delete(repairable_items);
  7786. }
  7787. }
  7788. void Client::ShowLottoWindow() {
  7789. Spawn* spawn = GetMerchantTransaction();
  7790. if (spawn) {
  7791. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7792. if (!item_id)
  7793. {
  7794. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7795. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7796. return;
  7797. }
  7798. else if (item_id == 0)
  7799. {
  7800. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7801. return;
  7802. }
  7803. Item* item = master_item_list.GetItem(item_id);
  7804. if (!item) {
  7805. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7806. return;
  7807. }
  7808. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7809. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7810. if (packet) {
  7811. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7812. packet->setArrayLengthByName("num_items", 1);
  7813. packet->setArrayDataByName("item_name", item->name.c_str());
  7814. packet->setArrayDataByName("price", item->sell_price);
  7815. packet->setArrayDataByName("item_id", item->details.item_id);
  7816. packet->setArrayDataByName("stack_size", item->details.count);
  7817. packet->setArrayDataByName("icon", item->details.icon);
  7818. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7819. if(rule_manager.GetGlobalRule(R_World, DisplayItemTiers)->GetBool()) {
  7820. packet->setArrayDataByName("tier", item->details.tier);
  7821. }
  7822. packet->setArrayDataByName("item_id2", item->details.item_id);
  7823. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7824. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7825. item_difficulty = ARROW_COLOR_WHITE;
  7826. item_difficulty -= 6;
  7827. if (item_difficulty < 0)
  7828. item_difficulty *= -1;
  7829. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7830. //if(item->details.count == 1)
  7831. packet->setArrayDataByName("quantity", 0xFFFF);
  7832. //else
  7833. // packet->setArrayDataByName("quantity", item->details.count);
  7834. packet->setArrayDataByName("stack_size2", item->details.count);
  7835. packet->setArrayDataByName("description", item->description.c_str());
  7836. if (GetVersion() <= 546) {
  7837. packet->setDataByName("type", 128);
  7838. }
  7839. else {
  7840. packet->setDataByName("type", 0x00000102);
  7841. }
  7842. QueuePacket(packet->serialize());
  7843. safe_delete(packet);
  7844. }
  7845. }
  7846. }
  7847. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7848. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7849. if (packet) {
  7850. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7851. int32 rolls[6] = { 0 };
  7852. int32 lottery_digits[6] = { 0 };
  7853. int8 num_matches = 0;
  7854. int64 jackpot = 0;
  7855. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7856. if (!item) {
  7857. return;
  7858. }
  7859. database.DeleteItem(GetCharacterID(), item, 0);
  7860. GetPlayer()->item_list.RemoveItem(item, true);
  7861. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7862. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7863. if (!winning_numbers) {
  7864. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7865. variables.AddVariable(winning_numbers);
  7866. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7867. }
  7868. if (strlen(winning_numbers->GetValue()) != 12) {
  7869. winning_numbers->SetValue("231205182236");
  7870. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7871. }
  7872. try {
  7873. for (int32 i = 0; i < 12; i += 2) {
  7874. char num[4];
  7875. strncpy(num, winning_numbers->GetValue() + i, 2);
  7876. lottery_digits[i / 2] = atoi(num);
  7877. }
  7878. }
  7879. catch (...) {
  7880. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7881. return;
  7882. }
  7883. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7884. if (!jackpot_var) {
  7885. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7886. variables.AddVariable(jackpot_var);
  7887. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7888. }
  7889. try {
  7890. jackpot = atoul(jackpot_var->GetValue());
  7891. if (jackpot < 10000)
  7892. jackpot = 10000;
  7893. }
  7894. catch (...) {
  7895. jackpot = 10000;
  7896. }
  7897. char new_jackpot[128] = { 0 };
  7898. sprintf(new_jackpot, "%llu", jackpot + price);
  7899. jackpot_var->SetValue(new_jackpot);
  7900. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7901. world.PickRandomLottoDigits(rolls);
  7902. packet->setDataByName("roll_digit1", rolls[0]);
  7903. packet->setDataByName("roll_digit2", rolls[1]);
  7904. packet->setDataByName("roll_digit3", rolls[2]);
  7905. packet->setDataByName("roll_digit4", rolls[3]);
  7906. packet->setDataByName("roll_digit5", rolls[4]);
  7907. packet->setDataByName("roll_digit6", rolls[5]);
  7908. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7909. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7910. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7911. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7912. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7913. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7914. QueuePacket(packet->serialize());
  7915. safe_delete(packet);
  7916. for (int32 i = 0; i < 6; i++) {
  7917. for (int32 j = 0; j < 6; j++) {
  7918. if (rolls[i] == lottery_digits[j]) {
  7919. num_matches++;
  7920. break;
  7921. }
  7922. }
  7923. }
  7924. char new_jackpot_str[16];
  7925. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7926. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7927. if (num_matches == 6) {
  7928. world.PickRandomLottoDigits(lottery_digits);
  7929. for (int32 i = 0; i < 12; i += 2)
  7930. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7931. winning_numbers->SetValue(new_jackpot_str);
  7932. jackpot_var->SetValue("10000");
  7933. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7934. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7935. }
  7936. }
  7937. }
  7938. void Client::SendGuildCreateWindow() {
  7939. if (GetVersion() <= 546) {
  7940. SimpleMessage(0, "Not implemented on this client...yet?");
  7941. }
  7942. else {
  7943. Spawn* spawn = GetPlayer()->GetTarget();
  7944. if (spawn) {
  7945. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7946. if (packet) {
  7947. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7948. packet->setArrayLengthByName("num_items", 0);
  7949. packet->setDataByName("type", 0x00008000);
  7950. QueuePacket(packet->serialize());
  7951. safe_delete(packet);
  7952. }
  7953. }
  7954. }
  7955. }
  7956. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7957. BuyBackItem* item = new BuyBackItem;
  7958. item->item_id = item_id;
  7959. item->unique_id = unique_id;
  7960. item->price = price;
  7961. item->quantity = quantity;
  7962. item->save_needed = save_needed;
  7963. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7964. buy_back_items.push_back(item);
  7965. if (buy_back_items.size() > 10) {
  7966. safe_delete(buy_back_items.front());
  7967. buy_back_items.pop_front();
  7968. }
  7969. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7970. }
  7971. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7972. return &buy_back_items;
  7973. }
  7974. vector<Item*>* Client::GetRepairableItems() {
  7975. vector<Item*>* repairable_items = new vector<Item*>;
  7976. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7977. map<int32, Item*>* items = player->GetItemList();
  7978. if (equipped_items && equipped_items->size() > 0) {
  7979. for (int32 i = 0; i < equipped_items->size(); i++) {
  7980. Item* item = equipped_items->at(i);
  7981. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  7982. repairable_items->push_back(item);
  7983. }
  7984. }
  7985. if (items && items->size() > 0) {
  7986. map<int32, Item*>::iterator itr;
  7987. for (itr = items->begin(); itr != items->end(); itr++) {
  7988. Item* item = itr->second;
  7989. if (item && !item->CheckFlag2(NO_REPAIR) && item->generic_info.condition < 100)
  7990. repairable_items->push_back(item);
  7991. }
  7992. }
  7993. safe_delete(equipped_items);
  7994. safe_delete(items);
  7995. return repairable_items;
  7996. }
  7997. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  7998. if(type == NO_EFFECT_TYPE)
  7999. return nullptr;
  8000. vector<Item*>* return_items = new vector<Item*>;
  8001. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  8002. map<int32, Item*>* items = player->GetItemList();
  8003. if (equipped_items && equipped_items->size() > 0) {
  8004. for (int32 i = 0; i < equipped_items->size(); i++) {
  8005. Item* item = equipped_items->at(i);
  8006. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8007. return_items->push_back(item);
  8008. }
  8009. }
  8010. if (items && items->size() > 0) {
  8011. map<int32, Item*>::iterator itr;
  8012. for (itr = items->begin(); itr != items->end(); itr++) {
  8013. Item* item = itr->second;
  8014. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  8015. return_items->push_back(item);
  8016. }
  8017. }
  8018. safe_delete(equipped_items);
  8019. safe_delete(items);
  8020. return return_items;
  8021. }
  8022. void Client::SendMailList() {
  8023. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8024. if (kiosk_id > 0) {
  8025. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  8026. if (p) {
  8027. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  8028. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  8029. int32 i = 0;
  8030. p->setDataByName("kiosk_id", kiosk_id);
  8031. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  8032. while (itr.Next()) {
  8033. Mail* mail = itr->second;
  8034. p->setArrayDataByName("mail_id", mail->mail_id, i);
  8035. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  8036. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  8037. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  8038. p->setArrayDataByName("already_read", mail->already_read, i);
  8039. if(mail->expire_time)
  8040. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  8041. else
  8042. p->setArrayDataByName("mail_deletion", 0, i);
  8043. p->setArrayDataByName("mail_type", mail->mail_type, i);
  8044. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  8045. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  8046. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  8047. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  8048. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  8049. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  8050. //p->setArrayDataByName("unknown2", 0, i);
  8051. bool successItemAdd = false;
  8052. if(mail->stack || mail->char_item_id)
  8053. {
  8054. Item* item = master_item_list.GetItem(mail->char_item_id);
  8055. if(item)
  8056. {
  8057. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8058. if (version < 860)
  8059. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  8060. else if (version < 1193)
  8061. p->setItemArrayDataByName("item", item, player, i);
  8062. else
  8063. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  8064. successItemAdd = true;
  8065. }
  8066. }
  8067. if(!successItemAdd)
  8068. {
  8069. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  8070. p->setArrayDataByName("end_tag3", 0xFF, i);
  8071. }
  8072. i++;
  8073. }
  8074. // GMs send mail for free!
  8075. if (GetAdminStatus() > 0)
  8076. {
  8077. p->setDataByName("postage_cost", 0);
  8078. p->setDataByName("attachment_cost", 0);
  8079. }
  8080. else
  8081. {
  8082. p->setDataByName("postage_cost", 10);
  8083. p->setDataByName("attachment_cost", 50);
  8084. }
  8085. p->setDataByName("unknown3", 0x01F4);
  8086. p->setDataByName("unknown4", 0x01000000);
  8087. EQ2Packet* pack = p->serialize();
  8088. //DumpPacket(pack);
  8089. //p->PrintPacket();
  8090. QueuePacket(pack);
  8091. safe_delete(p);
  8092. }
  8093. }
  8094. else
  8095. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8096. }
  8097. void Client::DisplayMailMessage(int32 mail_id) {
  8098. Mail* mail = player->GetMail(mail_id);
  8099. if (mail) {
  8100. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  8101. if (kiosk_id > 0) {
  8102. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8103. if (update) {
  8104. update->setDataByName("action", 0x03);
  8105. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  8106. update->setDataByName("packetsubtype", 0xFF);
  8107. QueuePacket(update->serialize());
  8108. safe_delete(update);
  8109. }
  8110. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  8111. if (packet) {
  8112. packet->setDataByName("kiosk_id", kiosk_id);
  8113. packet->setDataByName("mail_id", mail->mail_id);
  8114. packet->setDataByName("player_to_id", mail->player_to_id);
  8115. packet->setDataByName("player_from", mail->player_from.c_str());
  8116. packet->setDataByName("subject", mail->subject.c_str());
  8117. packet->setDataByName("mail_body", mail->mail_body.c_str());
  8118. packet->setDataByName("unknown1", 1);
  8119. packet->setDataByName("unknown2", 0);
  8120. packet->setDataByName("lock_report_button", 1);
  8121. packet->setDataByName("unknown3", 0xFFFFFFFF);
  8122. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  8123. packet->setDataByName("coin_copper", mail->coin_copper);
  8124. packet->setDataByName("coin_silver", mail->coin_silver);
  8125. packet->setDataByName("coin_gold", mail->coin_gold);
  8126. packet->setDataByName("coin_plat", mail->coin_plat);
  8127. if(mail->stack || mail->char_item_id)
  8128. {
  8129. Item* item = master_item_list.GetItem(mail->char_item_id);
  8130. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  8131. if (version < 860)
  8132. packet->setItemByName("item", item, player, 0, -1);
  8133. else if (version < 1193)
  8134. packet->setItemByName("item", item, player, 0, 0);
  8135. else
  8136. packet->setItemByName("item", item, player, 0, 2);
  8137. }
  8138. else
  8139. {
  8140. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8141. packet->setDataByName("end_tag3", 0xFF);
  8142. }
  8143. mail->already_read = true;
  8144. mail->save_needed = true;
  8145. EQ2Packet* pack = packet->serialize();
  8146. QueuePacket(pack);
  8147. safe_delete(packet);
  8148. // trying to update this causes the window not to open
  8149. //SendMailList();
  8150. }
  8151. }
  8152. else
  8153. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8154. }
  8155. }
  8156. /* 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
  8157. packet back to the client before the mail actually sent. */
  8158. void Client::HandleSentMail(EQApplicationPacket* app) {
  8159. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  8160. if (packet) {
  8161. if(packet->LoadPacketData(app->pBuffer, app->size)) {
  8162. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  8163. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  8164. vector<int32>* ids = 0;
  8165. MMailWindowMutex.lock();
  8166. if (reply_packet) {
  8167. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  8168. if (player_to.length() == 0)
  8169. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  8170. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  8171. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  8172. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  8173. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  8174. else {
  8175. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  8176. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  8177. ids = database.GetAllPlayerIDs();
  8178. else
  8179. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  8180. }
  8181. else {
  8182. ids = new vector<int32>;
  8183. ids->push_back(database.GetCharacterID(player_to.c_str()));
  8184. }
  8185. if (ids) {
  8186. for (int32 i = 0; i < ids->size(); i++) {
  8187. int32 player_to_id = ids->at(i);
  8188. if (player_to_id > 0) {
  8189. reply_type = MAIL_SEND_RESULT_SUCCESS;
  8190. Mail* mail = new Mail;
  8191. mail->mail_id = 0;
  8192. mail->player_to_id = player_to_id;
  8193. mail->player_from = string(GetPlayer()->GetName());
  8194. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  8195. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  8196. mail->already_read = 0;
  8197. mail->mail_type = MAIL_TYPE_REGULAR;
  8198. mail->coin_copper = mail_window.coin_copper;
  8199. mail->coin_silver = mail_window.coin_silver;
  8200. mail->coin_gold = mail_window.coin_gold;
  8201. mail->coin_plat = mail_window.coin_plat;
  8202. mail->char_item_id = mail_window.char_item_id;
  8203. mail->stack = mail_window.stack;
  8204. // GM's send mail for free!
  8205. if (GetAdminStatus() > 0)
  8206. {
  8207. mail->postage_cost = 0;
  8208. mail->attachment_cost = 0;
  8209. }
  8210. else
  8211. {
  8212. mail->postage_cost = 10;
  8213. mail->attachment_cost = 50;
  8214. }
  8215. mail->time_sent = Timer::GetUnixTimeStamp();
  8216. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  8217. mail->save_needed = false;
  8218. database.SavePlayerMail(mail);
  8219. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  8220. if (to_client) {
  8221. to_client->GetPlayer()->AddMail(mail);
  8222. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  8223. string popup_text = "You have unread mail!";
  8224. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  8225. }
  8226. else {
  8227. // don't need the pointer the client doesn't exist currently
  8228. safe_delete(mail);
  8229. }
  8230. ResetSendMail(false, false);
  8231. }
  8232. else
  8233. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  8234. }
  8235. }
  8236. }
  8237. string players_to = "";
  8238. if (ids) {
  8239. for (int32 i = 0; i < ids->size(); i++) {
  8240. if (ids->at(i) != 0)
  8241. players_to.append(database.GetCharacterName(ids->at(i)));
  8242. if (i < (ids->size() - 1))
  8243. players_to.append(", ");
  8244. }
  8245. }
  8246. reply_packet->setDataByName("player_to", players_to.c_str());
  8247. reply_packet->setDataByName("reply_type", reply_type);
  8248. QueuePacket(reply_packet->serialize());
  8249. safe_delete(reply_packet);
  8250. safe_delete(ids);
  8251. }
  8252. MMailWindowMutex.unlock();
  8253. }
  8254. safe_delete(packet);
  8255. }
  8256. }
  8257. void Client::DeleteMail(int32 mail_id, bool from_database) {
  8258. player->DeleteMail(mail_id, from_database);
  8259. }
  8260. bool Client::AddMailItem(Item* item)
  8261. {
  8262. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  8263. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  8264. return false;
  8265. }
  8266. bool ret = false;
  8267. if (GetMailTransaction()) {
  8268. MMailWindowMutex.lock();
  8269. if(mail_window.char_item_id == 0)
  8270. {
  8271. mail_window.item = item;
  8272. mail_window.char_item_id = item->details.item_id;
  8273. mail_window.stack = item->details.count;
  8274. ret = true;
  8275. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8276. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8277. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8278. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8279. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8280. if(item)
  8281. {
  8282. packet->setDataByName("stack", mail_window.stack);
  8283. item->stack_count = mail_window.stack;
  8284. if (version < 860)
  8285. packet->setItemByName("item", item, player, 0, -1);
  8286. else if (version < 1193)
  8287. packet->setItemByName("item", item, player, 0, 0);
  8288. else
  8289. packet->setItemByName("item", item, player, 0, 2);
  8290. }
  8291. else
  8292. {
  8293. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8294. packet->setDataByName("end_tag3", 0xFF);
  8295. }
  8296. QueuePacket(packet->serialize());
  8297. }
  8298. MMailWindowMutex.unlock();
  8299. }
  8300. return ret;
  8301. }
  8302. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8303. bool ret = false;
  8304. if (GetMailTransaction()) {
  8305. MMailWindowMutex.lock();
  8306. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8307. if (packet) {
  8308. if (copper > 0) {
  8309. if (player->RemoveCoins(copper)) {
  8310. mail_window.coin_copper += copper;
  8311. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  8312. ret = true;
  8313. }
  8314. }
  8315. else if (silver > 0) {
  8316. if (player->RemoveCoins(silver * 100)) {
  8317. mail_window.coin_silver += silver;
  8318. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  8319. ret = true;
  8320. }
  8321. }
  8322. else if (gold > 0) {
  8323. if (player->RemoveCoins(gold * 10000)) {
  8324. mail_window.coin_gold += gold;
  8325. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  8326. ret = true;
  8327. }
  8328. }
  8329. else if (plat > 0) {
  8330. if (player->RemoveCoins(plat * 1000000)) {
  8331. mail_window.coin_plat += plat;
  8332. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  8333. ret = true;
  8334. }
  8335. }
  8336. if (ret) {
  8337. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8338. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8339. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8340. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8341. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  8342. if(item)
  8343. {
  8344. packet->setDataByName("stack", mail_window.stack);
  8345. item->stack_count = mail_window.stack;
  8346. if (version < 860)
  8347. packet->setItemByName("item", item, player, 0, -1);
  8348. else if (version < 1193)
  8349. packet->setItemByName("item", item, player, 0, 0);
  8350. else
  8351. packet->setItemByName("item", item, player, 0, 2);
  8352. }
  8353. else
  8354. {
  8355. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  8356. packet->setDataByName("end_tag3", 0xFF);
  8357. }
  8358. //packet->PrintPacket();
  8359. QueuePacket(packet->serialize());
  8360. }
  8361. else
  8362. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  8363. safe_delete(packet);
  8364. }
  8365. MMailWindowMutex.unlock();
  8366. }
  8367. else
  8368. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8369. return ret;
  8370. }
  8371. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  8372. bool ret = false;
  8373. if (GetMailTransaction()) {
  8374. MMailWindowMutex.lock();
  8375. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8376. if (packet) {
  8377. if (copper > 0) {
  8378. player->AddCoins(copper);
  8379. mail_window.coin_copper -= copper;
  8380. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  8381. ret = true;
  8382. }
  8383. else if (silver > 0) {
  8384. player->AddCoins(silver * 100);
  8385. mail_window.coin_silver -= silver;
  8386. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  8387. ret = true;
  8388. }
  8389. else if (gold > 0) {
  8390. player->AddCoins(gold * 10000);
  8391. mail_window.coin_gold -= gold;
  8392. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  8393. ret = true;
  8394. }
  8395. else if (plat > 0) {
  8396. player->AddCoins(plat * 1000000);
  8397. mail_window.coin_plat -= plat;
  8398. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  8399. ret = true;
  8400. }
  8401. if (ret) {
  8402. packet->setDataByName("coin_copper", mail_window.coin_copper);
  8403. packet->setDataByName("coin_silver", mail_window.coin_silver);
  8404. packet->setDataByName("coin_gold", mail_window.coin_gold);
  8405. packet->setDataByName("coin_plat", mail_window.coin_plat);
  8406. packet->setDataByName("stack", 0);
  8407. packet->setDataByName("packettype", 0x2BFE);
  8408. packet->setDataByName("packetsubtype", 0xFF);
  8409. packet->setDataByName("unknown2", 0);
  8410. QueuePacket(packet->serialize());
  8411. }
  8412. safe_delete(packet);
  8413. }
  8414. MMailWindowMutex.unlock();
  8415. }
  8416. else
  8417. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8418. return ret;
  8419. }
  8420. void Client::TakeMailAttachments(int32 mail_id) {
  8421. if (GetMailTransaction()) {
  8422. Mail* mail = player->GetMail(mail_id);
  8423. if (mail) {
  8424. int64 amount = 0;
  8425. if (mail->coin_copper > 0) {
  8426. amount += mail->coin_copper;
  8427. mail->coin_copper = 0;
  8428. }
  8429. if (mail->coin_silver > 0) {
  8430. amount += mail->coin_silver * 100;
  8431. mail->coin_silver = 0;
  8432. }
  8433. if (mail->coin_gold > 0) {
  8434. amount += mail->coin_gold * 10000;
  8435. mail->coin_gold = 0;
  8436. }
  8437. if (mail->coin_plat > 0) {
  8438. amount += mail->coin_plat * 1000000;
  8439. mail->coin_plat = 0;
  8440. }
  8441. if (mail->char_item_id > 0) {
  8442. AddItem(mail->char_item_id, mail->stack);
  8443. mail->char_item_id = 0;
  8444. mail->stack = 0;
  8445. }
  8446. /* 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
  8447. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  8448. find it in any packet logs.*/
  8449. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  8450. if (packet) {
  8451. packet->setDataByName("unknown", 0x03);
  8452. packet->setDataByName("coin_copper", mail->coin_copper);
  8453. packet->setDataByName("coin_silver", mail->coin_silver);
  8454. packet->setDataByName("coin_gold", mail->coin_gold);
  8455. packet->setDataByName("coin_plat", mail->coin_plat);
  8456. packet->setDataByName("stack", 0);
  8457. packet->setDataByName("packettype", 0x2BFE);
  8458. packet->setDataByName("packetsubtype", 0xFF);
  8459. packet->setDataByName("unknown2", 0);
  8460. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  8461. DumpPacket(packet->serialize());
  8462. QueuePacket(packet->serialize());
  8463. safe_delete(packet);
  8464. }*/
  8465. database.SavePlayerMail(mail);
  8466. if (amount > 0)
  8467. player->AddCoins(amount);
  8468. SendMailList();
  8469. }
  8470. }
  8471. else
  8472. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  8473. }
  8474. void Client::ResetSendMail(bool cancel, bool needslock) {
  8475. if(cancel && mail_transaction)
  8476. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  8477. if(needslock)
  8478. MMailWindowMutex.lock();
  8479. if(cancel)
  8480. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  8481. if(!cancel)
  8482. mail_transaction = 0;
  8483. mail_window.coin_copper = 0;
  8484. mail_window.coin_silver = 0;
  8485. mail_window.coin_gold = 0;
  8486. mail_window.coin_plat = 0;
  8487. mail_window.char_item_id = 0;
  8488. mail_window.stack = 0;
  8489. if(mail_window.item){
  8490. if(cancel)
  8491. AddItem(mail_window.item);
  8492. else
  8493. safe_delete(mail_window.item);
  8494. }
  8495. mail_window.item = nullptr;
  8496. if(needslock)
  8497. MMailWindowMutex.unlock();
  8498. }
  8499. bool Client::GateAllowed() {
  8500. ZoneServer* zone = GetCurrentZone();
  8501. if (zone){
  8502. bool cangate = zone->GetCanGate();
  8503. return cangate;
  8504. }
  8505. return false;
  8506. }
  8507. bool Client::BindAllowed() {
  8508. ZoneServer* zone = GetCurrentZone();
  8509. if (zone){
  8510. bool canbind = zone->GetCanBind();
  8511. return canbind;
  8512. }
  8513. return false;
  8514. }
  8515. bool Client::Bind() {
  8516. int canbind = BindAllowed();
  8517. if(canbind == 0) {
  8518. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  8519. return false;
  8520. }
  8521. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  8522. player->GetPlayerInfo()->SetBindX(player->GetX());
  8523. player->GetPlayerInfo()->SetBindY(player->GetY());
  8524. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  8525. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  8526. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  8527. return true;
  8528. }
  8529. bool Client::Gate(bool is_spell) {
  8530. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  8531. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  8532. return false;
  8533. }
  8534. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  8535. if (zone) {
  8536. int cangate = GateAllowed();
  8537. if(cangate == 0) {
  8538. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  8539. return false;
  8540. }
  8541. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  8542. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  8543. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  8544. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  8545. Zone(zone, false, is_spell);
  8546. return true;
  8547. }
  8548. return false;
  8549. }
  8550. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  8551. if (!destinations || !spawn) {
  8552. return;
  8553. }
  8554. bool has_map = false;
  8555. if (transport_id > 0)
  8556. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  8557. transport_spawn = spawn;
  8558. vector<TransportDestination*> transport_list;
  8559. vector<TransportDestination*>::iterator itr;
  8560. TransportDestination* destination = 0;
  8561. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  8562. destination = *itr;
  8563. 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)))
  8564. transport_list.push_back(destination);
  8565. }
  8566. if (transport_list.size() == 0 && destination) {
  8567. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8568. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8569. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8570. else
  8571. {
  8572. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8573. if (app)
  8574. QueuePacket(app);
  8575. }
  8576. }
  8577. else {
  8578. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8579. // determine if this is an instanced zone that already exists
  8580. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  8581. if (instance_zone || new_zone) {
  8582. GetPlayer()->SetX(destination->destination_x);
  8583. GetPlayer()->SetY(destination->destination_y);
  8584. GetPlayer()->SetZ(destination->destination_z);
  8585. GetPlayer()->SetHeading(destination->destination_heading);
  8586. if (instance_zone)
  8587. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  8588. else
  8589. Zone(new_zone, false, is_spell);
  8590. }
  8591. }
  8592. if (destination->message.length() > 0)
  8593. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8594. }
  8595. else if (transport_list.size() > 0) {
  8596. if (!spawn->IsSoundsDisabled())
  8597. PlaySound("mariner_bell");
  8598. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  8599. if (packet) {
  8600. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8601. // Put all the destinations the player can go in a new vector
  8602. vector<TransportDestination*> destinations;
  8603. for (int32 i = 0; i < transport_list.size(); i++) {
  8604. destination = transport_list.at(i);
  8605. // Check min level
  8606. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  8607. continue;
  8608. // Check max level
  8609. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  8610. continue;
  8611. // Check quest complete
  8612. if (destination->req_quest_complete > 0 && GetPlayer()->HasQuestBeenCompleted(destination->req_quest_complete) == 0)
  8613. continue;
  8614. // Check req quest and step
  8615. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  8616. continue;
  8617. // 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
  8618. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  8619. packet->setDataByName("current_zone", destination->display_name.c_str());
  8620. packet->setDataByName("current_map_x", destination->map_x);
  8621. packet->setDataByName("current_map_y", destination->map_y);
  8622. }
  8623. else {
  8624. destinations.push_back(destination);
  8625. }
  8626. }
  8627. // Use the new vector to create the packet
  8628. destination = 0;
  8629. packet->setArrayLengthByName("num_destinations", destinations.size());
  8630. for (int32 i = 0; i < destinations.size(); i++) {
  8631. destination = destinations.at(i);
  8632. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  8633. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  8634. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  8635. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  8636. packet->setArrayDataByName("cost", destination->cost, i);
  8637. if (has_map) {
  8638. packet->setArrayDataByName("map_x", destination->map_x, i);
  8639. packet->setArrayDataByName("map_y", destination->map_y, i);
  8640. }
  8641. }
  8642. if (has_map)
  8643. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  8644. EQ2Packet* app = packet->serialize();
  8645. //DumpPacket(app);
  8646. if (destinations.size() > 0)
  8647. QueuePacket(app);
  8648. safe_delete(packet);
  8649. }
  8650. }
  8651. }
  8652. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  8653. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  8654. if (packet) {
  8655. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  8656. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  8657. int32 unique_id = packet->getType_int32_ByName("unique_id");
  8658. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  8659. int32 cost = packet->getType_int32_ByName("cost");
  8660. vector<TransportDestination*> destinations;
  8661. TransportDestination* destination = 0;
  8662. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  8663. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  8664. vector<TransportDestination*>::iterator itr;
  8665. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  8666. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  8667. destination = *itr;
  8668. break;
  8669. }
  8670. }
  8671. SetTemporaryTransportID(0);
  8672. if (!destination)
  8673. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  8674. else {
  8675. if (cost == 0 || player->RemoveCoins(cost)) {
  8676. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  8677. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  8678. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  8679. else
  8680. {
  8681. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  8682. if (outapp)
  8683. QueuePacket(outapp);
  8684. }
  8685. }
  8686. else {
  8687. GetPlayer()->SetX(destination->destination_x);
  8688. GetPlayer()->SetY(destination->destination_y);
  8689. GetPlayer()->SetZ(destination->destination_z);
  8690. GetPlayer()->SetHeading(destination->destination_heading);
  8691. // Test if where we're going is an Instanced zone
  8692. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  8693. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  8694. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  8695. Zone(new_zone, false);
  8696. }
  8697. }
  8698. if (destination->message.length() > 0)
  8699. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  8700. }
  8701. else
  8702. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  8703. }
  8704. }
  8705. safe_delete(packet);
  8706. }
  8707. }
  8708. void Client::SendNewSpells(int8 class_id) {
  8709. if (class_id > 0) {
  8710. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  8711. AddSendNewSpells(spells);
  8712. safe_delete(spells);
  8713. }
  8714. }
  8715. void Client::SendNewTSSpells(int8 class_id) {
  8716. if (class_id > 0) {
  8717. vector<Spell*>* spells = master_spell_list.GetSpellListByTradeskillClass(class_id, player->GetLevel(), 1);
  8718. AddSendNewSpells(spells);
  8719. safe_delete(spells);
  8720. }
  8721. }
  8722. void Client::AddSendNewSpells(vector<Spell*>* spells) {
  8723. Spell* spell = 0;
  8724. bool send_updates = false;
  8725. vector<Spell*>::iterator itr;
  8726. for (itr = spells->begin(); itr != spells->end(); itr++) {
  8727. spell = *itr;
  8728. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  8729. send_updates = true;
  8730. SendSpellUpdate(spell);
  8731. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  8732. player->UnlockSpell(spell);
  8733. }
  8734. }
  8735. if (send_updates) {
  8736. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  8737. if (outapp)
  8738. QueuePacket(outapp);
  8739. }
  8740. }
  8741. void Client::SetItemSearch(vector<Item*>* items) {
  8742. if (items) {
  8743. safe_delete(search_items);
  8744. search_items = items;
  8745. }
  8746. }
  8747. vector<Item*>* Client::GetSearchItems() {
  8748. return search_items;
  8749. }
  8750. void Client::SearchStore(int32 page) {
  8751. if (search_items) {
  8752. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8753. if (packet) {
  8754. int32 x = page * 8;
  8755. if (search_items->size() > 8) {
  8756. if ((search_items->size() - x) > 8)
  8757. packet->setArrayLengthByName("num_items", 8);
  8758. else
  8759. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8760. }
  8761. else
  8762. packet->setArrayLengthByName("num_items", search_items->size());
  8763. if (search_items->size() > 0) {
  8764. packet->setArrayLengthByName("num_sellers", 1);
  8765. packet->setArrayDataByName("seller_seller_id", 1);
  8766. packet->setDataByName("per_page", 8);
  8767. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8768. packet->setDataByName("page", page);
  8769. Item* item = 0;
  8770. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8771. for (int32 i = 0; i < limit; i++, x++) {
  8772. if (x >= search_items->size())
  8773. break;
  8774. item = search_items->at(x);
  8775. std::string teststr("test ");
  8776. teststr.append(std::to_string(i));
  8777. packet->setArrayDataByName("string_one", teststr.c_str(), i);
  8778. packet->setArrayDataByName("string_two", "testtwo", i);
  8779. packet->setArrayDataByName("seller_name", "EQ2EMuDev", i);
  8780. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8781. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8782. packet->setArrayDataByName("icon", item->details.icon, i);
  8783. //packet->setArrayDataByName("unknown2b", i, i);
  8784. packet->setArrayDataByName("item_seller_id", 1, i);
  8785. if (item->stack_count == 0)
  8786. packet->setArrayDataByName("quantity", 1, i);
  8787. else
  8788. packet->setArrayDataByName("quantity", item->stack_count, i);
  8789. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8790. packet->setArrayDataByName("sell_price", item->sell_price, i);
  8791. std::string tmpStr("");
  8792. tmpStr.append(item->name.c_str());
  8793. tmpStr.append(" (");
  8794. tmpStr.append(std::to_string(item->details.item_id));
  8795. tmpStr.append(")");
  8796. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8797. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8798. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8799. }
  8800. }
  8801. EQ2Packet* outapp = packet->serialize();
  8802. DumpPacket(outapp);
  8803. QueuePacket(outapp);
  8804. safe_delete(packet);
  8805. }
  8806. }
  8807. }
  8808. void Client::SetReadyForUpdates() {
  8809. if (!ready_for_updates) {
  8810. database.loadCharacterProperties(this);
  8811. SendDefaultGroupOptions();
  8812. }
  8813. ready_for_updates = true;
  8814. if(GetVersion() <= 546) {
  8815. SendRecipeList();
  8816. }
  8817. }
  8818. void Client::SetReadyForSpawns(bool val) {
  8819. ready_for_spawns = val;
  8820. if (GetPlayer()->GetActivityStatus() > 0) {
  8821. GetPlayer()->SetActivityStatus(0);
  8822. if (GetPlayer()->GetGroupMemberInfo()) {
  8823. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8824. }
  8825. }
  8826. GetPlayer()->SetActiveReward(false);
  8827. zone_list.CheckFriendZoned(this);
  8828. }
  8829. void Client::SendChatRelationship(int8 type, const char* name) {
  8830. if (!name) {
  8831. return;
  8832. }
  8833. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8834. if (packet) {
  8835. packet->setDataByName("account_id", GetAccountID());
  8836. packet->setDataByName("type", type);
  8837. packet->setArrayLengthByName("num_names", 1);
  8838. packet->setArrayDataByName("name", name);
  8839. if (type == 0) {
  8840. Client* client = zone_list.GetClientByCharName(name);
  8841. if (client) {
  8842. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8843. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8844. }
  8845. }
  8846. QueuePacket(packet->serialize());
  8847. safe_delete(packet);
  8848. }
  8849. }
  8850. void Client::SendFriendList() {
  8851. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8852. if (packet) {
  8853. packet->setDataByName("account_id", GetAccountID());
  8854. map<string, int8>::iterator itr;
  8855. map<string, int8>* friends = player->GetFriends();
  8856. if (friends && friends->size() > 0) {
  8857. Client* client = 0;
  8858. vector<string> names;
  8859. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8860. if (itr->second == 2)
  8861. continue;
  8862. names.push_back(itr->first);
  8863. }
  8864. packet->setArrayLengthByName("num_names", names.size());
  8865. for (int32 i = 0; i < names.size(); i++) {
  8866. client = zone_list.GetClientByCharName(names[i]);
  8867. packet->setArrayDataByName("name", names[i].c_str(), i);
  8868. if (client) {
  8869. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8870. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8871. }
  8872. }
  8873. }
  8874. QueuePacket(packet->serialize());
  8875. safe_delete(packet);
  8876. }
  8877. }
  8878. void Client::SendIgnoreList() {
  8879. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8880. if (packet) {
  8881. packet->setDataByName("account_id", GetAccountID());
  8882. packet->setDataByName("type", 2);
  8883. map<string, int8>::iterator itr;
  8884. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8885. if (ignored && ignored->size() > 0) {
  8886. vector<string> names;
  8887. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8888. if (itr->second == 2)
  8889. continue;
  8890. names.push_back(itr->first);
  8891. }
  8892. packet->setArrayLengthByName("num_names", names.size());
  8893. for (int32 i = 0; i < names.size(); i++)
  8894. packet->setArrayDataByName("name", names[i].c_str(), i);
  8895. }
  8896. QueuePacket(packet->serialize());
  8897. safe_delete(packet);
  8898. }
  8899. }
  8900. void Client::AddWaypoint(string name, int8 type) {
  8901. waypoint_id++;
  8902. WaypointInfo info;
  8903. info.id = waypoint_id;
  8904. info.type = type;
  8905. waypoints[name] = info;
  8906. }
  8907. void Client::SendWaypoints() {
  8908. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8909. if (packet) {
  8910. packet->setArrayLengthByName("num_updates", waypoints.size());
  8911. map<string, WaypointInfo>::iterator itr;
  8912. int16 i = 0;
  8913. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8914. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8915. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8916. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8917. i++;
  8918. }
  8919. packet->setDataByName("unknown", 0xFFFFFFFF);
  8920. QueuePacket(packet->serialize());
  8921. safe_delete(packet);
  8922. }
  8923. }
  8924. void Client::SelectWaypoint(int32 id) {
  8925. string found_name = "";
  8926. map<string, WaypointInfo>::iterator itr;
  8927. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8928. if (itr->second.id == id) {
  8929. found_name = itr->first;
  8930. break;
  8931. }
  8932. }
  8933. if (found_name.length() > 0) {
  8934. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8935. ShowPathToTarget(spawn);
  8936. }
  8937. }
  8938. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8939. if (waypoint_name) {
  8940. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8941. if (packet) {
  8942. packet->setArrayLengthByName("num_updates", 1);
  8943. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8944. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8945. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8946. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8947. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8948. packet->setDataByName("unknown", 0xFFFFFFFF);
  8949. QueuePacket(packet->serialize());
  8950. safe_delete(packet);
  8951. }
  8952. }
  8953. }
  8954. void Client::ClearWaypoint() {
  8955. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8956. if (packet) {
  8957. QueuePacket(packet->serialize());
  8958. safe_delete(packet);
  8959. }
  8960. }
  8961. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8962. if (current_zone->pathing) {
  8963. if (GetPlayer()->GetMap()) {
  8964. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8965. return false;
  8966. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8967. return false;
  8968. auto loc = glm::vec3(x, z, y);
  8969. float new_z = GetPlayer()->FindBestZ(loc, nullptr);
  8970. if (new_z != BEST_Z_INVALID) //this is actually y
  8971. y = new_z;
  8972. }
  8973. bool partial = false;
  8974. bool stuck = false;
  8975. PathfinderOptions opts;
  8976. opts.smooth_path = true;
  8977. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8978. opts.offset = y_offset + 1.0f;
  8979. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8980. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8981. if (packet) {
  8982. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8983. packet->setArrayLengthByName("num_points", path.size());
  8984. int i = 0;
  8985. for (auto& node : path)
  8986. {
  8987. packet->setArrayDataByName("x", node.pos.x, i);
  8988. packet->setArrayDataByName("y", node.pos.z, i);
  8989. packet->setArrayDataByName("z", node.pos.y, i);
  8990. packet->setDataByName("waypoint_x", x);
  8991. packet->setDataByName("waypoint_y", y);
  8992. packet->setDataByName("waypoint_z", z);
  8993. i++;
  8994. }
  8995. if (i > 0)
  8996. QueuePacket(packet->serialize());
  8997. safe_delete(packet);
  8998. return (i > 0);
  8999. }
  9000. }
  9001. return false;
  9002. }
  9003. bool Client::ShowPathToTarget(Spawn* spawn) {
  9004. if (spawn) {
  9005. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  9006. }
  9007. return false;
  9008. }
  9009. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  9010. if (waypoint_name) {
  9011. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  9012. if (packet) {
  9013. packet->setArrayLengthByName("num_points", 1);
  9014. packet->setArrayDataByName("x", x, 0);
  9015. packet->setArrayDataByName("y", y, 0);
  9016. packet->setArrayDataByName("z", z, 0);
  9017. packet->setDataByName("waypoint_x", x);
  9018. packet->setDataByName("waypoint_y", y);
  9019. packet->setDataByName("waypoint_z", z);
  9020. packet->setDataByName("waypoint_name", waypoint_name);
  9021. packet->setDataByName("unknown", 0);
  9022. QueuePacket(packet->serialize());
  9023. safe_delete(packet);
  9024. }
  9025. }
  9026. }
  9027. void Client::InspectPlayer(Player* player_to_inspect) {
  9028. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  9029. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  9030. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9031. if(pvp_allowed == true){
  9032. if(source_pvp_alignment != target_pvp_alignment){
  9033. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  9034. return;
  9035. }
  9036. }
  9037. if (player_to_inspect && player_to_inspect->GetClient()) {
  9038. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  9039. if (packet) {
  9040. packet->setDataByName("unknown", 0);
  9041. packet->setSmallStringByName("name", player_to_inspect->GetName());
  9042. packet->setDataByName("race", player_to_inspect->GetRace());
  9043. packet->setDataByName("gender", player_to_inspect->GetGender());
  9044. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  9045. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  9046. packet->setDataByName("adventure_level_effective", effective_level);
  9047. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  9048. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  9049. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  9050. packet->setDataByName("health", player_to_inspect->GetHP());
  9051. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  9052. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  9053. packet->setDataByName("power", player_to_inspect->GetPower());
  9054. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  9055. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  9056. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  9057. packet->setDataByName("unknown1", 0);
  9058. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  9059. packet->setDataByName("unknown2", 0);
  9060. packet->setDataByName("mitigation_percentage", 0);
  9061. packet->setDataByName("strength", player_to_inspect->GetStr());
  9062. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  9063. packet->setDataByName("stamina", player_to_inspect->GetSta());
  9064. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  9065. packet->setDataByName("agility", player_to_inspect->GetAgi());
  9066. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  9067. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  9068. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  9069. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  9070. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  9071. packet->setDataByName("unknown4", 0);
  9072. packet->setDataByName("unknown5", 0);
  9073. packet->setDataByName("unknown6", 0);
  9074. packet->setDataByName("unknown7", 0);
  9075. packet->setDataByName("unknown8", 0);
  9076. packet->setDataByName("unknown9", 0);
  9077. packet->setDataByName("unknown10", 0);
  9078. packet->setDataByName("unknown11", 0);
  9079. packet->setDataByName("unknown12", 0);
  9080. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  9081. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  9082. packet->setDataByName("heat_resist_percentage", 0);
  9083. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  9084. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  9085. packet->setDataByName("cold_resist_percentage", 0);
  9086. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  9087. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  9088. packet->setDataByName("magic_resist_percentage", 0);
  9089. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  9090. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  9091. packet->setDataByName("mental_resist_percentage", 0);
  9092. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  9093. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  9094. packet->setDataByName("divine_resist_percentage", 0);
  9095. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  9096. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  9097. packet->setDataByName("disease_resist_percentage", 0);
  9098. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  9099. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  9100. packet->setDataByName("poison_resist_percentage", 0);
  9101. packet->setArrayLengthByName("num_chars", 0x01FF);
  9102. string biography = player_to_inspect->GetBiography();
  9103. for (size_t i = 0; i < biography.length(); i++)
  9104. packet->setArrayDataByName("biography_char", biography[i], i);
  9105. if(GetVersion() <= 546) {
  9106. for(int32 s=0;s<22;s++) {
  9107. int32 slot = s;
  9108. char item_slot_name[64], item_slot_name_appearance[64];
  9109. _snprintf(item_slot_name,64,"slot_%u",slot);
  9110. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, GetVersion()));
  9111. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 5, true, true);
  9112. }
  9113. }
  9114. else {
  9115. for(int32 s=0;s<NUM_SLOTS;s++) {
  9116. int32 slot = s*2;
  9117. char item_slot_name[64], item_slot_name_appearance[64];
  9118. _snprintf(item_slot_name,64,"slot_%u",slot);
  9119. int32 slot_appearance = (s*2)+1;
  9120. _snprintf(item_slot_name_appearance,64,"slot_%u",slot_appearance);
  9121. Item* pw = player_to_inspect->GetEquipmentList()->GetItem(GetPlayer()->ConvertSlotFromClient(s, player_to_inspect->GetClient()->GetVersion()));
  9122. packet->setItemByName(item_slot_name, pw, this->GetPlayer(), 0, 13, false, true);
  9123. if(s <= EQ2_FEET_SLOT || s == EQ2_RANGE_SLOT || s == EQ2_CLOAK_SLOT) {
  9124. pw = player_to_inspect->GetAppearanceEquipmentList()->GetItem(s);
  9125. packet->setItemByName(item_slot_name_appearance, pw, this->GetPlayer(), 0, 13, false, true);
  9126. }
  9127. else {
  9128. packet->setItemByName(item_slot_name_appearance, nullptr, this->GetPlayer(), 0, 13, false, true);
  9129. }
  9130. }
  9131. }
  9132. QueuePacket(packet->serialize());
  9133. safe_delete(packet);
  9134. }
  9135. }
  9136. }
  9137. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  9138. pending_guild_invite.guild = guild;
  9139. pending_guild_invite.invited_by = invited_by;
  9140. }
  9141. void Client::ShowClaimWindow() {
  9142. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  9143. if (packet) {
  9144. int16 loaded = database.CountCharClaimItems(GetCharacterID());
  9145. vector<ClaimItems> claim = database.LoadCharacterClaimItems(GetCharacterID());
  9146. int32 account_age = database.GetAccountAge(GetAccountID());
  9147. //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.
  9148. if (loaded == 0 || claim.empty()) {
  9149. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9150. return;
  9151. }
  9152. packet->setArrayLengthByName("num_claim_items", loaded);
  9153. int j = 0; //use this to track skipped vet items.
  9154. for (int i = 0; i < claim.size(); i++)
  9155. {
  9156. if (j == claim.size()) {
  9157. Message(CHANNEL_COLOR_RED, "You have nothing to claim.");
  9158. return;
  9159. }
  9160. Item* item = master_item_list.GetItem(claim[i].item_id);
  9161. int16 claimed = 0;
  9162. if (claim[i].curr_claim < claim[i].max_claim) {
  9163. claimed = claim[i].max_claim - claim[i].curr_claim;
  9164. }
  9165. else {
  9166. claimed = 0;
  9167. }
  9168. //dont display vet rewards until they reach the age required
  9169. if (account_age < claim[i].vet_reward_time) {
  9170. j++;
  9171. continue;
  9172. }
  9173. packet->setArrayDataByName("id", i, i);
  9174. packet->setArrayDataByName("not_yet_claimed", 1, i);
  9175. packet->setArrayDataByName("num_remaining", claim[i].curr_claim, i);
  9176. packet->setArrayDataByName("one_per_character", claim[i].one_per_char, i);
  9177. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  9178. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  9179. packet->setArrayDataByName("text", "If you ever see this text, let a developer know!", i); //I've not seen this!
  9180. //packet->setArrayDataByName("category", "Scott's Shit", i); //devn00b: not using so commenting out, leaving in case we ever do implement categories.
  9181. packet->setArrayDataByName("icon", item->details.icon, i);
  9182. packet->setArrayDataByName("item_id", item->details.item_id, i);
  9183. j++;
  9184. }
  9185. }
  9186. packet->setDataByName("unknown3", 1);
  9187. QueuePacket(packet->serialize());
  9188. safe_delete(packet);
  9189. }
  9190. void Client::ShowGuildSearchWindow() {
  9191. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  9192. if (packet) {
  9193. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  9194. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  9195. packet->setArrayLengthByName("num_guilds", guilds->size());
  9196. int32 i = 0;
  9197. while (itr.Next()) {
  9198. Guild* guild = itr.second;
  9199. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  9200. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  9201. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  9202. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  9203. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  9204. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  9205. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  9206. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  9207. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  9208. packet->setArrayDataByName("unknown7", 0x02, i);
  9209. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  9210. i++;
  9211. }
  9212. QueuePacket(packet->serialize());
  9213. safe_delete(packet);
  9214. }
  9215. }
  9216. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  9217. PacketStruct* packet;
  9218. vector<int8>* slot_data;
  9219. vector<int8>::iterator itr;
  9220. int32 slots = 0;
  9221. assert(item);
  9222. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  9223. return;
  9224. }
  9225. slot_data = &item->slot_data;
  9226. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  9227. if (version >= 1188)
  9228. slots = *itr;
  9229. else
  9230. slots += (int8)pow(2.0, *itr);
  9231. }
  9232. packet->setDataByName("slot", slots);
  9233. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  9234. if (slots == 2) {
  9235. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  9236. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  9237. }
  9238. else {
  9239. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  9240. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  9241. }
  9242. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  9243. if (slots == 4) {
  9244. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  9245. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9246. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  9247. }
  9248. else if (slots == 7) {
  9249. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  9250. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  9251. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9252. }
  9253. else {
  9254. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  9255. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  9256. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  9257. }
  9258. packet->setDataByName("icon", item->details.icon);
  9259. packet->setDataByName("item_id", item->details.item_id);
  9260. packet->setDataByName("item_crc", crc);
  9261. packet->setDataByName("unknown2", 0xFFFFFFFF);
  9262. packet->setDataByName("unknown4", 0xFFFFFFFF);
  9263. packet->setDataByName("unknown5", 0xFF, 9);
  9264. packet->setDataByName("unknown5", 0xFF, 10);
  9265. QueuePacket(packet->serialize());
  9266. safe_delete(packet);
  9267. }
  9268. void Client::SendCollectionList() {
  9269. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  9270. map<int32, Collection*>::iterator itr;
  9271. vector<struct CollectionItem*>* collection_items;
  9272. Collection* collection;
  9273. struct CollectionItem* collection_item;
  9274. PacketStruct* packet = 0;
  9275. int16 i = 0, j;
  9276. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  9277. return;
  9278. packet->setArrayLengthByName("num_collections", collections->size());
  9279. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9280. collection = itr->second;
  9281. collection_items = collection->GetCollectionItems();
  9282. packet->setArrayDataByName("unknown", 1, i);
  9283. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  9284. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  9285. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  9286. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9287. packet->setArrayDataByName("level", collection->GetLevel(), i);
  9288. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  9289. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  9290. for (j = 0; j < collection_items->size(); j++) {
  9291. collection_item = collection_items->at(j);
  9292. Item* item = master_item_list.GetItem(collection_item->item);
  9293. if (item) {
  9294. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  9295. if (version < 955)
  9296. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  9297. else
  9298. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  9299. }
  9300. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  9301. }
  9302. i++;
  9303. }
  9304. packet->setDataByName("new_collection_flag", 1);
  9305. QueuePacket(packet->serialize());
  9306. safe_delete(packet);
  9307. }
  9308. bool Client::SendCollectionsForItem(Item* item) {
  9309. map<int32, Collection*> collections_to_send;
  9310. map<int32, Collection*>* collections;
  9311. map<int32, Collection*>::iterator itr;
  9312. vector<struct CollectionItem*>* collection_items;
  9313. Collection* collection;
  9314. struct CollectionItem* collection_item;
  9315. PacketStruct* packet;
  9316. int16 i;
  9317. assert(item);
  9318. /* get any collections required by this item that the player already has */
  9319. collections = player->GetCollectionList()->GetCollections();
  9320. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9321. collection = itr->second;
  9322. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  9323. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  9324. collections_to_send[collection->GetID()] = collection;
  9325. }
  9326. }
  9327. /* get any collections required by this item that the player does not have and send it to the client */
  9328. collections = master_collection_list.GetCollections();
  9329. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9330. collection = itr->second;
  9331. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  9332. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  9333. return false;
  9334. }
  9335. packet->setArrayLengthByName("num_collections", 1);
  9336. packet->setArrayDataByName("unknown", 1, 0);
  9337. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  9338. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  9339. packet->setArrayDataByName("completed", 0, 0);
  9340. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  9341. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  9342. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  9343. packet->setArrayDataByName("unknown3", 0x28, 0);
  9344. collection_items = collection->GetCollectionItems();
  9345. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  9346. for (i = 0; i < collection_items->size(); i++) {
  9347. collection_item = collection_items->at(i);
  9348. Item* item2 = master_item_list.GetItem(collection_item->item);
  9349. if (item2) {
  9350. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  9351. if (version < 955)
  9352. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  9353. else
  9354. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  9355. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  9356. }
  9357. }
  9358. packet->setDataByName("new_collection_flag", 0);
  9359. QueuePacket(packet->serialize());
  9360. safe_delete(packet);
  9361. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  9362. collections_to_send[collection->GetID()] = collection;
  9363. }
  9364. }
  9365. /* send the client a list of collections that should be filtered for this item */
  9366. if (collections_to_send.size() > 0) {
  9367. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  9368. return false;
  9369. }
  9370. i = 0;
  9371. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  9372. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  9373. collection = itr->second;
  9374. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  9375. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  9376. i++;
  9377. }
  9378. packet->setDataByName("item_icon", item->details.icon);
  9379. packet->setDataByName("item_name", item->name.c_str());
  9380. packet->setDataByName("item_id", item->details.item_id);
  9381. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  9382. QueuePacket(packet->serialize());
  9383. safe_delete(packet);
  9384. }
  9385. return collections_to_send.size() > 0;
  9386. }
  9387. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  9388. Collection* collection;
  9389. struct CollectionItem* collection_item;
  9390. PacketStruct* packet;
  9391. char tmp[200] = { 0 };
  9392. assert(item);
  9393. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  9394. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  9395. /* get the item struct that represents the item for this collection */
  9396. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9397. SendCollectionList();
  9398. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9399. return;
  9400. }
  9401. /* sanity check */
  9402. if (collection_item->found) {
  9403. SendCollectionList();
  9404. 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());
  9405. return;
  9406. }
  9407. }
  9408. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  9409. collection = new Collection(collection);
  9410. /* get the item struct that represents the item for this collection */
  9411. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  9412. SendCollectionList();
  9413. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  9414. safe_delete(collection);
  9415. return;
  9416. }
  9417. /* add the new collection to the player's collection list */
  9418. if (!player->GetCollectionList()->AddCollection(collection)) {
  9419. SendCollectionList();
  9420. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  9421. safe_delete(collection);
  9422. return;
  9423. }
  9424. }
  9425. else {
  9426. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  9427. return;
  9428. }
  9429. collection_item->found = 1;
  9430. collection->SetSaveNeeded(true);
  9431. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  9432. SendCollectionList();
  9433. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  9434. return;
  9435. }
  9436. packet->setDataByName("collection_id", collection_id);
  9437. packet->setDataByName("collection_item_num", collection_item->index);
  9438. packet->setDataByName("add", 1);
  9439. QueuePacket(packet->serialize());
  9440. Item* item2 = master_item_list.GetItem(collection_item->item);
  9441. if (item2) {
  9442. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9443. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  9444. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  9445. }
  9446. safe_delete(packet);
  9447. RemoveItem(item, 1);
  9448. SendCollectionList();
  9449. }
  9450. void Client::DisplayCollectionComplete(Collection* collection) {
  9451. vector<struct CollectionRewardItem*>* reward_items;
  9452. vector<struct CollectionRewardItem*>* selectable_reward_items;
  9453. struct CollectionRewardItem* reward_item;
  9454. PacketStruct* packet;
  9455. int32 i;
  9456. assert(collection);
  9457. reward_items = collection->GetRewardItems();
  9458. selectable_reward_items = collection->GetSelectableRewardItems();
  9459. if (GetVersion() <= 546) {
  9460. int32 source_id = collection->GetID();
  9461. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  9462. if (packet2) {
  9463. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  9464. packet2->setSubstructDataByName("reward_data", "reward", "Quest Reward!");
  9465. packet2->setSubstructDataByName("reward_data", "max_coin", collection->GetRewardCoin());
  9466. packet2->setSubstructDataByName("reward_data", "exp_bonus", collection->GetRewardXP());
  9467. if(reward_items){
  9468. int32 item_count = reward_items->size();
  9469. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", item_count);
  9470. i = 0;
  9471. if(reward_items) {
  9472. for (i = 0; i < reward_items->size(); i++) {
  9473. Item* item = reward_items->at(i)->item;
  9474. if (item) {
  9475. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  9476. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  9477. }
  9478. }
  9479. }
  9480. }
  9481. if (selectable_reward_items) {
  9482. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_reward_items->size());
  9483. for (i = 0; i < selectable_reward_items->size(); i++) {
  9484. Item* item = selectable_reward_items->at(i)->item;
  9485. if (item) {
  9486. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  9487. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  9488. }
  9489. }
  9490. }
  9491. }
  9492. EQ2Packet* app = packet2->serialize();
  9493. QueuePacket(app);
  9494. safe_delete(packet2);
  9495. return;
  9496. }
  9497. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  9498. return;
  9499. }
  9500. packet->setDataByName("title", "Quest Reward!");
  9501. packet->setDataByName("name", collection->GetName());
  9502. packet->setDataByName("description", collection->GetCategory());
  9503. packet->setDataByName("level", collection->GetLevel());
  9504. packet->setDataByName("max_coin", collection->GetRewardCoin());
  9505. packet->setDataByName("min_coin", collection->GetRewardCoin());
  9506. //packet->setDataByName("status_points", quest->GetStatusPoints());
  9507. packet->setArrayLengthByName("num_rewards", reward_items->size());
  9508. for (i = 0; i < reward_items->size(); i++) {
  9509. reward_item = reward_items->at(i);
  9510. if(!reward_item->item)
  9511. {
  9512. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9513. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9514. continue;
  9515. }
  9516. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  9517. if (version < 860)
  9518. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  9519. else if (version < 1193)
  9520. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  9521. else
  9522. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  9523. }
  9524. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  9525. for (i = 0; i < selectable_reward_items->size(); i++) {
  9526. reward_item = selectable_reward_items->at(i);
  9527. if(!reward_item->item)
  9528. {
  9529. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9530. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  9531. continue;
  9532. }
  9533. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  9534. if (version < 860)
  9535. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  9536. else if (version < 1193)
  9537. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  9538. else
  9539. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  9540. }
  9541. QueuePacket(packet->serialize());
  9542. safe_delete(packet);
  9543. }
  9544. void Client::HandInCollections() {
  9545. map<int32, Collection*>* collections;
  9546. map<int32, Collection*>::iterator itr;
  9547. Collection* collection;
  9548. /* only show 1 collection reward dialog at a time */
  9549. if (player->GetPendingCollectionReward()) {
  9550. return;
  9551. }
  9552. collections = player->GetCollectionList()->GetCollections();
  9553. /* 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
  9554. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  9555. for (itr = collections->begin(); itr != collections->end(); itr++) {
  9556. collection = itr->second;
  9557. if (collection->GetIsReadyToTurnIn()) {
  9558. player->SetPendingCollectionReward(collection);
  9559. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  9560. QuestRewardData* data = new QuestRewardData;
  9561. data->quest_id = 0;
  9562. data->is_temporary = false;
  9563. data->description = std::string("");
  9564. data->is_collection = true;
  9565. data->has_displayed = false;
  9566. data->tmp_coin = 0;
  9567. data->tmp_status = 0;
  9568. data->db_saved = false;
  9569. data->db_index = 0;
  9570. quest_pending_reward.push_back(data);
  9571. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  9572. quest_updates = true;
  9573. break;
  9574. }
  9575. }
  9576. if(quest_updates) {
  9577. SaveQuestRewardData(true);
  9578. }
  9579. }
  9580. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  9581. vector<struct CollectionRewardItem*>* reward_items;
  9582. vector<struct CollectionRewardItem*>::iterator itr;
  9583. struct CollectionRewardItem* reward_item;
  9584. int16 num_slots_needed;
  9585. int16 num_slots;
  9586. assert(collection);
  9587. reward_items = collection->GetRewardItems();
  9588. num_slots_needed = (int16)reward_items->size();
  9589. if (selectable_item_id > 0)
  9590. num_slots_needed++;
  9591. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  9592. if (num_slots < num_slots_needed) {
  9593. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  9594. DisplayCollectionComplete(collection);
  9595. return;
  9596. }
  9597. /* add manditory items */
  9598. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9599. reward_item = *itr;
  9600. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9601. }
  9602. /* find and add the selectable item if there's one */
  9603. if (selectable_item_id > 0) {
  9604. reward_items = collection->GetSelectableRewardItems();
  9605. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  9606. reward_item = *itr;
  9607. if (reward_item->item->details.item_id == selectable_item_id) {
  9608. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  9609. break;
  9610. }
  9611. }
  9612. }
  9613. if (collection->GetRewardXP() > 0) {
  9614. player->AddXP((int32)collection->GetRewardXP());
  9615. }
  9616. if (collection->GetRewardCoin() > 0) {
  9617. player->AddCoins(collection->GetRewardCoin());
  9618. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  9619. }
  9620. collection->SetCompleted(true);
  9621. //update achievements for completeing collection here
  9622. collection->SetSaveNeeded(true);
  9623. SendCollectionList();
  9624. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  9625. player->SetPendingCollectionReward(0);
  9626. RemoveQueuedQuestReward();
  9627. GetPlayer()->SetActiveReward(false);
  9628. HandInCollections();
  9629. GetPlayer()->GetZone()->SendSubSpawnUpdates(SUBSPAWN_TYPES::COLLECTOR);
  9630. }
  9631. void Client::SendRecipeList() {
  9632. if(GetRecipeListSent()) {
  9633. return;
  9634. }
  9635. PacketStruct* packet = 0;
  9636. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  9637. map<int32, Recipe*>::iterator itr;
  9638. int16 i = 0;
  9639. Recipe* recipe;
  9640. if(version <= 546) {
  9641. PacketStruct* packet = 0;
  9642. if (!(packet = configReader.getStruct("WS_UpdateRecipeBook", GetVersion()))) {
  9643. return;
  9644. }
  9645. packet->setArrayLengthByName("recipe_count", recipes->size());
  9646. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9647. recipe = itr->second;
  9648. int32 recipe_id = recipe->GetID();
  9649. packet->setArrayDataByName("recipe_id", recipe_id, i);
  9650. packet->setArrayDataByName("recipe_data_crc", GetRecipeCRC(recipe), i);
  9651. packet->setArrayDataByName("unknown", 0x7005BE3, i); //0x7005BE3
  9652. i++;
  9653. }
  9654. //packet->PrintPacket();
  9655. EQ2Packet* ret = packet->serializeCountPacket(GetVersion(), 0, nullptr, nullptr);
  9656. QueuePacket(ret);
  9657. safe_delete(packet);
  9658. SetRecipeListSent(true);
  9659. return;
  9660. }
  9661. else if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  9662. return;
  9663. }
  9664. int8 level = player->GetTSLevel();
  9665. int index = 0;
  9666. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9667. recipe = itr->second;
  9668. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9669. if (res != devices.end())
  9670. index = res - devices.begin();
  9671. else
  9672. devices.push_back(recipe->GetDevice());
  9673. }
  9674. packet->setDataByName("command_type", 0);
  9675. packet->setArrayLengthByName("num_recipes", recipes->size());
  9676. int stringsize = 0;
  9677. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  9678. recipe = itr->second;
  9679. int32 myid = recipe->GetID();
  9680. int8 rlevel = recipe->GetLevel();
  9681. int8 even = level - level * .05 + .5;
  9682. int8 easymin = level - level * .25 + .5;
  9683. int8 veasymin = level - level * .35 + .5;
  9684. if (rlevel > level )
  9685. packet->setArrayDataByName("tier", 4, i);
  9686. else if ((rlevel <= level) & (rlevel >= even))
  9687. packet->setArrayDataByName("tier", 3, i);
  9688. else if ((rlevel <= even) & (rlevel >= easymin))
  9689. packet->setArrayDataByName("tier", 2, i);
  9690. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  9691. packet->setArrayDataByName("tier", 1, i);
  9692. else if ((rlevel <= veasymin) & (rlevel >= 0))
  9693. packet->setArrayDataByName("tier", 0, i);
  9694. if (rlevel == 2)
  9695. int xxx = 1;
  9696. packet->setArrayDataByName("recipe_id", myid, i);
  9697. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  9698. packet->setArrayDataByName("unknown1", recipe->GetLevel(), i);
  9699. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  9700. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  9701. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  9702. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  9703. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  9704. if (recipe_device != devices.end())
  9705. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), i);
  9706. else
  9707. {//TODO error should never get here
  9708. }
  9709. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  9710. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  9711. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  9712. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  9713. i++;
  9714. }
  9715. //packet->PrintPacket();
  9716. EQ2Packet* pack = packet->serialize();
  9717. QueuePacket(pack);
  9718. safe_delete(packet);
  9719. SetRecipeListSent(true);
  9720. }
  9721. void Client::ShowRecipeBook() {
  9722. PacketStruct* packet = 0;
  9723. Spawn* target = 0;
  9724. int index = 0;
  9725. if (!(target = player->GetTarget())) {
  9726. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  9727. return;
  9728. }
  9729. if (!target->IsObject()) {
  9730. return;
  9731. }
  9732. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  9733. return;
  9734. }
  9735. packet->setDataByName("device", target->GetName());
  9736. packet->setDataByName("unknown1", 1);
  9737. auto res = std::find(devices.begin(), devices.end(), target->GetName());
  9738. if (res != devices.end()){
  9739. index = res - devices.begin();
  9740. int32 deviceID = 0;
  9741. deviceID |= 1UL << index;
  9742. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  9743. packet->setDataByName("unknown2", devices.size());
  9744. packet->setDataByName("unknown3", deviceID);
  9745. }
  9746. else
  9747. packet->setDataByName("unknown2", devices.size());
  9748. QueuePacket(packet->serialize());
  9749. safe_delete(packet);
  9750. }
  9751. void Client::SendTitleUpdate() {
  9752. // must call release read lock before leaving function on GetPlayerTitles
  9753. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  9754. vector<Title*>::iterator itr;
  9755. Title* title;
  9756. sint32 i = 0;
  9757. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  9758. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  9759. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  9760. if (packet) {
  9761. packet->setArrayLengthByName("num_titles", titles->size());
  9762. for (itr = titles->begin(); itr != titles->end(); itr++) {
  9763. title = *itr;
  9764. packet->setArrayDataByName("title", title->GetName(), i);
  9765. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  9766. i++;
  9767. }
  9768. packet->setDataByName("current_prefix", prefix_index);
  9769. packet->setDataByName("current_suffix", suffix_index);
  9770. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9771. #if EQDEBUG >= 9
  9772. packet->PrintPacket();
  9773. #endif
  9774. QueuePacket(packet->serialize());
  9775. safe_delete(packet);
  9776. SendUpdateTitles(prefix_index, suffix_index);
  9777. }
  9778. player->GetPlayerTitles()->ReleaseReadLock();
  9779. }
  9780. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  9781. Title* suffix_title = 0;
  9782. Title* prefix_title = 0;
  9783. if (suffix != -1) {
  9784. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  9785. if(suffix_title)
  9786. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  9787. }
  9788. else
  9789. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  9790. if (prefix != -1) {
  9791. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  9792. if(prefix_title)
  9793. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  9794. }
  9795. else
  9796. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  9797. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  9798. }
  9799. void Client::SendLanguagesUpdate(int32 id, bool setlang) {
  9800. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  9801. list<Language*>::iterator itr;
  9802. Language* language;
  9803. int32 i = 0;
  9804. if(setlang==1){
  9805. GetPlayer()->SetCurrentLanguage(id);
  9806. }
  9807. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  9808. if (packet) {
  9809. packet->setArrayLengthByName("num_languages", languages->size());
  9810. for (itr = languages->begin(); itr != languages->end(); itr++) {
  9811. language = *itr;
  9812. packet->setArrayDataByName("language_id", language->GetID(), i);
  9813. i++;
  9814. }
  9815. packet->setDataByName("current_language", id);
  9816. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  9817. #if EQDEBUG >= 9
  9818. packet->PrintPacket();
  9819. #endif
  9820. QueuePacket(packet->serialize());
  9821. safe_delete(packet);
  9822. }
  9823. }
  9824. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  9825. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  9826. if (packet) {
  9827. if (pet_name)
  9828. packet->setDataByName("pet_name", pet_name);
  9829. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  9830. packet->setDataByName("protect_master", 1);
  9831. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  9832. packet->setDataByName("protect_self", 1);
  9833. if (player->GetInfoStruct()->get_pet_movement() == 2)
  9834. packet->setDataByName("stay_follow_toggle", 1);
  9835. packet->setDataByName("pet_type", type);
  9836. QueuePacket(packet->serialize());
  9837. }
  9838. safe_delete(packet);
  9839. }
  9840. bool Client::IsCrafting() {
  9841. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  9842. }
  9843. void Client::SendBiography() {
  9844. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  9845. if (packet) {
  9846. char biography[512];
  9847. if(player->GetInfoStruct()->get_biography().size() < 1)
  9848. {
  9849. safe_delete(packet);
  9850. return;
  9851. }
  9852. else
  9853. {
  9854. int16 size = player->GetInfoStruct()->get_biography().size();
  9855. if(size>511)
  9856. size = 511;
  9857. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  9858. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  9859. }
  9860. packet->setDataByName("biography", biography);
  9861. QueuePacket(packet->serialize());
  9862. }
  9863. safe_delete(packet);
  9864. }
  9865. PendingResurrection* Client::GetCurrentRez() {
  9866. return &current_rez;
  9867. }
  9868. Mutex* Client::GetResurrectMutex() {
  9869. return &m_resurrect;
  9870. }
  9871. void Client::SendResurrectionWindow() {
  9872. Spawn* caster = current_rez.caster;
  9873. if (!caster || !player)
  9874. return;
  9875. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9876. if (!packet)
  9877. return;
  9878. char* tmp = new char[512];
  9879. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  9880. packet->setMediumStringByName("text", tmp);
  9881. packet->setMediumStringByName("accept_text", "Yes");
  9882. packet->setMediumStringByName("cancel_text", "No");
  9883. sprintf(tmp, "accept_resurrection %u", player->GetID());
  9884. packet->setMediumStringByName("accept_command", tmp);
  9885. sprintf(tmp, "decline_resurrection %u", player->GetID());
  9886. packet->setMediumStringByName("cancel_command", tmp);
  9887. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  9888. QueuePacket(packet->serialize());
  9889. safe_delete(packet);
  9890. safe_delete_array(tmp);
  9891. }
  9892. void Client::AcceptResurrection() {
  9893. Spawn* caster = current_rez.caster;
  9894. if (!player || !caster)
  9895. return;
  9896. if (player->Alive())
  9897. return;
  9898. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9899. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9900. SendResurrectionWindow();
  9901. return;
  9902. }
  9903. player->GetZone()->ResurrectSpawn(player, this);
  9904. current_rez.should_delete = true;
  9905. }
  9906. void Client::SetPendingLastName(string last_name) {
  9907. pending_last_name = new string;
  9908. pending_last_name->assign(last_name);
  9909. }
  9910. string* Client::GetPendingLastName() {
  9911. return pending_last_name;
  9912. }
  9913. void Client::RemovePendingLastName() {
  9914. safe_delete(pending_last_name);
  9915. }
  9916. void Client::SendLastNameConfirmation() {
  9917. if (!pending_last_name)
  9918. return;
  9919. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9920. if (packet) {
  9921. char* text = new char[128];
  9922. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9923. packet->setDataByName("text", text);
  9924. packet->setDataByName("accept_text", "Yes");
  9925. packet->setDataByName("accept_command", "confirmedlastname");
  9926. packet->setDataByName("cancel_text", "No");
  9927. packet->setDataByName("max_length", 50);
  9928. packet->setDataByName("unknown4", 1);
  9929. packet->setDataByName("unknown5", 1);
  9930. QueuePacket(packet->serialize());
  9931. safe_delete(packet);
  9932. safe_delete_array(text);
  9933. }
  9934. }
  9935. void Client::AddQuestTimer(int32 quest_id) {
  9936. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9937. quest_timers.push_back(quest_id);
  9938. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9939. }
  9940. void Client::RemoveQuestTimer(int32 quest_id) {
  9941. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9942. vector<int32>::iterator itr;
  9943. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9944. if ((*itr) == quest_id) {
  9945. quest_timers.erase(itr);
  9946. break;
  9947. }
  9948. }
  9949. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9950. }
  9951. void Client::SavePlayerImages() {
  9952. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9953. // Save the paperdoll image if the server allows it
  9954. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9955. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9956. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9957. // Save the head shot if the server allows it
  9958. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9959. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9960. // Send the head shot to the login server
  9961. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9962. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9963. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9964. memset(packet->pBuffer, 0, size);
  9965. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9966. pic->account_id = GetAccountID();
  9967. pic->char_id = GetCharacterID();
  9968. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9969. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9970. loginserver.SendPacket(packet);
  9971. safe_delete(packet);
  9972. }
  9973. }
  9974. safe_delete_array(incoming_paperdoll.image_bytes);
  9975. incoming_paperdoll.current_size_bytes = 0;
  9976. }
  9977. void Client::EndAutoMount() {
  9978. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9979. if (packet) {
  9980. packet->setDataByName("parameter1", 128);
  9981. packet->setDataByName("parameter2", 64);
  9982. packet->setDataByName("value", 1);
  9983. QueuePacket(packet->serialize());
  9984. safe_delete(packet);
  9985. }
  9986. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9987. if (packet) {
  9988. packet->setDataByName("parameter3", 4);
  9989. packet->setDataByName("parameter5", 2);
  9990. packet->setDataByName("value", 0);
  9991. QueuePacket(packet->serialize());
  9992. safe_delete(packet);
  9993. }
  9994. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9995. if (packet) {
  9996. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  9997. QueuePacket(packet->serialize());
  9998. safe_delete(packet);
  9999. }
  10000. on_auto_mount = false;
  10001. player->SetMount(((Player*)player)->GetTempMount());
  10002. EQ2_Color mount_color = player->GetTempMountColor();
  10003. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  10004. player->SetMountColor(&mount_color);
  10005. player->SetMountSaddleColor(&saddle_color);
  10006. player->SetTempMount(0);
  10007. }
  10008. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  10009. const char* spawn_script = spawn->GetSpawnScript();
  10010. bool should_use_spawn = true;
  10011. if (spawn_script) {
  10012. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  10013. if (state) {
  10014. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  10015. if (state_mutex)
  10016. state_mutex->writelock(__FUNCTION__, __LINE__);
  10017. lua_getglobal(state, "can_use_command");
  10018. if (lua_isfunction(state, -1)) {
  10019. lua_interface->SetSpawnValue(state, spawn);
  10020. lua_interface->SetSpawnValue(state, GetPlayer());
  10021. lua_interface->SetStringValue(state, command ? command : "");
  10022. if (lua_pcall(state, 3, 1, 0) == 0) {
  10023. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  10024. }
  10025. }
  10026. lua_interface->ResetFunctionStack(state);
  10027. if (state_mutex)
  10028. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  10029. }
  10030. }
  10031. return should_use_spawn;
  10032. }
  10033. bool Client::IsCurrentTransmuteID(int32 req_id) {
  10034. return req_id == transmuteID;
  10035. }
  10036. void Client::SetTransmuteID(int32 trans_id) {
  10037. transmuteID = trans_id;
  10038. }
  10039. int32 Client::GetTransmuteID() {
  10040. return transmuteID;
  10041. }
  10042. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  10043. {
  10044. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  10045. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  10046. if (zar)
  10047. {
  10048. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  10049. if (database.IsActiveQuery(charID))
  10050. {
  10051. delayedLogin = true;
  10052. delayedAccountID = account_id;
  10053. delayedAccessKey = access_code;
  10054. delayTimer.Start(500);
  10055. 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);
  10056. return true;
  10057. }
  10058. delayedLogin = false;
  10059. delayTimer.Disable();
  10060. firstlogin = zar->isFirstLogin();
  10061. SetReadyForSpawns(false);
  10062. ready_for_updates = false;
  10063. 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);
  10064. Client* client = zone_list.GetClientByCharName(zar->GetCharacterName());
  10065. if (client || database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10066. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  10067. GetPlayer()->vis_changed = false;
  10068. GetPlayer()->info_changed = false;
  10069. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  10070. if (pvp_allowed)
  10071. this->GetPlayer()->SetAttackable(1);
  10072. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  10073. if (client) {
  10074. if (client->getConnection())
  10075. client->getConnection()->SendDisconnect(true);
  10076. bool restore_ld_success = false;
  10077. if (client->GetCurrentZone() && !client->IsZoning()) {
  10078. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  10079. if (client->GetVersion() == version) {
  10080. client->DisableSave();
  10081. client->ReplaceGroupClient(this);
  10082. Player* current_player = GetPlayer();
  10083. SetPlayer(client->GetPlayer());
  10084. GetPlayer()->SetClient(this);
  10085. GetPlayer()->SetReturningFromLD(true);
  10086. SetCharacterID(client->GetCharacterID());
  10087. SetAccountID(client->GetAccountID());
  10088. SetAdminStatus(client->GetAdminStatus());
  10089. SetCurrentZone(GetPlayer()->GetZone());
  10090. client->SetPlayer(current_player);
  10091. GetPlayer()->ResetSavedSpawns();
  10092. restore_ld_success = true;
  10093. char tmpldname[128];
  10094. snprintf(tmpldname, 128, "%s Linkdead",GetPlayer()->GetName());
  10095. client->GetPlayer()->SetName(tmpldname, false);
  10096. }
  10097. ZoneServer* tmpZone = client->GetCurrentZone();
  10098. tmpZone->RemoveClientImmediately(client);
  10099. }
  10100. if(!restore_ld_success && !database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  10101. LogWrite(ZONE__ERROR, 0, "Zone", "Error reloading LD character and loading DB character: %s", player->GetName());
  10102. ClientPacketFunctions::SendLoginDenied(this);
  10103. Disconnect();
  10104. return false;
  10105. }
  10106. }
  10107. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  10108. if (!GetCurrentZone()) {
  10109. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  10110. ClientPacketFunctions::SendLoginDenied(this);
  10111. Disconnect();
  10112. return false;
  10113. }
  10114. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  10115. getConnection()->SetClientVersion(version);
  10116. GetCurrentZone()->SetSpawnStructs(this);
  10117. connected_to_zone = true;
  10118. client_list.Remove(this); //remove from master client list
  10119. GetCurrentZone()->AddClient(this); //add to zones client list
  10120. zone_list.AddClientToMap(player->GetName(), this);
  10121. // 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.
  10122. if(GetCurrentZone()->IsLoading()) {
  10123. new_client_login = NewLoginState::LOGIN_DELAYED;
  10124. }
  10125. else {
  10126. new_client_login = NewLoginState::LOGIN_ALLOWED;
  10127. }
  10128. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  10129. if (zone_script && lua_interface)
  10130. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  10131. }
  10132. else {
  10133. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  10134. version = 0;
  10135. ClientPacketFunctions::SendLoginDenied(this);
  10136. Disconnect();
  10137. return false;
  10138. }
  10139. }
  10140. else {
  10141. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  10142. ClientPacketFunctions::SendLoginDenied(this);
  10143. Disconnect();
  10144. return false;
  10145. }
  10146. zone_auth.RemoveAuth(zar);
  10147. }
  10148. else
  10149. {
  10150. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  10151. Disconnect();
  10152. return false;
  10153. }
  10154. return true;
  10155. }
  10156. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  10157. if (!IsReadyForUpdates())
  10158. return;
  10159. map<int32, SpawnData> info_changes;
  10160. map<int32, SpawnData> pos_changes;
  10161. map<int32, SpawnData> vis_changes;
  10162. map<int32, SpawnData> empty_changes;
  10163. int32 info_size = 0;
  10164. int32 pos_size = 0;
  10165. int32 vis_size = 0;
  10166. int count = 0;
  10167. for (const auto& spawn : spawns) {
  10168. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  10169. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  10170. continue;
  10171. int16 tmp_info_size = 0;
  10172. int16 tmp_pos_size = 0;
  10173. int16 tmp_vis_size = 0;
  10174. if (spawn->vis_changed)
  10175. {
  10176. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10177. if (vis_change) {
  10178. SpawnData data;
  10179. data.spawn = spawn;
  10180. data.data = vis_change;
  10181. data.size = tmp_vis_size;
  10182. map<int32, SpawnData> tmp_vis_changes;
  10183. tmp_vis_changes[index] = data;
  10184. map<int32, SpawnData> tmp_info_changes;
  10185. map<int32, SpawnData> tmp_pos_changes;
  10186. if (spawn->info_changed) {
  10187. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10188. if (info_change) {
  10189. SpawnData data;
  10190. data.spawn = spawn;
  10191. data.data = info_change;
  10192. data.size = tmp_info_size;
  10193. tmp_info_changes[index] = data;
  10194. }
  10195. }
  10196. if (spawn->position_changed) {
  10197. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10198. if (pos_change) {
  10199. SpawnData data;
  10200. data.spawn = spawn;
  10201. data.data = pos_change;
  10202. data.size = tmp_pos_size;
  10203. tmp_pos_changes[index] = data;
  10204. }
  10205. }
  10206. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  10207. for (auto& kv : tmp_info_changes) {
  10208. safe_delete_array(kv.second.data);
  10209. }
  10210. for (auto& kv : tmp_pos_changes) {
  10211. safe_delete_array(kv.second.data);
  10212. }
  10213. for (auto& kv : tmp_vis_changes) {
  10214. safe_delete_array(kv.second.data);
  10215. }
  10216. continue;
  10217. }
  10218. }
  10219. if (spawn->info_changed) {
  10220. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion(), &tmp_info_size);
  10221. if (info_change) {
  10222. SpawnData data;
  10223. data.spawn = spawn;
  10224. data.data = info_change;
  10225. data.size = tmp_info_size;
  10226. info_size += tmp_info_size;
  10227. info_changes[index] = data;
  10228. }
  10229. count++;
  10230. }
  10231. if (spawn->position_changed) {
  10232. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion(), &tmp_pos_size);
  10233. if (pos_change) {
  10234. SpawnData data;
  10235. data.spawn = spawn;
  10236. data.data = pos_change;
  10237. data.size = tmp_pos_size;
  10238. pos_size += tmp_pos_size;
  10239. pos_changes[index] = data;
  10240. }
  10241. count++;
  10242. }
  10243. if (spawn->vis_changed) {
  10244. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion(), &tmp_vis_size);
  10245. if (vis_change) {
  10246. SpawnData data;
  10247. data.spawn = spawn;
  10248. data.data = vis_change;
  10249. data.size = tmp_vis_size;
  10250. vis_size += tmp_vis_size;
  10251. vis_changes[index] = data;
  10252. }
  10253. count++;
  10254. }
  10255. }
  10256. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  10257. return;
  10258. }
  10259. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  10260. for (auto& kv : info_changes) {
  10261. safe_delete_array(kv.second.data);
  10262. }
  10263. for (auto& kv : pos_changes) {
  10264. safe_delete_array(kv.second.data);
  10265. }
  10266. for (auto& kv : vis_changes) {
  10267. safe_delete_array(kv.second.data);
  10268. }
  10269. }
  10270. 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)
  10271. {
  10272. static const int8 oversized = 255;
  10273. int16 opcode_val = 0;
  10274. if (EQOpcodeManager.count(GetOpcodeVersion(version)) != 0) {
  10275. opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  10276. }
  10277. int32 size = info_size + pos_size + vis_size + 8;
  10278. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  10279. size += 3;
  10280. size += CheckOverLoadSize(info_size);
  10281. size += CheckOverLoadSize(pos_size);
  10282. size += CheckOverLoadSize(vis_size);
  10283. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  10284. size += 2;
  10285. }
  10286. uchar* tmp = new uchar[size];
  10287. uchar* ptr = tmp;
  10288. memset(tmp, 0, size);
  10289. if (version <= 283) {
  10290. if (size >= 255) {
  10291. size -= 3;
  10292. memcpy(ptr, &oversized, sizeof(int8));
  10293. ptr += sizeof(int8);
  10294. memcpy(ptr, &size, sizeof(int16));
  10295. ptr += sizeof(int16);
  10296. size += 3;
  10297. }
  10298. else {
  10299. size -= 1;
  10300. memcpy(ptr, &size, sizeof(int8));
  10301. ptr += sizeof(int8);
  10302. size += 1;
  10303. }
  10304. }
  10305. else {
  10306. size -= 4;
  10307. memcpy(ptr, &size, sizeof(int32));
  10308. ptr += sizeof(int32);
  10309. size += 4;
  10310. }
  10311. memcpy(ptr, &oversized, sizeof(int8));
  10312. ptr += sizeof(int8);
  10313. memcpy(ptr, &opcode_val, sizeof(int16));
  10314. ptr += sizeof(int16);
  10315. int32 current_time = Timer::GetCurrentTime2();
  10316. memcpy(ptr, &current_time, sizeof(int32));
  10317. ptr += sizeof(int32);
  10318. ptr += DoOverLoad(info_size, ptr);
  10319. for (const auto& kv : info_changes) {
  10320. auto info = kv.second;
  10321. memcpy(ptr, info.data, info.size);
  10322. ptr += info.size;
  10323. }
  10324. ptr += DoOverLoad(pos_size, ptr);
  10325. for (const auto& kv : pos_changes) {
  10326. auto pos = kv.second;
  10327. memcpy(ptr, pos.data, pos.size);
  10328. ptr += pos.size;
  10329. }
  10330. ptr += DoOverLoad(vis_size, ptr);
  10331. for (const auto& kv : vis_changes) {
  10332. auto vis = kv.second;
  10333. memcpy(ptr, vis.data, vis.size);
  10334. ptr += vis.size;
  10335. }
  10336. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  10337. if (packet) {
  10338. /*char blah[64];
  10339. snprintf(blah, 64, "Sending %i", current_time);
  10340. SimpleMessage(4, blah);*/
  10341. QueuePacket(packet);
  10342. }
  10343. delete[] tmp;
  10344. }
  10345. void Client::SendHailCommand(Spawn* spawn)
  10346. {
  10347. // hardcoded 'hail' entity commands
  10348. switch (spawn->secondary_command_list_id)
  10349. {
  10350. case 9:
  10351. case 1262:
  10352. case 1265:
  10353. case 1267:
  10354. {
  10355. EQ2_16BitString* command = new EQ2_16BitString();
  10356. command->data = "";
  10357. command->size = 0;
  10358. commands.Process(COMMAND_HAIL, command, this, spawn);
  10359. safe_delete(command);
  10360. break;
  10361. }
  10362. }
  10363. }
  10364. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  10365. {
  10366. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  10367. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  10368. if (packet) {
  10369. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10370. packet->setMediumStringByName("command_name", command);
  10371. packet->setDataByName("distance", distance);
  10372. QueuePacket(packet->serialize());
  10373. safe_delete(packet);
  10374. }
  10375. }
  10376. }
  10377. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  10378. {
  10379. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  10380. return false;
  10381. if (command == "house_spawn_examine")
  10382. {
  10383. uint32 itemID = spawn->GetPickupItemID();
  10384. if (itemID)
  10385. {
  10386. Item* item = master_item_list.GetItem(itemID);
  10387. if (item)
  10388. {
  10389. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  10390. //DumpPacket(app);
  10391. QueuePacket(app);
  10392. }
  10393. }
  10394. return true;
  10395. }
  10396. return false;
  10397. }
  10398. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  10399. {
  10400. if (GetTempPlacementSpawn())
  10401. {
  10402. Spawn* tmp = GetTempPlacementSpawn();
  10403. int32 spawn_group_id = database.GetNextSpawnLocation();
  10404. tmp->SetSpawnLocationID(spawn_group_id);
  10405. float newHeading = place_object->getType_float_ByName("heading") + 180;
  10406. int32 spawnDBID = 0;
  10407. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  10408. {
  10409. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  10410. tmp->SetDatabaseID(spawnDBID);
  10411. }
  10412. else
  10413. {
  10414. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  10415. if (spawnDBID)
  10416. {
  10417. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  10418. tmp->SetDatabaseID(spawnDBID);
  10419. }
  10420. }
  10421. tmp->SetX(place_object->getType_float_ByName("x"));
  10422. tmp->SetY(place_object->getType_float_ByName("y"));
  10423. tmp->SetZ(place_object->getType_float_ByName("z"));
  10424. tmp->SetHeading(newHeading);
  10425. tmp->SetSpawnOrigX(tmp->GetX());
  10426. tmp->SetSpawnOrigY(tmp->GetY());
  10427. tmp->SetSpawnOrigZ(tmp->GetZ());
  10428. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  10429. database.SaveSpawnInfo(tmp);
  10430. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  10431. if (!spawnDBID)
  10432. {
  10433. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  10434. // we need to copy as to not delete the ZoneServer object_list entry this on house item pickup
  10435. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), ((Object*)tmp)->Copy());
  10436. }
  10437. return true;
  10438. }
  10439. return false;
  10440. }
  10441. bool Client::PopulateHouseSpawnFinalize()
  10442. {
  10443. if (GetTempPlacementSpawn())
  10444. {
  10445. Spawn* tmp = GetTempPlacementSpawn();
  10446. GetCurrentZone()->AddSpawn(tmp);
  10447. GetCurrentZone()->SendSpawnChanges(tmp, this);
  10448. SetTempPlacementSpawn(nullptr);
  10449. int32 uniqueID = GetPlacementUniqueItemID();
  10450. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10451. tmp->SetPickupItemID(uniqueItem->details.item_id);
  10452. tmp->SetPickupUniqueItemID(uniqueID);
  10453. if (uniqueItem)
  10454. {
  10455. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  10456. {
  10457. Query query;
  10458. 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);
  10459. }
  10460. if(uniqueItem->GetItemScript() &&
  10461. lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  10462. {
  10463. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  10464. }
  10465. if(uniqueItem) {
  10466. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  10467. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  10468. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  10469. }
  10470. SetPlacementUniqueItemID(0);
  10471. }
  10472. return true;
  10473. }
  10474. return false;
  10475. }
  10476. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  10477. {
  10478. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  10479. packet->setDataByName("placement_mode", placementMode);
  10480. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  10481. packet->setDataByName("model_type", spawn->GetModelType());
  10482. packet->setDataByName("unknown", 1); //size
  10483. packet->setDataByName("unknown2", 1); //size 2
  10484. packet->setDataByName("unknown2", .5, 1); //size 3
  10485. packet->setDataByName("unknown2", 3, 2);
  10486. packet->setDataByName("unknown2", unknown2_3, 3);
  10487. packet->setDataByName("max_distance", 500);
  10488. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  10489. QueuePacket(packet->serialize());
  10490. safe_delete(packet);
  10491. }
  10492. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  10493. {
  10494. SetPendingFlightPath(path_id);
  10495. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  10496. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  10497. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  10498. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  10499. if (packet) {
  10500. QueuePacket(packet->serialize());
  10501. safe_delete(packet);
  10502. }
  10503. if (mount_id)
  10504. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  10505. }
  10506. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  10507. {
  10508. if (!sender)
  10509. {
  10510. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10511. return;
  10512. }
  10513. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10514. if (!packet) {
  10515. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10516. return;
  10517. }
  10518. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10519. packet->setDataByName("book_title", title.c_str());
  10520. packet->setDataByName("book_type", "simple");
  10521. packet->setDataByName("unknown2", 1);
  10522. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10523. packet->setDataByName("language", language);
  10524. if (GetVersion() > 546)
  10525. packet->setDataByName("unknown5", 1, 4);
  10526. packet->setArrayLengthByName("num_pages", num_pages);
  10527. va_list args;
  10528. va_start(args, num_pages);
  10529. std::string endString("");
  10530. for (int8 p = 0; p < num_pages; p++)
  10531. {
  10532. std::string page = va_arg(args, string);
  10533. switch (GetVersion())
  10534. {
  10535. // release client
  10536. case 283:
  10537. {
  10538. endString.append(page);
  10539. break;
  10540. }
  10541. // DoF trial
  10542. case 546:
  10543. {
  10544. if (p == 0)
  10545. packet->setDataByName("cover_page", page.c_str());
  10546. else
  10547. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  10548. break;
  10549. }
  10550. // all other clients
  10551. default:
  10552. {
  10553. packet->setArrayDataByName("page_text", page.c_str(), p);
  10554. break;
  10555. }
  10556. }
  10557. }
  10558. if (GetVersion() == 283)
  10559. {
  10560. packet->setDataByName("page_text", endString.c_str());
  10561. }
  10562. va_end(args);
  10563. QueuePacket(packet->serialize());
  10564. safe_delete(packet);
  10565. }
  10566. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  10567. {
  10568. if (!sender)
  10569. {
  10570. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  10571. return;
  10572. }
  10573. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  10574. if (!packet) {
  10575. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  10576. return;
  10577. }
  10578. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  10579. packet->setDataByName("book_title", title.c_str());
  10580. packet->setDataByName("book_type", "simple");
  10581. packet->setDataByName("unknown2", 1);
  10582. if(language > 0 && !GetPlayer()->HasLanguage(language))
  10583. packet->setDataByName("language", language);
  10584. if (GetVersion() > 546)
  10585. packet->setDataByName("unknown5", 1, 4);
  10586. packet->setArrayLengthByName("num_pages", pages.size());
  10587. std::string endString("");
  10588. for (int8 p = 0; p < pages.size(); p++)
  10589. {
  10590. Item::BookPage* page = pages[p];
  10591. std::string pageText = string(page->page_text.data);
  10592. switch (GetVersion())
  10593. {
  10594. // release client
  10595. case 283:
  10596. {
  10597. endString.append(pageText);
  10598. break;
  10599. }
  10600. // DoF trial
  10601. case 546:
  10602. {
  10603. if (p == 0)
  10604. packet->setDataByName("cover_page", pageText.c_str());
  10605. else
  10606. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  10607. break;
  10608. }
  10609. // all other clients
  10610. default:
  10611. {
  10612. int8 valign = int8(page->valign);
  10613. int8 halign = int8(page->halign);
  10614. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  10615. packet->setArrayDataByName("page_text_valign", valign, p);
  10616. packet->setArrayDataByName("page_text_halign", halign, p);
  10617. break;
  10618. }
  10619. }
  10620. }
  10621. if (GetVersion() == 283)
  10622. {
  10623. packet->setDataByName("page_text", endString.c_str());
  10624. }
  10625. QueuePacket(packet->serialize());
  10626. safe_delete(packet);
  10627. }
  10628. void Client::ReplaceGroupClient(Client* new_client)
  10629. {
  10630. if (this->GetPlayer()->GetGroupMemberInfo())
  10631. {
  10632. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10633. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10634. if(group)
  10635. {
  10636. group->MGroupMembers.writelock();
  10637. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10638. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  10639. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  10640. group->MGroupMembers.releasewritelock();
  10641. }
  10642. else
  10643. {
  10644. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10645. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10646. this->GetPlayer()->SetGroupMemberInfo(0);
  10647. }
  10648. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10649. }
  10650. }
  10651. void Client::TempRemoveGroup()
  10652. {
  10653. if (this->GetPlayer()->GetGroupMemberInfo())
  10654. {
  10655. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  10656. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  10657. if(group)
  10658. {
  10659. group->MGroupMembers.writelock();
  10660. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  10661. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10662. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10663. this->GetPlayer()->SetGroupMemberInfo(0);
  10664. group->MGroupMembers.releasewritelock();
  10665. group->RemoveClientReference(this);
  10666. }
  10667. else
  10668. {
  10669. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  10670. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  10671. this->GetPlayer()->SetGroupMemberInfo(0);
  10672. }
  10673. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  10674. }
  10675. }
  10676. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  10677. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10678. {
  10679. Mail mail;
  10680. mail.mail_id = 0;
  10681. mail.already_read = 0;
  10682. mail.postage_cost = 0;
  10683. mail.attachment_cost = 0;
  10684. mail.save_needed = 1;
  10685. //uhh...mail has std::strings so
  10686. //memset(&mail,0,sizeof(Mail));
  10687. mail.player_to_id = charID;
  10688. mail.player_from = fromName;
  10689. mail.subject = subjectName;
  10690. mail.mail_body = mailBody;
  10691. mail.mail_type = mailType;
  10692. mail.coin_copper = copper;
  10693. mail.coin_silver = silver;
  10694. mail.coin_gold = gold;
  10695. mail.coin_plat = platinum;
  10696. mail.char_item_id = item_id;
  10697. mail.stack = stack_size;
  10698. mail.time_sent = time_sent;
  10699. mail.expire_time = expire_time;
  10700. database.SavePlayerMail(&mail);
  10701. }
  10702. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  10703. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  10704. {
  10705. Mail* mail = new Mail();
  10706. mail->player_to_id = GetCharacterID();
  10707. mail->player_from = fromName;
  10708. mail->subject = subjectName;
  10709. mail->mail_body = mailBody;
  10710. mail->mail_type = mailType;
  10711. mail->coin_copper = copper;
  10712. mail->coin_silver = silver;
  10713. mail->coin_gold = gold;
  10714. mail->coin_plat = platinum;
  10715. mail->char_item_id = item_id;
  10716. mail->stack = stack_size;
  10717. mail->time_sent = time_sent;
  10718. mail->expire_time = expire_time;
  10719. mail->postage_cost = 0;
  10720. mail->save_needed = 1;
  10721. mail->already_read = 0;
  10722. database.SavePlayerMail(mail);
  10723. GetPlayer()->AddMail(mail);
  10724. }
  10725. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  10726. {
  10727. if(slot < NUM_SLOTS)
  10728. {
  10729. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  10730. if (app)
  10731. QueuePacket(app);
  10732. }
  10733. else
  10734. {
  10735. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  10736. if (outapp)
  10737. QueuePacket(outapp);
  10738. }
  10739. }
  10740. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  10741. {
  10742. if(spawn_player_id < 1)
  10743. return;
  10744. MQueueStateCmds.writelock();
  10745. queued_state_commands.insert(make_pair(spawn_player_id, state));
  10746. MQueueStateCmds.releasewritelock();
  10747. }
  10748. void Client::ProcessStateCommands()
  10749. {
  10750. if(!IsReadyForUpdates())
  10751. return;
  10752. MQueueStateCmds.writelock();
  10753. map<int32, int32>::iterator itr = queued_state_commands.begin();
  10754. for(; itr != queued_state_commands.end(); itr++)
  10755. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  10756. queued_state_commands.clear();
  10757. MQueueStateCmds.releasewritelock();
  10758. }
  10759. void Client::PurgeItem(Item* item)
  10760. {
  10761. std::unique_lock lock(MConversation);
  10762. map<int32, Item*>::iterator itr;
  10763. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  10764. {
  10765. if ( itr->second == item )
  10766. {
  10767. conversation_items.erase(itr);
  10768. break;
  10769. }
  10770. }
  10771. }
  10772. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  10773. {
  10774. if(GetPlayer()->StopSaveSpellEffects())
  10775. return;
  10776. if(item) {
  10777. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  10778. if(item->GetItemScript() && lua_interface){
  10779. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  10780. if (slot == 22)
  10781. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  10782. else
  10783. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  10784. }
  10785. if (item->details.count > 1) {
  10786. item->details.count -= 1;
  10787. item->save_needed = true;
  10788. }
  10789. else {
  10790. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  10791. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  10792. }
  10793. GetPlayer()->SetCharSheetChanged(true);
  10794. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  10795. }
  10796. }
  10797. void Client::AwardCoins(int64 total_coins, std::string reason)
  10798. {
  10799. if (total_coins > 0) {
  10800. player->AddCoins(total_coins);
  10801. PlaySound("coin_cha_ching");
  10802. char tmp[64] = { 0 };
  10803. string message = "You receive ";
  10804. int32 val = 0;
  10805. if (total_coins >= 1000000) {
  10806. val = total_coins / 1000000;
  10807. total_coins -= 1000000 * val;
  10808. sprintf(tmp, "%u Platinum ", val);
  10809. message.append(tmp);
  10810. memset(tmp, 0, 64);
  10811. }
  10812. if (total_coins >= 10000) {
  10813. val = total_coins / 10000;
  10814. total_coins -= 10000 * val;
  10815. sprintf(tmp, "%u Gold ", val);
  10816. message.append(tmp);
  10817. memset(tmp, 0, 64);
  10818. }
  10819. if (total_coins >= 100) {
  10820. val = total_coins / 100;
  10821. total_coins -= 100 * val;
  10822. sprintf(tmp, "%u Silver ", val);
  10823. message.append(tmp);
  10824. memset(tmp, 0, 64);
  10825. }
  10826. if (total_coins > 0) {
  10827. sprintf(tmp, "%u Copper ", (int32)total_coins);
  10828. message.append(tmp);
  10829. }
  10830. message.append(reason);
  10831. int8 type = CHANNEL_LOOT;
  10832. SimpleMessage(type, message.c_str());
  10833. }
  10834. }
  10835. void Client::TriggerSpellSave()
  10836. {
  10837. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  10838. // default to not have some bogus value in the rule
  10839. if(interval < 1)
  10840. interval = 100;
  10841. MSaveSpellStateMutex.lock();
  10842. if(!save_spell_state_timer.Enabled())
  10843. {
  10844. save_spell_state_time_bucket = 0;
  10845. save_spell_state_timer.Start(interval, true);
  10846. }
  10847. else
  10848. {
  10849. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  10850. save_spell_state_time_bucket += elapsed_time;
  10851. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  10852. // default to not have some bogus value in the rule
  10853. if(save_wait_cap < interval)
  10854. save_wait_cap = interval+1;
  10855. if(save_spell_state_time_bucket >= save_wait_cap)
  10856. {
  10857. save_spell_state_timer.Trigger();
  10858. }
  10859. }
  10860. MSaveSpellStateMutex.unlock();
  10861. }
  10862. void Client::UpdateSentSpellList() {
  10863. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  10864. std::map<int32, int32>::iterator itr;
  10865. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  10866. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  10867. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  10868. QueuePacket(app);
  10869. }
  10870. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  10871. }
  10872. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  10873. tempPlacementSpawn = tmp;
  10874. hasSentTempPlacementSpawn = false;
  10875. if(tempPlacementSpawn)
  10876. temp_placement_timer.Start();
  10877. else
  10878. temp_placement_timer.Disable();
  10879. }
  10880. void Client::SetPlayer(Player* new_player) {
  10881. if (player && player != new_player)
  10882. zone_list.RemoveClientFromMap(player->GetName(), this);
  10883. player = new_player;
  10884. player->SetClient(this);
  10885. }
  10886. bool Client::UseItem(Item* item, Spawn* target) {
  10887. if (item && item->GetItemScript()) {
  10888. int16 item_index = item->details.index;
  10889. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  10890. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  10891. }
  10892. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  10893. Message(0, "%s requires an evil race.", item->name.c_str());
  10894. }
  10895. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  10896. Message(0, "%s requires a good race.", item->name.c_str());
  10897. }
  10898. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  10899. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  10900. return true;
  10901. }
  10902. else {
  10903. if (item->details.count > 0) {
  10904. std::string itemName = string(item->name);
  10905. int32 item_id = item->details.item_id;
  10906. sint64 flags = 0;
  10907. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  10908. {
  10909. //reobtain item make sure it wasn't removed
  10910. item = player->item_list.GetItemFromIndex(item_index);
  10911. if(!item) {
  10912. 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);
  10913. return true;
  10914. }
  10915. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  10916. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10917. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10918. return true;
  10919. }
  10920. else
  10921. {
  10922. item->details.count--; // charges
  10923. item->save_needed = true;
  10924. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  10925. if(!item->details.count) {
  10926. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10927. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10928. }
  10929. return true;
  10930. }
  10931. }
  10932. else {
  10933. 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);
  10934. return true;
  10935. }
  10936. }
  10937. else
  10938. {
  10939. //reobtain item make sure it wasn't removed
  10940. item = player->item_list.GetItemFromIndex(item_index);
  10941. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10942. if(item) {
  10943. 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);
  10944. }
  10945. }
  10946. }
  10947. }
  10948. return false;
  10949. }
  10950. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10951. VoiceOverStruct* garble, bool success, bool garble_success) {
  10952. VoiceOverStruct* resStruct = nullptr;
  10953. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10954. if(success) {
  10955. resStruct = non_garble;
  10956. }
  10957. }
  10958. else if(garble_success) {
  10959. resStruct = garble;
  10960. }
  10961. if(resStruct) {
  10962. 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);
  10963. }
  10964. }
  10965. void Client::SaveQuestRewardData(bool force_refresh) {
  10966. Query query;
  10967. if(force_refresh) {
  10968. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10969. GetCharacterID());
  10970. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10971. GetCharacterID());
  10972. }
  10973. vector<QuestRewardData*>::iterator itr;
  10974. vector<QuestRewardData*> tmp_quest_rewards;
  10975. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10976. int index = 0;
  10977. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10978. int32 questID = (*itr)->quest_id;
  10979. if(!(*itr)->db_saved || force_refresh) {
  10980. 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')",
  10981. 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());
  10982. (*itr)->db_saved = true;
  10983. (*itr)->db_index = index;
  10984. if(questID && (*itr)->is_temporary) {
  10985. std::vector<Item*> items;
  10986. GetPlayer()->GetQuestTemporaryRewards(questID, &items);
  10987. if(!force_refresh && items.size() > 0) {
  10988. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10989. GetCharacterID(), questID);
  10990. }
  10991. for(int i=0;i<items.size();i++) {
  10992. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id, count) values(%u, %u, %u, %u)",
  10993. GetCharacterID(), questID, items[i]->details.item_id, items[i]->details.count);
  10994. }
  10995. }
  10996. }
  10997. index++;
  10998. }
  10999. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  11000. }
  11001. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  11002. if(!data)
  11003. return;
  11004. if(data->db_saved) {
  11005. Query query;
  11006. 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",
  11007. 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);
  11008. }
  11009. }
  11010. void Client::AddRecipeToPlayerPack(Recipe* recipe, PacketStruct* packet, int16* i) {
  11011. int index = 0;
  11012. if(recipe == nullptr)
  11013. return;
  11014. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11015. if (prl->GetRecipe(recipe->GetID())) {
  11016. delete recipe;
  11017. return;
  11018. }
  11019. auto res = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11020. if (res != devices.end())
  11021. index = res - devices.begin();
  11022. else
  11023. devices.push_back(recipe->GetDevice());
  11024. prl->AddRecipe(recipe);
  11025. database.SavePlayerRecipe(GetPlayer(), recipe->GetID());
  11026. Message(CHANNEL_NARRATIVE, "Recipe: \"%s\" put in recipe book.", recipe->GetName());
  11027. if (packet && GetRecipeListSent()) {
  11028. packet->setArrayDataByName("id", recipe->GetID(), *i);
  11029. packet->setArrayDataByName("tier", recipe->GetTier(), *i);
  11030. packet->setArrayDataByName("level", recipe->GetLevel(), *i);
  11031. packet->setArrayDataByName("icon", recipe->GetIcon(), *i);
  11032. packet->setArrayDataByName("classes", recipe->GetClasses(), *i);
  11033. //packet->setArrayDataByName("skill", recipe->GetSkill(), *i);
  11034. packet->setArrayDataByName("technique", recipe->GetTechnique(), *i);
  11035. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), *i);
  11036. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11037. if (recipe_device != devices.end())
  11038. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), *i);
  11039. else
  11040. {//TODO error should never get here
  11041. }
  11042. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), *i);
  11043. packet->setArrayDataByName("recipe_name", recipe->GetName(), *i);
  11044. packet->setArrayDataByName("recipe_book", recipe->GetBook(), *i);
  11045. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), *i);
  11046. if(i) {
  11047. (*i)++;
  11048. }
  11049. }
  11050. }
  11051. bool Client::SetPlayerPOVGhost(Spawn* spawn) {
  11052. if(!spawn) {
  11053. pov_ghost_spawn_id = 0;
  11054. SendCharPOVGhost();
  11055. return true;
  11056. }
  11057. int32 ghost_id = player->GetIDWithPlayerSpawn(spawn);
  11058. if(ghost_id) {
  11059. pov_ghost_spawn_id = spawn->GetID();
  11060. SendCharPOVGhost();
  11061. return true;
  11062. }
  11063. return false;
  11064. }
  11065. void Client::HandleDialogSelectMsg(int32 conversation_id, int32 response_index) {
  11066. std::string conversation = "";
  11067. bool conv_established = false;
  11068. MConversation.lock_shared();
  11069. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  11070. conversation = std::string(conversation_map[conversation_id][response_index].c_str());
  11071. conv_established = true;
  11072. }
  11073. int32 spawn_id = conversation_spawns[conversation_id];
  11074. Item* item = conversation_items[conversation_id];
  11075. MConversation.unlock_shared();
  11076. if (GetCurrentZone()) {
  11077. Spawn* spawn = nullptr;
  11078. if(spawn_id) {
  11079. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  11080. }
  11081. if (conv_established) {
  11082. if (spawn) {
  11083. if(conversation == "CloseItemConversation") {
  11084. LogWrite(LUA__ERROR, 0, "LUA", "CloseItemConversation is an invalid function call for this conversation with spawn id %u", spawn_id);
  11085. }
  11086. else {
  11087. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation.c_str());
  11088. }
  11089. }
  11090. else if (item && lua_interface && item->GetItemScript())
  11091. lua_interface->RunItemScript(item->GetItemScript(), conversation.c_str(), item, player);
  11092. else
  11093. CloseDialog(conversation_id);
  11094. }
  11095. else
  11096. CloseDialog(conversation_id);
  11097. }
  11098. }
  11099. bool Client::SetPetName(const char* petName) {
  11100. int8 result = database.CheckNameFilter(petName,4,31);
  11101. if (result == BADNAMELENGTH_REPLY) {
  11102. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name length is invalid, must be greater then 3 characters and less then 31.");
  11103. return false;
  11104. }
  11105. else if (result == NAMEINVALID_REPLY) {
  11106. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is invalid, can only contain letters.");
  11107. return false;
  11108. }
  11109. else if (result == NAMETAKEN_REPLY) {
  11110. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name is already taken, please choose another.");
  11111. return false;
  11112. }
  11113. else if (result == NAMEFILTER_REPLY) {
  11114. SimpleMessage(CHANNEL_COLOR_YELLOW, "Name failed the filter check.");
  11115. return false;
  11116. }
  11117. else if (result == UNKNOWNERROR_REPLY) {
  11118. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unknown error while checking the name.");
  11119. return false;
  11120. }
  11121. GetPlayer()->GetInfoStruct()->set_pet_name(petName);
  11122. return true;
  11123. }
  11124. bool Client::CheckConsumptionAllowed(int16 slot, bool send_message) {
  11125. switch(slot) {
  11126. case EQ2_FOOD_SLOT: {
  11127. if(GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_FOOD)) {
  11128. if(send_message) {
  11129. Message(CHANNEL_NARRATIVE, "If you ate anymore you would explode!");
  11130. }
  11131. return false;
  11132. }
  11133. break;
  11134. }
  11135. case EQ2_DRINK_SLOT: {
  11136. if (GetPlayer()->GetSpellEffectBySpellType(SPELL_TYPE_DRINK))
  11137. {
  11138. if(send_message) {
  11139. Message(CHANNEL_NARRATIVE, "If you drank anymore you would explode!");
  11140. }
  11141. return false;
  11142. }
  11143. break;
  11144. }
  11145. default: {
  11146. return false;
  11147. break;
  11148. }
  11149. }
  11150. return true;
  11151. }
  11152. void Client::StartLinkdeadTimer() {
  11153. if(!linkdead_timer) {
  11154. int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
  11155. LogWrite(CCLIENT__DEBUG, 0, "Client", "Starting linkdead timer for %s (timer %u seconds)", GetPlayer()->GetName(), (LD_Timer/1000));
  11156. linkdead_timer = new Timer(LD_Timer);
  11157. linkdead_timer->Enable();
  11158. if(GetPlayer()->GetGroupMemberInfo()) {
  11159. LogWrite(CCLIENT__DEBUG, 0, "Client", "Telling player %s group they are disconnecting", GetPlayer()->GetName());
  11160. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", GetPlayer()->GetName());
  11161. }
  11162. }
  11163. }
  11164. bool Client::IsLinkdeadTimerEnabled() {
  11165. if(linkdead_timer) {
  11166. return linkdead_timer->Enabled();
  11167. }
  11168. return false;
  11169. }
  11170. void Client::SendNewAdventureSpells() {
  11171. SendNewSpells(player->GetAdventureClass());
  11172. int8 base_class = classes.GetBaseClass(player->GetAdventureClass());
  11173. int secondary_class = classes.GetSecondaryBaseClass(player->GetAdventureClass());
  11174. if(base_class != player->GetAdventureClass()) {
  11175. SendNewSpells(base_class);
  11176. }
  11177. if(secondary_class != player->GetAdventureClass() && secondary_class != base_class) {
  11178. SendNewSpells(secondary_class);
  11179. }
  11180. }
  11181. void Client::SendNewTradeskillSpells() {
  11182. SendNewTSSpells(player->GetTradeskillClass());
  11183. int8 secondary_class = classes.GetSecondaryTSBaseClass(player->GetTradeskillClass());
  11184. if(secondary_class != player->GetTradeskillClass()) {
  11185. SendNewTSSpells(secondary_class);
  11186. }
  11187. }
  11188. bool Client::AddRecipeBookToPlayer(int32 recipe_book_id, Item* item) {
  11189. Recipe* master_recipe = master_recipebook_list.GetRecipeBooks(recipe_book_id);
  11190. if(master_recipe) {
  11191. Recipe* recipe_book = new Recipe(master_recipe);
  11192. // if valid recipe book and the player doesn't have it
  11193. if (recipe_book && recipe_book->GetLevel() > GetPlayer()->GetTSLevel()) {
  11194. if(item) {
  11195. Message(CHANNEL_NARRATIVE, "Your tradeskill level is not high enough to scribe this book.");
  11196. }
  11197. safe_delete(recipe_book);
  11198. }
  11199. else if(recipe_book && item && !recipe_book->CanUseRecipeByClass(item, GetPlayer()->GetTradeskillClass())) {
  11200. if(item) {
  11201. Message(CHANNEL_NARRATIVE, "Your tradeskill class cannot use this recipe.");
  11202. }
  11203. safe_delete(recipe_book);
  11204. }
  11205. else if (recipe_book && (!item || !(GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)))){
  11206. LogWrite(PLAYER__DEBUG, 0, "Recipe", "Valid recipe book that the player doesn't have");
  11207. // Add recipe book to the players list
  11208. if(!GetPlayer()->GetRecipeBookList()->HasRecipeBook(recipe_book_id)) {
  11209. GetPlayer()->GetRecipeBookList()->AddRecipeBook(recipe_book);
  11210. }
  11211. std::vector<Recipe*> recipes;
  11212. // Get a list of all recipes this book contains
  11213. if (item && item->recipebook_info) {
  11214. //Backup I guess if the recipe book is empty for whatever reason?
  11215. for (auto& itr : item->recipebook_info->recipes) {
  11216. Recipe* r = master_recipe_list.GetRecipeByCRC(itr); //GetRecipeByName(itr.c_str());
  11217. if (r) {
  11218. recipes.push_back(r);
  11219. }
  11220. }
  11221. LogWrite(PLAYER__DEBUG, 0, "Recipe", "%i recipes found for %s book", recipes.size(), recipe_book->GetBookName());
  11222. }
  11223. else {
  11224. LogWrite(PLAYER__ERROR, 0, "Recipe", "no recipes found for %s book", recipe_book->GetBookName());
  11225. }
  11226. //Filter out duplicate recipes the player already has
  11227. for (auto itr = recipes.begin(); itr != recipes.end();) {
  11228. Recipe* recipe = *itr;
  11229. if (GetPlayer()->GetRecipeList()->GetRecipe(recipe->GetID())) {
  11230. itr = recipes.erase(itr);
  11231. }
  11232. else itr++;
  11233. }
  11234. int16 i = 0;
  11235. // Create the packet to send to update the players recipe list
  11236. PacketStruct* packet = 0;
  11237. if (!recipes.empty() && GetRecipeListSent()) {
  11238. packet = configReader.getStruct("WS_RecipeList", GetVersion());
  11239. if (packet) {
  11240. packet->setArrayLengthByName("num_recipes", recipes.size());
  11241. }
  11242. }
  11243. for (int32 r = 0; r < recipes.size(); r++) {
  11244. Recipe* recipe = recipes[r];
  11245. if (recipe) {
  11246. Recipe* player_recipe = new Recipe(recipe);
  11247. AddRecipeToPlayerPack(player_recipe, packet, &i);
  11248. }
  11249. }
  11250. LogWrite(TRADESKILL__DEBUG, 0, "Recipe", "Done adding recipes");
  11251. database.SavePlayerRecipeBook(GetPlayer(), recipe_book->GetBookID());
  11252. if(item) {
  11253. database.DeleteItem(GetCharacterID(), item, 0);
  11254. GetPlayer()->item_list.RemoveItem(item, true);
  11255. }
  11256. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  11257. SetRecipeListSent(false);
  11258. SendRecipeList();
  11259. safe_delete(packet);
  11260. return true;
  11261. }
  11262. else {
  11263. if (recipe_book && item) {
  11264. Message(CHANNEL_NARRATIVE, "You have already learned all you can from this item.");
  11265. }
  11266. safe_delete(recipe_book);
  11267. }
  11268. }
  11269. else {
  11270. LogWrite(PLAYER__ERROR, 0, "Player", "%u recipe book id does not exist. Cannot AddRecipeToPlayer.", recipe_book_id);
  11271. }
  11272. return false;
  11273. }
  11274. bool Client::RemoveRecipeFromPlayer(int32 recipe_id) {
  11275. PlayerRecipeList* prl = GetPlayer()->GetRecipeList();
  11276. PacketStruct* packet = configReader.getStruct("WS_RecipeList", version);
  11277. Recipe* recipe = prl->GetRecipe(recipe_id);
  11278. int8 level = player->GetTSLevel();
  11279. if(packet && recipe) {
  11280. packet->setDataByName("command_type", 1);
  11281. packet->setArrayLengthByName("num_recipes", 1);
  11282. int32 myid = recipe->GetID();
  11283. int8 rlevel = recipe->GetLevel();
  11284. int8 even = level - level * .05 + .5;
  11285. int8 easymin = level - level * .25 + .5;
  11286. int8 veasymin = level - level * .35 + .5;
  11287. if (rlevel > level )
  11288. packet->setArrayDataByName("tier", 4, 0);
  11289. else if ((rlevel <= level) & (rlevel >= even))
  11290. packet->setArrayDataByName("tier", 3, 0);
  11291. else if ((rlevel <= even) & (rlevel >= easymin))
  11292. packet->setArrayDataByName("tier", 2, 0);
  11293. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11294. packet->setArrayDataByName("tier", 1, 0);
  11295. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11296. packet->setArrayDataByName("tier", 0, 0);
  11297. if (rlevel == 2)
  11298. int xxx = 1;
  11299. packet->setArrayDataByName("recipe_id", myid, 0);
  11300. packet->setArrayDataByName("level", recipe->GetLevel(), 0);
  11301. packet->setArrayDataByName("unknown1", recipe->GetLevel(), 0);
  11302. packet->setArrayDataByName("icon", recipe->GetIcon(), 0);
  11303. packet->setArrayDataByName("classes", recipe->GetClasses(), 0);
  11304. packet->setArrayDataByName("technique", recipe->GetTechnique(), 0);
  11305. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), 0);
  11306. auto recipe_device = std::find(devices.begin(), devices.end(), recipe->GetDevice());
  11307. if (recipe_device != devices.end())
  11308. packet->setArrayDataByName("device_type", recipe_device - devices.begin(), 0);
  11309. else
  11310. {//TODO error should never get here
  11311. }
  11312. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), 0);
  11313. packet->setArrayDataByName("recipe_name", recipe->GetName(), 0);
  11314. packet->setArrayDataByName("recipe_book", recipe->GetBook(), 0);
  11315. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), 0);
  11316. QueuePacket(packet->serialize());
  11317. }
  11318. safe_delete(packet);
  11319. bool res = prl->RemoveRecipe(recipe_id);
  11320. if(res) {
  11321. Query query;
  11322. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "DELETE FROM character_recipes where char_id=%u and recipe_id=%u", GetCharacterID(), recipe_id);
  11323. }
  11324. return res;
  11325. }
  11326. void Client::SaveSpells() {
  11327. MSaveSpellStateMutex.lock();
  11328. player->SaveSpellEffects();
  11329. player->SetSaveSpellEffects(true);
  11330. MSaveSpellStateMutex.unlock();
  11331. }
  11332. void Client::SendReplaceWidget(int32 widget_id, bool delete_widget, float x, float y, float z, int32 grid_id) {
  11333. Widget* new_spawn = new Widget();
  11334. new_spawn->SetWidgetID(widget_id);
  11335. new_spawn->SetLocation(grid_id);
  11336. new_spawn->SetWidgetX(x);
  11337. new_spawn->SetWidgetY(y);
  11338. new_spawn->SetWidgetZ(z);
  11339. new_spawn->SetX(x);
  11340. new_spawn->SetY(y);
  11341. new_spawn->SetZ(z);
  11342. EQ2Packet* ret = new_spawn->serialize(GetPlayer(), GetVersion());
  11343. QueuePacket(ret);
  11344. // we have to delete spawn* references anyway, we don't keep this widget live in the spawn list
  11345. GetPlayer()->RemoveSpawn(new_spawn, delete_widget);
  11346. safe_delete(new_spawn);
  11347. }
  11348. void Client::ProcessZoneIgnoreWidgets() {
  11349. GetPlayer()->MIgnoredWidgets.lock_shared();
  11350. std::map<int32, bool>::iterator itr;
  11351. for(itr = GetPlayer()->ignored_widgets.begin(); itr != GetPlayer()->ignored_widgets.end(); itr++) {
  11352. SendReplaceWidget(itr->first, true);
  11353. }
  11354. GetPlayer()->MIgnoredWidgets.unlock_shared();
  11355. }
  11356. void Client::PopulateRecipeData(Recipe* recipe, PacketStruct* packet, int i) {
  11357. if(!recipe || !packet)
  11358. return;
  11359. int8 level = player->GetTSLevel();
  11360. int32 myid = recipe->GetID();
  11361. int8 rlevel = recipe->GetLevel();
  11362. int8 even = level - level * .05 + .5;
  11363. int8 easymin = level - level * .25 + .5;
  11364. int8 veasymin = level - level * .35 + .5;
  11365. if (rlevel > level )
  11366. packet->setArrayDataByName("tier", 4, i);
  11367. else if ((rlevel <= level) & (rlevel >= even))
  11368. packet->setArrayDataByName("tier", 3, i);
  11369. else if ((rlevel <= even) & (rlevel >= easymin))
  11370. packet->setArrayDataByName("tier", 2, i);
  11371. else if ((rlevel <= easymin) & (rlevel >= veasymin))
  11372. packet->setArrayDataByName("tier", 1, i);
  11373. else if ((rlevel <= veasymin) & (rlevel >= 0))
  11374. packet->setArrayDataByName("tier", 0, i);
  11375. if (rlevel == 2)
  11376. int xxx = 1;
  11377. packet->setArrayDataByName("recipe_id", myid, i);
  11378. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  11379. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  11380. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  11381. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  11382. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  11383. packet->setArrayDataByName("device", recipe->GetDevice(), i);
  11384. packet->setArrayDataByName("device_sub_type", recipe->GetDevice_Sub_Type(), i);
  11385. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  11386. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  11387. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  11388. packet->setArrayDataByName("book_volume", 0x01, i);
  11389. packet->setArrayDataByName("device_id", 0x01, i);
  11390. }
  11391. int32 Client::GetRecipeCRC(Recipe* recipe) {
  11392. PacketStruct* packet = 0;
  11393. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11394. return 0;
  11395. }
  11396. packet->setArrayLengthByName("num_recipes", 1);
  11397. PopulateRecipeData(recipe, packet);
  11398. string* generic_string_data = packet->serializeString();
  11399. int32 size = generic_string_data->length();
  11400. if(size < 5)
  11401. return 0;
  11402. uchar* out_data = new uchar[size+1];
  11403. uchar* out_ptr = out_data;
  11404. memcpy(out_ptr, (uchar*)generic_string_data->c_str()+4, generic_string_data->length()-4);
  11405. uint32 out_crc = GenerateCRCRecipe(0, (void*)out_ptr, size-4);
  11406. safe_delete(packet);
  11407. safe_delete_array(out_data);
  11408. return out_crc;
  11409. }
  11410. void Client::SendRecipeDetails(vector<int32>* recipes) {
  11411. if(!recipes || recipes->size() == 0)
  11412. return;
  11413. PacketStruct* packet = 0;
  11414. if (!(packet = configReader.getStruct("WS_RecipeDetailList", GetVersion()))) {
  11415. return;
  11416. }
  11417. int32 recipe_size = player->GetRecipeList()->Size();
  11418. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11419. int16 i = 0;
  11420. int32 count = 0;
  11421. vector<int32>::iterator recipe_itr;
  11422. for(recipe_itr = recipes->begin(); recipe_itr != recipes->end(); recipe_itr++) {
  11423. Recipe* recipe = player->GetRecipeList()->GetRecipe(*recipe_itr);
  11424. if(!recipe) {
  11425. continue;
  11426. }
  11427. else if(i > 99) {
  11428. QueuePacket(packet->serialize());
  11429. safe_delete(packet);
  11430. packet = configReader.getStruct("WS_RecipeDetailList", GetVersion());
  11431. recipe_size -= i;
  11432. packet->setArrayLengthByName("num_recipes", recipe_size > 100 ? 100 : recipe_size);
  11433. i = 0;
  11434. }
  11435. count++;
  11436. PopulateRecipeData(recipe, packet, i);
  11437. i++;
  11438. }
  11439. //packet->PrintPacket();
  11440. QueuePacket(packet->serialize());
  11441. safe_delete(packet);
  11442. }
  11443. ZoneServer* Client::GetHouseZoneServer(int32 spawn_id, int64 house_id) {
  11444. PlayerHouse* ph = nullptr;
  11445. HouseZone* hz = nullptr;
  11446. if(spawn_id) {
  11447. Spawn* houseWidget = GetPlayer()->GetSpawnByIndex(spawn_id);
  11448. if(houseWidget && houseWidget->IsWidget() && ((Widget*)houseWidget)->GetHouseID()) {
  11449. hz = world.GetHouseZone(((Widget*)houseWidget)->GetHouseID());
  11450. if (hz) {
  11451. ph = world.GetPlayerHouseByHouseID(GetPlayer()->GetCharacterID(), hz->id);
  11452. } else {
  11453. Message(CHANNEL_COLOR_YELLOW, "HouseWidget spawn index %u house zone could not be found.", spawn_id);
  11454. }
  11455. }
  11456. }
  11457. if(!ph && house_id) {
  11458. ph = world.GetPlayerHouseByUniqueID(house_id);
  11459. if (ph) {
  11460. hz = world.GetHouseZone(ph->house_id);
  11461. }
  11462. }
  11463. if (ph && hz) {
  11464. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id, false, true);
  11465. return house;
  11466. }
  11467. return nullptr;
  11468. }
  11469. void Client::SendHearCast(Spawn* caster, Spawn* target, int32 spell_visual, int16 cast_time) {
  11470. PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", GetVersion());
  11471. if (packet) {
  11472. int32 caster_id = GetPlayer()->GetIDWithPlayerSpawn(caster);
  11473. int32 target_id = GetPlayer()->GetIDWithPlayerSpawn(target);
  11474. packet->setDataByName("spawn_id", caster_id);
  11475. packet->setArrayLengthByName("num_targets", 1);
  11476. packet->setArrayDataByName("target", target_id);
  11477. packet->setDataByName("num_targets", 1);
  11478. int32 visual = GetSpellVisualOverride(spell_visual);
  11479. packet->setDataByName("spell_visual", visual); //result
  11480. packet->setDataByName("cast_time", cast_time*.01f); //delay
  11481. packet->setDataByName("spell_id", 1);
  11482. packet->setDataByName("spell_level", 1);
  11483. packet->setDataByName("spell_tier", 1);
  11484. EQ2Packet* outapp = packet->serialize();
  11485. DumpPacket(outapp);
  11486. QueuePacket(outapp);
  11487. safe_delete(packet);
  11488. }
  11489. }
  11490. int32 Client::GetSpellVisualOverride(int32 spell_visual) {
  11491. int32 visual = spell_visual;
  11492. if(GetVersion() <= 546) { // spell's spell_visual field is based on newer clients, DoF has to convert
  11493. Emote* spellVisualEmote = visual_states.FindSpellVisualByID(visual, 60085);
  11494. if(spellVisualEmote != nullptr && spellVisualEmote->GetMessageString().size() > 0) {
  11495. spellVisualEmote = visual_states.FindSpellVisual(spellVisualEmote->GetMessageString(), GetVersion());
  11496. if(spellVisualEmote) {
  11497. visual = (int32)spellVisualEmote->GetVisualState();
  11498. }
  11499. }
  11500. }
  11501. return visual;
  11502. }