client.cpp 391 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "IRC/IRC.h"
  36. #include "Chat/Chat.h"
  37. #include "SpellProcess.h"
  38. #include "Zone/ChestTrap.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. extern WorldDatabase database;
  81. extern const char* ZONE_NAME;
  82. extern LoginServer loginserver;
  83. extern sint32 numclients;
  84. extern NetConnection net;
  85. extern Commands commands;
  86. extern ClientList client_list;
  87. extern ZoneList zone_list;
  88. extern ZoneAuth zone_auth;
  89. extern MasterItemList master_item_list;
  90. extern MasterSkillList master_skill_list;
  91. extern MasterSpellList master_spell_list;
  92. extern MasterTraitList master_trait_list;
  93. extern MasterQuestList master_quest_list;
  94. extern MasterFactionList master_faction_list;
  95. extern MasterRecipeList master_recipe_list;
  96. extern volatile bool RunLoops;
  97. extern ConfigReader configReader;
  98. extern LuaInterface* lua_interface;
  99. extern World world;
  100. extern Variables variables;
  101. extern Classes classes;
  102. extern Races races;
  103. extern GuildList guild_list;
  104. extern MasterCollectionList master_collection_list;
  105. extern MasterAchievementList master_achievement_list;
  106. extern RuleManager rule_manager;
  107. extern IRC irc;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. using namespace std;
  113. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  114. eqs = ieqs;
  115. ip = eqs->GetrIP();
  116. port = ntohs(eqs->GetrPort());
  117. merchant_transaction = nullptr;
  118. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  119. ResetSendMail(false);
  120. timestamp_flag = 0;
  121. current_quest_id = 0;
  122. last_update_time = 0;
  123. quest_updates = false;
  124. //autobootup_timeout = new Timer(10000);
  125. //autobootup_timeout->Disable();
  126. CLE_keepalive_timer = new Timer(15000);
  127. connect = new Timer(1000);
  128. connect->Disable();
  129. zoneID = 0;
  130. account_name[0] = 0;
  131. character_id = 0;
  132. account_id = 0;
  133. pwaitingforbootup = 0;
  134. current_zone = 0;
  135. connected_to_zone = false;
  136. connected = false;
  137. camp_timer = 0;
  138. client_zoning = false;
  139. zoning_id = 0;
  140. zoning_x = 0;
  141. zoning_y = 0;
  142. zoning_z = 0;
  143. zoning_instance_id = 0;
  144. player_pos_changed = false;
  145. ++numclients;
  146. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  147. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  148. remove_from_list = false;
  149. new_client_login = false;
  150. UpdateWindowTitle(0);
  151. num_active_failures = 0;
  152. player = new Player();
  153. player->SetClient(this);
  154. combine_spawn = 0;
  155. lua_debug = false;
  156. ready_for_spawns = false;
  157. ready_for_updates = false;
  158. lua_debug_timer.Disable();
  159. transport_spawn = 0;
  160. MBuyBack.SetName("Client::MBuyBack");
  161. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  162. MDeletePlayer.SetName("Client::MDeletePlayer");
  163. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  164. search_items = 0;
  165. version = 0;
  166. next_conversation_id = 0;
  167. pending_guild_invite.guild = 0;
  168. pending_guild_invite.invited_by = 0;
  169. m_recipeListSent = false;
  170. m_resurrect.SetName("Client::m_resurrect");
  171. current_rez.expire_timer = 0;
  172. current_rez.should_delete = true;
  173. pending_last_name = 0;
  174. should_target = false;
  175. initial_spawns_sent = false;
  176. MQuestTimers.SetName("Client::quest_timers");
  177. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  178. on_auto_mount = false;
  179. should_load_spells = true;
  180. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  181. delayedLogin = false;
  182. delayedAccountID = 0;
  183. delayedAccessKey = 0;
  184. delayTimer.Disable();
  185. tempPlacementSpawn = nullptr;
  186. placement_unique_item_id = 0;
  187. SetHasOwnerOrEditAccess(false);
  188. temporary_transport_id = 0;
  189. rejoin_group_id = 0;
  190. lastRegionRemapTime = 0;
  191. regionDebugMessaging = false;
  192. client_reloading_zone = false;
  193. last_saved_timestamp = 0;
  194. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  195. MConversation.SetName("Client::MConversation");
  196. save_spell_state_timer.Disable();
  197. save_spell_state_time_bucket = 0;
  198. player_loading_complete = false;
  199. MItemDetails.SetName("Client::MItemDetails");
  200. MSpellDetails.SetName("Client::MSpellDetails");
  201. hasSentTempPlacementSpawn = false;
  202. spawn_removal_timer.Start();
  203. disable_save = false;
  204. SetZoningDestination(nullptr);
  205. }
  206. Client::~Client() {
  207. RemoveClientFromZone();
  208. //let the stream factory know were done with this stream
  209. if (eqs) {
  210. eqs->Close();
  211. try {
  212. eqs->ReleaseFromUse();
  213. }
  214. catch (...) {}
  215. }
  216. eqs = NULL;
  217. //safe_delete(autobootup_timeout);
  218. vector<QueuedQuest*>::iterator itr;
  219. QueuedQuest* queued_quest = 0;
  220. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  221. queued_quest = *itr;
  222. safe_delete(queued_quest);
  223. }
  224. quest_queue.clear();
  225. vector<QuestRewardData*>::iterator rwd_itr;
  226. QuestRewardData* quest_rwd_data = 0;
  227. for (rwd_itr = quest_pending_reward.begin(); rwd_itr != quest_pending_reward.end(); rwd_itr++) {
  228. quest_rwd_data = *rwd_itr;
  229. safe_delete(quest_rwd_data);
  230. }
  231. quest_pending_reward.clear();
  232. safe_delete(CLE_keepalive_timer);
  233. safe_delete(connect);
  234. --numclients;
  235. UpdateWindowTitle(0);
  236. }
  237. void Client::RemoveClientFromZone() {
  238. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  239. Spawn* tmp = GetTempPlacementSpawn();
  240. SetTempPlacementSpawn(nullptr);
  241. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  242. }
  243. if(player && player->GetZone())
  244. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  245. if (current_zone && player) {
  246. if (player->GetGroupMemberInfo())
  247. {
  248. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  249. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  250. else
  251. TempRemoveGroup();
  252. }
  253. world.GetGroupManager()->ClearPendingInvite(player);
  254. }
  255. if (lua_interface)
  256. lua_interface->RemoveDebugClients(this);
  257. if (player)
  258. zone_list.RemoveClientFromMap(player->GetName(), this);
  259. safe_delete(camp_timer);
  260. safe_delete(search_items);
  261. safe_delete(current_rez.expire_timer);
  262. safe_delete(pending_last_name);
  263. safe_delete_array(incoming_paperdoll.image_bytes);
  264. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  265. if (player && !player->GetPendingDeletion())
  266. safe_delete(player);
  267. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  268. deque<BuyBackItem*>::iterator itr;
  269. MBuyBack.writelock(__FUNCTION__, __LINE__);
  270. for (itr = buy_back_items.begin(); itr != buy_back_items.end();) {
  271. safe_delete(*itr);
  272. itr = buy_back_items.erase(itr);
  273. }
  274. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  275. }
  276. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  277. if (eqs) {
  278. if (!eqs->CheckActive()) {
  279. client_list.Remove(this);
  280. eqs = 0;
  281. }
  282. }
  283. if (app && eqs && version > 0)
  284. eqs->EQ2QueuePacket(app, attemptedCombine);
  285. else {
  286. safe_delete(app);
  287. }
  288. }
  289. void Client::PopulateSkillMap() {
  290. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  291. if (app)
  292. QueuePacket(app);
  293. else {
  294. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  295. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  296. }
  297. }
  298. void Client::SendLoginInfo() {
  299. if(GetPlayer()->IsReturningFromLD())
  300. firstlogin = true;
  301. if (firstlogin) {
  302. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  303. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  304. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  305. PopulateSkillMap();
  306. // 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!
  307. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  308. }
  309. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  310. database.ToggleCharacterOnline(this, 1);
  311. int32 count = 0;
  312. if(!GetPlayer()->IsReturningFromLD())
  313. {
  314. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  315. count = database.LoadCharacterSkills(GetCharacterID(), player);
  316. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  317. count = database.LoadCharacterSpells(GetCharacterID(), player);
  318. }
  319. else
  320. {
  321. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  322. }
  323. // get the latest character starting skills / spells, may have been updated after character creation
  324. world.SyncCharacterAbilities(this);
  325. if(!GetPlayer()->IsReturningFromLD())
  326. {
  327. count = database.LoadCharacterTitles(GetCharacterID(), player);
  328. if (count == 0) {
  329. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  330. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  331. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  332. }
  333. }
  334. if(!GetPlayer()->IsReturningFromLD())
  335. {
  336. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  337. if (count == 0)
  338. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  339. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  340. if (count == 0)
  341. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  342. }
  343. ClientPacketFunctions::SendLoginAccepted(this);
  344. ClientPacketFunctions::SendAbilities ( this );
  345. ClientPacketFunctions::SendCommandNamePacket(this);
  346. ClientPacketFunctions::SendQuickBarInit(this);
  347. // we only need to send the MOTD if it is the first time the person is logging in.
  348. if (firstlogin) {
  349. ClientPacketFunctions::SendMOTD(this);
  350. ClientPacketFunctions::SendCharacterMacros(this);
  351. zone_list.CheckFriendList(this);
  352. }
  353. if(!GetPlayer()->IsReturningFromLD())
  354. {
  355. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  356. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  357. {
  358. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  359. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  360. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  361. }
  362. database.LoadPlayerFactions(this);
  363. database.LoadCharacterQuests(this);
  364. database.LoadCharacterQuestRewards(this);
  365. database.LoadPlayerMail(this);
  366. }
  367. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  368. SendQuestJournal(true, 0, false);
  369. if (version > 546) // right version? possibly not!
  370. master_aa_list.DisplayAA(this, 0, 3);
  371. if (version > 283)
  372. SendCollectionList();
  373. SendBiography();
  374. map<int32, Quest*>::iterator itr;
  375. Quest* quest = 0;
  376. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  377. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  378. quest = itr->second;
  379. if (quest->IsTracked()) {
  380. quest->SetTracked(false);
  381. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  382. quest->SetTracked(true);
  383. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  384. }
  385. }
  386. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  387. // SendAchievementsList();
  388. /*Guild* guild = player->GetGuild();
  389. if (guild) {
  390. guild->UpdateGuildMemberInfo(GetPlayer());
  391. if (firstlogin)
  392. guild->SendGuildMOTD(this);
  393. guild->SendGuildUpdate(this);
  394. guild->SendGuildMember(GetPlayer(), firstlogin);
  395. guild->SendGuildEventList(this);
  396. guild->SendGuildBankEventList(this);
  397. guild->SendAllGuildEvents(this);
  398. guild->SendGuildMemberList(this);
  399. }*/
  400. if (version > 283) {
  401. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  402. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  403. if (outapp) {
  404. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  405. //DumpPacket(outapp);
  406. QueuePacket(outapp);
  407. }
  408. }
  409. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  410. ClientPacketFunctions::SendCommandList(this);
  411. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  412. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  413. ClientPacketFunctions::SendInstanceList(this);
  414. SendZoneInfo();
  415. /*Spell* spell = 0;
  416. vector<QuickBarItem*>::iterator itr;
  417. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  418. if((*itr)->type == 1){
  419. spell = master_spell_list.GetSpell((*itr)->id);
  420. if(spell)
  421. QueuePacket(spell->serialize(this, false, 0x20));
  422. }
  423. }*/
  424. }
  425. void Client::SendPlayerDeathWindow()
  426. {
  427. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  428. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  429. vector<RevivePoint*>::iterator itr;
  430. if (results && results->size() > 0)
  431. {
  432. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  433. if (packet)
  434. {
  435. packet->setArrayLengthByName("location_count", results->size());
  436. RevivePoint* point = 0;
  437. int32 i = 0;
  438. for (itr = results->begin(); itr != results->end(); itr++, i++)
  439. {
  440. point = *itr;
  441. if (point)
  442. {
  443. packet->setArrayDataByName("location_id", point->id, i);
  444. //zone_name = database.GetZoneName(point->zone_id);
  445. string zone_name = database.GetZoneDescription(point->zone_id);
  446. if (zone_name.length() > 0)
  447. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  448. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  449. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  450. }
  451. if (point->id == 0xFFFFFFFF)//tmp location
  452. safe_delete(point);
  453. }
  454. // done with the revive points so lets free up the pointer
  455. safe_delete(results);
  456. #if EQDEBUG >= 3
  457. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  458. packet->PrintPacket();
  459. #endif
  460. EQ2Packet* outapp = packet->serialize();
  461. QueuePacket(outapp);
  462. safe_delete(packet);
  463. }
  464. }
  465. }
  466. void Client::DisplayDeadWindow()
  467. {
  468. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  469. player->SetHP(0);
  470. player->SetPower(0);
  471. GetCurrentZone()->TriggerCharSheetTimer();
  472. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  473. if (packet)
  474. {
  475. packet->setDataByName("parameter1", 8);
  476. packet->setDataByName("value", 1);
  477. QueuePacket(packet->serialize());
  478. packet->setDataByName("parameter1", 16);
  479. QueuePacket(packet->serialize());
  480. safe_delete(packet);
  481. }
  482. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  483. if (packet)
  484. {
  485. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  486. QueuePacket(packet->serialize());
  487. safe_delete(packet);
  488. }
  489. SendPlayerDeathWindow();
  490. }
  491. void Client::HandlePlayerRevive(int32 point_id)
  492. {
  493. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  494. if (packet)
  495. {
  496. packet->setDataByName("parameter1", 8);
  497. QueuePacket(packet->serialize());
  498. packet->setDataByName("parameter1", 16);
  499. QueuePacket(packet->serialize());
  500. safe_delete(packet);
  501. }
  502. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  503. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  504. if (packet)
  505. {
  506. QueuePacket(packet->serialize());
  507. safe_delete(packet);
  508. }
  509. float origX, origY, origZ, origHeading = 0.0f;
  510. origX = player->GetX();
  511. origY = player->GetY();
  512. origZ = player->GetZ();
  513. origHeading = player->GetHeading();
  514. ZoneServer* originalZone = GetCurrentZone();
  515. int32 origGridID = GetPlayer()->appearance.pos.grid_id;
  516. float x, y, z, heading;
  517. RevivePoint* revive_point = 0;
  518. if (point_id != 0xFFFFFFFF)
  519. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  520. string zone_desc;
  521. const char* location_name = "Unknown";
  522. //revive at zone safe coords
  523. if (!revive_point)
  524. {
  525. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  526. x = GetCurrentZone()->GetSafeX();
  527. y = GetCurrentZone()->GetSafeY();
  528. z = GetCurrentZone()->GetSafeZ();
  529. heading = GetCurrentZone()->GetSafeHeading();
  530. zone_desc = GetCurrentZone()->GetZoneDescription();
  531. location_name = "Zone Safe Point";
  532. Zone(GetCurrentZone()->GetZoneName(), false);
  533. }
  534. else
  535. {
  536. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  537. x = revive_point->x;
  538. y = revive_point->y;
  539. z = revive_point->z;
  540. heading = revive_point->heading;
  541. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  542. location_name = revive_point->location_name.c_str();
  543. Zone(GetCurrentZone()->GetZoneName(), false);
  544. }
  545. player->SetResurrecting(true);
  546. player->SetX(x);
  547. player->SetY(y);
  548. player->SetZ(z);
  549. player->SetHeading(heading);
  550. player->SetHP(player->GetTotalHP());
  551. player->SetPower(player->GetTotalPower());
  552. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  553. zone_desc.c_str(),
  554. player->GetX(),
  555. player->GetY(),
  556. player->GetZ(),
  557. player->GetHeading(),
  558. player->GetHP(),
  559. player->GetPower(),
  560. location_name);
  561. //player->ClearEverything();
  562. Save();
  563. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  564. {
  565. string zone_name = database.GetZoneName(revive_point->zone_id);
  566. if (zone_name.length() == 0)
  567. {
  568. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  569. x = GetCurrentZone()->GetSafeX();
  570. y = GetCurrentZone()->GetSafeY();
  571. z = GetCurrentZone()->GetSafeZ();
  572. heading = GetCurrentZone()->GetSafeHeading();
  573. location_name = "Zone Safe Point";
  574. }
  575. else
  576. {
  577. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  578. location_name = revive_point->location_name.c_str();
  579. player->ClearEverything();
  580. Zone(zone_name.c_str(), false);
  581. }
  582. }
  583. zone_desc = GetCurrentZone()->GetZoneDescription();
  584. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  585. player->SetSpawnType(4);
  586. if (version > 283) {
  587. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  588. if (packet)
  589. {
  590. QueuePacket(packet->serialize());
  591. safe_delete(packet);
  592. }
  593. }
  594. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  595. if (packet)
  596. {
  597. packet->setDataByName("x", x);
  598. packet->setDataByName("y", y);
  599. packet->setDataByName("z", z);
  600. QueuePacket(packet->serialize());
  601. safe_delete(packet);
  602. }
  603. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  604. if (packet)
  605. {
  606. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  607. packet->setDataByName("speed", 32);
  608. packet->setDataByName("unknown2", 0);
  609. //DoF Merge: old value and speed wasn't included
  610. //packet->setDataByName("unknown2", 255);
  611. QueuePacket(packet->serialize());
  612. safe_delete(packet);
  613. }
  614. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  615. if (packet)
  616. {
  617. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  618. QueuePacket(packet->serialize());
  619. safe_delete(packet);
  620. }
  621. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  622. {
  623. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  624. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  625. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  626. originalZone->RemoveSpawn(player, false, true, true, true, true);
  627. originalZone->AddSpawn(shard);
  628. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  629. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  630. }
  631. m_resurrect.writelock(__FUNCTION__, __LINE__);
  632. if (current_rez.active)
  633. current_rez.should_delete = true;
  634. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  635. }
  636. void Client::SendCharInfo() {
  637. EQ2Packet* app;
  638. player->SetEquippedItemAppearances();
  639. ClientPacketFunctions::SendCharacterData(this);
  640. SendCharPOVGhost();
  641. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  642. if (packet) {
  643. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  644. packet->setDataByName("size", .56);
  645. packet->setDataByName("unknown2", 255);
  646. packet->setDataByName("speed", player->GetSpeed());
  647. packet->setDataByName("air_speed", player->GetAirSpeed());
  648. EQ2Packet* app = packet->serialize();
  649. QueuePacket(app);
  650. safe_delete(packet);
  651. }
  652. if (version <= 283) {
  653. //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
  654. Sleep(2000);
  655. }
  656. //sending bad spawn packet?
  657. //SendAchievementsList();
  658. ClientPacketFunctions::SendCharacterSheet(this);
  659. ClientPacketFunctions::SendTraitList(this);// moved from below
  660. ClientPacketFunctions::SendAbilities(this);
  661. ClientPacketFunctions::SendSkillBook(this);
  662. if (!IsReloadingZone() && !player->IsResurrecting()) {
  663. if(GetVersion() > 546) //we will send this later on for 546 and below
  664. ClientPacketFunctions::SendUpdateSpellBook(this);
  665. }
  666. else {
  667. player->SetResurrecting(false);
  668. }
  669. ClientPacketFunctions::SendLoginCommandMessages(this);
  670. GetCurrentZone()->AddSpawn(player);
  671. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  672. GetPlayer()->SetX(zoning_x);
  673. GetPlayer()->SetY(zoning_y);
  674. GetPlayer()->SetZ(zoning_z);
  675. GetPlayer()->SetHeading(zoning_h);
  676. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  677. QueuePacket(packet);
  678. }
  679. //SendCollectionList();
  680. Guild* guild = player->GetGuild();
  681. if (guild)
  682. guild->GuildMemberLogin(this, firstlogin);
  683. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  684. if (app) {
  685. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  686. //DumpPacket(app);
  687. QueuePacket(app);
  688. }
  689. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  690. if (app) {
  691. QueuePacket(app);
  692. }
  693. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  694. if (app) {
  695. QueuePacket(app);
  696. }
  697. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  698. if (items && items->size() > 0) {
  699. for (int32 i = 0; i < items->size(); i++) {
  700. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  701. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  702. //DumpPacket(outapp);
  703. QueuePacket(outapp);
  704. }
  705. }
  706. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  707. QueuePacket(app);
  708. safe_delete(items);
  709. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  710. if (items && items->size() > 0) {
  711. for (int32 i = 0; i < items->size(); i++)
  712. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  713. }
  714. safe_delete(items);
  715. if (version > 283) {
  716. SendTitleUpdate();
  717. }
  718. GetPlayer()->ChangePrimaryWeapon();
  719. GetPlayer()->ChangeSecondaryWeapon();
  720. GetPlayer()->ChangeRangedWeapon();
  721. if(!GetPlayer()->IsReturningFromLD()) {
  722. database.LoadBuyBacks(this);
  723. }
  724. if (version > 546)
  725. master_aa_list.DisplayAA(this, 0, 0);
  726. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  727. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  728. string zone_motd_send = "Zone MOTD: " + zone_motd;
  729. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  730. }
  731. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  732. if (zone_script && lua_interface)
  733. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  734. this->client_zoning = false;
  735. this->zoning_id = 0;
  736. this->zoning_instance_id = 0;
  737. SetZoningDestination(nullptr);
  738. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  739. GetCurrentZone()->AddDamagedSpawn(player);
  740. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  741. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  742. if (firstlogin)
  743. firstlogin = false;
  744. player->ClearProcs();
  745. items = player->GetEquippedItemList();
  746. if (items && items->size() > 0) {
  747. for (int32 i = 0; i < items->size(); i++) {
  748. Item* item = items->at(i);
  749. if (item && item->GetItemScript() && lua_interface)
  750. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  751. }
  752. }
  753. //Allow this player to change their last name if they meet the level requirement
  754. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  755. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  756. safe_delete(items);
  757. if (!player->Alive())
  758. DisplayDeadWindow();
  759. ClientPacketFunctions::SendLocalizedTextMessage(this);
  760. if (GetCurrentZone()->GetInstanceID())
  761. {
  762. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  763. if (ph) {
  764. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  765. string name = string(GetPlayer()->GetName());
  766. if (name.compare(ph->player_name) == 0)
  767. SetHasOwnerOrEditAccess(true);
  768. }
  769. }
  770. if (version > 546)
  771. ClientPacketFunctions::SendHousingList(this);
  772. bool groupMentor = false;
  773. GetPlayer()->group_id = rejoin_group_id;
  774. if(!world.RejoinGroup(this, rejoin_group_id))
  775. GetPlayer()->group_id = 0;
  776. else
  777. {
  778. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  779. if(ent && ent->IsPlayer())
  780. {
  781. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  782. groupMentor = true;
  783. }
  784. }
  785. if(!groupMentor)
  786. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  787. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  788. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  789. GetPlayer()->SetSaveSpellEffects(false);
  790. GetPlayer()->SetCharSheetChanged(true);
  791. GetPlayer()->SetReturningFromLD(false);
  792. }
  793. void Client::SendZoneSpawns() {
  794. //Allows us to place spawns almost anywhere
  795. if (version > 283) {
  796. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  797. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  798. QueuePacket(app);
  799. }
  800. ClientPacketFunctions::SendSkillSlotMappings(this);
  801. ClientPacketFunctions::SendGameWorldTime(this);
  802. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  803. }
  804. void Client::SendCharPOVGhost() {
  805. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  806. if (set_pov) {
  807. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  808. EQ2Packet* app_pov = set_pov->serialize();
  809. QueuePacket(app_pov);
  810. safe_delete(set_pov);
  811. }
  812. }
  813. void Client::SendZoneInfo() {
  814. ZoneServer* zone = GetCurrentZone();
  815. if (zone) {
  816. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  817. QueuePacket(packet);
  818. if (version > 283) {
  819. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  820. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  821. #if EQDEBUG >= 9
  822. fog_packet->PrintPacket();
  823. #endif
  824. if (fog_packet) {
  825. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  826. QueuePacket(fog_packet->serialize());
  827. safe_delete(fog_packet);
  828. }
  829. zone->SendFlightPathsPackets(this);
  830. }
  831. }
  832. /*
  833. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  834. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  835. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  836. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  837. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  838. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  839. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  840. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  843. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  844. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  847. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  848. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  849. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  853. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  854. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  855. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  856. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  857. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  858. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  859. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  860. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  861. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  862. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  863. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  864. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0xFF,0x00};
  869. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  870. QueuePacket(appA);
  871. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  872. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  873. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  874. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  875. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  876. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  877. QueuePacket(appB);
  878. */
  879. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  880. SendFriendList();
  881. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  882. SendIgnoreList();
  883. }
  884. void Client::SendDefaultGroupOptions() {
  885. /*
  886. 0 - loot method
  887. 1 - loot items rarity
  888. 2 - Auto split coin
  889. 4 - default yell method
  890. 6 - group autolock
  891. 7 - solo autolock
  892. */
  893. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  894. if (default_options) {
  895. default_options->setDataByName("loot_method", 1);
  896. default_options->setDataByName("loot_items_rarity", 1);
  897. default_options->setDataByName("auto_split_coin", 1);
  898. default_options->setDataByName("default_yell_method", 1);
  899. EQ2Packet* app7 = default_options->serialize();
  900. QueuePacket(app7);
  901. safe_delete(default_options);
  902. }
  903. }
  904. bool Client::HandlePacket(EQApplicationPacket* app) {
  905. bool ret = true;
  906. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  907. //DumpPacket(app);
  908. #if EQDEBUG >= 9
  909. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  910. DumpPacket(app, true);
  911. #endif
  912. EmuOpcode opcode = app->GetOpcode();
  913. #if EQDEBUG >= 9
  914. const char* name = app->GetOpcodeName();
  915. if (name)
  916. cout << name;
  917. else
  918. cout << "Unknown";
  919. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  920. DumpPacket(app);
  921. #endif
  922. //if (opcode != OP_UpdatePositionMsg) {
  923. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  924. //}
  925. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  926. {
  927. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  928. }
  929. switch (opcode) {
  930. case _maxEmuOpcode:
  931. break;
  932. case OP_LoginByNumRequestMsg: {
  933. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  934. PacketStruct* request;
  935. request = configReader.getStruct("LoginByNumRequest", 1);
  936. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  937. // test the original location of Version for clients older than 1212
  938. version = request->getType_int16_ByName("version");
  939. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  940. // must be new client data version method, re-fetch the packet
  941. safe_delete(request);
  942. request = configReader.getStruct("LoginByNumRequest", 1208);
  943. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  944. // Xinux suggests using an INT16 here. Our first new version = 57000
  945. version = request->getType_int16_ByName("version");
  946. }
  947. else {
  948. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  949. break;
  950. }
  951. }
  952. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  953. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  954. ClientPacketFunctions::SendLoginDenied(this);
  955. return false;
  956. }
  957. int32 account_id = request->getType_int32_ByName("account_id");
  958. int32 access_code = request->getType_int32_ByName("access_code");
  959. if (!HandleNewLogin(account_id, access_code))
  960. return false;
  961. }
  962. safe_delete(request);
  963. break;
  964. }
  965. case OP_MapRequest: {
  966. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  967. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  968. if (packet && app->size > 2 && GetCurrentZone()) {
  969. packet->LoadPacketData(app->pBuffer, app->size);
  970. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  971. if (fog_packet) {
  972. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  973. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  974. fog_packet->setDataByName("unknown1", 1);
  975. fog_packet->setDataByName("unknown3", 1);
  976. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  977. //fog_packet->PrintPacket();
  978. QueuePacket(fog_packet->serialize());
  979. safe_delete(fog_packet);
  980. }
  981. safe_delete(packet);
  982. }
  983. break;
  984. }
  985. case OP_RequestCampMsg: {
  986. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  987. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  988. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  989. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  990. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  991. request->getType_int8_ByName("quit"),
  992. request->getType_int8_ByName("camp_desktop"),
  993. request->getType_int16_ByName("camp_char_select"),
  994. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  995. //DumpPacket(app->pBuffer, app->size);
  996. //request->PrintPacket();
  997. if (!camp_timer) {
  998. int16 camp_time = 20; // default if rule cannot be found
  999. if (GetAdminStatus() >= 100)
  1000. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  1001. else
  1002. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  1003. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  1004. if (response) {
  1005. bool disconnect = false;
  1006. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  1007. // Command: /camp desktop
  1008. // Command: /quit
  1009. response->setDataByName("camp_desktop", 1);
  1010. disconnect = true;
  1011. }
  1012. else {
  1013. // Command: /camp
  1014. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  1015. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  1016. response->setDataByName("seconds", camp_time);
  1017. }
  1018. camp_timer = new Timer(camp_time * 1000);
  1019. camp_timer->Enable();
  1020. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  1021. // /camp {char_name}
  1022. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1023. }
  1024. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1025. // /camp (go back to char selection screen)
  1026. response->setDataByName("char_name", " ");
  1027. response->setDataByName("camp_char_select", 1);
  1028. }
  1029. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1030. response->getType_int8_ByName("seconds"),
  1031. response->getType_int8_ByName("camp_desktop"),
  1032. response->getType_int8_ByName("camp_char_select"),
  1033. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1034. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1035. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1036. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1037. //response->PrintPacket();
  1038. QueuePacket(response->serialize());
  1039. safe_delete(response);
  1040. if (disconnect)
  1041. Disconnect();
  1042. }
  1043. }
  1044. }
  1045. safe_delete(request);
  1046. break;
  1047. }
  1048. case OP_StoodMsg: {
  1049. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1050. if (camp_timer)
  1051. {
  1052. // JA: clear camping flag
  1053. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1054. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1055. safe_delete(camp_timer);
  1056. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1057. QueuePacket(outapp);
  1058. }
  1059. player->SetTempVisualState(0);
  1060. break;
  1061. }
  1062. case OP_StandMsg: {
  1063. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1064. if (camp_timer)
  1065. {
  1066. // JA: clear camping flag
  1067. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1068. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1069. safe_delete(camp_timer);
  1070. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1071. QueuePacket(outapp);
  1072. }
  1073. player->SetTempVisualState(539);
  1074. break;
  1075. }
  1076. case OP_SitMsg: {
  1077. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1078. player->SetTempVisualState(538);
  1079. break;
  1080. }
  1081. case OP_SatMsg: {
  1082. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1083. player->SetTempVisualState(540);
  1084. break;
  1085. }
  1086. case OP_QuestJournalOpenMsg:
  1087. case OP_QuestJournalInspectMsg: {
  1088. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1089. if (app->size < sizeof(int32))
  1090. break;
  1091. int32 quest_id = 0;
  1092. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1093. Quest* quest = GetActiveQuest(quest_id);
  1094. if (quest)
  1095. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1096. else {
  1097. quest = player->GetCompletedQuest(quest_id);
  1098. if (quest)
  1099. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1100. }
  1101. break;
  1102. }
  1103. case OP_QuestJournalSetVisibleMsg: {
  1104. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1105. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1106. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1107. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1108. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1109. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1110. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1111. if (player_quests) {
  1112. if (player_quests->count(quest_id) > 0)
  1113. player_quests->at(quest_id)->SetHidden(hidden);
  1114. else
  1115. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1116. }
  1117. else
  1118. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1119. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1120. safe_delete(packet);
  1121. }
  1122. break;
  1123. }
  1124. case OP_MacroUpdateMsg: {
  1125. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1126. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1127. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1128. vector<string>* update = new vector<string>;
  1129. int8 number = macro_update->getType_int8_ByName("number");
  1130. int16 icon = macro_update->getType_int16_ByName("icon");
  1131. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1132. int8 count = macro_update->getType_int8_ByName("macro_count");
  1133. if (GetVersion() <= 283) {
  1134. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1135. }
  1136. else {
  1137. for (int8 i = 0; i < count; i++) {
  1138. char tmp_command[15] = { 0 };
  1139. sprintf(tmp_command, "command_%i", i);
  1140. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1141. }
  1142. }
  1143. if (name.length() == 0)
  1144. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1145. else
  1146. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1147. safe_delete(update);
  1148. safe_delete(macro_update);
  1149. }
  1150. break;
  1151. }
  1152. case OP_DialogSelectMsg: {
  1153. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1154. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1155. if (packet) {
  1156. packet->LoadPacketData(app->pBuffer, app->size);
  1157. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1158. int32 response_index = packet->getType_int32_ByName("response");
  1159. if (GetCurrentZone()) {
  1160. MConversation.readlock();
  1161. int32 spawn_id = conversation_spawns[conversation_id];
  1162. Spawn* spawn = nullptr;
  1163. if(spawn_id) {
  1164. spawn = GetCurrentZone()->GetSpawnByID(spawn_id);
  1165. }
  1166. Item* item = conversation_items[conversation_id];
  1167. MConversation.releasereadlock();
  1168. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1169. if (spawn)
  1170. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1171. else if (item && lua_interface && item->GetItemScript())
  1172. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1173. else
  1174. CloseDialog(conversation_id);
  1175. }
  1176. else
  1177. CloseDialog(conversation_id);
  1178. }
  1179. safe_delete(packet);
  1180. }
  1181. break;
  1182. }
  1183. case OP_CancelMoveObjectModeMsg: {
  1184. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1185. if (GetTempPlacementSpawn())
  1186. {
  1187. Spawn* tmp = GetTempPlacementSpawn();
  1188. SetTempPlacementSpawn(nullptr);
  1189. SetPlacementUniqueItemID(0);
  1190. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1191. break; // break out early if we are tied to a temp spawn
  1192. }
  1193. // if we are moving some other object? other use-cases not covered
  1194. break;
  1195. }
  1196. case OP_PositionMoveableObject: {
  1197. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1198. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1199. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1200. Spawn* spawn = 0;
  1201. if (GetTempPlacementSpawn())
  1202. spawn = GetTempPlacementSpawn();
  1203. else
  1204. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1205. if (!spawn) {
  1206. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1207. break;
  1208. }
  1209. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1210. {
  1211. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1212. break;
  1213. }
  1214. // handles instantiation logic + adding to zone of a new house object
  1215. PopulateHouseSpawn(place_object);
  1216. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1217. char query[256];
  1218. switch (GetSpawnPlacementMode())
  1219. {
  1220. case ServerSpawnPlacementMode::OPEN_HEADING:
  1221. {
  1222. if (spawn && spawn->IsWidget())
  1223. {
  1224. Widget* widget = (Widget*)spawn;
  1225. widget->SetOpenHeading(newHeading);
  1226. widget->SetIncludeHeading(true);
  1227. spawn->position_changed = true;
  1228. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1229. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1230. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1231. }
  1232. else
  1233. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1234. break;
  1235. }
  1236. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1237. {
  1238. if (spawn && spawn->IsWidget())
  1239. {
  1240. Widget* widget = (Widget*)spawn;
  1241. widget->SetClosedHeading(newHeading);
  1242. widget->SetIncludeHeading(true);
  1243. spawn->position_changed = true;
  1244. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1245. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1246. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1247. if (spawn->GetSpawnLocationID())
  1248. {
  1249. Query query;
  1250. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1251. }
  1252. }
  1253. else
  1254. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1255. break;
  1256. }
  1257. default:
  1258. {
  1259. spawn->SetX(place_object->getType_float_ByName("x"));
  1260. spawn->SetY(place_object->getType_float_ByName("y"));
  1261. spawn->SetZ(place_object->getType_float_ByName("z"));
  1262. spawn->SetHeading(newHeading);
  1263. spawn->SetSpawnOrigX(spawn->GetX());
  1264. spawn->SetSpawnOrigY(spawn->GetY());
  1265. spawn->SetSpawnOrigZ(spawn->GetZ());
  1266. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1267. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1268. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1269. else if (spawn->GetSpawnLocationID() > 0)
  1270. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1271. }
  1272. }
  1273. PopulateHouseSpawnFinalize();
  1274. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1275. safe_delete(place_object);
  1276. }
  1277. break;
  1278. }
  1279. case OP_CampAbortedMsg: {
  1280. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1281. if (camp_timer)
  1282. {
  1283. // JA: clear camping flag
  1284. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1285. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1286. safe_delete(camp_timer);
  1287. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1288. QueuePacket(outapp);
  1289. }
  1290. break;
  1291. }
  1292. case OP_DoneLoadingUIResourcesMsg: {
  1293. ClientPacketFunctions::SendUpdateSpellBook(this);
  1294. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1295. QueuePacket(app);
  1296. if(!player_loading_complete)
  1297. {
  1298. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1299. if (zone_script && lua_interface)
  1300. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1301. player_loading_complete = true;
  1302. }
  1303. break;
  1304. }
  1305. case OP_DoneLoadingZoneResourcesMsg: {
  1306. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1307. SendZoneSpawns();
  1308. break;
  1309. }
  1310. case OP_DefaultGroupOptionsRequestMsg: {
  1311. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1312. SendDefaultGroupOptions();
  1313. break;
  1314. }
  1315. case OP_DoneLoadingEntityResourcesMsg: {
  1316. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1317. if (!IsReadyForSpawns())
  1318. SetReadyForSpawns(true);
  1319. SendCharInfo();
  1320. pos_update.Start();
  1321. quest_pos_timer.Start();
  1322. break;
  1323. }
  1324. case OP_LootItemsRequestMsg: {
  1325. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1326. HandleLoot(app);
  1327. break;
  1328. }
  1329. case OP_WaypointSelectMsg: {
  1330. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1331. if (packet) {
  1332. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1333. int32 selection = packet->getType_int32_ByName("selection");
  1334. if (selection > 0) {
  1335. SelectWaypoint(selection);
  1336. }
  1337. }
  1338. }
  1339. break;
  1340. }
  1341. case OP_KnowledgeWindowSlotMappingMsg: {
  1342. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1343. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1344. if (packet) {
  1345. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1346. int num_updates = packet->getType_int16_ByName("spell_count");
  1347. int32 spell_id = 0;
  1348. int16 slot_id = 0;
  1349. char tmp_spell_id[15];
  1350. char tmp_slot[15];
  1351. for (int i = 0; i < num_updates; i++) {
  1352. memset(tmp_spell_id, 0, 15);
  1353. memset(tmp_slot, 0, 15);
  1354. sprintf(tmp_spell_id, "spell_id_%i", i);
  1355. sprintf(tmp_slot, "slot_id_%i", i);
  1356. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1357. if (spell_id > 0) {
  1358. slot_id = packet->getType_int16_ByName(tmp_slot);
  1359. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1360. if (spell && spell->slot != slot_id) {
  1361. spell->slot = slot_id;
  1362. spell->save_needed = true;
  1363. }
  1364. }
  1365. }
  1366. }
  1367. safe_delete(packet);
  1368. }
  1369. //SendKnowledgeWindowSlot();
  1370. break;
  1371. }
  1372. case OP_ReadyToZoneMsg: {
  1373. if (!IsReadyForSpawns())
  1374. {
  1375. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1376. }
  1377. else
  1378. {
  1379. if(zoning_destination)
  1380. SetCurrentZone(zoning_destination);
  1381. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1382. bool succeed_override_zone = true;
  1383. if(!GetCurrentZone()) {
  1384. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1385. if(zoning_instance_id) {
  1386. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1387. if(!zone) {
  1388. 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);
  1389. succeed_override_zone = false;
  1390. }
  1391. else {
  1392. SetCurrentZone(zone);
  1393. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1394. }
  1395. }
  1396. else if(zoning_id) {
  1397. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1398. if(!zone) {
  1399. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1400. succeed_override_zone = false;
  1401. }
  1402. else {
  1403. SetCurrentZone(zone);
  1404. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1405. }
  1406. }
  1407. }
  1408. if (client_zoning)
  1409. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1410. else
  1411. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1412. Disconnect();
  1413. }
  1414. break;
  1415. }
  1416. case OP_ClientFellMsg: {
  1417. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1418. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1419. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1420. float height = request->getType_float_ByName("height");
  1421. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1422. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1423. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1424. break;
  1425. }*/
  1426. float safe_height = 13.0f;
  1427. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1428. GetPlayer()->MStats.lock();
  1429. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1430. GetPlayer()->MStats.unlock();
  1431. if (skill)
  1432. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1433. if (height > safe_height) {
  1434. int16 damage = (int16)ceil((height - safe_height) * 125);
  1435. if (height >= 80)
  1436. damage = 30000;
  1437. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1438. if (damage > 0) {
  1439. GetPlayer()->TakeDamage(damage);
  1440. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1441. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1442. if (!GetPlayer()->GetInvulnerable())
  1443. GetPlayer()->SetCharSheetChanged(true);
  1444. 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);
  1445. if (GetPlayer()->GetHP() == 0) {
  1446. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1447. }
  1448. }
  1449. }
  1450. safe_delete(request);
  1451. }
  1452. break;
  1453. }
  1454. case OP_MapFogDataUpdateMsg: {
  1455. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1456. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1457. break;
  1458. }
  1459. case OP_SelectZoneTeleporterDestinatio: {
  1460. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1461. ProcessTeleportLocation(app);
  1462. break;
  1463. }
  1464. case OP_SendLatestRequestMsg: {
  1465. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1466. uchar blah25[] = { 0x01 };
  1467. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1468. QueuePacket(app25);
  1469. break;
  1470. }
  1471. case OP_ShowCreateFromRecipeUIMsg: {
  1472. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1473. break;
  1474. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1475. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1476. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1477. QueuePacket(app);
  1478. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1479. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1480. QueuePacket(app);
  1481. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1482. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1483. ,0xff,0xff,0xff};
  1484. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1485. QueuePacket(app);
  1486. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1487. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1488. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1489. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1490. QueuePacket(app);
  1491. uchar blah5[] ={0x00,0x00};
  1492. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1493. QueuePacket(app);
  1494. break;*/
  1495. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1496. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1497. //QueuePacket(app);
  1498. }
  1499. case OP_BeginItemCreationMsg: {
  1500. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1501. //DumpPacket(app->pBuffer, app->size);
  1502. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1503. if (packet) {
  1504. packet->LoadPacketData(app->pBuffer, app->size);
  1505. int32 item = 0;
  1506. vector<int32> items;
  1507. char tmp_item_id[20];
  1508. item = packet->getType_int32_ByName("primary_component_id");
  1509. if (item > 0)
  1510. items.push_back(item);
  1511. item = 0;
  1512. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1513. for (int8 i = 0; i < build_components; i++) {
  1514. memset(tmp_item_id, 0, 20);
  1515. sprintf(tmp_item_id, "component_id_%i", i);
  1516. item = packet->getType_int32_ByName(tmp_item_id);
  1517. if (item > 0)
  1518. items.push_back(item);
  1519. item = 0;
  1520. }
  1521. item = packet->getType_int32_ByName("fuel_id");
  1522. if (item > 0)
  1523. items.push_back(item);
  1524. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1525. safe_delete(packet);
  1526. }
  1527. break;
  1528. }
  1529. case OP_StopItemCreationMsg: {
  1530. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1531. //DumpPacket(app->pBuffer, app->size);
  1532. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1533. break;
  1534. }
  1535. case OP_SysClient:
  1536. case OP_SignalMsg: {
  1537. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1538. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1539. if (packet) {
  1540. packet->LoadPacketData(app->pBuffer, app->size);
  1541. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1542. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1543. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1544. SetReloadingZone(false);
  1545. if(GetPlayer()->IsDeletedSpawn()) {
  1546. GetPlayer()->SetDeletedSpawn(false);
  1547. }
  1548. ResetZoningCoords();
  1549. SetReadyForUpdates();
  1550. GetPlayer()->SendSpawnChanges(true);
  1551. ProcessStateCommands();
  1552. GetPlayer()->changed = true;
  1553. GetPlayer()->info_changed = true;
  1554. GetPlayer()->vis_changed = true;
  1555. player_pos_changed = true;
  1556. GetPlayer()->AddChangedZoneSpawn();
  1557. }
  1558. else {
  1559. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1560. }
  1561. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1562. if (zone_script && lua_interface)
  1563. {
  1564. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1565. }
  1566. }
  1567. break;
  1568. }
  1569. case OP_EntityVerbsRequestMsg: {
  1570. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1571. HandleVerbRequest(app);
  1572. break;
  1573. }
  1574. case OP_EntityVerbsVerbMsg: {
  1575. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1576. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1577. if (packet) {
  1578. packet->LoadPacketData(app->pBuffer, app->size);
  1579. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1580. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1581. Spawn* spawn = player->GetTarget();
  1582. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1583. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1584. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1585. {
  1586. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1587. if (spawn->IsGroundSpawn())
  1588. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1589. else if (spawn->IsObject())
  1590. ((Object*)spawn)->HandleUse(this, command);
  1591. else if (spawn->IsWidget())
  1592. ((Widget*)spawn)->HandleUse(this, command);
  1593. else if (spawn->IsSign())
  1594. ((Sign*)spawn)->HandleUse(this, command);
  1595. }
  1596. }
  1597. }
  1598. else {
  1599. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1600. if (command.size > 0) {
  1601. string command_name = command.data;
  1602. if (command_name.find(" ") < 0xFFFFFFFF) {
  1603. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1604. string::size_type pos = command_name.find(" ");
  1605. while(pos != string::npos){
  1606. command_name.replace(pos, 1, "_");
  1607. pos = command_name.find(" ");
  1608. }
  1609. }
  1610. else
  1611. command_name = command_name.substr(0, command_name.find(" "));
  1612. }
  1613. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1614. if (handler != 0xFFFFFFFF) {
  1615. if (command.data == command_name) {
  1616. command.data = "";
  1617. command.size = 0;
  1618. }
  1619. else {
  1620. command.data = command.data.substr(command.data.find(" ") + 1);
  1621. command.size = command.data.length();
  1622. }
  1623. commands.Process(handler, &command, this);
  1624. }
  1625. else {
  1626. if (spawn && spawn->IsNPC()) {
  1627. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1628. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1629. command_name = command.data;
  1630. string::size_type pos = command_name.find(" ");
  1631. while (pos != string::npos) {
  1632. command_name.replace(pos, 1, "_");
  1633. pos = command_name.find(" ");
  1634. }
  1635. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1636. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1637. }
  1638. }
  1639. }
  1640. }
  1641. else
  1642. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1643. }
  1644. }
  1645. }
  1646. safe_delete(packet);
  1647. }
  1648. break;
  1649. }
  1650. case OP_SkillInfoRequest: {
  1651. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1652. HandleSkillInfoRequest(app);
  1653. break;
  1654. }
  1655. case OP_UpdateTargetMsg: {
  1656. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1657. int16 index = 0;
  1658. memcpy(&index, app->pBuffer, sizeof(int16));
  1659. if (index == 0xFFFF)
  1660. GetPlayer()->SetTarget(0);
  1661. else {
  1662. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1663. if(spawn)
  1664. GetPlayer()->SetTarget(spawn);
  1665. else {
  1666. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1667. }
  1668. }
  1669. if (GetPlayer()->GetTarget())
  1670. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1671. //player->SetTarget((int16*)app->pBuffer);
  1672. break;
  1673. }
  1674. case OP_ExamineInfoRequestMsg: {
  1675. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1676. HandleExamineInfoRequest(app);
  1677. break;
  1678. }
  1679. case OP_QuickbarUpdateMsg:
  1680. //case OP_QuickbarAddMsg:
  1681. {
  1682. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1683. HandleQuickbarUpdateRequest(app);
  1684. break;
  1685. }
  1686. case OP_PredictionUpdateMsg: {
  1687. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1688. if (version <= 546) {
  1689. int8 offset = 9;
  1690. if (app->pBuffer[0] == 0xFF)
  1691. offset += 2;
  1692. if (app->size > offset) {
  1693. if (player->IsCasting()) {
  1694. float distance = 0;
  1695. float x = player->GetX();
  1696. float y = player->GetY();
  1697. float z = player->GetZ();
  1698. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1699. distance = player->GetDistance(x, y, z, false);
  1700. if (distance > .5)
  1701. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1702. }
  1703. else
  1704. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1705. player_pos_changed = true;
  1706. //DumpPacket(app);
  1707. }
  1708. }
  1709. else {
  1710. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1711. QueuePacket(app);
  1712. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1713. }
  1714. break;
  1715. }
  1716. case OP_RemoteCmdMsg: {
  1717. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1718. if (app->size > 0) {
  1719. EQ2_CommandString remote(app->pBuffer, app->size);
  1720. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1721. #if EQDEBUG >= 9
  1722. DumpPacket(app);
  1723. #endif
  1724. commands.Process(remote.handler, &remote.command, this);
  1725. }
  1726. else //bad client, disconnect
  1727. Disconnect();
  1728. break;
  1729. }
  1730. case OP_CancelSpellCast: {
  1731. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1732. current_zone->Interrupted(player, 0, 0, true);
  1733. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1734. break;
  1735. }
  1736. case OP_UpdatePositionMsg: {
  1737. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1738. int8 offset = 13;
  1739. if (app->pBuffer[0] == 0xFF)
  1740. offset += 2;
  1741. if (app->size > offset) {
  1742. if (player->IsCasting()) {
  1743. float distance = 0;
  1744. float x = player->GetX();
  1745. float y = player->GetY();
  1746. float z = player->GetZ();
  1747. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1748. distance = player->GetDistance(x, y, z, false);
  1749. if (distance > .5)
  1750. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1751. }
  1752. else
  1753. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1754. player_pos_changed = true;
  1755. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1756. //DumpPacket(app);
  1757. }
  1758. break;
  1759. }
  1760. case OP_MailSendMessageMsg: {
  1761. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1762. HandleSentMail(app);
  1763. break;
  1764. }
  1765. case OP_StopTrackingMsg: {
  1766. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1767. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1768. break;
  1769. }
  1770. case OP_BeginTrackingMsg: {
  1771. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1772. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1773. if (packet) {
  1774. packet->LoadPacketData(app->pBuffer, app->size);
  1775. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1776. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1777. if (spawn) {
  1778. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1779. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1780. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1781. }
  1782. safe_delete(packet);
  1783. }
  1784. break;
  1785. }
  1786. case OP_BioUpdateMsg: {
  1787. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1788. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1789. if (packet) {
  1790. packet->LoadPacketData(app->pBuffer, app->size);
  1791. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1792. safe_delete(packet);
  1793. }
  1794. break;
  1795. }
  1796. case OP_RewardPackMsg: {
  1797. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1798. /* 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
  1799. when we come across it (scatman) */
  1800. const char* name = app->GetOpcodeName();
  1801. if (name)
  1802. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1803. else
  1804. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1805. //DumpPacket(app);
  1806. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1807. if (packet) {
  1808. packet->LoadPacketData(app->pBuffer, app->size);
  1809. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1810. /* Player has contacted a guild recruiter */
  1811. if (recruiter_name.length() > 0) {
  1812. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1813. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1814. if (recruiter && guild) {
  1815. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1816. 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()));
  1817. recruiter->PlaySound("ui_guild_page");
  1818. }
  1819. }
  1820. /* New picture taken for guild recruiting */
  1821. else {
  1822. //DumpPacket(app->pBuffer, app->size);
  1823. int32 guild_id = 0;
  1824. int16 picture_data_size = 0;
  1825. unsigned char* recruiter_picture_data = 0;
  1826. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1827. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1828. Guild* guild = guild_list.GetGuild(guild_id);
  1829. if (guild) {
  1830. GuildMember* gm = guild->GetGuildMember(player);
  1831. if (gm) {
  1832. safe_delete_array(gm->recruiter_picture_data);
  1833. recruiter_picture_data = new unsigned char[picture_data_size];
  1834. for (int16 i = 0; i < picture_data_size; i++)
  1835. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1836. gm->recruiter_picture_data = recruiter_picture_data;
  1837. gm->recruiter_picture_data_size = picture_data_size;
  1838. guild->SetMemberSaveNeeded(true);
  1839. }
  1840. }
  1841. }
  1842. safe_delete(packet);
  1843. }
  1844. break;
  1845. }
  1846. case OP_PetOptions: {
  1847. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1848. Spawn* target = player->GetTarget();
  1849. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1850. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1851. bool change = false;
  1852. packet->LoadPacketData(app->pBuffer, app->size);
  1853. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1854. if (strlen(name.c_str()) != 0) {
  1855. target->SetName(name.c_str());
  1856. player->GetInfoStruct()->set_pet_name(name);
  1857. GetCurrentZone()->SendUpdateTitles(target);
  1858. change = true;
  1859. }
  1860. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1861. // Check protect self setting and update if needed
  1862. if (packet->getType_int8_ByName("protect_self") == 1) {
  1863. if ((pet_behavior & 2) == 0) {
  1864. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1865. change = true;
  1866. }
  1867. }
  1868. else {
  1869. if ((pet_behavior & 2) != 0) {
  1870. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1871. change = true;
  1872. }
  1873. }
  1874. // Check protect master setting and update if needed
  1875. if (packet->getType_int8_ByName("protect_master") == 1) {
  1876. if ((pet_behavior & 1) == 0) {
  1877. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1878. change = true;
  1879. }
  1880. }
  1881. else {
  1882. if ((pet_behavior & 1) != 0) {
  1883. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1884. change = true;
  1885. }
  1886. }
  1887. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1888. // Check stay/follow setting and update if needed
  1889. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1890. if (pet_movement != 2) {
  1891. player->GetInfoStruct()->set_pet_movement(2);
  1892. change = true;
  1893. }
  1894. }
  1895. else {
  1896. if (pet_movement != 1) {
  1897. player->GetInfoStruct()->set_pet_movement(1);
  1898. change = true;
  1899. }
  1900. }
  1901. // Ranged/Melee settings are not implemented yet
  1902. if (change)
  1903. player->SetCharSheetChanged(true);
  1904. safe_delete(packet);
  1905. }
  1906. break;
  1907. }
  1908. case OP_RecipeBook: {
  1909. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1910. SendRecipeList();
  1911. break;
  1912. }
  1913. case OP_BuyPlayerHouseMsg: {
  1914. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1915. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1916. if (packet) {
  1917. packet->LoadPacketData(app->pBuffer, app->size);
  1918. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1919. if (hz) {
  1920. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1921. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1922. if (houses.size() > 24)
  1923. {
  1924. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1925. safe_delete(packet);
  1926. break;
  1927. }
  1928. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1929. {
  1930. std::string req = "You must be of ";
  1931. if (hz->alignment == 1)
  1932. req.append("Good");
  1933. else
  1934. req.append("Evil");
  1935. req.append(" alignment to purchase this house");
  1936. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1937. safe_delete(packet);
  1938. break;
  1939. }
  1940. int32 status_req = hz->upkeep_status + hz->cost_status;
  1941. int32 available_status = player->GetInfoStruct()->get_status_points();
  1942. if (status_req <= available_status &&
  1943. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1944. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1945. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1946. {
  1947. player->GetInfoStruct()->subtract_status_points(status_req);
  1948. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1949. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1950. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1951. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1952. //ClientPacketFunctions::SendHousingList(this);
  1953. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1954. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1955. PlaySound("coin_cha_ching");
  1956. }
  1957. else
  1958. {
  1959. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1960. PlaySound("buy_failed");
  1961. }
  1962. }
  1963. }
  1964. safe_delete(packet);
  1965. break;
  1966. }
  1967. case OP_EnterHouseMsg: {
  1968. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1969. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1970. if (packet) {
  1971. packet->LoadPacketData(app->pBuffer, app->size);
  1972. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1973. if (ph) {
  1974. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1975. if (hz) {
  1976. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1977. if (house) {
  1978. Zone(house, true);
  1979. }
  1980. }
  1981. }
  1982. }
  1983. safe_delete(packet);
  1984. break;
  1985. }
  1986. case OP_PayHouseUpkeepMsg: {
  1987. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1988. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1989. if (packet) {
  1990. packet->LoadPacketData(app->pBuffer, app->size);
  1991. int64 houseID = packet->getType_int64_ByName("house_id");
  1992. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1993. if (ph)
  1994. {
  1995. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1996. if (!hz)
  1997. {
  1998. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1999. safe_delete(packet);
  2000. break;
  2001. }
  2002. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  2003. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  2004. {
  2005. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  2006. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  2007. {
  2008. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  2009. PlaySound("buy_failed");
  2010. safe_delete(packet);
  2011. break;
  2012. }
  2013. }
  2014. bool escrowChange = false;
  2015. int64 statusReq = hz->upkeep_status;
  2016. int64 tmpRecoverStatus = 0;
  2017. if(ph->escrow_status && statusReq >= ph->escrow_status )
  2018. {
  2019. escrowChange = true;
  2020. tmpRecoverStatus = ph->escrow_status;
  2021. statusReq -= ph->escrow_status;
  2022. ph->escrow_status = 0;
  2023. }
  2024. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2025. {
  2026. escrowChange = true;
  2027. ph->escrow_status -= statusReq;
  2028. tmpRecoverStatus = statusReq;
  2029. statusReq = 0;
  2030. }
  2031. int64 coinReq = hz->upkeep_coin;
  2032. int64 tmpRecoverCoins = 0;
  2033. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2034. {
  2035. escrowChange = true;
  2036. tmpRecoverCoins = ph->escrow_coins;
  2037. coinReq -= ph->escrow_coins;
  2038. ph->escrow_coins = 0;
  2039. }
  2040. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2041. {
  2042. escrowChange = true;
  2043. // more than enough in escrow, subtract and make our cost 0!
  2044. ph->escrow_coins -= coinReq;
  2045. tmpRecoverCoins = coinReq;
  2046. coinReq = 0;
  2047. }
  2048. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2049. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2050. {
  2051. if(coinReq && player->RemoveCoins(coinReq))
  2052. coinReq = 0;
  2053. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2054. statusReq = 0;
  2055. }
  2056. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2057. {
  2058. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2059. if (escrowChange)
  2060. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2061. ph->upkeep_due = upkeep_due;
  2062. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2063. //ClientPacketFunctions::SendHousingList(this);
  2064. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  2065. PlaySound("coin_cha_ching");
  2066. }
  2067. else
  2068. {
  2069. // recover the escrow we were going to use but could not spend due to lack of funds
  2070. if (tmpRecoverCoins)
  2071. ph->escrow_coins += tmpRecoverCoins;
  2072. if(tmpRecoverStatus)
  2073. ph->escrow_status += tmpRecoverStatus;
  2074. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2075. PlaySound("buy_failed");
  2076. }
  2077. }
  2078. else
  2079. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2080. }
  2081. safe_delete(packet);
  2082. break;
  2083. }
  2084. case OP_ExitHouseMsg: {
  2085. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2086. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2087. if (instance_id > 0) {
  2088. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2089. if (ph) {
  2090. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2091. if (hz) {
  2092. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2093. // determine if this is an instanced zone that already exists
  2094. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2095. if (instance_zone || new_zone) {
  2096. GetPlayer()->SetX(hz->exit_x);
  2097. GetPlayer()->SetY(hz->exit_y);
  2098. GetPlayer()->SetZ(hz->exit_z);
  2099. GetPlayer()->SetHeading(hz->exit_heading);
  2100. if (instance_zone)
  2101. Zone(instance_zone->GetInstanceID(), false, true);
  2102. else
  2103. Zone(new_zone, false);
  2104. }
  2105. }
  2106. }
  2107. }
  2108. break;
  2109. }
  2110. case OP_QuestJournalWaypointMsg: {
  2111. //DumpPacket(app);
  2112. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2113. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2114. if (packet) {
  2115. packet->LoadPacketData(app->pBuffer, app->size);
  2116. int32 quests = packet->getType_int32_ByName("num_quests");
  2117. if (quests > 100) // just picking a number higher than max allowed
  2118. {
  2119. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2120. break;
  2121. }
  2122. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2123. for (int32 i = 0; i < quests; i++) {
  2124. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2125. if (id == 0)
  2126. continue;
  2127. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2128. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2129. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2130. if (player->player_quests.count(id) > 0) {
  2131. player->player_quests[id]->SetTracked(tracked);
  2132. player->player_quests[id]->SetSaveNeeded(true);
  2133. }
  2134. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2135. }
  2136. safe_delete(packet);
  2137. }
  2138. break;
  2139. }
  2140. case OP_PaperdollImage: {
  2141. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2142. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2143. //First check if this is a new image... delete an existing partial image if one exists
  2144. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2145. if (packet_index == 0) {
  2146. safe_delete_array(incoming_paperdoll.image_bytes);
  2147. incoming_paperdoll.last_received_packet_index = 0;
  2148. incoming_paperdoll.current_size_bytes = 0;
  2149. }
  2150. //return if this packet is not the one we are expecting...
  2151. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2152. safe_delete(packet);
  2153. break;
  2154. }
  2155. //Check how many packets we're supposed to be receiving for this/these images
  2156. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2157. //Check the image type, if this is a new type in the same series of packets we have a new image
  2158. int8 img_type = packet->getType_int8_ByName("image_type");
  2159. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2160. //We have a new image. Save the old data and clear before continuing
  2161. SavePlayerImages();
  2162. }
  2163. incoming_paperdoll.image_type = img_type;
  2164. //Get the size of the image data in this packet
  2165. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2166. if (image_size <= 0 || image_size > 1048576) {
  2167. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2168. safe_delete(packet);
  2169. break;
  2170. }
  2171. //Create a new array
  2172. int32 new_image_size = image_size;
  2173. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2174. if (incoming_paperdoll.image_bytes) {
  2175. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2176. safe_delete_array(incoming_paperdoll.image_bytes);
  2177. }
  2178. //variable i should be the index in the packet of the first PNG file byte
  2179. vector<DataStruct*>* d_structs = packet->getStructs();
  2180. vector<DataStruct*>::iterator itr;
  2181. int32 i = 0;
  2182. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2183. DataStruct* ds = (*itr);
  2184. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2185. i += ds->GetDataSizeInBytes();
  2186. else
  2187. break;
  2188. }
  2189. //Return if this packet is bad and we would read out of bounds
  2190. if (app->size - i < new_image_size) {
  2191. safe_delete(packet);
  2192. safe_delete_array(new_image);
  2193. break;
  2194. }
  2195. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2196. memcpy(tmp, app->pBuffer + i, new_image_size);
  2197. incoming_paperdoll.current_size_bytes += new_image_size;
  2198. incoming_paperdoll.image_bytes = new_image;
  2199. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2200. if (incoming_paperdoll.image_num_packets == 1 ||
  2201. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2202. SavePlayerImages();
  2203. }
  2204. incoming_paperdoll.last_received_packet_index = packet_index;
  2205. }
  2206. safe_delete(packet);
  2207. */
  2208. break;
  2209. }
  2210. case OP_ReadyForTakeOffMsg:
  2211. {
  2212. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2213. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2214. if (GetPendingFlightPath() > 0) {
  2215. if (index != -1) {
  2216. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2217. if (packet) {
  2218. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2219. packet->setDataByName("path_id", index);
  2220. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2221. QueuePacket(packet->serialize());
  2222. safe_delete(packet);
  2223. on_auto_mount = true;
  2224. }
  2225. }
  2226. else {
  2227. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2228. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2229. EndAutoMount();
  2230. }
  2231. SetPendingFlightPath(0);
  2232. }
  2233. else
  2234. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2235. break;
  2236. }
  2237. case OP_EarlyLandingRequestMsg:
  2238. {
  2239. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2240. EndAutoMount();
  2241. break;
  2242. }
  2243. case OP_SubmitCharCust:
  2244. {
  2245. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2246. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2247. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2248. int8 type = packet->getType_int8_ByName("type");
  2249. if (type == 0) {
  2250. if (player->custNPC) {
  2251. player->custNPCTarget->CustomizeAppearance(packet);
  2252. current_zone->SendSpawnChanges(player->custNPCTarget);
  2253. }
  2254. else {
  2255. player->CustomizeAppearance(packet);
  2256. current_zone->SendSpawnChanges(player);
  2257. }
  2258. }
  2259. }
  2260. if (player->custNPC) {
  2261. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2262. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2263. if (player->custNPCTarget->IsBot())
  2264. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2265. player->custNPC = false;
  2266. player->custNPCTarget = 0;
  2267. player->changed = true;
  2268. player->info_changed = true;
  2269. current_zone->SendSpawnChanges(player, this);
  2270. }
  2271. break;
  2272. }
  2273. default: {
  2274. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2275. const char* name = app->GetOpcodeName();
  2276. if (name)
  2277. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2278. else
  2279. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2280. //DumpPacket(app);
  2281. }
  2282. }
  2283. if (!eqs || !eqs->CheckActive()) {
  2284. return false;
  2285. }
  2286. return ret;
  2287. }
  2288. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2289. if (!item) {
  2290. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2291. return false;
  2292. }
  2293. int32 conflictItemList = 0, conflictequipmentList = 0, conflictAppearanceEquipmentList = 0;
  2294. int16 lore_stack_count = 0;
  2295. if(((conflictItemList = player->item_list.CheckSlotConflict(item, true, true, &lore_stack_count)) == LORE ||
  2296. (conflictequipmentList = player->equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE ||
  2297. (conflictAppearanceEquipmentList = player->appearance_equipment_list.CheckSlotConflict(item, true, &lore_stack_count)) == LORE) && !item->CheckFlag(STACK_LORE)) {
  2298. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to lore conflict.", item->name.c_str());
  2299. return false;
  2300. }
  2301. else if(conflictItemList == STACK_LORE || conflictequipmentList == STACK_LORE || conflictAppearanceEquipmentList == STACK_LORE) {
  2302. Message(CHANNEL_COLOR_RED, "You cannot loot %s due to stack lore conflict.", item->name.c_str());
  2303. return false;
  2304. }
  2305. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2306. if (player->item_list.AssignItemToFreeSlot(item)) {
  2307. if(item->CheckFlag2(HEIRLOOM)) { // TODO: RAID Support
  2308. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  2309. if (gmi && gmi->group_id)
  2310. {
  2311. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  2312. if (group)
  2313. {
  2314. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  2315. deque<GroupMemberInfo*>* members = group->GetMembers();
  2316. if(members) {
  2317. for (int8 i = 0; i < members->size(); i++) {
  2318. Entity* member = members->at(i)->member;
  2319. if(!member)
  2320. continue;
  2321. if ((member->GetZone() != this->GetPlayer()->GetZone()))
  2322. continue;
  2323. if(member->IsPlayer()) {
  2324. item->grouped_char_ids.insert(std::make_pair(((Player*)member)->GetCharacterID(), true));
  2325. item->save_needed = true;
  2326. }
  2327. }
  2328. }
  2329. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  2330. }
  2331. }
  2332. }
  2333. int8 type = CHANNEL_LOOT;
  2334. if (entity) {
  2335. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2336. }
  2337. else {
  2338. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2339. }
  2340. Guild* guild = player->GetGuild();
  2341. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2342. char adjective[32];
  2343. int8 type;
  2344. memset(adjective, 0, sizeof(adjective));
  2345. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2346. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2347. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2348. }
  2349. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2350. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2351. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2352. }
  2353. else {
  2354. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2355. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2356. }
  2357. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2358. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2359. }
  2360. if (item->GetItemScript() && lua_interface)
  2361. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2362. CheckPlayerQuestsItemUpdate(item);
  2363. return true;
  2364. }
  2365. else
  2366. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2367. }
  2368. else
  2369. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2370. return false;
  2371. }
  2372. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2373. if (!entity) {
  2374. return false;
  2375. }
  2376. Item* item = entity->LootItem(item_id);
  2377. bool success = false;
  2378. success = HandleLootItem(entity, item);
  2379. if(!success)
  2380. entity->AddLootItem(item);
  2381. return success;
  2382. }
  2383. void Client::HandleLoot(EQApplicationPacket* app) {
  2384. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2385. if (packet) {
  2386. packet->LoadPacketData(app->pBuffer, app->size);
  2387. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2388. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2389. safe_delete(packet);
  2390. int32 item_id = 0;
  2391. Item* item = 0;
  2392. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2393. if (player->HasPendingLootItems(loot_id)) {
  2394. Item* master_item = 0;
  2395. if (loot_all) {
  2396. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2397. if (items) {
  2398. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2399. master_item = items->at(i);
  2400. if (master_item) {
  2401. item = new Item(master_item);
  2402. if (item) {
  2403. loot_all = HandleLootItem(0, item);
  2404. if (loot_all)
  2405. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2406. }
  2407. }
  2408. }
  2409. safe_delete(items);
  2410. }
  2411. }
  2412. else {
  2413. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2414. if (packet) {
  2415. packet->LoadPacketData(app->pBuffer, app->size);
  2416. item_id = packet->getType_int32_ByName("item_id");
  2417. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2418. if (items) {
  2419. for (int32 i = 0; i < items->size(); i++) {
  2420. master_item = items->at(i);
  2421. if (master_item && master_item->details.item_id == item_id) {
  2422. item = new Item(master_item);
  2423. if (item && HandleLootItem(0, item))
  2424. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2425. break;
  2426. }
  2427. }
  2428. safe_delete(items);
  2429. }
  2430. safe_delete(packet);
  2431. }
  2432. }
  2433. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2434. if (outapp)
  2435. QueuePacket(outapp);
  2436. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2437. }
  2438. else {
  2439. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2440. if (loot_all) {
  2441. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2442. loot_all = HandleLootItem(spawn, item_id);
  2443. }
  2444. }
  2445. else {
  2446. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2447. if (packet) {
  2448. packet->LoadPacketData(app->pBuffer, app->size);
  2449. item_id = packet->getType_int32_ByName("item_id");
  2450. HandleLootItem(spawn, item_id);
  2451. safe_delete(packet);
  2452. }
  2453. }
  2454. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2455. if (outapp)
  2456. QueuePacket(outapp);
  2457. Loot(spawn);
  2458. if (!spawn->HasLoot()) {
  2459. CloseLoot(loot_id);
  2460. if (spawn->IsNPC())
  2461. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2462. }
  2463. }
  2464. else {
  2465. if (!spawn) {
  2466. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2467. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2468. }
  2469. else
  2470. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2471. }
  2472. }
  2473. }
  2474. }
  2475. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2476. PacketStruct* request = 0;
  2477. // cout << "Request: \n";
  2478. // DumpPacket(app);
  2479. switch (app->pBuffer[0]) {
  2480. case 0: { //items
  2481. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2482. if (request) {
  2483. request->LoadPacketData(app->pBuffer, app->size);
  2484. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2485. if (!item)
  2486. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2487. if (item) {
  2488. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2489. if (response) {
  2490. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2491. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2492. response->setSmallStringByName("name", item->name.c_str());
  2493. EQ2Packet* app2 = response->serialize();
  2494. //DumpPacket(app2);
  2495. QueuePacket(app2);
  2496. safe_delete(response);
  2497. }
  2498. }
  2499. }
  2500. break;
  2501. }
  2502. case 2: {//spells
  2503. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2504. if (request) {
  2505. request->LoadPacketData(app->pBuffer, app->size);
  2506. int32 id = request->getType_int32_ByName("id");
  2507. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2508. Spell* spell = master_spell_list.GetSpell(id, tier);
  2509. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2510. if (response) {
  2511. response->setDataByName("request_type", 2);
  2512. response->setDataByName("unique_id", tier);
  2513. response->setDataByName("id", id);
  2514. if (spell)
  2515. response->setSmallStringByName("name", spell->GetName());
  2516. else
  2517. response->setSmallStringByName("name", "Unknown Spell");
  2518. EQ2Packet* app2 = response->serialize();
  2519. // DumpPacket(app2);
  2520. QueuePacket(app2);
  2521. safe_delete(response);
  2522. }
  2523. }
  2524. break;
  2525. }
  2526. default: {
  2527. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2528. }
  2529. }
  2530. safe_delete(request);
  2531. }
  2532. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2533. PacketStruct* request = 0;
  2534. if (!app || app->size == 0)
  2535. return;
  2536. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2537. //DumpPacket(app);
  2538. int8 type = app->pBuffer[0];
  2539. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2540. if (version <= 283) {
  2541. if (type == 1)
  2542. type = 4;
  2543. else if (type == 2)
  2544. type = 5;
  2545. }
  2546. if (type == 3) {
  2547. Spell* spell = 0;
  2548. bool trait_display;
  2549. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2550. if (!request) {
  2551. return;
  2552. }
  2553. request->LoadPacketData(app->pBuffer, app->size);
  2554. int32 id = request->getType_int32_ByName("id");
  2555. int32 tier = request->getType_int32_ByName("tier");
  2556. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2557. bool display = true;
  2558. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2559. display = false;
  2560. else if (version <= 546)
  2561. display = request->getType_int8_ByName("display");
  2562. else if (version > 546)
  2563. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2564. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2565. if (trait_tier != 0xFFFFFFFF) {
  2566. spell = master_spell_list.GetSpell(id, trait_tier);
  2567. if (!spell) {
  2568. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2569. }
  2570. trait_display = true;
  2571. }
  2572. else {
  2573. spell = master_spell_list.GetSpell(id, tier);
  2574. trait_display = false;
  2575. }
  2576. // if we can't find it on the master spell list, see if it is a custom spell
  2577. if (!spell)
  2578. {
  2579. lua_interface->FindCustomSpellLock();
  2580. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2581. if (tmpSpell)
  2582. spell = tmpSpell->spell;
  2583. lua_interface->FindCustomSpellUnlock();
  2584. }
  2585. if (spell && !CountSentSpell(id, tier)) {
  2586. if (!spell->IsCopiedSpell())
  2587. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2588. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2589. //DumpPacket(app);
  2590. QueuePacket(app);
  2591. }
  2592. }
  2593. else if (type == 0) {
  2594. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2595. if (!request) {
  2596. return;
  2597. }
  2598. request->LoadPacketData(app->pBuffer, app->size);
  2599. int32 id = request->getType_int32_ByName("id");
  2600. Item* item = 0;
  2601. // translate from unique id to spawn id for houses
  2602. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2603. bool wasSpawn = false;
  2604. if (spawn)
  2605. {
  2606. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2607. if (item)
  2608. {
  2609. wasSpawn = true;
  2610. item = new Item(item);
  2611. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2612. }
  2613. }
  2614. if (!item)
  2615. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2616. if (!item)
  2617. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2618. if (!item)
  2619. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2620. if (!item)
  2621. item = master_item_list.GetItem(id);
  2622. if (item) {// && sent_item_details.count(id) == 0){
  2623. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2624. sent_item_details[id] = true;
  2625. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2626. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2627. //DumpPacket(app);
  2628. QueuePacket(app);
  2629. if (wasSpawn)
  2630. delete item;
  2631. }
  2632. else {
  2633. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2634. DumpPacket(app);
  2635. }
  2636. }
  2637. else if (type == 1) {
  2638. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2639. if (!request) {
  2640. return;
  2641. }
  2642. request->LoadPacketData(app->pBuffer, app->size);
  2643. int32 id = request->getType_int32_ByName("id");
  2644. int32 unique_id = request->getType_int32_ByName("unique_id");
  2645. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2646. if (!item)
  2647. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2648. if (!item)
  2649. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2650. if (!item)
  2651. item = master_item_list.GetItem(id);
  2652. if (item) {
  2653. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2654. sent_item_details[id] = true;
  2655. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2656. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2657. //DumpPacket(app);
  2658. QueuePacket(app);
  2659. }
  2660. else {
  2661. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2662. DumpPacket(app);
  2663. }
  2664. }
  2665. else if (type == 2) {
  2666. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2667. if (!request) {
  2668. return;
  2669. }
  2670. request->LoadPacketData(app->pBuffer, app->size);
  2671. int32 id = request->getType_int32_ByName("item_id");
  2672. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2673. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2674. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2675. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2676. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2677. //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);
  2678. Item* item = master_item_list.GetItem(id);
  2679. if (item) {
  2680. //only display popup for non merchant links
  2681. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2682. //DumpPacket(app);
  2683. QueuePacket(app);
  2684. }
  2685. else {
  2686. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2687. DumpPacket(app);
  2688. }
  2689. }
  2690. else if (type == 4) { //spell effect
  2691. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2692. if (!request) {
  2693. return;
  2694. }
  2695. request->LoadPacketData(app->pBuffer, app->size);
  2696. int32 id = request->getType_int32_ByName("id");
  2697. int16 display = request->getType_int8_ByName("partial_info");
  2698. SpellEffects* effect = player->GetSpellEffect(id);
  2699. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2700. if (effect) {
  2701. int8 tier = effect->tier;
  2702. Spell* spell = master_spell_list.GetSpell(id, tier);
  2703. // if we can't find it on the master spell list, see if it is a custom spell
  2704. if (!spell)
  2705. {
  2706. lua_interface->FindCustomSpellLock();
  2707. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2708. EQ2Packet* pack = 0;
  2709. if (tmpSpell)
  2710. spell = tmpSpell->spell;
  2711. lua_interface->FindCustomSpellUnlock();
  2712. }
  2713. if (spell && !CountSentSpell(id, tier)) {
  2714. if (!spell->IsCopiedSpell())
  2715. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2716. int8 type = 0;
  2717. if (version <= 283)
  2718. type = 1;
  2719. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2720. //DumpPacket(app);
  2721. QueuePacket(app);
  2722. }
  2723. }
  2724. }
  2725. else if (type == 5) { // recipe info
  2726. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2727. if (!request)
  2728. return;
  2729. request->LoadPacketData(app->pBuffer, app->size);
  2730. int32 id = request->getType_int32_ByName("unknown_id");
  2731. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2732. if (recipe) {
  2733. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2734. //DumpPacket(app);
  2735. QueuePacket(app);
  2736. }
  2737. }
  2738. else if (type == 6) { // AA spell info
  2739. Spell* spell = 0;
  2740. //Spell* spell2 = 0;
  2741. //AltAdvanceData* data = 0;
  2742. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2743. if (!request)
  2744. return;
  2745. request->LoadPacketData(app->pBuffer, app->size);
  2746. int32 id = request->getType_int32_ByName("id");
  2747. int32 tier = GetPlayer()->GetSpellTier(id);
  2748. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2749. //data = master_aa_list.GetAltAdvancement(id);
  2750. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2751. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2752. spell = master_spell_list.GetSpell(id, tier);
  2753. if (!spell)
  2754. spell = master_spell_list.GetSpell(id, 1);
  2755. if (!spell)
  2756. {
  2757. lua_interface->FindCustomSpellLock();
  2758. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2759. if (tmpSpell)
  2760. spell = tmpSpell->spell;
  2761. lua_interface->FindCustomSpellUnlock();
  2762. }
  2763. if (!spell)
  2764. {
  2765. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2766. return;
  2767. }
  2768. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2769. if (!spell->IsCopiedSpell())
  2770. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2771. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2772. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2773. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2774. //DumpPacket(app);
  2775. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2776. QueuePacket(app);
  2777. //}
  2778. }
  2779. else {
  2780. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2781. DumpPacket(app);
  2782. }
  2783. safe_delete(request);
  2784. }
  2785. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2786. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2787. if (request) {
  2788. request->LoadPacketData(app->pBuffer, app->size);
  2789. int32 id = request->getType_int32_ByName("id");
  2790. int32 bar = request->getType_int32_ByName("hotbar_number");
  2791. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2792. int32 type = request->getType_int32_ByName("type");
  2793. int8 tier = request->getType_int32_ByName("unique_id");
  2794. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2795. Spell* spell = 0;
  2796. if (type == 0xFFFFFFFF)
  2797. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2798. else {
  2799. if (type == QUICKBAR_NORMAL)
  2800. spell = master_spell_list.GetSpell(id, tier);
  2801. if (spell)
  2802. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2803. else
  2804. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2805. }
  2806. safe_delete(request);
  2807. }
  2808. }
  2809. bool Client::Process(bool zone_process) {
  2810. if (!eqs) {
  2811. return false;
  2812. }
  2813. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2814. return true;
  2815. }
  2816. if (new_client_login) {
  2817. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2818. SendLoginInfo();
  2819. new_client_login = false;
  2820. }
  2821. bool ret = true;
  2822. sockaddr_in to;
  2823. memset((char*)&to, 0, sizeof(to));
  2824. to.sin_family = AF_INET;
  2825. to.sin_port = port;
  2826. to.sin_addr.s_addr = ip;
  2827. /************ Get all packets from packet manager out queue and process them ************/
  2828. EQApplicationPacket* app = 0;
  2829. if (eqs && !eqs->CheckActive()) {
  2830. num_active_failures++;
  2831. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2832. if (num_active_failures > 100) {
  2833. return false;
  2834. }
  2835. return true;
  2836. }
  2837. while (ret && eqs && (app = eqs->PopPacket())) {
  2838. ret = HandlePacket(app);
  2839. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2840. delete app;
  2841. }
  2842. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2843. player->ApplyPassiveSpells();
  2844. //database.LoadCharacterActiveSpells(player);
  2845. player->UnlockAllSpells(true);
  2846. should_load_spells = false;
  2847. }
  2848. if(spawn_removal_timer.Check() && GetPlayer()) {
  2849. GetPlayer()->CheckSpawnStateQueue();
  2850. }
  2851. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2852. {
  2853. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2854. return false;
  2855. }
  2856. if (quest_updates) {
  2857. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2858. ProcessQuestUpdates();
  2859. }
  2860. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2861. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2862. CheckQuestQueue();
  2863. }
  2864. MSaveSpellStateMutex.lock();
  2865. if(save_spell_state_timer.Check())
  2866. {
  2867. save_spell_state_timer.Disable();
  2868. GetPlayer()->SaveSpellEffects();
  2869. }
  2870. MSaveSpellStateMutex.unlock();
  2871. if (temp_placement_timer.Check()) {
  2872. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2873. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2874. hasSentTempPlacementSpawn = true;
  2875. temp_placement_timer.Disable();
  2876. }
  2877. }
  2878. if (pos_update.Check())
  2879. {
  2880. ProcessStateCommands();
  2881. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2882. if(GetPlayer()->GetRegionMap())
  2883. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2884. if(player_pos_changed && IsReadyForUpdates()) {
  2885. //GetPlayer()->CalculateLocation();
  2886. client_list.CheckPlayersInvisStatus(this);
  2887. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2888. player_pos_changed = false;
  2889. GetCurrentZone()->CheckTransporters(this);
  2890. if(GetPlayer()->GetRegionMap())
  2891. {
  2892. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2893. {
  2894. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2895. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2896. }
  2897. else
  2898. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2899. }
  2900. }
  2901. }
  2902. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2903. lua_interface->UpdateDebugClients(this);
  2904. if (quest_pos_timer.Check())
  2905. CheckPlayerQuestsLocationUpdate();
  2906. if (player->GetSkills()->HasSkillUpdates()) {
  2907. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2908. if (skills) {
  2909. Skill* skill = 0;
  2910. vector<Skill*>::iterator itr;
  2911. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2912. skill = *itr;
  2913. SkillChanged(skill, skill->previous_val, skill->current_val);
  2914. }
  2915. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2916. if (app) QueuePacket(app);
  2917. safe_delete(skills);
  2918. }
  2919. }
  2920. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2921. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2922. safe_delete(current_rez.expire_timer);
  2923. current_rez.expire_timer = 0;
  2924. current_rez.active = false;
  2925. current_rez.caster = 0;
  2926. current_rez.crit = false;
  2927. current_rez.crit_mod = 0;
  2928. current_rez.expire_timer = 0;
  2929. current_rez.heal_name = "";
  2930. current_rez.hp_perc = 0;
  2931. current_rez.mp_perc = 0;
  2932. current_rez.no_calcs = false;
  2933. current_rez.range = 0;
  2934. current_rez.should_delete = false;
  2935. current_rez.spell_name = "";
  2936. current_rez.spell_visual = 0;
  2937. current_rez.subspell = 0;
  2938. }
  2939. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2940. // Quest timers
  2941. Quest* failed_step = 0;
  2942. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2943. if (quest_timers.size() > 0) {
  2944. vector<int32>::iterator itr;
  2945. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2946. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2947. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2948. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2949. Quest* quest = player_quests->at(*itr);
  2950. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2951. failed_step = quest;
  2952. break;
  2953. }
  2954. }
  2955. else {
  2956. itr = quest_timers.erase(itr);
  2957. break;
  2958. }
  2959. }
  2960. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  2961. }
  2962. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2963. if (failed_step)
  2964. failed_step->StepFailed(failed_step->GetTimerStep());
  2965. if (player->ControlFlagsChanged())
  2966. player->SendControlFlagUpdates(this);
  2967. if (camp_timer && camp_timer->Check()) {
  2968. ResetSendMail();
  2969. if(getConnection())
  2970. getConnection()->SendDisconnect(false);
  2971. safe_delete(camp_timer);
  2972. ret = false;
  2973. }
  2974. if (!eqs || (eqs && !eqs->CheckActive()))
  2975. ret = false;
  2976. // redundant to client disconnect
  2977. // if(!ret)
  2978. // Save();
  2979. return ret;
  2980. }
  2981. ClientList::ClientList() {
  2982. MClients.SetName("ClientList::MClients");
  2983. }
  2984. ClientList::~ClientList() {
  2985. }
  2986. void ClientList::ReloadQuests() {
  2987. list<Client*>::iterator client_iter;
  2988. Client* client = 0;
  2989. MClients.readlock(__FUNCTION__, __LINE__);
  2990. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2991. client = *client_iter;
  2992. if (client)
  2993. client->ReloadQuests();
  2994. }
  2995. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2996. }
  2997. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2998. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2999. return;
  3000. list<Client*>::iterator client_iter;
  3001. Client* client = 0;
  3002. MClients.readlock(__FUNCTION__, __LINE__);
  3003. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3004. client = *client_iter;
  3005. if (client == owner || client->GetPlayer() == NULL)
  3006. continue;
  3007. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  3008. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  3009. }
  3010. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3011. }
  3012. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  3013. list<Client*>::iterator client_iter;
  3014. Client* client = 0;
  3015. MClients.readlock(__FUNCTION__, __LINE__);
  3016. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3017. client = *client_iter;
  3018. if (!client->GetPlayer())
  3019. continue;
  3020. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  3021. }
  3022. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3023. }
  3024. int32 ClientList::Count() {
  3025. return client_list.size();
  3026. }
  3027. void ClientList::Add(Client* client) {
  3028. MClients.writelock(__FUNCTION__, __LINE__);
  3029. client_list.push_back(client);
  3030. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3031. }
  3032. Client* ClientList::FindByAccountID(int32 account_id) {
  3033. list<Client*>::iterator client_iter;
  3034. Client* client = 0;
  3035. Client* ret = 0;
  3036. MClients.readlock(__FUNCTION__, __LINE__);
  3037. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3038. client = *client_iter;
  3039. if (client->GetAccountID() == account_id) {
  3040. ret = client;
  3041. break;
  3042. }
  3043. }
  3044. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3045. return ret;
  3046. }
  3047. Client* ClientList::FindByName(char* charName) {
  3048. list<Client*>::iterator client_iter;
  3049. Client* client = 0;
  3050. Client* ret = 0;
  3051. MClients.readlock(__FUNCTION__, __LINE__);
  3052. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3053. client = *client_iter;
  3054. if (!client || !client->GetPlayer())
  3055. continue;
  3056. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  3057. ret = client;
  3058. break;
  3059. }
  3060. }
  3061. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3062. return ret;
  3063. }
  3064. Client* ClientList::Get(int32 ip, int16 port) {
  3065. list<Client*>::iterator client_iter;
  3066. Client* client = 0;
  3067. Client* ret = 0;
  3068. MClients.readlock(__FUNCTION__, __LINE__);
  3069. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3070. client = *client_iter;
  3071. if (client->GetIP() == ip && client->GetPort() == port) {
  3072. ret = client;
  3073. break;
  3074. }
  3075. }
  3076. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3077. return ret;
  3078. }
  3079. void ClientList::Process() {
  3080. list<Client*>::iterator client_iter;
  3081. list<Client*>::iterator erase_iter;
  3082. Client* client = 0;
  3083. MClients.readlock(__FUNCTION__, __LINE__);
  3084. erase_iter = client_list.end();
  3085. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3086. client = *client_iter;
  3087. // have a sanity check because the client list can sometimes obtain null client pointers
  3088. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3089. erase_iter = client_iter;
  3090. break;
  3091. }
  3092. }
  3093. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3094. if (erase_iter != client_list.end()) {
  3095. client = *erase_iter;
  3096. MClients.writelock(__FUNCTION__, __LINE__);
  3097. client_list.erase(erase_iter);
  3098. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3099. if (client && !client->remove_from_list) {
  3100. struct in_addr in;
  3101. in.s_addr = client->GetIP();
  3102. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3103. safe_delete(client);
  3104. }
  3105. }
  3106. }
  3107. void ClientList::RemoveConnection(EQStream* eqs) {
  3108. Client* client;
  3109. if (eqs) {
  3110. list<Client*>::iterator client_iter;
  3111. MClients.readlock(__FUNCTION__, __LINE__);
  3112. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3113. client = *client_iter;
  3114. if (client->getConnection() == eqs)
  3115. client->Disconnect(true);
  3116. }
  3117. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3118. }
  3119. }
  3120. bool ClientList::ContainsStream(EQStream* eqs) {
  3121. if (!eqs) {
  3122. return false;
  3123. }
  3124. list<Client*>::iterator client_iter;
  3125. bool ret = false;
  3126. MClients.readlock(__FUNCTION__, __LINE__);
  3127. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3128. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3129. ret = true;
  3130. break;
  3131. }
  3132. }
  3133. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3134. return ret;
  3135. }
  3136. void ClientList::Remove(Client* client, bool remove_data) {
  3137. client->remove_from_list = true;
  3138. if (remove_data) {
  3139. safe_delete(client);
  3140. }
  3141. }
  3142. void Client::SetCurrentZone(int32 id) {
  3143. if (current_zone) {
  3144. //current_zone->GetCombat()->RemoveHate(player);
  3145. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3146. }
  3147. SetCurrentZone(zone_list.Get(id));
  3148. }
  3149. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3150. if (current_zone) {
  3151. //current_zone->GetCombat()->RemoveHate(player);
  3152. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3153. }
  3154. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3155. }
  3156. ZoneServer* Client::GetCurrentZone() {
  3157. return current_zone;
  3158. }
  3159. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3160. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3161. if (channel_type == CHANNEL_LOOT)
  3162. return CHANNEL_COLOR_NEW_LOOT;
  3163. }
  3164. else if (GetVersion() >= 973) {
  3165. if (channel_type == CHANNEL_LOOT)
  3166. return CHANNEL_COLOR_NEWEST_LOOT;
  3167. }
  3168. if (GetVersion() <= 283) {
  3169. if (channel_type <=12)
  3170. return channel_type;
  3171. switch (channel_type) {
  3172. case CHANNEL_GROUP_CHAT:
  3173. case CHANNEL_GROUP_SAY:
  3174. case CHANNEL_RAID_SAY:
  3175. case CHANNEL_GUILD_CHAT:
  3176. case CHANNEL_GUILD_SAY:
  3177. case CHANNEL_OFFICER_SAY:
  3178. case CHANNEL_GUILD_MOTD:
  3179. return channel_type - 1;
  3180. case CHANNEL_PRIVATE_CHAT:
  3181. case CHANNEL_NONPLAYER_TELL:
  3182. return channel_type - 5;
  3183. case CHANNEL_PRIVATE_TELL:
  3184. case CHANNEL_TELL_FROM_CS:
  3185. return channel_type - 6;
  3186. case CHANNEL_CHAT_CHANNEL_TEXT:
  3187. case CHANNEL_OUT_OF_CHARACTER:
  3188. case CHANNEL_AUCTION:
  3189. case CHANNEL_CUSTOM_CHANNEL:
  3190. case CHANNEL_CHARACTER_TEXT:
  3191. case CHANNEL_REWARD:
  3192. case CHANNEL_DEATH:
  3193. case CHANNEL_PET_CHAT:
  3194. case CHANNEL_SKILL:
  3195. return channel_type - 7;
  3196. case CHANNEL_SPELLS:
  3197. case CHANNEL_YOU_CAST:
  3198. case CHANNEL_YOU_FAIL:
  3199. return channel_type - 8;
  3200. case CHANNEL_FRIENDLY_CAST:
  3201. case CHANNEL_FRIENDLY_FAIL:
  3202. case CHANNEL_OTHER_CAST:
  3203. case CHANNEL_OTHER_FAIL:
  3204. case CHANNEL_HOSTILE_CAST:
  3205. case CHANNEL_HOSTILE_FAIL:
  3206. case CHANNEL_WORN_OFF:
  3207. case CHANNEL_SPELLS_OTHER:
  3208. return channel_type - 9;
  3209. case CHANNEL_COMBAT:
  3210. return channel_type - 15;
  3211. case CHANNEL_HEROIC_OPPORTUNITY:
  3212. case CHANNEL_NON_MELEE_DAMAGE:
  3213. case CHANNEL_DAMAGE_SHIELD:
  3214. return channel_type - 16;
  3215. case CHANNEL_MELEE_COMBAT:
  3216. case CHANNEL_WARNINGS:
  3217. case CHANNEL_YOU_HIT:
  3218. case CHANNEL_YOU_MISS:
  3219. case CHANNEL_ATTACKER_HITS:
  3220. case CHANNEL_ATTACKER_MISSES:
  3221. return channel_type - 18;
  3222. case CHANNEL_OTHER_HIT:
  3223. case CHANNEL_OTHER_MISSES:
  3224. case CHANNEL_CRITICAL_HIT:
  3225. return channel_type - 22;
  3226. case CHANNEL_OTHER:
  3227. case CHANNEL_MONEY_SPLIT:
  3228. case CHANNEL_LOOT:
  3229. return channel_type - 30;
  3230. case CHANNEL_COMMAND_TEXT:
  3231. case CHANNEL_BROADCAST:
  3232. case CHANNEL_WHO:
  3233. case CHANNEL_COMMANDS:
  3234. case CHANNEL_MERCHANT:
  3235. case CHANNEL_MERCHANT_BUY_SELL:
  3236. case CHANNEL_CONSIDER_MESSAGE:
  3237. case CHANNEL_CON_MINUS_2:
  3238. case CHANNEL_CON_MINUS_1:
  3239. case CHANNEL_CON_0:
  3240. case CHANNEL_CON_1:
  3241. case CHANNEL_CON_2:
  3242. return channel_type - 31;
  3243. default: {
  3244. return CHANNEL_DEFAULT;
  3245. }
  3246. }
  3247. }
  3248. else if (GetVersion() <= 546) {
  3249. if (channel_type < 20)
  3250. return channel_type;
  3251. switch (channel_type) {
  3252. case CHANNEL_GUILD_MOTD:
  3253. case CHANNEL_GUILD_MEMBER_ONLINE:
  3254. case CHANNEL_GUILD_EVENT:
  3255. return channel_type + 1;
  3256. case CHANNEL_PRIVATE_CHAT:
  3257. case CHANNEL_NONPLAYER_TELL:
  3258. return channel_type - 1;
  3259. case CHANNEL_PRIVATE_TELL:
  3260. case CHANNEL_TELL_FROM_CS:
  3261. case CHANNEL_ARENA:
  3262. case CHANNEL_CHAT_CHANNEL_TEXT:
  3263. case CHANNEL_OUT_OF_CHARACTER:
  3264. case CHANNEL_AUCTION:
  3265. case CHANNEL_CUSTOM_CHANNEL:
  3266. case CHANNEL_CHARACTER_TEXT:
  3267. case CHANNEL_REWARD:
  3268. case CHANNEL_DEATH:
  3269. case CHANNEL_PET_CHAT:
  3270. case CHANNEL_SKILL:
  3271. case CHANNEL_FACTION:
  3272. case CHANNEL_SPELLS:
  3273. case CHANNEL_YOU_CAST:
  3274. case CHANNEL_YOU_FAIL:
  3275. return channel_type - 2;
  3276. case CHANNEL_FRIENDLY_CAST:
  3277. case CHANNEL_FRIENDLY_FAIL:
  3278. case CHANNEL_OTHER_CAST:
  3279. case CHANNEL_OTHER_FAIL:
  3280. case CHANNEL_HOSTILE_CAST:
  3281. case CHANNEL_HOSTILE_FAIL:
  3282. case CHANNEL_WORN_OFF:
  3283. case CHANNEL_SPELLS_OTHER:
  3284. case CHANNEL_HEAL_SPELLS:
  3285. case CHANNEL_HEALS:
  3286. case CHANNEL_FRIENDLY_HEALS:
  3287. case CHANNEL_OTHER_HEALS:
  3288. case CHANNEL_HOSTILE_HEALS:
  3289. return channel_type - 3;
  3290. case CHANNEL_COMBAT:
  3291. case CHANNEL_GENERAL_COMBAT:
  3292. case CHANNEL_HEROIC_OPPORTUNITY:
  3293. case CHANNEL_NON_MELEE_DAMAGE:
  3294. case CHANNEL_DAMAGE_SHIELD:
  3295. case CHANNEL_WARD:
  3296. return channel_type - 4;
  3297. case CHANNEL_MELEE_COMBAT:
  3298. case CHANNEL_WARNINGS:
  3299. case CHANNEL_YOU_HIT:
  3300. case CHANNEL_YOU_MISS:
  3301. case CHANNEL_ATTACKER_HITS:
  3302. case CHANNEL_ATTACKER_MISSES:
  3303. case CHANNEL_YOUR_PET_HITS:
  3304. case CHANNEL_YOUR_PET_MISSES:
  3305. case CHANNEL_ATTACKER_HITS_PET:
  3306. case CHANNEL_ATTACKER_MISSES_PET:
  3307. case CHANNEL_OTHER_HIT:
  3308. case CHANNEL_OTHER_MISSES:
  3309. return channel_type - 5;
  3310. case CHANNEL_OTHER:
  3311. case CHANNEL_MONEY_SPLIT:
  3312. case CHANNEL_LOOT:
  3313. return channel_type - 14;
  3314. case CHANNEL_COMMAND_TEXT:
  3315. case CHANNEL_BROADCAST:
  3316. case CHANNEL_WHO:
  3317. case CHANNEL_COMMANDS:
  3318. case CHANNEL_MERCHANT:
  3319. case CHANNEL_MERCHANT_BUY_SELL:
  3320. case CHANNEL_CONSIDER_MESSAGE:
  3321. case CHANNEL_CON_MINUS_2:
  3322. case CHANNEL_CON_MINUS_1:
  3323. case CHANNEL_CON_0:
  3324. case CHANNEL_CON_1:
  3325. case CHANNEL_CON_2:
  3326. case CHANNEL_TRADESKILLS:
  3327. case CHANNEL_HARVESTING:
  3328. case CHANNEL_HARVESTING_WARNINGS:
  3329. return channel_type - 15;
  3330. default: {
  3331. return CHANNEL_DEFAULT;
  3332. }
  3333. }
  3334. }
  3335. else {
  3336. switch (channel_type) {
  3337. default: {
  3338. return channel_type;
  3339. }
  3340. }
  3341. }
  3342. return channel_type;
  3343. }
  3344. void Client::HandleTellMessage(Client* from, const char* message, const char* to, int32 current_language_id) {
  3345. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3346. return;
  3347. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3348. if (packet) {
  3349. packet->setDataByName("from", from->GetPlayer()->GetName());
  3350. packet->setDataByName("to", to);
  3351. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3352. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3353. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3354. packet->setDataByName("unknown2", 1, 1);
  3355. packet->setDataByName("show_bubble", 1);
  3356. if (current_language_id == 0 || GetPlayer()->HasLanguage(current_language_id)) {
  3357. packet->setDataByName("understood", 1);
  3358. }
  3359. packet->setDataByName("time", 2);
  3360. packet->setDataByName("language", current_language_id);
  3361. packet->setMediumStringByName("message", message);
  3362. EQ2Packet* outpacket = packet->serialize();
  3363. QueuePacket(outpacket);
  3364. safe_delete(packet);
  3365. }
  3366. }
  3367. void Client::SimpleMessage(int8 color, const char* message) {
  3368. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3369. if (command_packet) {
  3370. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3371. command_packet->setMediumStringByName("text", message);
  3372. command_packet->setDataByName("unknown02", 0x00ff);
  3373. EQ2Packet* outapp = command_packet->serialize();
  3374. QueuePacket(outapp);
  3375. safe_delete(command_packet);
  3376. }
  3377. }
  3378. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3379. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3380. if (packet) {
  3381. int8 xxx = spell->GetSpellData()->is_aa;
  3382. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3383. packet->setDataByName("spell_id", spell->GetSpellID());
  3384. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3385. packet->setDataByName("spell_name", spell->GetName());
  3386. if(add_silently)
  3387. packet->setDataByName("add_silently", 1);
  3388. if(add_to_hotbar)
  3389. packet->setDataByName("add_to_hotbar", 1);
  3390. packet->setDataByName("unknown", xxx);
  3391. packet->setDataByName("display_spell_tier", 1);
  3392. packet->setDataByName("unknown3", 1);
  3393. packet->setDataByName("tier", spell->GetSpellTier());
  3394. packet->setDataByName("icon", spell->GetSpellIcon());
  3395. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3396. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3397. //packet->PrintPacket();
  3398. EQ2Packet* outapp = packet->serialize();
  3399. //DumpPacket(outapp);
  3400. QueuePacket(outapp);
  3401. safe_delete(packet);
  3402. }
  3403. }
  3404. void Client::Message(int8 type, const char* message, ...) {
  3405. va_list argptr;
  3406. char buffer[4096];
  3407. va_start(argptr, message);
  3408. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3409. va_end(argptr);
  3410. SimpleMessage(type, buffer);
  3411. }
  3412. void Client::Disconnect(bool send_disconnect)
  3413. {
  3414. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3415. this->Save();
  3416. this->GetPlayer()->WritePlayerStatistics();
  3417. SetConnected(false);
  3418. if (send_disconnect && getConnection())
  3419. getConnection()->SendDisconnect(true);
  3420. eqs = 0;
  3421. }
  3422. bool Client::Summon(const char* search_name) {
  3423. Spawn* target = 0;
  3424. if (search_name || GetPlayer()->GetTarget()) {
  3425. Client* search_client = 0;
  3426. if (search_name) {
  3427. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3428. if (target && target->IsPlayer())
  3429. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3430. if (!target) {
  3431. search_client = zone_list.GetClientByCharName(string(search_name));
  3432. if (search_client)
  3433. target = search_client->GetPlayer();
  3434. }
  3435. }
  3436. else
  3437. target = GetPlayer()->GetTarget();
  3438. if (target && target != GetPlayer()) {
  3439. target->SetX(GetPlayer()->GetX());
  3440. target->SetY(GetPlayer()->GetY());
  3441. target->SetZ(GetPlayer()->GetZ());
  3442. target->SetHeading(GetPlayer()->GetHeading());
  3443. if (!target->IsPlayer()) {
  3444. target->SetSpawnOrigX(target->GetX());
  3445. target->SetSpawnOrigY(target->GetY());
  3446. target->SetSpawnOrigZ(target->GetZ());
  3447. target->SetSpawnOrigHeading(target->GetHeading());
  3448. }
  3449. target->SetLocation(GetPlayer()->GetLocation());
  3450. }
  3451. else if (target)
  3452. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3453. if (search_client && search_client != this) {
  3454. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3455. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3456. if (search_client->GetCurrentZone() != GetCurrentZone())
  3457. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3458. else {
  3459. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3460. if (app)
  3461. search_client->QueuePacket(app);
  3462. }
  3463. }
  3464. }
  3465. if (!target)
  3466. return false;
  3467. else
  3468. return true;
  3469. }
  3470. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3471. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3472. if(instanceType < 1)
  3473. return std::string("");
  3474. ZoneServer* instance_zone = nullptr;
  3475. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3476. if (data) {
  3477. // If lockout instances check to see if we are locked out
  3478. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3479. int32 time = 0;
  3480. // Check success timer
  3481. if (data->last_success_timestamp > 0) {
  3482. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3483. // Timer has not expired yet can't re enter
  3484. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3485. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3486. }
  3487. }
  3488. // Check failure timer
  3489. if (data->last_failure_timestamp > 0) {
  3490. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3491. // Timer has not expired yet
  3492. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3493. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3494. }
  3495. }
  3496. // Time > 0 then we are locked out, make the message and send it and return true
  3497. if (time > 0) {
  3498. string time_msg = "";
  3499. int16 hour;
  3500. int8 min;
  3501. int8 sec;
  3502. hour = time / 3600;
  3503. time = time % 3600;
  3504. min = time / 60;
  3505. time = time % 60;
  3506. sec = time;
  3507. if (hour > 0) {
  3508. char temp[10];
  3509. snprintf(temp, 9," %i", hour);
  3510. time_msg.append(temp);
  3511. time_msg.append(" hour");
  3512. time_msg.append((hour > 1) ? "s" : "");
  3513. }
  3514. if (min > 0) {
  3515. char temp[5];
  3516. snprintf(temp, 4," %i", min);
  3517. time_msg.append(temp);
  3518. time_msg.append(" minute");
  3519. time_msg.append((min > 1) ? "s" : "");
  3520. }
  3521. // Only add seconds if minutes and hours are 0
  3522. if (hour == 0 && min == 0 && sec > 0) {
  3523. char temp[5];
  3524. snprintf(temp, 4," %i", sec);
  3525. time_msg.append(temp);
  3526. time_msg.append(" second");
  3527. time_msg.append((sec > 1) ? "s" : "");
  3528. }
  3529. if(displayClient)
  3530. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3531. return time_msg;
  3532. }
  3533. }
  3534. }
  3535. return std::string("");
  3536. }
  3537. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3538. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3539. if(instanceType < 1)
  3540. return nullptr;
  3541. ZoneServer* instance_zone = nullptr;
  3542. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3543. if (data) {
  3544. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3545. // If lockout instances check to see if we are locked out
  3546. if (lockoutTime.length() > 0) {
  3547. return nullptr;
  3548. }
  3549. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3550. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3551. // 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
  3552. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3553. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3554. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3555. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3556. }
  3557. else
  3558. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3559. data->instance_id = instance_zone->GetInstanceID();
  3560. }
  3561. }
  3562. return instance_zone;
  3563. }
  3564. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3565. ZoneServer* instance_zone = NULL;
  3566. int8 instanceType = 0;
  3567. // determine if this is a group instanced zone that already exists
  3568. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3569. if (instance_zone != NULL)
  3570. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3571. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3572. {
  3573. // best to check if we already have our own instance!
  3574. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3575. {
  3576. switch (instanceType)
  3577. {
  3578. case SOLO_LOCKOUT_INSTANCE:
  3579. case GROUP_LOCKOUT_INSTANCE:
  3580. case RAID_LOCKOUT_INSTANCE:
  3581. {
  3582. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3583. if (instance_zone) {
  3584. // 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
  3585. // so delete `instances` entry for the zone when it shuts down.
  3586. 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());
  3587. if (db_id > 0)
  3588. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3589. }
  3590. break;
  3591. }
  3592. case SOLO_PERSIST_INSTANCE:
  3593. case GROUP_PERSIST_INSTANCE:
  3594. case RAID_PERSIST_INSTANCE:
  3595. {
  3596. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3597. if (instance_zone) {
  3598. 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());
  3599. if (db_id > 0)
  3600. 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()));
  3601. }
  3602. break;
  3603. }
  3604. case PUBLIC_INSTANCE:
  3605. case TRADESKILL_INSTANCE:
  3606. {
  3607. // if its public/tradeskill, look for a public already setup
  3608. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3609. if (instance_zone) {
  3610. // Check the current population against the max population, if greater or equal start a new version
  3611. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3612. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3613. }
  3614. else
  3615. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3616. break;
  3617. }
  3618. case PERSONAL_HOUSE_INSTANCE:
  3619. case GUILD_HOUSE_INSTANCE:
  3620. {
  3621. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3622. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3623. // with the OP_EnterHouseMsg opcode
  3624. break;
  3625. }
  3626. case QUEST_INSTANCE:
  3627. {
  3628. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3629. break;
  3630. /*
  3631. 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`;
  3632. */
  3633. }
  3634. default:
  3635. {
  3636. // NONE
  3637. }
  3638. }
  3639. }
  3640. if (instance_zone != NULL)
  3641. Zone(instance_zone, zone_coords_valid);
  3642. }
  3643. if (instance_zone != NULL)
  3644. return true;
  3645. else
  3646. return false;
  3647. }
  3648. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3649. Spawn* target = 0;
  3650. if (search_name || GetPlayer()->GetTarget()) {
  3651. Client* search_client = 0;
  3652. if (search_name) {
  3653. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3654. if (!target) {
  3655. search_client = zone_list.GetClientByCharName(search_name);
  3656. if (search_client)
  3657. target = search_client->GetPlayer();
  3658. }
  3659. if (target)
  3660. GetPlayer()->SetTarget(target);
  3661. }
  3662. else
  3663. target = GetPlayer()->GetTarget();
  3664. if (target && target != GetPlayer()) {
  3665. GetPlayer()->SetX(target->GetX());
  3666. GetPlayer()->SetY(target->GetY());
  3667. GetPlayer()->SetZ(target->GetZ());
  3668. GetPlayer()->SetHeading(target->GetHeading());
  3669. GetPlayer()->SetLocation(target->GetLocation());
  3670. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3671. }
  3672. else if (target)
  3673. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3674. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3675. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3676. else if (target) {
  3677. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3678. if (app)
  3679. QueuePacket(app);
  3680. }
  3681. }
  3682. if (!target)
  3683. return false;
  3684. else
  3685. return true;
  3686. }
  3687. bool Client::CheckZoneAccess(const char* zoneName) {
  3688. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3689. ZoneServer* zone = zone_list.Get(zoneName, false);
  3690. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3691. if (zone && zone->GetZoneLockState())
  3692. {
  3693. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3694. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3695. return false;
  3696. }
  3697. sint16 zoneMinStatus = 0;
  3698. int16 zoneMinLevel = 0;
  3699. int16 zoneMaxLevel = 0;
  3700. int16 zoneMinVersion = 0;
  3701. if (!zone)
  3702. {
  3703. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3704. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3705. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3706. return true;
  3707. }
  3708. }
  3709. else
  3710. {
  3711. zoneMinStatus = zone->GetMinimumStatus();
  3712. zoneMinLevel = zone->GetMinimumLevel();
  3713. zoneMaxLevel = zone->GetMaximumLevel();
  3714. zoneMinVersion = zone->GetMinimumVersion();
  3715. }
  3716. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3717. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3718. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3719. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3720. {
  3721. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3722. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3723. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3724. return false;
  3725. }
  3726. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3727. {
  3728. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3729. {
  3730. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3731. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3732. return false;
  3733. }
  3734. }
  3735. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3736. {
  3737. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3738. {
  3739. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3740. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3741. return false;
  3742. }
  3743. }
  3744. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3745. {
  3746. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3747. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3748. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3749. {
  3750. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3751. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3752. return false;
  3753. }
  3754. }
  3755. return true;
  3756. }
  3757. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3758. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3759. }
  3760. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3761. if (!new_zone) {
  3762. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3763. return;
  3764. }
  3765. client_zoning = true;
  3766. zoning_id = new_zone->GetZoneID();
  3767. zoning_instance_id = new_zone->GetInstanceID();
  3768. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3769. player->SetResurrecting(true);
  3770. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3771. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3772. MSaveSpellStateMutex.lock();
  3773. player->SaveSpellEffects();
  3774. player->SetSaveSpellEffects(true);
  3775. MSaveSpellStateMutex.unlock();
  3776. ResetSendMail();
  3777. // Remove players pet from zone if there is one
  3778. ((Entity*)player)->DismissAllPets();
  3779. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3780. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3781. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3782. SetZoningDestination(new_zone);
  3783. SetCurrentZone(new_zone);
  3784. if (player->GetGroupMemberInfo())
  3785. {
  3786. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3787. player->UpdateGroupMemberInfo();
  3788. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3789. }
  3790. // block out the member info for the group
  3791. TempRemoveGroup();
  3792. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3793. if (set_coords)
  3794. {
  3795. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3796. __FUNCTION__,
  3797. GetCurrentZone()->GetSafeX(),
  3798. GetCurrentZone()->GetSafeY(),
  3799. GetCurrentZone()->GetSafeZ(),
  3800. GetCurrentZone()->GetSafeHeading(),
  3801. new_zone->GetZoneName()
  3802. );
  3803. player->SetX(GetCurrentZone()->GetSafeX());
  3804. player->SetY(GetCurrentZone()->GetSafeY());
  3805. player->SetZ(GetCurrentZone()->GetSafeZ());
  3806. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3807. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  3808. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  3809. }
  3810. else {
  3811. ResetZoningCoords();
  3812. }
  3813. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3814. Save();
  3815. char* new_zone_ip = 0;
  3816. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3817. new_zone_ip = net.GetInternalWorldAddress();
  3818. else
  3819. new_zone_ip = net.GetWorldAddress();
  3820. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3821. int32 key = Timer::GetUnixTimeStamp();
  3822. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3823. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3824. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3825. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3826. if (version > 283) {
  3827. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3828. if (packet)
  3829. {
  3830. QueuePacket(packet->serialize());
  3831. safe_delete(packet);
  3832. }
  3833. }
  3834. }
  3835. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3836. {
  3837. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3838. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3839. }
  3840. float Client::DistanceFrom(Client* client) {
  3841. float ret = 0;
  3842. if (client && client != this) {
  3843. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3844. ret = sqrt(ret);
  3845. }
  3846. return ret;
  3847. }
  3848. void Client::DetermineCharacterUpdates() {
  3849. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3850. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3851. cdu->account_id = GetAccountID();
  3852. cdu->char_id = GetCharacterID();
  3853. int32 timestamp = Timer::GetUnixTimeStamp();
  3854. int8 flag = GetTimeStampFlag();
  3855. if (flag & LEVEL_UPDATE_FLAG)
  3856. {
  3857. cdu->update_field = LEVEL_UPDATE_FLAG;
  3858. cdu->update_data = player->GetLevel();
  3859. loginserver.SendPacket(outpack);
  3860. }
  3861. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3862. if (flag & CLASS_UPDATE_FLAG)
  3863. {
  3864. cdu->update_field = CLASS_UPDATE_FLAG;
  3865. cdu->update_data = player->GetAdventureClass();
  3866. loginserver.SendPacket(outpack);
  3867. }
  3868. if (flag & GENDER_UPDATE_FLAG)
  3869. {
  3870. cdu->update_field = GENDER_UPDATE_FLAG;
  3871. cdu->update_data = player->GetGender();
  3872. loginserver.SendPacket(outpack);
  3873. }
  3874. if (flag & DELETE_UPDATE_FLAG) {
  3875. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3876. }
  3877. safe_delete(outpack); // Zone, armor and name use a different structure
  3878. if (flag & RACE_UPDATE_FLAG)
  3879. {
  3880. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3881. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3882. ru->account_id = GetAccountID();
  3883. ru->char_id = GetCharacterID();
  3884. ru->race = player->GetRace();
  3885. ru->model_type = player->GetModelType();
  3886. loginserver.SendPacket(outpack);
  3887. safe_delete(outpack);
  3888. }
  3889. if (flag & ZONE_UPDATE_FLAG) {
  3890. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3891. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3892. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3893. czu->account_id = GetAccountID();
  3894. czu->char_id = GetCharacterID();
  3895. czu->zone_id = GetCurrentZone()->GetZoneID();
  3896. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3897. czu->zone_length = strlen(zone_file);
  3898. if (czu->zone_length > 64)
  3899. czu->zone_length = 64;
  3900. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3901. loginserver.SendPacket(outpack);
  3902. safe_delete(outpack);
  3903. }
  3904. if (flag & ARMOR_UPDATE_FLAG) {
  3905. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3906. }
  3907. if (flag & NAME_UPDATE_FLAG) {
  3908. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3909. }
  3910. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3911. }
  3912. void Client::Save() {
  3913. if (GetCharacterID() == 0)
  3914. return;
  3915. if (current_zone) {
  3916. DetermineCharacterUpdates();
  3917. UpdateCharacterInstances();
  3918. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3919. database.Save(this);
  3920. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3921. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3922. GetPlayer()->ResetQuickbarNeeded();
  3923. }
  3924. database.SaveItems(this);
  3925. database.SaveBuyBacks(this);
  3926. GetPlayer()->SaveHistory();
  3927. GetPlayer()->SaveLUAHistory();
  3928. MSaveSpellStateMutex.lock();
  3929. GetPlayer()->SaveSpellEffects();
  3930. MSaveSpellStateMutex.unlock();
  3931. }
  3932. }
  3933. void Client::UpdateCharacterInstances() {
  3934. if (GetPlayer() != NULL)
  3935. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3936. /*if ( GetPlayer() != NULL )
  3937. {
  3938. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3939. // to use for applying the update to each instances timer
  3940. int32 lastSaveTS = GetLastSavedTimeStamp();
  3941. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3942. int32 diffTS = newSaveTS - lastSaveTS;
  3943. // update instance timers
  3944. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3945. // update with the new timestamp and save the db
  3946. this->SetLastSavedTimeStamp(newSaveTS);
  3947. }*/
  3948. }
  3949. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3950. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3951. if (packet) {
  3952. packet->LoadPacketData(app->pBuffer, app->size);
  3953. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3954. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3955. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3956. vector<EntityCommand*> commands;
  3957. vector<EntityCommand*> delete_commands;
  3958. if (out && spawn) {
  3959. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3960. {
  3961. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3962. if (!spawn->primary_command_list[i]->default_allow_list)
  3963. {
  3964. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3965. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3966. continue;
  3967. }
  3968. else
  3969. {
  3970. // default is allow list, only deny if added to the list as deny (false itr second)
  3971. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3972. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3973. continue;
  3974. }
  3975. commands.push_back(spawn->primary_command_list[i]);
  3976. }
  3977. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3978. commands.push_back(spawn->secondary_command_list[i]);
  3979. if (spawn->IsPlayer()) {
  3980. if (player->IsFriend(spawn->GetName()))
  3981. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3982. else
  3983. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3984. if (player->IsIgnored(spawn->GetName()))
  3985. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3986. else
  3987. {
  3988. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3989. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3990. }
  3991. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3992. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3993. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3994. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3995. }
  3996. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  3997. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  3998. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  3999. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  4000. }
  4001. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  4002. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  4003. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  4004. }
  4005. out->setDataByName("spawn_id", spawn_id);
  4006. out->setArrayLengthByName("num_verbs", commands.size());
  4007. for (int32 i = 0; i < commands.size(); i++) {
  4008. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  4009. out->setArrayDataByName("distance", commands[i]->distance, i);
  4010. if (commands[i]->error_text.length() == 0)
  4011. out->setArrayAddToPacketByName("error", false, i);
  4012. else {
  4013. out->setArrayDataByName("display_error", 1, i);
  4014. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  4015. }
  4016. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  4017. }
  4018. EQ2Packet* outapp = out->serialize();
  4019. //DumpPacket(outapp);
  4020. QueuePacket(outapp);
  4021. safe_delete(out);
  4022. for (int32 i = 0; i < delete_commands.size(); i++) {
  4023. safe_delete(delete_commands[i]);
  4024. }
  4025. }
  4026. safe_delete(packet);
  4027. }
  4028. }
  4029. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  4030. if (previous_value != new_value) {
  4031. 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);
  4032. char tmp[200] = { 0 };
  4033. 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);
  4034. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  4035. }
  4036. }
  4037. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  4038. {
  4039. /* JA notes on the unknown:
  4040. 2 = ding glimmer
  4041. 16 = Achievement Unlocked
  4042. 6 no longer does anything
  4043. */
  4044. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  4045. if (packet) {
  4046. packet->setDataByName("unknown", unknown);
  4047. packet->setMediumStringByName("text", text);
  4048. if (type && strlen(type) > 0)
  4049. packet->setMediumStringByName("message_type", type);
  4050. packet->setDataByName("size", size);
  4051. packet->setDataByName("red", red);
  4052. packet->setDataByName("green", green);
  4053. packet->setDataByName("blue", blue);
  4054. QueuePacket(packet->serialize());
  4055. safe_delete(packet);
  4056. }
  4057. }
  4058. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  4059. if (new_level < 1) {
  4060. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4061. return;
  4062. }
  4063. if (player->GetLevel() != new_level) {
  4064. player->SetLevel(new_level);
  4065. if (player->GetGroupMemberInfo()) {
  4066. player->UpdateGroupMemberInfo();
  4067. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4068. }
  4069. }
  4070. if (new_level > old_level) {
  4071. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4072. }
  4073. if (player->GetPet()) {
  4074. NPC* pet = (NPC*)player->GetPet();
  4075. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4076. pet->SetLevel(new_level);
  4077. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4078. if (command_packet) {
  4079. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4080. command_packet->setDataByName("anim_type", 1753);
  4081. QueuePacket(command_packet->serialize());
  4082. safe_delete(command_packet);
  4083. }
  4084. }
  4085. }
  4086. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4087. if (level_update) {
  4088. level_update->setDataByName("old_level", old_level);
  4089. level_update->setDataByName("new_level", new_level);
  4090. QueuePacket(level_update->serialize());
  4091. safe_delete(level_update);
  4092. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4093. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4094. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4095. }
  4096. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4097. if (command_packet) {
  4098. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4099. command_packet->setDataByName("anim_type", 1753);
  4100. QueuePacket(command_packet->serialize());
  4101. safe_delete(command_packet);
  4102. }
  4103. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4104. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4105. SendNewSpells(player->GetAdventureClass());
  4106. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4107. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4108. GetPlayer()->ChangePrimaryWeapon();
  4109. GetPlayer()->ChangeSecondaryWeapon();
  4110. GetPlayer()->ChangeRangedWeapon();
  4111. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4112. // GetPlayer()->SetLevel(new_level);
  4113. 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__);
  4114. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4115. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4116. GetPlayer()->CalculateBonuses();
  4117. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4118. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4119. InfoStruct* info = player->GetInfoStruct();
  4120. info->set_agi_base(new_level * 2 + 15);
  4121. info->set_intel_base(new_level * 2 + 15);
  4122. info->set_wis_base(new_level * 2 + 15);
  4123. info->set_str_base(new_level * 2 + 15);
  4124. info->set_sta_base(new_level * 2 + 15);
  4125. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4126. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4127. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4128. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4129. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4130. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4131. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4132. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));
  4133. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4134. GetPlayer()->SetCharSheetChanged(true);
  4135. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4136. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4137. int16 new_skill_cap = 5 * new_level;
  4138. PlayerSkillList* player_skills = player->GetSkills();
  4139. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4140. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4141. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4142. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4143. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4144. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4145. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4146. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4147. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4148. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4149. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4150. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4151. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4152. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4153. if (new_level > player->GetTSLevel())
  4154. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4155. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4156. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4157. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4158. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4159. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4160. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4161. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4162. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4163. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4164. Guild* guild = GetPlayer()->GetGuild();
  4165. if (guild) {
  4166. int8 event_type = 0;
  4167. if (new_level < 10)
  4168. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4169. else if (new_level == 10)
  4170. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4171. else if (new_level >= 11 && new_level < 20)
  4172. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4173. else if (new_level == 20)
  4174. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4175. else if (new_level >= 21 && new_level < 30)
  4176. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4177. else if (new_level == 30)
  4178. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4179. else if (new_level >= 31 && new_level < 40)
  4180. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4181. else if (new_level == 40)
  4182. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4183. else if (new_level >= 41 && new_level < 50)
  4184. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4185. else if (new_level == 50)
  4186. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4187. else if (new_level >= 51 && new_level < 60)
  4188. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4189. else if (new_level == 60)
  4190. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4191. else if (new_level >= 61 && new_level < 70)
  4192. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4193. else if (new_level == 70)
  4194. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4195. else if (new_level >= 71 && new_level < 80)
  4196. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4197. else if (new_level == 80)
  4198. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4199. 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());
  4200. 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());
  4201. guild->UpdateGuildMemberInfo(GetPlayer());
  4202. guild->SendGuildMember(GetPlayer());
  4203. guild->SendGuildMemberList();
  4204. }
  4205. // Need to send the trait list every time the players level changes
  4206. // Also need to force the char sheet update or else there can be a large delay from when you level
  4207. // to when you are actually able to select traits.
  4208. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4209. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4210. if (version > 546)
  4211. master_aa_list.DisplayAA(this, 0, 0);
  4212. if (GetPlayer()->SpawnedBots.size() > 0) {
  4213. map<int32, int32>::iterator itr;
  4214. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4215. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4216. if (bot && bot->IsBot())
  4217. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4218. }
  4219. }
  4220. }
  4221. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4222. if (new_level < 1) {
  4223. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4224. return;
  4225. }
  4226. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4227. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4228. return;
  4229. }
  4230. if (new_level > old_level)
  4231. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4232. if (player->GetTSLevel() != new_level) {
  4233. player->SetTSLevel(new_level);
  4234. if (player->GetGroupMemberInfo()) {
  4235. player->UpdateGroupMemberInfo();
  4236. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4237. }
  4238. }
  4239. // Only tradeskill skills should increace, and then only those related to your class
  4240. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4241. if (level_update) {
  4242. level_update->setDataByName("old_level", old_level);
  4243. level_update->setDataByName("new_level", new_level);
  4244. level_update->setDataByName("type", 1);
  4245. QueuePacket(level_update->serialize());
  4246. safe_delete(level_update);
  4247. }
  4248. // Need to make tradeskill versions of the following
  4249. //SendNewSpells(player->GetAdventureClass());
  4250. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4251. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4252. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4253. if (command_packet) {
  4254. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4255. command_packet->setDataByName("anim_type", 1753);
  4256. QueuePacket(command_packet->serialize());
  4257. safe_delete(command_packet);
  4258. }
  4259. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4260. GetPlayer()->SetTSLevel(new_level);
  4261. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4262. GetPlayer()->SetCharSheetChanged(true);
  4263. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4264. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4265. PlayerSkillList* player_skills = player->GetSkills();
  4266. int16 specialize_skill_cap = new_level * 5;
  4267. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4268. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4269. int8 ts_class = player->GetTradeskillClass();
  4270. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4271. int32 skill_id_1, skill_id_2, skill_id_3;
  4272. switch (base_ts_class) {
  4273. case ARTISAN:
  4274. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4275. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4276. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4277. break;
  4278. case OUTFITTER:
  4279. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4280. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4281. skill_id_1 = SKILL_ID_TAILORING;
  4282. skill_id_2 = SKILL_ID_METALSHAPING;
  4283. skill_id_3 = SKILL_ID_METALWORKING;
  4284. if (ts_class == TAILOR) {
  4285. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4286. skill_id_1 = 0;
  4287. }
  4288. else if (ts_class == ARMORER) {
  4289. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4290. skill_id_2 = 0;
  4291. }
  4292. else if (ts_class == WEAPONSMITH) {
  4293. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4294. skill_id_3 = 0;
  4295. }
  4296. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4297. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4298. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4299. break;
  4300. case SCHOLAR:
  4301. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4302. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4303. skill_id_1 = SKILL_ID_SCRIBING;
  4304. skill_id_2 = SKILL_ID_CHEMISTRY;
  4305. skill_id_3 = SKILL_ID_ARTIFICING;
  4306. if (ts_class == SAGE) {
  4307. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4308. skill_id_1 = 0;
  4309. }
  4310. else if (ts_class == ALCHEMIST) {
  4311. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4312. skill_id_2 = 0;
  4313. }
  4314. else if (ts_class == JEWELER) {
  4315. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4316. skill_id_3 = 0;
  4317. }
  4318. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4319. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4320. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4321. break;
  4322. case CRAFTSMAN:
  4323. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4324. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4325. skill_id_1 = SKILL_ID_ARTISTRY;
  4326. skill_id_2 = SKILL_ID_FLETCHING;
  4327. skill_id_3 = SKILL_ID_SCULPTING;
  4328. if (ts_class == PROVISIONER) {
  4329. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4330. skill_id_1 = 0;
  4331. }
  4332. else if (ts_class == WOODWORKER) {
  4333. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4334. skill_id_2 = 0;
  4335. }
  4336. else if (ts_class == CARPENTER) {
  4337. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4338. skill_id_3 = 0;
  4339. }
  4340. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4341. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4342. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4343. break;
  4344. default:
  4345. break;
  4346. }
  4347. if (new_level > player->GetAdventureClass())
  4348. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4349. Guild* guild = GetPlayer()->GetGuild();
  4350. if (guild) {
  4351. int8 event_type = 0;
  4352. if (new_level < 10)
  4353. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4354. else if (new_level == 10)
  4355. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4356. else if (new_level >= 11 && new_level < 20)
  4357. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4358. else if (new_level == 20)
  4359. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4360. else if (new_level >= 21 && new_level < 30)
  4361. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4362. else if (new_level == 30)
  4363. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4364. else if (new_level >= 31 && new_level < 40)
  4365. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4366. else if (new_level == 40)
  4367. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4368. else if (new_level >= 41 && new_level < 50)
  4369. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4370. else if (new_level == 50)
  4371. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4372. else if (new_level >= 51 && new_level < 60)
  4373. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4374. else if (new_level == 60)
  4375. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4376. else if (new_level >= 61 && new_level < 70)
  4377. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4378. else if (new_level == 70)
  4379. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4380. else if (new_level >= 71 && new_level < 80)
  4381. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4382. else if (new_level == 80)
  4383. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4384. 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());
  4385. 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());
  4386. guild->UpdateGuildMemberInfo(GetPlayer());
  4387. guild->SendGuildMember(GetPlayer());
  4388. guild->SendGuildMemberList();
  4389. }
  4390. // Need to send the trait list every time the players level changes
  4391. // Also need to force the char sheet update or else there can be a large delay from when you level
  4392. // to when you are actually able to select traits.
  4393. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4394. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4395. }
  4396. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4397. if (entity)
  4398. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4399. }
  4400. void Client::CloseLoot(int32 spawn_id) {
  4401. if (GetVersion() > 546) {
  4402. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4403. if (packet) {
  4404. packet->setDataByName("window_id", 4);
  4405. EQ2Packet* outapp = packet->serialize();
  4406. if (outapp) {
  4407. //DumpPacket(outapp);
  4408. QueuePacket(outapp);
  4409. }
  4410. safe_delete(packet);
  4411. }
  4412. }
  4413. else if(spawn_id > 0){
  4414. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4415. if (packet) {
  4416. packet->setDataByName("spawn_id", spawn_id);
  4417. EQ2Packet* outapp = packet->serialize();
  4418. if (outapp)
  4419. QueuePacket(outapp);
  4420. safe_delete(packet);
  4421. }
  4422. }
  4423. }
  4424. string Client::GetCoinMessage(int32 total_coins) {
  4425. if (total_coins == 0) {
  4426. return " 0 Copper";
  4427. }
  4428. char tmp[64] = { 0 };
  4429. string message = "";
  4430. int32 val = 0;
  4431. if (total_coins >= 1000000) {
  4432. val = total_coins / 1000000;
  4433. total_coins -= 1000000 * val;
  4434. sprintf(tmp, " %u Platinum", val);
  4435. message.append(tmp);
  4436. memset(tmp, 0, 64);
  4437. }
  4438. if (total_coins >= 10000) {
  4439. val = total_coins / 10000;
  4440. total_coins -= 10000 * val;
  4441. sprintf(tmp, " %u Gold", val);
  4442. message.append(tmp);
  4443. memset(tmp, 0, 64);
  4444. }
  4445. if (total_coins >= 100) {
  4446. val = total_coins / 100;
  4447. total_coins -= 100 * val;
  4448. sprintf(tmp, " %u Silver", val);
  4449. message.append(tmp);
  4450. memset(tmp, 0, 64);
  4451. }
  4452. if (total_coins > 0) {
  4453. sprintf(tmp, " %u Copper", (int32)total_coins);
  4454. message.append(tmp);
  4455. }
  4456. return message;
  4457. }
  4458. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4459. if (!entity) {
  4460. CloseLoot(0);
  4461. return;
  4462. }
  4463. if (total_coins > 0) {
  4464. player->AddCoins(total_coins);
  4465. //PlaySound("coin_cha_ching");
  4466. string message = "";
  4467. if (entity->GetHP() == 0) {
  4468. message = "You loot ";
  4469. entity->SetLootCoins(0);
  4470. }
  4471. else
  4472. message = "You receive ";
  4473. message.append(GetCoinMessage(total_coins));
  4474. if (entity->GetHP() == 0)
  4475. message.append(" from the corpse of ").append(entity->GetName());
  4476. int8 type = CHANNEL_LOOT;
  4477. SimpleMessage(type, message.c_str());
  4478. }
  4479. if (!items || items->size() == 0)
  4480. CloseLoot(entity->GetID());
  4481. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4482. if (packet) {
  4483. vector<Item*>::iterator itr;
  4484. int32 packet_size = 0;
  4485. EQ2Packet* outapp = 0;
  4486. uchar* data = 0;
  4487. if (GetVersion() >= 284) {
  4488. if (GetVersion() > 546) {
  4489. if (items && items->size() > 0) {
  4490. packet->setDataByName("loot_count", items->size());
  4491. packet->setDataByName("display", 1);
  4492. }
  4493. packet->setDataByName("loot_type", 1);
  4494. if (version >= 1096)
  4495. packet->setDataByName("lotto_timeout", 0x78);
  4496. else
  4497. packet->setDataByName("lotto_timeout", 0x3C);
  4498. packet->setDataByName("loot_id", entity->GetID());
  4499. EQ2Packet* tmpPacket = packet->serialize();
  4500. packet_size += tmpPacket->size;
  4501. if (items && items->size() > 0) {
  4502. data = new uchar[items->size() * 1000 + packet_size];
  4503. memset(data, 0, items->size() * 1000 + packet_size);
  4504. }
  4505. else {
  4506. data = new uchar[packet_size];
  4507. memset(data, 0, packet_size);
  4508. }
  4509. uchar* ptr = data;
  4510. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4511. ptr += tmpPacket->size;
  4512. safe_delete(tmpPacket);
  4513. Item* item = 0;
  4514. if (items && items->size() > 0) {
  4515. for (itr = items->begin(); itr != items->end(); itr++) {
  4516. item = *itr;
  4517. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4518. ptr += sizeof(int32);
  4519. packet_size += sizeof(int32);
  4520. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4521. int8 offset = 0;
  4522. if (GetVersion() >= 1188) {
  4523. offset = 13;
  4524. }
  4525. else if (GetVersion() >= 860) {
  4526. offset = 11;
  4527. }
  4528. else if (GetVersion() <= 546) {
  4529. offset = 19;
  4530. }
  4531. else {
  4532. offset = 10;
  4533. }
  4534. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4535. ptr += tmpPacket->size - offset;
  4536. packet_size += tmpPacket->size - offset;
  4537. safe_delete(tmpPacket);
  4538. }
  4539. }
  4540. packet_size -= sizeof(int32);
  4541. memcpy(data, &packet_size, sizeof(int32));
  4542. packet_size += sizeof(int32);
  4543. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4544. }
  4545. else {
  4546. if (items && items->size() > 0) {
  4547. packet->setArrayLengthByName("loot_count", items->size());
  4548. Item* item = 0;
  4549. if (items && items->size() > 0) {
  4550. int i = 0;
  4551. for (itr = items->begin(); itr != items->end(); itr++) {
  4552. item = *itr;
  4553. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4554. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4555. i++;
  4556. }
  4557. }
  4558. packet->setDataByName("display", 1);
  4559. }
  4560. packet->setDataByName("loot_type", 1); // normal
  4561. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4562. packet->setDataByName("spawn_id", entity->GetID());
  4563. outapp = packet->serialize();
  4564. }
  4565. }
  4566. else {
  4567. if (items && items->size() > 0) {
  4568. packet->setArrayLengthByName("loot_count", items->size());
  4569. for (int i = 0; i < items->size(); i++) {
  4570. Item* item = (*items)[i];
  4571. packet->setArrayDataByName("name", item->name.c_str(), i);
  4572. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4573. packet->setArrayDataByName("count", item->details.count, i);
  4574. packet->setArrayDataByName("icon", item->details.icon, i);
  4575. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4576. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4577. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4578. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4579. else
  4580. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4581. }
  4582. }
  4583. packet->setDataByName("object_id", entity->GetID());
  4584. packet->setDataByName("unknown3", 1);
  4585. packet->setDataByName("unknown4", 1);
  4586. packet->setDataByName("unknown5", 60);
  4587. outapp = packet->serialize();
  4588. }
  4589. if (outapp) {
  4590. QueuePacket(outapp);
  4591. }
  4592. safe_delete_array(data);
  4593. safe_delete(packet);
  4594. }
  4595. }
  4596. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4597. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4598. int32 total_coins = entity->GetLootCoins();
  4599. entity->LockLoot();
  4600. Loot(total_coins, entity->GetLootItems(), entity);
  4601. entity->UnlockLoot();
  4602. OpenChest(entity, attemptDisarm);
  4603. }
  4604. else
  4605. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4606. }
  4607. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4608. {
  4609. if (!entity)
  4610. return;
  4611. int8 chest_difficulty = 0;
  4612. int32 state = 0;
  4613. // Check for the chest and set the action state
  4614. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4615. string modelName;
  4616. if (entity->GetModelType() == 4034) {
  4617. // small chest, open with copper coins
  4618. // does not include traps, however can be disarmed
  4619. chest_difficulty = 1;
  4620. state = 11899;
  4621. modelName.append("Small Chest");
  4622. }
  4623. else if (entity->GetModelType() == 5864) {
  4624. // treasure chest, open with silver coins
  4625. chest_difficulty = 2;
  4626. state = 11901;
  4627. modelName.append("Treasure Chest");
  4628. }
  4629. else if (entity->GetModelType() == 5865) {
  4630. // ornate chest, open with gold coins
  4631. chest_difficulty = 3;
  4632. state = 11900;
  4633. modelName.append("Ornate Chest");
  4634. }
  4635. else if (entity->GetModelType() == 4015) {
  4636. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4637. chest_difficulty = 5;
  4638. state = 11898;
  4639. modelName.append("Exquisite Chest");
  4640. }
  4641. bool firstChestOpen = false;
  4642. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4643. {
  4644. ChestTrap::ChestTrapInfo nextTrap;
  4645. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4646. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4647. firstChestOpen = true;
  4648. entity->SetTrapTriggered(true, state);
  4649. if (ret)
  4650. {
  4651. if (disarmSkill && attemptDisarm)
  4652. {
  4653. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4654. {
  4655. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4656. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4657. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4658. }
  4659. else
  4660. {
  4661. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4662. }
  4663. // despite fail/succeed we should always try to increase skill if disarm is available
  4664. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4665. }
  4666. else // no disarm skill, always fail
  4667. {
  4668. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4669. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4670. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4671. }
  4672. }
  4673. }
  4674. else if (!entity->HasTrapTriggered())
  4675. {
  4676. firstChestOpen = true;
  4677. entity->SetTrapTriggered(true, state);
  4678. }
  4679. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4680. // for those in range the SendStateCommand will cause it to animate open.
  4681. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4682. if (firstChestOpen)
  4683. GetCurrentZone()->SendStateCommand(entity, state);
  4684. }
  4685. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4686. {
  4687. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4688. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4689. if (source == NULL)
  4690. source = (Entity*)GetPlayer();
  4691. if (spell)
  4692. {
  4693. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4694. if (gmi && gmi->group_id)
  4695. {
  4696. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4697. if (group)
  4698. {
  4699. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4700. deque<GroupMemberInfo*>* members = group->GetMembers();
  4701. for (int8 i = 0; i < members->size(); i++) {
  4702. Entity* member = members->at(i)->member;
  4703. if(!member)
  4704. continue;
  4705. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4706. continue;
  4707. // if we have a radius provided then check if the group member is outside the radius or not
  4708. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4709. continue;
  4710. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4711. }
  4712. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4713. }
  4714. }
  4715. else
  4716. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4717. }
  4718. }
  4719. Spawn* Client::GetBanker() {
  4720. return banker;
  4721. }
  4722. void Client::SetBanker(Spawn* in_banker) {
  4723. banker = in_banker;
  4724. }
  4725. void Client::Bank(Spawn* banker, bool cancel) {
  4726. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4727. if (!cancel)
  4728. SetBanker(banker);
  4729. else
  4730. SetBanker(0);
  4731. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4732. if (packet) {
  4733. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4734. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4735. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4736. int32 coins1, coins2;
  4737. coins1 = ((int32*)&coins)[0];
  4738. coins2 = ((int32*)&coins)[1];
  4739. packet->setDataByName("bank_coins", coins1);
  4740. packet->setDataByName("bank_coins2", coins2);
  4741. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4742. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4743. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4744. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4745. if (!cancel)
  4746. packet->setDataByName("display", 1);
  4747. QueuePacket(packet->serialize());
  4748. safe_delete(packet);
  4749. }
  4750. }
  4751. }
  4752. void Client::BankWithdrawal(int64 amount) {
  4753. bool cheater = false;
  4754. if (GetBanker() && amount > 0) {
  4755. string withdrawal = "";
  4756. char withdrawal_data[512] = { 0 };
  4757. int32 tmp = 0;
  4758. if (amount >= 1000000) {
  4759. tmp = amount / 1000000;
  4760. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4761. if (tmp > bank_coins_plat)
  4762. cheater = true;
  4763. else {
  4764. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4765. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4766. amount -= (int64)tmp * 1000000;
  4767. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4768. withdrawal.append(withdrawal_data);
  4769. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4770. }
  4771. }
  4772. if (!cheater && amount >= 10000) {
  4773. tmp = amount / 10000;
  4774. if (tmp > GetPlayer()->GetBankCoinsGold())
  4775. cheater = true;
  4776. else {
  4777. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4778. bank_coins_gold -= tmp;
  4779. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4780. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4781. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4782. }
  4783. else
  4784. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4785. amount -= tmp * 10000;
  4786. sprintf(withdrawal_data, "%u Gold ", tmp);
  4787. withdrawal.append(withdrawal_data);
  4788. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4789. }
  4790. }
  4791. if (!cheater && amount >= 100) {
  4792. tmp = amount / 100;
  4793. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4794. if (tmp > bank_coins_silver)
  4795. cheater = true;
  4796. else {
  4797. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4798. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4799. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4800. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4801. }
  4802. else
  4803. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4804. amount -= tmp * 100;
  4805. sprintf(withdrawal_data, "%u Silver ", tmp);
  4806. withdrawal.append(withdrawal_data);
  4807. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4808. }
  4809. }
  4810. if (!cheater) {
  4811. if (amount > 0) {
  4812. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4813. withdrawal.append(withdrawal_data);
  4814. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4815. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4816. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4817. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4818. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4819. }
  4820. else
  4821. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4822. }
  4823. if (withdrawal.length() > 0) {
  4824. withdrawal.append("withdrawn ");
  4825. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4826. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4827. withdrawal.append(withdrawal_data);
  4828. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4829. }
  4830. }
  4831. else
  4832. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4833. player->SetCharSheetChanged(true);
  4834. Bank(banker);
  4835. }
  4836. }
  4837. void Client::BankDeposit(int64 amount) {
  4838. bool cheater = false;
  4839. if (GetBanker() && amount > 0) {
  4840. int32 tmp = 0;
  4841. char deposit_data[512] = { 0 };
  4842. string deposit = "";
  4843. if (amount >= 1000000) {
  4844. tmp = amount / 1000000;
  4845. if (tmp > GetPlayer()->GetCoinsPlat())
  4846. cheater = true;
  4847. else {
  4848. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4849. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4850. amount -= (int64)tmp * 1000000;
  4851. sprintf(deposit_data, "%u Platinum ", tmp);
  4852. deposit.append(deposit_data);
  4853. memset(deposit_data, 0, sizeof(deposit_data));
  4854. }
  4855. }
  4856. if (!cheater && amount >= 10000) {
  4857. tmp = amount / 10000;
  4858. if (tmp > GetPlayer()->GetCoinsGold())
  4859. cheater = true;
  4860. else {
  4861. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4862. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4863. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4864. }
  4865. else
  4866. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4867. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4868. amount -= tmp * 10000;
  4869. sprintf(deposit_data, "%u Gold ", tmp);
  4870. deposit.append(deposit_data);
  4871. memset(deposit_data, 0, sizeof(deposit_data));
  4872. }
  4873. }
  4874. if (!cheater && amount >= 100) {
  4875. tmp = amount / 100;
  4876. if (tmp > GetPlayer()->GetCoinsSilver())
  4877. cheater = true;
  4878. else {
  4879. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4880. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4881. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4882. }
  4883. else
  4884. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4885. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4886. amount -= tmp * 100;
  4887. sprintf(deposit_data, "%u Silver ", tmp);
  4888. deposit.append(deposit_data);
  4889. memset(deposit_data, 0, sizeof(deposit_data));
  4890. }
  4891. }
  4892. if (!cheater) {
  4893. if (amount > 0) {
  4894. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4895. deposit.append(deposit_data);
  4896. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4897. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4898. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4899. }
  4900. else
  4901. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4902. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4903. }
  4904. if (deposit.length() > 0) {
  4905. deposit.append("deposited ");
  4906. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4907. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4908. deposit.append(deposit_data);
  4909. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4910. }
  4911. }
  4912. else
  4913. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4914. player->SetCharSheetChanged(true);
  4915. Bank(banker);
  4916. }
  4917. }
  4918. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4919. {
  4920. MPendingQuestAccept.lock();
  4921. pending_quest_accept.push_back(quest->GetQuestID());
  4922. MPendingQuestAccept.unlock();
  4923. }
  4924. void Client::AddPendingQuestReward(Quest* quest, bool update, bool is_temporary, std::string description) {
  4925. QueueQuestReward(quest->GetQuestID(), is_temporary, false, false, (is_temporary ? quest->GetCoinTmpReward() : 0),
  4926. (is_temporary ? quest->GetStatusTmpReward() : 0), description, false, 0);
  4927. quest_updates = update;
  4928. if(quest_updates) {
  4929. SaveQuestRewardData(true);
  4930. }
  4931. }
  4932. 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) {
  4933. if(HasQuestRewardQueued(quest_id, is_temporary, is_collection))
  4934. return;
  4935. QuestRewardData* data = new QuestRewardData;
  4936. data->quest_id = quest_id;
  4937. data->is_temporary = is_temporary;
  4938. data->is_collection = is_collection;
  4939. data->has_displayed = has_displayed;
  4940. data->tmp_coin = tmp_coin;
  4941. data->tmp_status = tmp_status;
  4942. data->description = std::string(description);
  4943. data->db_saved = db_saved;
  4944. data->db_index = index;
  4945. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4946. quest_pending_reward.push_back(data);
  4947. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4948. }
  4949. bool Client::HasQuestRewardQueued(int32 quest_id, bool is_temporary, bool is_collection) {
  4950. bool success = false;
  4951. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  4952. if (quest_pending_reward.size() > 0) {
  4953. vector<QuestRewardData*>::iterator itr;
  4954. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  4955. int32 questID = (*itr)->quest_id;
  4956. bool temporary = (*itr)->is_temporary;
  4957. bool collection = (*itr)->is_collection;
  4958. if( questID == quest_id && is_temporary == temporary && is_collection == collection ) {
  4959. success = true;
  4960. break;
  4961. }
  4962. }
  4963. }
  4964. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  4965. return success;
  4966. }
  4967. void Client::RemoveQueuedQuestReward() {
  4968. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4969. if(quest_pending_reward.size() > 0) {
  4970. QuestRewardData* data = quest_pending_reward.at(0);
  4971. if(data->db_saved) {
  4972. Query query;
  4973. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_rewards where char_id = %u and indexed = %u", GetCharacterID(), data->db_index);
  4974. if(data->is_temporary && data->quest_id) {
  4975. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete FROM character_quest_temporary_rewards where char_id = %u and quest_id = %u", GetCharacterID(), data->quest_id);
  4976. }
  4977. }
  4978. quest_pending_reward.erase(quest_pending_reward.begin());
  4979. }
  4980. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4981. SaveQuestRewardData(true);
  4982. }
  4983. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4984. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4985. quest_pending_updates[quest_id][step_id] = progress;
  4986. quest_updates = true;
  4987. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4988. }
  4989. void Client::ProcessQuestUpdates() {
  4990. if(!GetPlayer()->IsFullyLoggedIn())
  4991. return;
  4992. if (quest_pending_updates.size() > 0) {
  4993. map<int32, map<int32, int32> > tmp_quest_updates;
  4994. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4995. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4996. quest_pending_updates.clear();
  4997. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4998. map<int32, map<int32, int32> >::iterator quest_itr;
  4999. map<int32, int32>::iterator step_itr;
  5000. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  5001. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  5002. if (step_itr->second == 0xFFFFFFFF) {
  5003. SetStepComplete(quest_itr->first, step_itr->first);
  5004. player->SendQuestRequiredSpawns(quest_itr->first);
  5005. }
  5006. else
  5007. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  5008. }
  5009. }
  5010. }
  5011. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5012. if (quest_pending_reward.size() > 0) {
  5013. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5014. // only able to display one reward at a time
  5015. if(GetPlayer()->IsActiveReward())
  5016. return;
  5017. Query query;
  5018. vector<QuestRewardData*>::iterator itr;
  5019. vector<QuestRewardData*> tmp_quest_rewards;
  5020. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  5021. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.begin()+1);
  5022. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  5023. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  5024. int32 questID = (*itr)->quest_id;
  5025. Quest* quest = 0;
  5026. if((*itr)->is_collection && GetPlayer()->GetPendingCollectionReward()) {
  5027. DisplayCollectionComplete(GetPlayer()->GetPendingCollectionReward());
  5028. GetPlayer()->SetActiveReward(true);
  5029. (*itr)->has_displayed = true;
  5030. UpdateCharacterRewardData((*itr));
  5031. }
  5032. else if(questID > 0 && (quest = GetPlayer()->GetAnyQuest(questID))) {
  5033. quest->SetQuestTemporaryState((*itr)->is_temporary, (*itr)->description);
  5034. if((*itr)->is_temporary) {
  5035. quest->SetStatusTmpReward((*itr)->tmp_status);
  5036. quest->SetCoinTmpReward((*itr)->tmp_coin);
  5037. }
  5038. GiveQuestReward(quest, (*itr)->has_displayed);
  5039. GetPlayer()->SetActiveReward(true);
  5040. (*itr)->has_displayed = true;
  5041. UpdateCharacterRewardData((*itr));
  5042. // only able to display one reward at a time
  5043. break;
  5044. } else {
  5045. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, skipping quest id from tmp_quest_rewards.", questID, GetPlayer()->GetName());
  5046. }
  5047. }
  5048. } else {
  5049. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5050. }
  5051. MQuestPendingUpdates.readlock(__FUNCTION__, __LINE__);
  5052. if (quest_pending_reward.size() > 0) {
  5053. quest_updates = true;
  5054. }
  5055. else {
  5056. quest_updates = false;
  5057. }
  5058. MQuestPendingUpdates.releasereadlock(__FUNCTION__, __LINE__);
  5059. }
  5060. void Client::CheckQuestQueue() {
  5061. MQuestQueue.writelock();
  5062. last_update_time = 0;
  5063. vector<QueuedQuest*>::iterator itr;
  5064. QueuedQuest* queued_quest = 0;
  5065. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  5066. queued_quest = *itr;
  5067. Quest* quest = GetPlayer()->GetAnyQuest(queued_quest->quest_id);
  5068. if(quest) {
  5069. SendQuestUpdateStepImmediately(quest, queued_quest->step, queued_quest->display_quest_helper);
  5070. if(quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  5071. SendQuestJournal();
  5072. }
  5073. else {
  5074. LogWrite(CCLIENT__ERROR, 0, "Client", "Queued Quest ID %u missing for Player %s, cannot send quest step update.", queued_quest->quest_id, GetPlayer()->GetName());
  5075. }
  5076. safe_delete(queued_quest);
  5077. }
  5078. quest_queue.clear();
  5079. MQuestQueue.releasewritelock();
  5080. }
  5081. void Client::SetStepComplete(int32 quest_id, int32 step) {
  5082. Quest* quest = player->SetStepComplete(quest_id, step);
  5083. if (quest) {
  5084. SendQuestUpdate(quest);
  5085. GetCurrentZone()->SendQuestUpdates(this);
  5086. }
  5087. }
  5088. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  5089. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  5090. if (quest) {
  5091. SendQuestUpdate(quest);
  5092. GetCurrentZone()->SendQuestUpdates(this);
  5093. }
  5094. }
  5095. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  5096. bool hadUpdates = false;
  5097. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  5098. if (quest_updates) {
  5099. for (int32 i = 0; i < quest_updates->size(); i++)
  5100. {
  5101. SendQuestUpdate(quest_updates->at(i));
  5102. hadUpdates = true;
  5103. }
  5104. }
  5105. safe_delete(quest_updates);
  5106. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5107. if (quest_failures) {
  5108. for (int32 i = 0; i < quest_failures->size(); i++)
  5109. {
  5110. SendQuestFailure(quest_failures->at(i));
  5111. hadUpdates = true;
  5112. }
  5113. }
  5114. safe_delete(quest_failures);
  5115. if (hadUpdates)
  5116. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5117. }
  5118. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  5119. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  5120. if (quest_updates) {
  5121. for (int32 i = 0; i < quest_updates->size(); i++)
  5122. SendQuestUpdate(quest_updates->at(i));
  5123. GetCurrentZone()->SendQuestUpdates(this);
  5124. }
  5125. safe_delete(quest_updates);
  5126. }
  5127. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  5128. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  5129. if (quest_updates) {
  5130. for (int32 i = 0; i < quest_updates->size(); i++)
  5131. SendQuestUpdate(quest_updates->at(i));
  5132. }
  5133. safe_delete(quest_updates);
  5134. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5135. if (quest_failures) {
  5136. for (int32 i = 0; i < quest_failures->size(); i++)
  5137. SendQuestFailure(quest_failures->at(i));
  5138. }
  5139. safe_delete(quest_failures);
  5140. }
  5141. void Client::CheckPlayerQuestsLocationUpdate() {
  5142. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  5143. if (quest_updates) {
  5144. for (int32 i = 0; i < quest_updates->size(); i++)
  5145. SendQuestUpdate(quest_updates->at(i));
  5146. }
  5147. safe_delete(quest_updates);
  5148. }
  5149. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  5150. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  5151. if (quest_updates) {
  5152. for (int32 i = 0; i < quest_updates->size(); i++)
  5153. SendQuestUpdate(quest_updates->at(i));
  5154. }
  5155. safe_delete(quest_updates);
  5156. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  5157. if (quest_failures) {
  5158. for (int32 i = 0; i < quest_failures->size(); i++)
  5159. SendQuestFailure(quest_failures->at(i));
  5160. }
  5161. safe_delete(quest_failures);
  5162. }
  5163. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5164. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5165. player->pending_quests[quest->GetQuestID()] = quest;
  5166. AcceptQuest(quest->GetQuestID());
  5167. }
  5168. else {
  5169. player->pending_quests[quest->GetQuestID()] = quest;
  5170. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5171. //DumpPacket(outapp);
  5172. QueuePacket(outapp);
  5173. }
  5174. }
  5175. Quest* Client::GetActiveQuest(int32 quest_id) {
  5176. Quest* quest = 0;
  5177. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  5178. if (player->player_quests.count(quest_id) > 0) {
  5179. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  5180. quest = player->player_quests[quest_id];
  5181. }
  5182. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  5183. return quest;
  5184. }
  5185. void Client::AcceptQuest(int32 id) {
  5186. Quest* quest = GetPendingQuest(id);
  5187. if (quest) {
  5188. RemovePendingQuest(quest);
  5189. AddPlayerQuest(quest);
  5190. GetCurrentZone()->SendQuestUpdates(this);
  5191. // If character has already completed this quest once update the given date in the database
  5192. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  5193. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  5194. if (quest2)
  5195. quest->SetCompleteCount(quest2->GetCompleteCount());
  5196. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  5197. }
  5198. }
  5199. }
  5200. Quest* Client::GetPendingQuest(int32 id) {
  5201. if (player->pending_quests.count(id) > 0) {
  5202. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  5203. return player->pending_quests[id];
  5204. }
  5205. return 0;
  5206. }
  5207. void Client::RemovePendingQuest(Quest* quest) {
  5208. player->pending_quests.erase(quest->GetQuestID());
  5209. }
  5210. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5211. if (!quest || !progress) {
  5212. return;
  5213. }
  5214. map<int32, int32>::iterator itr;
  5215. QuestStep* step = 0;
  5216. player->SetZone(GetCurrentZone(), GetVersion());
  5217. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5218. step = quest->GetQuestStep(itr->first);
  5219. if (step && itr->second > 0) {
  5220. step->SetStepProgress(itr->second);
  5221. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5222. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5223. }
  5224. }
  5225. if (lua_interface && step)
  5226. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5227. else if(!step) {
  5228. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5229. }
  5230. }
  5231. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5232. bool lockCleared = false;
  5233. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5234. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5235. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5236. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5237. int32 questID = quest->GetQuestID();
  5238. lockCleared = true;
  5239. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5240. RemovePlayerQuest(questID, false, false);
  5241. }
  5242. player->player_quests[quest->GetQuestID()] = quest;
  5243. if(!lockCleared)
  5244. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5245. quest->SetPlayer(player);
  5246. current_quest_id = quest->GetQuestID();
  5247. if (send_packets && quest->GetQuestGiver() > 0)
  5248. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5249. if (lua_interface && call_accepted)
  5250. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5251. if (send_packets) {
  5252. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5253. //SendQuestJournal();
  5254. SendQuestJournalUpdate(quest);
  5255. // sent twice to match live
  5256. quest->SetTracked(false);
  5257. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5258. quest->SetTracked(true);
  5259. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5260. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5261. }
  5262. //This isn't during a load screen, so update spawns with required quests
  5263. if (call_accepted)
  5264. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5265. }
  5266. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5267. if (current_quest_id == id)
  5268. current_quest_id = 0;
  5269. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5270. if (player->player_quests.count(id) > 0) {
  5271. if (delete_quest) {
  5272. player->player_quests[id]->SetDeleted(true);
  5273. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5274. }
  5275. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5276. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5277. if (send_update && quest_giver > 0)
  5278. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5279. if (send_update) {
  5280. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5281. SendQuestJournal(false, 0, true);
  5282. }
  5283. player->RemoveQuest(id, delete_quest);
  5284. if (send_update) {
  5285. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5286. SendQuestJournal(false, 0, true);
  5287. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5288. }
  5289. }
  5290. else {
  5291. // if we don't have any quests to count then release the write lock
  5292. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5293. }
  5294. }
  5295. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5296. if (quest) {
  5297. QuestStep* quest_step = quest->GetQuestStep(step);
  5298. if (quest_step) {
  5299. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5300. quest_step->WasUpdated(false);
  5301. }
  5302. }
  5303. }
  5304. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5305. QueuedQuest* item = new QueuedQuest;
  5306. item->quest_id = quest->GetQuestID();
  5307. item->step = step;
  5308. item->display_quest_helper = display_quest_helper;
  5309. MQuestQueue.writelock();
  5310. quest_queue.push_back(item);
  5311. last_update_time = Timer::GetCurrentTime2();
  5312. MQuestQueue.releasewritelock();
  5313. }
  5314. void Client::SendQuestFailure(Quest* quest) {
  5315. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5316. if (failures) {
  5317. QuestStep* step = 0;
  5318. for (int32 i = 0; i < failures->size(); i++) {
  5319. step = failures->at(i);
  5320. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5321. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5322. SendQuestJournal(false, 0, true);
  5323. }
  5324. failures->clear();
  5325. }
  5326. }
  5327. void Client::SendQuestUpdate(Quest* quest) {
  5328. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5329. if (updates) {
  5330. QuestStep* step = 0;
  5331. bool updated = false;
  5332. for (int32 i = 0; i < updates->size(); i++) {
  5333. step = updates->at(i);
  5334. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5335. {
  5336. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5337. SendQuestUpdateStep(quest, step->GetStepID());
  5338. updated = true;
  5339. }
  5340. if (step->WasUpdated()) {
  5341. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5342. SendQuestJournal(false, 0, true);
  5343. if(!updated)
  5344. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5345. updated = true;
  5346. }
  5347. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5348. }
  5349. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5350. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5351. SendQuestJournalUpdate(quest, true);
  5352. }
  5353. if (quest->GetCompleted()) {
  5354. if (quest->GetQuestReturnNPC() > 0)
  5355. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5356. if (quest->GetCompletedFlag())
  5357. quest->SetCompletedFlag(false);
  5358. }
  5359. updates->clear();
  5360. }
  5361. }
  5362. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5363. if (!client)
  5364. client = this;
  5365. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5366. if (packet) {
  5367. EQ2Packet* outapp = packet->serialize();
  5368. //DumpPacket(outapp);
  5369. client->QueuePacket(outapp);
  5370. safe_delete(packet);
  5371. }
  5372. }
  5373. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5374. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5375. if (packet) {
  5376. QueuePacket(packet->serialize());
  5377. safe_delete(packet);
  5378. }
  5379. }
  5380. void Client::ReloadQuests() {
  5381. vector<int32> ids = player->GetQuestIDs();
  5382. Quest* quest = 0;
  5383. for (int32 i = 0; i < ids.size(); i++) {
  5384. quest = master_quest_list.GetQuest(ids[i]);
  5385. if (quest)
  5386. AddPlayerQuest(quest, false);
  5387. else
  5388. RemovePlayerQuest(ids[i]);
  5389. }
  5390. }
  5391. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5392. bool found_quest = false;
  5393. vector<int32>::iterator itr;
  5394. vector<Item*>* items = 0;
  5395. int32 questID = 0;
  5396. Quest* quest = 0;
  5397. MPendingQuestAccept.lock();
  5398. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  5399. questID = *itr;
  5400. quest = GetPlayer()->GetAnyQuest(questID);
  5401. if(!quest) {
  5402. LogWrite(CCLIENT__ERROR, 0, "Client", "Quest ID %u missing for Player %s, removing quest id from pending_quest_accept.", questID, GetPlayer()->GetName());
  5403. pending_quest_accept.erase(itr);
  5404. continue;
  5405. }
  5406. if(quest->GetQuestTemporaryState())
  5407. items = quest->GetTmpRewardItems();
  5408. else
  5409. items = quest->GetRewardItems();
  5410. if (item_id == 0) {
  5411. found_quest = true;
  5412. }
  5413. else {
  5414. items = quest->GetSelectableRewardItems();
  5415. if (items && items->size() > 0) {
  5416. for (int32 i = 0; i < items->size(); i++) {
  5417. if (items->at(i)->details.item_id == item_id) {
  5418. found_quest = true;
  5419. break;
  5420. }
  5421. }
  5422. }
  5423. }
  5424. if (found_quest) {
  5425. pending_quest_accept.erase(itr);
  5426. break;
  5427. }
  5428. }
  5429. MPendingQuestAccept.unlock();
  5430. if (found_quest)
  5431. return quest;
  5432. return 0;
  5433. }
  5434. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5435. int8 num_slots_needed = 0;
  5436. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5437. Item* master_item = 0;
  5438. if (item_id > 0) {
  5439. num_slots_needed++;
  5440. master_item = master_item_list.GetItem(item_id);
  5441. }
  5442. int32 totalItems = 0;
  5443. vector<Item*>* items = 0;
  5444. vector<Item*>* tmpItems = 0;
  5445. bool isTempState = quest->GetQuestTemporaryState();
  5446. if(isTempState)
  5447. {
  5448. tmpItems = quest->GetTmpRewardItems();
  5449. if (tmpItems && tmpItems->size() > 0)
  5450. {
  5451. num_slots_needed += tmpItems->size();
  5452. totalItems += tmpItems->size();
  5453. }
  5454. }
  5455. else
  5456. {
  5457. items = quest->GetRewardItems();
  5458. if (items && items->size() > 0)
  5459. {
  5460. num_slots_needed += items->size();
  5461. totalItems += items->size();
  5462. }
  5463. }
  5464. RemoveQueuedQuestReward();
  5465. GetPlayer()->SetActiveReward(false);
  5466. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5467. if (master_item)
  5468. AddItem(item_id);
  5469. if (tmpItems && tmpItems->size() > 0) {
  5470. for (int32 i = 0; i < tmpItems->size(); i++)
  5471. AddItem(new Item(tmpItems->at(i)));
  5472. }
  5473. if (items && items->size() > 0) {
  5474. for (int32 i = 0; i < items->size(); i++)
  5475. AddItem(new Item(items->at(i)));
  5476. }
  5477. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5478. if (outapp)
  5479. QueuePacket(outapp);
  5480. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5481. map<int32, sint32>::iterator itr;
  5482. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5483. int32 faction_id = itr->first;
  5484. sint32 amount = itr->second;
  5485. if (amount > 0)
  5486. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5487. else
  5488. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5489. }
  5490. if(quest->GetQuestTemporaryState())
  5491. {
  5492. int64 total_coins = quest->GetCoinTmpReward();
  5493. if (total_coins > 0)
  5494. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5495. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5496. }
  5497. else {
  5498. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5499. }
  5500. quest->SetQuestTemporaryState(false);
  5501. player->SetCharSheetChanged(true);
  5502. }
  5503. else {
  5504. GetPlayer()->SetActiveReward(true);
  5505. AddPendingQuestAcceptReward(quest);
  5506. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5507. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5508. }
  5509. }
  5510. 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) {
  5511. 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))) {
  5512. /*if (quest)
  5513. text = quest->GetName();
  5514. else*/
  5515. return;//nothing to give
  5516. }
  5517. GetPlayer()->ClearPendingSelectableItemRewards(0, true);
  5518. GetPlayer()->ClearPendingItemRewards();
  5519. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5520. if (packet2) {
  5521. int32 source_id = 0;
  5522. if (quest)
  5523. source_id = quest->GetQuestID();
  5524. int64 rewarded_coin = 0;
  5525. if (quest) {
  5526. if (quest->GetCoinsReward() > 0) {
  5527. if (quest->GetCoinsRewardMax() > 0)
  5528. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5529. else
  5530. rewarded_coin = quest->GetCoinsReward();
  5531. }
  5532. quest->SetGeneratedCoin(rewarded_coin);
  5533. }
  5534. if (rewarded_coin > coin)
  5535. coin = rewarded_coin;
  5536. if (!quest && !was_displayed) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5537. if (coin > 0) {
  5538. player->AddCoins(coin);
  5539. PlaySound("coin_cha_ching");
  5540. }
  5541. }
  5542. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5543. packet2->setSubstructDataByName("reward_data", "reward", header);
  5544. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5545. if (player->GetGuild() && !was_displayed) {
  5546. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5547. player->GetInfoStruct()->add_status_points(status_points);
  5548. player->SetCharSheetChanged(true);
  5549. }
  5550. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5551. }
  5552. if(text)
  5553. packet2->setSubstructDataByName("reward_data", "text", text);
  5554. if(rewards){
  5555. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5556. for (int i = 0; i < rewards->size(); i++) {
  5557. Item* item = rewards->at(i);
  5558. if (item) {
  5559. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5560. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5561. }
  5562. if(!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5563. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5564. }
  5565. }
  5566. if (selectable_rewards) {
  5567. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5568. for (int i = 0; i < selectable_rewards->size(); i++) {
  5569. Item* item = selectable_rewards->at(i);
  5570. if (item) {
  5571. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5572. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5573. if (!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5574. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5575. }
  5576. }
  5577. }
  5578. if (factions) {
  5579. map<int32, sint32>::iterator itr;
  5580. map<Faction*, signed int> factions_map;
  5581. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5582. Faction* faction = master_faction_list.GetFaction(itr->first);
  5583. if (faction)
  5584. factions_map[faction] = itr->second;
  5585. }
  5586. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5587. map<Faction*, signed int>::iterator faction_itr;
  5588. int8 i = 0;
  5589. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5590. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5591. sint32 amount = faction_itr->second;
  5592. packet2->setArrayDataByName("amount", amount, i);
  5593. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5594. if (amount > 0)
  5595. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5596. else
  5597. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5598. }
  5599. i++;
  5600. }
  5601. }
  5602. QueuePacket(packet2->serialize());
  5603. safe_delete(packet2);
  5604. }
  5605. }
  5606. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription, bool was_displayed) {
  5607. if (!quest)
  5608. return;
  5609. if (GetVersion() <= 546) {
  5610. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints(), customDescription.c_str(), was_displayed);
  5611. return;
  5612. }
  5613. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5614. if (packet) {
  5615. packet->setDataByName("title", "Quest Reward!");
  5616. packet->setDataByName("name", quest->GetName());
  5617. if(customDescription.size() > 0)
  5618. {
  5619. packet->setDataByName("description", customDescription.c_str());
  5620. }
  5621. else
  5622. packet->setDataByName("description", quest->GetDescription());
  5623. packet->setDataByName("level", quest->GetLevel());
  5624. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5625. int8 difficulty = 0;
  5626. if ((string)quest->GetType() == "Tradeskill")
  5627. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5628. else
  5629. difficulty = player->GetArrowColor(quest->GetLevel());
  5630. packet->setDataByName("difficulty", difficulty);
  5631. if(tempReward)
  5632. {
  5633. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5634. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5635. packet->setDataByName("status_points", quest->GetStatusPoints());
  5636. }
  5637. else
  5638. {
  5639. int64 rewarded_coin = 0;
  5640. if (quest->GetCoinsReward() > 0) {
  5641. if (quest->GetCoinsRewardMax() > 0)
  5642. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5643. else
  5644. rewarded_coin = quest->GetCoinsReward();
  5645. }
  5646. quest->SetGeneratedCoin(rewarded_coin);
  5647. packet->setDataByName("max_coin", rewarded_coin);
  5648. packet->setDataByName("min_coin", rewarded_coin);
  5649. packet->setDataByName("status_points", quest->GetStatusPoints());
  5650. }
  5651. vector<Item*>* items = quest->GetTmpRewardItems();
  5652. if(tempReward)
  5653. {
  5654. if (items) {
  5655. packet->setArrayLengthByName("num_rewards", items->size());
  5656. for (int32 i = 0; i < items->size(); i++) {
  5657. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5658. if (version < 860)
  5659. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5660. else if (version < 1193)
  5661. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5662. else
  5663. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5664. }
  5665. }
  5666. }
  5667. else
  5668. {
  5669. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5670. vector<Item*>* items = quest->GetRewardItems();
  5671. if (items) {
  5672. packet->setArrayLengthByName("num_rewards", items->size());
  5673. for (int32 i = 0; i < items->size(); i++) {
  5674. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5675. if (version < 860)
  5676. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5677. else if (version < 1193)
  5678. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5679. else
  5680. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5681. }
  5682. }
  5683. if (items2 && items2->size() > 0) {
  5684. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5685. for (int32 i = 0; i < items2->size(); i++) {
  5686. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5687. if (version < 860)
  5688. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5689. else if (version < 1193)
  5690. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5691. else
  5692. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5693. }
  5694. }
  5695. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5696. if (reward_factions && reward_factions->size() > 0) {
  5697. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5698. map<int32, sint32>::iterator itr;
  5699. int16 index = 0;
  5700. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5701. int32 faction_id = itr->first;
  5702. sint32 amount = itr->second;
  5703. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5704. if (faction_name) {
  5705. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5706. packet->setArrayDataByName("amount", amount, index);
  5707. }
  5708. index++;
  5709. }
  5710. }
  5711. }
  5712. EQ2Packet* outapp = packet->serialize();
  5713. // DumpPacket(outapp);
  5714. QueuePacket(outapp);
  5715. safe_delete(packet);
  5716. }
  5717. }
  5718. void Client::DisplayRandomizeFeatures(int32 flags) {
  5719. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5720. if (flags > 0) {
  5721. if (flags & RANDOMIZE_GENDER)
  5722. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5723. if (flags & RANDOMIZE_RACE)
  5724. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5725. if (flags & RANDOMIZE_MODEL_TYPE)
  5726. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5727. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5728. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5729. if (flags & RANDOMIZE_HAIR_TYPE)
  5730. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5731. if (flags & RANDOMIZE_WING_TYPE)
  5732. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5733. if (flags & RANDOMIZE_CHEEK_TYPE)
  5734. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5735. if (flags & RANDOMIZE_CHIN_TYPE)
  5736. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5737. if (flags & RANDOMIZE_EAR_TYPE)
  5738. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5739. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5740. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5741. if (flags & RANDOMIZE_EYE_TYPE)
  5742. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5743. if (flags & RANDOMIZE_LIP_TYPE)
  5744. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5745. if (flags & RANDOMIZE_NOSE_TYPE)
  5746. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5747. if (flags & RANDOMIZE_EYE_COLOR)
  5748. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5749. if (flags & RANDOMIZE_HAIR_COLOR1)
  5750. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5751. if (flags & RANDOMIZE_HAIR_COLOR2)
  5752. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5753. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5754. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5755. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5756. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5757. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5758. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5759. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5760. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5761. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5762. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5763. if (flags & RANDOMIZE_SKIN_COLOR)
  5764. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5765. if (flags & RANDOMIZE_WING_COLOR1)
  5766. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5767. if (flags & RANDOMIZE_WING_COLOR2)
  5768. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5769. }
  5770. else
  5771. {
  5772. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5773. }
  5774. }
  5775. void Client::GiveQuestReward(Quest* quest, bool has_displayed) {
  5776. current_quest_id = 0;
  5777. if(!quest->GetQuestTemporaryState() && !has_displayed)
  5778. {
  5779. quest->IncrementCompleteCount();
  5780. player->AddCompletedQuest(quest);
  5781. }
  5782. AddPendingQuestAcceptReward(quest);
  5783. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5784. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5785. SendQuestJournal();
  5786. if(quest->GetQuestTemporaryState()) {
  5787. return;
  5788. }
  5789. if(!has_displayed) {
  5790. if (quest->GetExpReward() > 0) {
  5791. int16 level = player->GetLevel();
  5792. int32 xp = quest->GetExpReward();
  5793. if (player->AddXP(xp)) {
  5794. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5795. if (player->GetLevel() != level)
  5796. ChangeLevel(level, player->GetLevel());
  5797. player->SetCharSheetChanged(true);
  5798. }
  5799. }
  5800. if (quest->GetTSExpReward() > 0) {
  5801. int8 ts_level = player->GetTSLevel();
  5802. int32 xp = quest->GetTSExpReward();
  5803. if (player->AddTSXP(xp)) {
  5804. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5805. if (player->GetTSLevel() != ts_level)
  5806. ChangeTSLevel(ts_level, player->GetTSLevel());
  5807. player->SetCharSheetChanged(true);
  5808. }
  5809. }
  5810. int64 total_coins = quest->GetGeneratedCoin();
  5811. if (total_coins > 0)
  5812. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5813. player->RemoveQuest(quest->GetQuestID(), false);
  5814. }
  5815. if (quest->GetQuestGiver() > 0)
  5816. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5817. if(!has_displayed) {
  5818. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5819. }
  5820. }
  5821. 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) {
  5822. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5823. if (packet) {
  5824. packet->setDataByName("conversation_id", conversation_id);
  5825. packet->setDataByName("text", text);
  5826. packet->setDataByName("language", language); // default 0
  5827. packet->setDataByName("can_close", can_close); // default 1
  5828. conversation_map[conversation_id].clear();
  5829. if (conversations) {
  5830. packet->setArrayLengthByName("num_responses", conversations->size());
  5831. for (int32 i = 0; i < conversations->size(); i++) {
  5832. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5833. if (conversations->at(i).function.length() > 0)
  5834. conversation_map[conversation_id][i] = conversations->at(i).function;
  5835. }
  5836. }
  5837. packet->setDataByName("spawn_id", spawn_id);
  5838. if (mp3) {
  5839. packet->setDataByName("voice", mp3);
  5840. packet->setDataByName("key1", key1);
  5841. packet->setDataByName("key2", key2);
  5842. }
  5843. QueuePacket(packet->serialize());
  5844. safe_delete(packet);
  5845. }
  5846. }
  5847. 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) {
  5848. if (!item || !text || !conversations || conversations->size() == 0) {
  5849. return;
  5850. }
  5851. int32 conversation_id = GetConversationID(0, item);
  5852. if (conversation_id == 0) {
  5853. next_conversation_id++;
  5854. conversation_id = next_conversation_id;
  5855. }
  5856. MConversation.writelock();
  5857. conversation_items[conversation_id] = item;
  5858. MConversation.releasewritelock();
  5859. if (type == 4)
  5860. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5861. else
  5862. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5863. }
  5864. 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) {
  5865. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5866. return;
  5867. }
  5868. int32 conversation_id = GetConversationID(src, 0);
  5869. if (conversation_id == 0) {
  5870. next_conversation_id++;
  5871. conversation_id = next_conversation_id;
  5872. }
  5873. MConversation.writelock();
  5874. conversation_spawns[conversation_id] = src->GetID();
  5875. MConversation.releasewritelock();
  5876. /* Spawns can start two different types of conversations.
  5877. * Type 1: The chat type with bubbles.
  5878. * Type 2: The dialog type with the blue box. */
  5879. if (type == 1)
  5880. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2, language, can_close);
  5881. else if (type == 2)
  5882. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2, language, can_close);
  5883. else //if (type == 3)
  5884. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2, language, can_close);
  5885. }
  5886. void Client::CloseDialog(int32 conversation_id) {
  5887. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5888. if (packet) {
  5889. packet->setDataByName("conversation_id", conversation_id);
  5890. QueuePacket(packet->serialize());
  5891. safe_delete(packet);
  5892. }
  5893. MConversation.writelock();
  5894. std::map<int32, Item*>::iterator itr;
  5895. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5896. {
  5897. conversation_items.erase(itr);
  5898. }
  5899. std::map<int32, int32>::iterator itr2 = conversation_spawns.find(conversation_id);
  5900. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5901. {
  5902. conversation_spawns.erase(itr2);
  5903. }
  5904. MConversation.releasewritelock();
  5905. }
  5906. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5907. int32 conversation_id = 0;
  5908. MConversation.readlock();
  5909. if (spawn) {
  5910. map<int32, int32>::iterator itr;
  5911. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5912. if (itr->second == spawn->GetID()) {
  5913. conversation_id = itr->first;
  5914. break;
  5915. }
  5916. }
  5917. }
  5918. else if (item) {
  5919. map<int32, Item*>::iterator itr;
  5920. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5921. if (itr->second == item) {
  5922. conversation_id = itr->first;
  5923. break;
  5924. }
  5925. }
  5926. }
  5927. MConversation.releasereadlock();
  5928. return conversation_id;
  5929. }
  5930. Spawn* Client::GetCombineSpawn() {
  5931. return combine_spawn;
  5932. }
  5933. bool Client::ShouldTarget() {
  5934. return should_target;
  5935. }
  5936. void Client::TargetSpawn(Spawn* spawn) {
  5937. should_target = false;
  5938. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5939. if (packet) {
  5940. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5941. QueuePacket(packet->serialize());
  5942. safe_delete(packet);
  5943. }
  5944. }
  5945. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5946. combine_spawn = spawn;
  5947. spawn->RemoveSpawnFromGroup(true);
  5948. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5949. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5950. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5951. should_target = true;
  5952. }
  5953. void Client::AddCombineSpawn(Spawn* spawn) {
  5954. if (combine_spawn && combine_spawn != spawn && spawn) {
  5955. combine_spawn->AddSpawnToGroup(spawn);
  5956. spawn->AddSpawnToGroup(combine_spawn);
  5957. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5958. }
  5959. else if (spawn)
  5960. combine_spawn = spawn;
  5961. should_target = true;
  5962. }
  5963. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5964. if (combine_spawn && spawn)
  5965. spawn->RemoveSpawnFromGroup();
  5966. if (combine_spawn == spawn)
  5967. combine_spawn->RemoveSpawnFromGroup(true);
  5968. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5969. if (combine_spawn == spawn)
  5970. combine_spawn = 0;
  5971. }
  5972. void Client::SaveCombineSpawns(const char* name) {
  5973. if (!combine_spawn) {
  5974. return;
  5975. }
  5976. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5977. if (!spawns) {
  5978. return;
  5979. }
  5980. int32 count = spawns->size();
  5981. int32 spawnLocationID = 0;
  5982. if (count == 1)
  5983. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5984. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5985. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5986. // we remove the spawn inside SaveCombinedSpawnLocation
  5987. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5988. }
  5989. else
  5990. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5991. safe_delete(spawns);
  5992. combine_spawn = 0;
  5993. }
  5994. bool Client::AddItem(int32 item_id, int16 quantity, AddItemType type) {
  5995. Item* master_item = master_item_list.GetItem(item_id);
  5996. Item* item = 0;
  5997. if (master_item)
  5998. item = new Item(master_item);
  5999. if (item) {
  6000. if (quantity > 0)
  6001. item->details.count = quantity;
  6002. return AddItem(item, nullptr, type);
  6003. }
  6004. else
  6005. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6006. return false;
  6007. }
  6008. bool Client::AddItem(Item* item, bool* item_deleted, AddItemType type) {
  6009. if (!item) {
  6010. return false;
  6011. }
  6012. if (item->IsBag()) {
  6013. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  6014. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  6015. }
  6016. if (player->AddItem(item, type)) {
  6017. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6018. if (outapp) {
  6019. //DumpPacket(outapp);
  6020. QueuePacket(outapp);
  6021. //resend bag desc with new item name added
  6022. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  6023. if (outapp) {
  6024. //DumpPacket(outapp);
  6025. QueuePacket(outapp);
  6026. }
  6027. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6028. DumpPacket(app);
  6029. client->QueuePacket(app);
  6030. */
  6031. }
  6032. CheckPlayerQuestsItemUpdate(item);
  6033. if (item->GetItemScript() && lua_interface)
  6034. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6035. }
  6036. else {
  6037. // likely lore conflict
  6038. safe_delete(item);
  6039. if(item_deleted)
  6040. *item_deleted = true;
  6041. return false;
  6042. }
  6043. return true;
  6044. }
  6045. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  6046. Item* master_item = master_item_list.GetItem(item_id);
  6047. Item* item = 0;
  6048. if (master_item)
  6049. item = new Item(master_item);
  6050. if (item) {
  6051. if (quantity > 0)
  6052. item->details.count = quantity;
  6053. return AddItemToBank(item);
  6054. }
  6055. else
  6056. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  6057. return false;
  6058. }
  6059. bool Client::AddItemToBank(Item* item) {
  6060. if (!item) {
  6061. return false;
  6062. }
  6063. if (player->AddItemToBank(item)) {
  6064. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6065. if (outapp) {
  6066. QueuePacket(outapp);
  6067. //resend bag desc with new item name added
  6068. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  6069. if (outapp)
  6070. QueuePacket(outapp);
  6071. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  6072. DumpPacket(app);
  6073. client->QueuePacket(app);
  6074. */
  6075. }
  6076. CheckPlayerQuestsItemUpdate(item);
  6077. if (item->GetItemScript() && lua_interface)
  6078. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  6079. }
  6080. else {
  6081. // likely lore conflict
  6082. safe_delete(item);
  6083. return false;
  6084. }
  6085. return true;
  6086. }
  6087. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  6088. EQ2Packet* outapp;
  6089. bool delete_item = false;
  6090. assert(item);
  6091. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  6092. item->details.count -= quantity;
  6093. item->save_needed = true;
  6094. }
  6095. else {
  6096. database.DeleteItem(character_id, item, 0);
  6097. player->GetPlayerItemList()->RemoveItem(item, false);
  6098. delete_item = true;
  6099. }
  6100. if(force_override_no_delete)
  6101. delete_item = false;
  6102. if ((outapp = player->SendInventoryUpdate(version))) {
  6103. QueuePacket(outapp);
  6104. if (item->GetItemScript() && lua_interface)
  6105. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  6106. if (delete_item)
  6107. {
  6108. PurgeItem(item);
  6109. safe_delete(item);
  6110. }
  6111. return true;
  6112. }
  6113. return false;
  6114. }
  6115. void Client::SetLuaDebugClient(bool val) {
  6116. if (val)
  6117. lua_debug_timer.Start();
  6118. lua_debug = val;
  6119. if (lua_interface && !val) {
  6120. lua_interface->RemoveDebugClients(this);
  6121. lua_debug_timer.Disable();
  6122. }
  6123. }
  6124. void Client::SetMerchantTransaction(Spawn* spawn) {
  6125. merchant_transaction = spawn;
  6126. }
  6127. Spawn* Client::GetMerchantTransaction() {
  6128. return merchant_transaction;
  6129. }
  6130. void Client::SetMailTransaction(Spawn* spawn) {
  6131. ResetSendMail(spawn ? false : true);
  6132. MMailWindowMutex.lock();
  6133. mail_transaction = spawn;
  6134. MMailWindowMutex.unlock();
  6135. }
  6136. Spawn* Client::GetMailTransaction() {
  6137. return mail_transaction;
  6138. }
  6139. void Client::PlaySound(const char* name) {
  6140. if (name) {
  6141. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  6142. if (packet) {
  6143. packet->setMediumStringByName("name", name);
  6144. QueuePacket(packet->serialize());
  6145. safe_delete(packet);
  6146. }
  6147. }
  6148. }
  6149. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  6150. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6151. if(multiplier){
  6152. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6153. float diff_low = faction_val - multiplier->faction_min;
  6154. if(diff_low < 0)
  6155. diff_low*=-1;
  6156. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6157. if(total_diff < 0)
  6158. total_diff*=-1;
  6159. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  6160. float total1 = (diff_low/total_diff);
  6161. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  6162. return final_buy_multiplier;
  6163. }*/
  6164. return 1;
  6165. }
  6166. float Client::CalculateSellMultiplier(int32 merchant_id) {
  6167. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  6168. if(multiplier){
  6169. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  6170. float diff_low = faction_val - multiplier->faction_min;
  6171. if(diff_low < 0)
  6172. diff_low*=-1;
  6173. float total_diff = multiplier->faction_max - multiplier->faction_min;
  6174. if(total_diff < 0)
  6175. total_diff*=-1;
  6176. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6177. float total1 = (diff_low/total_diff);
  6178. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6179. return final_sell_multiplier;
  6180. }*/
  6181. return 1;
  6182. }
  6183. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6184. Spawn* spawn = GetMerchantTransaction();
  6185. Guild* guild = GetPlayer()->GetGuild();
  6186. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6187. spawn->IsClientInMerchantLevelRange(this)) {
  6188. int32 total_sell_price = 0;
  6189. int32 total_status_sell_price = 0; //for status
  6190. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6191. int32 sell_price = 0;
  6192. int32 status_sell_price = 0; //for status
  6193. Item* master_item = master_item_list.GetItem(item_id);
  6194. Item* item = 0;
  6195. if (unique_id == 0)
  6196. item = player->item_list.GetItemFromID(item_id, quantity);
  6197. else
  6198. item = player->item_list.GetItemFromUniqueID(unique_id);
  6199. if (!item)
  6200. item = player->item_list.GetItemFromID(item_id);
  6201. if (item && master_item) {
  6202. if(item->details.item_locked)
  6203. {
  6204. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6205. return;
  6206. }
  6207. else if(item->CheckFlag(NO_VALUE))
  6208. {
  6209. SimpleMessage(CHANNEL_COLOR_RED, "This item has no value.");
  6210. return;
  6211. }
  6212. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6213. if (sell_price > item->sell_price)
  6214. sell_price = item->sell_price;
  6215. if (quantity > item->details.count)
  6216. quantity = item->details.count;
  6217. total_sell_price = sell_price * quantity;
  6218. //------------------------------For Selling Status Items
  6219. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6220. if (status_sell_price > item->sell_status)
  6221. status_sell_price = item->sell_status;
  6222. if (quantity > item->details.count)
  6223. quantity = item->details.count;
  6224. total_status_sell_price = status_sell_price * quantity;
  6225. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6226. total_status_sell_price = 0;
  6227. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6228. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6229. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6230. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6231. guild->SendGuildMemberList();
  6232. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6233. }
  6234. if (quantity > 1)
  6235. {
  6236. if(total_status_sell_price)
  6237. 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);
  6238. else
  6239. 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());
  6240. }
  6241. else
  6242. {
  6243. if(total_status_sell_price)
  6244. 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);
  6245. else
  6246. 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());
  6247. }
  6248. player->AddCoins(total_sell_price);
  6249. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6250. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6251. if (quantity >= item->details.count) {
  6252. database.DeleteItem(GetCharacterID(), item, 0);
  6253. player->item_list.DestroyItem(item->details.index);
  6254. }
  6255. else {
  6256. item->details.count -= quantity;
  6257. item->save_needed = true;
  6258. }
  6259. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6260. if (outapp)
  6261. QueuePacket(outapp);
  6262. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6263. SendBuyBackList();
  6264. }
  6265. }
  6266. }
  6267. void Client::BuyBack(int32 item_id, int16 quantity) {
  6268. Spawn* spawn = GetMerchantTransaction();
  6269. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6270. spawn->IsClientInMerchantLevelRange(this)) {
  6271. deque<BuyBackItem*>::iterator itr;
  6272. BuyBackItem* buyback = 0;
  6273. BuyBackItem* closest = 0;
  6274. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6275. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6276. buyback = *itr;
  6277. if (buyback->unique_id == item_id) {
  6278. closest = buyback;
  6279. quantity = buyback->quantity;
  6280. break;
  6281. }
  6282. }
  6283. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6284. if (closest) {
  6285. Item* item = 0;
  6286. Item* master_item = master_item_list.GetItem(closest->item_id);
  6287. if (master_item) {
  6288. item = new Item(master_item);
  6289. if (closest->quantity >= quantity)
  6290. item->details.count = quantity;
  6291. else
  6292. item->details.count = closest->quantity;
  6293. }
  6294. bool itemDeleted = false;
  6295. bool itemAdded = false;
  6296. sint64 dispFlags = 0;
  6297. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, nullptr, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6298. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6299. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6300. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6301. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6302. bool removed = false;
  6303. if (closest->quantity == quantity) {
  6304. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6305. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6306. if (*itr == closest) {
  6307. buy_back_items.erase(itr);
  6308. removed = true;
  6309. break;
  6310. }
  6311. }
  6312. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6313. }
  6314. else {
  6315. closest->quantity -= quantity;
  6316. closest->save_needed = true;
  6317. }
  6318. itemAdded = AddItem(item, &itemDeleted);
  6319. if (removed) {
  6320. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6321. safe_delete(closest);
  6322. }
  6323. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6324. SendBuyBackList();
  6325. }
  6326. else
  6327. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6328. if(!itemAdded && !itemDeleted)
  6329. safe_delete(item);
  6330. }
  6331. }
  6332. }
  6333. void Client::BuyItem(int32 item_id, int16 quantity) {
  6334. // Get the merchant we are buying from
  6335. Spawn* spawn = GetMerchantTransaction();
  6336. // Make sure the spawn has a merchant list
  6337. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6338. int32 total_buy_price = 0;
  6339. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6340. int32 sell_price = 0;
  6341. Item* master_item = master_item_list.GetItem(item_id);
  6342. Item* item = 0;
  6343. int16 total_available = 0;
  6344. vector<MerchantItemInfo>* temp;
  6345. vector<MerchantItemInfo>::iterator itr;
  6346. MerchantItemInfo* ItemInfo = 0;
  6347. temp = world.GetMerchantList(spawn->GetMerchantID());
  6348. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6349. if ((*itr).item_id == item_id) {
  6350. ItemInfo = &(*itr);
  6351. break;
  6352. }
  6353. }
  6354. if (master_item && ItemInfo) {
  6355. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6356. quantity = 1;
  6357. total_available = 0xFFFF;
  6358. sell_price = master_item->sell_price;
  6359. }
  6360. else {
  6361. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6362. sell_price = (int32)(master_item->sell_price * multiplier);
  6363. if (quantity > total_available)
  6364. quantity = total_available;
  6365. }
  6366. sint64 dispFlags = 0;
  6367. 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))
  6368. {
  6369. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6370. return;
  6371. }
  6372. if(quantity < 1)
  6373. {
  6374. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6375. return;
  6376. }
  6377. total_buy_price = sell_price * quantity;
  6378. item = new Item(master_item);
  6379. item->details.count = quantity;
  6380. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6381. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6382. safe_delete(item);
  6383. }
  6384. else {
  6385. // Price not set in the merchant_inventory table, use the old method
  6386. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6387. if (player->RemoveCoins(total_buy_price)) {
  6388. item->SetMaxSellValue(sell_price);
  6389. if (quantity > 1)
  6390. 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());
  6391. else
  6392. 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());
  6393. bool itemDeleted = false;
  6394. AddItem(item, &itemDeleted);
  6395. if(!itemDeleted) {
  6396. CheckPlayerQuestsItemUpdate(item);
  6397. if (item && total_available < 0xFF) {
  6398. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6399. SendBuyMerchantList();
  6400. }
  6401. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6402. PlayLotto(total_buy_price, item->details.item_id);
  6403. }
  6404. }
  6405. else {
  6406. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6407. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6408. PlaySound("buy_failed");
  6409. }
  6410. }
  6411. else {
  6412. // Price set in merchant_inventory table
  6413. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6414. // TODO: need to add support for station cash
  6415. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6416. // Check items
  6417. int16 item_quantity = 0;
  6418. // Default these to true in case price_item_id or price_item2_id was never set
  6419. bool hasItem1 = true;
  6420. bool hasItem2 = true;
  6421. Item* tempItem1 = 0;
  6422. Item* tempItem2 = 0;
  6423. if (ItemInfo->price_item_id != 0) {
  6424. // Same item for whatever reason lets add the quantities together
  6425. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6426. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6427. else
  6428. item_quantity = ItemInfo->price_item_qty;
  6429. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6430. if (tempItem1) {
  6431. if (tempItem1->details.count < item_quantity)
  6432. hasItem1 = false;
  6433. }
  6434. else {
  6435. hasItem1 = false;
  6436. }
  6437. }
  6438. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6439. // as item1 and we already checked for it so we can skip this check
  6440. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6441. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6442. if (tempItem2) {
  6443. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6444. hasItem2 = false;
  6445. }
  6446. else {
  6447. hasItem2 = false;
  6448. }
  6449. }
  6450. // if we have every thing then remove the price and give the item
  6451. if (hasItem1 && hasItem2) {
  6452. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6453. // TODO: station cash
  6454. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6455. // so there is no need to send it more then that one time
  6456. if (tempItem1) {
  6457. if (tempItem1->details.count > item_quantity) {
  6458. tempItem1->details.count -= item_quantity;
  6459. tempItem1->save_needed = true;
  6460. }
  6461. else {
  6462. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6463. player->item_list.DestroyItem(tempItem1->details.index);
  6464. }
  6465. }
  6466. if (tempItem2) {
  6467. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6468. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6469. tempItem2->save_needed = true;
  6470. }
  6471. else {
  6472. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6473. player->item_list.DestroyItem(tempItem2->details.index);
  6474. }
  6475. }
  6476. // 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
  6477. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6478. item->SetMaxSellValue(sell_price);
  6479. if (quantity > 1)
  6480. 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());
  6481. else
  6482. 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());
  6483. bool itemDeleted = false;
  6484. AddItem(item, &itemDeleted);
  6485. if(!itemDeleted) {
  6486. CheckPlayerQuestsItemUpdate(item);
  6487. if (item && total_available < 0xFF) {
  6488. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6489. SendBuyMerchantList();
  6490. }
  6491. SendSellMerchantList();
  6492. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6493. PlayLotto(total_buy_price, item->details.item_id);
  6494. }
  6495. }
  6496. else {
  6497. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6498. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6499. PlaySound("buy_failed");
  6500. }
  6501. }
  6502. else {
  6503. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6504. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6505. PlaySound("buy_failed");
  6506. }
  6507. }
  6508. }
  6509. }
  6510. }
  6511. }
  6512. void Client::RepairItem(int32 item_id) {
  6513. Spawn* spawn = GetMerchantTransaction();
  6514. if (spawn) {
  6515. Item* item = player->item_list.GetItemFromID(item_id);
  6516. if (!item)
  6517. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6518. if (item) {
  6519. if(item->CheckFlag(NO_REPAIR)) {
  6520. Message(CHANNEL_MERCHANT, "The mender was unable to repair your items.");
  6521. PlaySound("buy_failed");
  6522. }
  6523. else {
  6524. int32 repair_cost = item->CalculateRepairCost();
  6525. if (player->RemoveCoins((int32)repair_cost)) {
  6526. item->generic_info.condition = 100;
  6527. item->save_needed = true;
  6528. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6529. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6530. QueuePacket(item->serialize(version, false, player));
  6531. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6532. PlaySound("coin_cha_ching");
  6533. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6534. SendRepairList();
  6535. }
  6536. else {
  6537. string popup_text = "You do not have enough coin to repair ";
  6538. string popup_item = item->CreateItemLink(GetVersion()).c_str();
  6539. popup_text.append(popup_item);
  6540. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6541. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6542. PlaySound("buy_failed");
  6543. }
  6544. }
  6545. }
  6546. }
  6547. }
  6548. void Client::RepairAllItems() {
  6549. Spawn* spawn = GetMerchantTransaction();
  6550. if (spawn) {
  6551. vector<Item*>* repairable_items = GetRepairableItems();
  6552. if (repairable_items && repairable_items->size() > 0) {
  6553. vector<Item*>::iterator itr;
  6554. int64 total_cost = 0;
  6555. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6556. total_cost += (*itr)->CalculateRepairCost();
  6557. if (player->RemoveCoins((int32)total_cost)) {
  6558. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6559. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6560. Item* item = *itr;
  6561. if (item) {
  6562. item->generic_info.condition = 100;
  6563. item->save_needed = true;
  6564. QueuePacket(item->serialize(version, false, player));
  6565. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6566. }
  6567. }
  6568. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6569. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6570. PlaySound("coin_cha_ching");
  6571. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6572. SendRepairList();
  6573. }
  6574. else {
  6575. string popup_text = "You do not have enough coin to repair all of your items. ";
  6576. SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  6577. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6578. PlaySound("buy_failed");
  6579. }
  6580. }
  6581. safe_delete(repairable_items);
  6582. }
  6583. }
  6584. void Client::SendAchievementsList()
  6585. {
  6586. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6587. map<int32, Achievement *>::iterator itr;
  6588. Achievement *achievement;
  6589. vector<AchievementRequirements *> *requirements = 0;
  6590. vector<AchievementRequirements *>::iterator itr2;
  6591. AchievementRequirements *requirement;
  6592. vector<AchievementRewards *> *rewards = 0;
  6593. vector<AchievementRewards *>::iterator itr3;
  6594. AchievementRewards *reward;
  6595. PacketStruct *packet;
  6596. int16 i = 0;
  6597. int16 j = 0;
  6598. int16 k = 0;
  6599. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6600. return;
  6601. }
  6602. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6603. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6604. achievement = itr->second;
  6605. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6606. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6607. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6608. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6609. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6610. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6611. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6612. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6613. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6614. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6615. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6616. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6617. requirements = achievement->GetRequirements();
  6618. rewards = achievement->GetRewards();
  6619. j = 0;
  6620. k = 0;
  6621. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6622. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6623. requirement = *itr2;
  6624. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6625. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6626. j++;
  6627. }
  6628. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6629. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6630. reward = *itr3;
  6631. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6632. k++;
  6633. }
  6634. i++;
  6635. }
  6636. //packet->PrintPacket();
  6637. EQ2Packet* data = packet->serialize();
  6638. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6639. safe_delete(packet);
  6640. safe_delete(data);
  6641. //DumpPacket(app);
  6642. QueuePacket(app);*/
  6643. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6644. SendAchievementUpdate(true);
  6645. }
  6646. void Client::SendAchievementUpdate(bool first_login) {
  6647. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6648. map<int32, AchievementUpdate*>::iterator itr;
  6649. AchievementUpdate* update;
  6650. vector<AchievementUpdateItems*>* update_items = 0;
  6651. vector<AchievementUpdateItems*>::iterator itr2;
  6652. AchievementUpdateItems* update_item;
  6653. int16 i = 0;
  6654. int16 j = 0;
  6655. PacketStruct* packet;
  6656. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6657. return;
  6658. }
  6659. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6660. packet->setArrayLengthByName("num_achievements", updates->size());
  6661. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6662. update = itr->second;
  6663. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6664. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6665. update_items = update->GetUpdateItems();
  6666. j = 0;
  6667. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6668. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6669. update_item = *itr2;
  6670. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6671. j++;
  6672. }
  6673. i++;
  6674. }
  6675. //packet->PrintPacket();
  6676. EQ2Packet* data = packet->serialize();
  6677. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6678. safe_delete(packet);
  6679. safe_delete(data);
  6680. //DumpPacket(app);
  6681. QueuePacket(app);
  6682. }
  6683. void Client::SendBuyMerchantList(bool sell) {
  6684. Spawn* spawn = GetMerchantTransaction();
  6685. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6686. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6687. if (items) {
  6688. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6689. if (packet) {
  6690. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6691. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6692. packet->setArrayLengthByName("num_items", items->size());
  6693. vector<MerchantItemInfo>::iterator itr;
  6694. sint8 item_difficulty = 0;
  6695. int32 sell_price = 0;
  6696. int i = 0;
  6697. int tmp_level = 0;
  6698. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6699. MerchantItemInfo ItemInfo = *itr;
  6700. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6701. if (!item)
  6702. continue;
  6703. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6704. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6705. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6706. packet->setArrayDataByName("icon", item->details.icon, i);
  6707. if (item->generic_info.adventure_default_level > 0)
  6708. tmp_level = item->generic_info.adventure_default_level;
  6709. else
  6710. tmp_level = item->generic_info.tradeskill_default_level;
  6711. packet->setArrayDataByName("level", tmp_level, i);
  6712. packet->setArrayDataByName("tier", item->details.tier, i);
  6713. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6714. item_difficulty = player->GetArrowColor(tmp_level);
  6715. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6716. item_difficulty = ARROW_COLOR_WHITE;
  6717. sint64 overrideValue = 0;
  6718. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6719. item_difficulty = (sint8)overrideValue;
  6720. item_difficulty -= 6;
  6721. if (item_difficulty < 0)
  6722. item_difficulty *= -1;
  6723. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6724. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6725. packet->setArrayDataByName("unknown5", 255, i);
  6726. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6727. sint64 dispFlags = 0;
  6728. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, nullptr, &dispFlags))
  6729. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6730. std::string overrideValueStr;
  6731. // 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)
  6732. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6733. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6734. // If no price set in the merchant_inventory table then use the old method
  6735. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6736. sell_price = (int32)(item->sell_price * multiplier);
  6737. packet->setArrayDataByName("price", sell_price, i);
  6738. }
  6739. else {
  6740. int8 count = 0;
  6741. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6742. count++;
  6743. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6744. count++;
  6745. if (count != 0) {
  6746. packet->setSubArrayLengthByName("num_tokens", count, i);
  6747. int8 index = 0;
  6748. Item* token = 0;
  6749. if (ItemInfo.price_item_id != 0) {
  6750. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6751. if (item) {
  6752. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6753. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6754. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6755. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6756. }
  6757. token = 0;
  6758. index++;
  6759. }
  6760. if (ItemInfo.price_item2_id != 0) {
  6761. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6762. if (item) {
  6763. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6764. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6765. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6766. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6767. }
  6768. }
  6769. }
  6770. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6771. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6772. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6773. }
  6774. }
  6775. if (GetVersion() <= 546) {
  6776. //buy is 0 so dont need to set it
  6777. if (sell)
  6778. packet->setDataByName("type", 1);
  6779. }
  6780. else {
  6781. if (sell)
  6782. packet->setDataByName("type", 130);
  6783. else
  6784. packet->setDataByName("type", 2);
  6785. }
  6786. EQ2Packet* outapp = packet->serialize();
  6787. // DumpPacket(outapp);
  6788. QueuePacket(outapp);
  6789. safe_delete(packet);
  6790. }
  6791. safe_delete(items);
  6792. }
  6793. else {
  6794. // Need to send an empty packet in the event there is no item list, otherwise the
  6795. // last item list sent to the player will show for this merchant
  6796. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6797. if (packet) {
  6798. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6799. if (GetVersion() <= 546) {
  6800. //buy is 0 so dont need to set it
  6801. if (sell)
  6802. packet->setDataByName("type", 1);
  6803. }
  6804. else {
  6805. if (sell)
  6806. packet->setDataByName("type", 130);
  6807. else
  6808. packet->setDataByName("type", 2);
  6809. }
  6810. EQ2Packet* outapp = packet->serialize();
  6811. QueuePacket(outapp);
  6812. safe_delete(packet);
  6813. }
  6814. }
  6815. }
  6816. }
  6817. void Client::SendSellMerchantList(bool sell) {
  6818. Spawn* spawn = GetMerchantTransaction();
  6819. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6820. return;
  6821. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6822. map<int32, Item*>* items = player->GetItemList();
  6823. if (items) {
  6824. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6825. if (packet) {
  6826. vector<Item*> sellable_items;
  6827. map<int32, Item*>::iterator test_itr;
  6828. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6829. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6830. sellable_items.push_back(test_itr->second);
  6831. }
  6832. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6833. packet->setArrayLengthByName("num_items", sellable_items.size());
  6834. vector<Item*>::iterator itr;
  6835. Item* item = 0;
  6836. sint8 item_difficulty = 0;
  6837. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6838. int32 sell_price = 0;
  6839. Item* master_item = 0;
  6840. int i = 0;
  6841. int tmp_level = 0;
  6842. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6843. item = *itr;
  6844. master_item = master_item_list.GetItem(item->details.item_id);
  6845. if (master_item)
  6846. sell_price = (int32)(master_item->sell_price * multiplier);
  6847. else
  6848. sell_price = 0;
  6849. if (sell_price > item->sell_price)
  6850. sell_price = item->sell_price;
  6851. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6852. string thename = item->name;
  6853. packet->setArrayDataByName("price", sell_price, i);
  6854. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6855. int8 dispFlags = 0;
  6856. // only city merchants allow selling for status
  6857. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6858. {
  6859. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6860. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6861. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6862. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6863. }
  6864. }
  6865. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6866. {
  6867. if(GetVersion() < 1188)
  6868. 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
  6869. else
  6870. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6871. }
  6872. if(item->no_sale)
  6873. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6874. packet->setArrayDataByName("display_flags", dispFlags, i);
  6875. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6876. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6877. packet->setArrayDataByName("stack_size", item->details.count, i);
  6878. packet->setArrayDataByName("icon", item->details.icon, i);
  6879. if (item->generic_info.adventure_default_level > 0)
  6880. tmp_level = item->generic_info.adventure_default_level;
  6881. else
  6882. tmp_level = item->generic_info.tradeskill_default_level;
  6883. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6884. packet->setArrayDataByName("tier", item->details.tier, i);
  6885. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6886. item_difficulty = player->GetArrowColor(tmp_level);
  6887. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6888. item_difficulty = ARROW_COLOR_WHITE;
  6889. sint64 overrideValue = 0;
  6890. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, nullptr, &overrideValue))
  6891. item_difficulty = (sint8)overrideValue;
  6892. item_difficulty -= 6;
  6893. if (item_difficulty < 0)
  6894. item_difficulty *= -1;
  6895. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6896. if (item->details.count == 1)
  6897. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6898. else
  6899. packet->setArrayDataByName("quantity", item->details.count, i);
  6900. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6901. if (GetVersion() <= 1096)
  6902. packet->setArrayDataByName("description", item->description.c_str(), i);
  6903. }
  6904. if (GetVersion() <= 546) {
  6905. packet->setDataByName("type", 1);
  6906. }
  6907. else {
  6908. if (sell)
  6909. packet->setDataByName("type", 129);
  6910. else
  6911. packet->setDataByName("type", 1);
  6912. }
  6913. packet->setDataByName("unknown8a", 16256, 6);
  6914. packet->setDataByName("unknown8a", 16256, 10);
  6915. //packet->PrintPacket();
  6916. EQ2Packet* outapp = packet->serialize();
  6917. //DumpPacket(outapp);
  6918. QueuePacket(outapp);
  6919. safe_delete(packet);
  6920. }
  6921. safe_delete(items);
  6922. }
  6923. }
  6924. }
  6925. void Client::SendBuyBackList(bool sell) {
  6926. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6927. return;
  6928. Spawn* spawn = GetMerchantTransaction();
  6929. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6930. deque<BuyBackItem*>::iterator itr;
  6931. int i = 0;
  6932. Item* master_item = 0;
  6933. BuyBackItem* buyback = 0;
  6934. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6935. if (packet) {
  6936. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6937. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6938. sint8 item_difficulty = 0;
  6939. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6940. int tmp_level = 0;
  6941. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6942. buyback = *itr;
  6943. master_item = master_item_list.GetItem(buyback->item_id);
  6944. if (master_item) {
  6945. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6946. packet->setArrayDataByName("price", buyback->price, i);
  6947. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6948. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6949. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6950. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6951. if (master_item->generic_info.adventure_default_level > 0)
  6952. tmp_level = master_item->generic_info.adventure_default_level;
  6953. else
  6954. tmp_level = master_item->generic_info.tradeskill_default_level;
  6955. packet->setArrayDataByName("level", tmp_level, i);
  6956. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6957. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6958. item_difficulty = player->GetArrowColor(tmp_level);
  6959. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6960. item_difficulty = ARROW_COLOR_WHITE;
  6961. sint64 overrideValue = 0;
  6962. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, nullptr, &overrideValue))
  6963. item_difficulty = (sint8)overrideValue;
  6964. item_difficulty -= 6;
  6965. if (item_difficulty < 0)
  6966. item_difficulty *= -1;
  6967. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6968. sint64 dispFlags = 0;
  6969. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, nullptr, &dispFlags))
  6970. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6971. if (buyback->quantity == 1)
  6972. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6973. else
  6974. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6975. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6976. if (GetVersion() <= 1096)
  6977. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6978. }
  6979. }
  6980. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6981. if (sell)
  6982. packet->setDataByName("type", 640);
  6983. else
  6984. packet->setDataByName("type", 512);
  6985. EQ2Packet* outapp = packet->serialize();
  6986. // DumpPacket(outapp);
  6987. QueuePacket(outapp);
  6988. safe_delete(packet);
  6989. }
  6990. }
  6991. }
  6992. void Client::SendRepairList() {
  6993. Spawn* spawn = GetMerchantTransaction();
  6994. if (spawn) {
  6995. vector<Item*>* repairable_items = GetRepairableItems();
  6996. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6997. if (packet) {
  6998. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6999. packet->setArrayLengthByName("num_items", repairable_items->size());
  7000. Item* item = 0;
  7001. sint8 item_difficulty = 0;
  7002. int32 i = 0;
  7003. vector<Item*>::iterator itr;
  7004. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  7005. item = *itr;
  7006. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7007. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  7008. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7009. packet->setArrayDataByName("stack_size", item->details.count, i);
  7010. packet->setArrayDataByName("icon", item->details.icon, i);
  7011. /*if (item->generic_info.adventure_default_level > 0)
  7012. tmp_level = item->generic_info.adventure_default_level;
  7013. else
  7014. tmp_level = item->generic_info.tradeskill_default_level;
  7015. packet->setArrayDataByName("level", tmp_level, i);*/
  7016. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  7017. packet->setArrayDataByName("tier", item->details.tier, i);
  7018. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7019. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7020. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7021. item_difficulty = ARROW_COLOR_WHITE;
  7022. item_difficulty -= 6;
  7023. if (item_difficulty < 0)
  7024. item_difficulty *= -1;
  7025. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  7026. if (item->details.count == 1)
  7027. packet->setArrayDataByName("quantity", 0xFFFF, i);
  7028. else
  7029. packet->setArrayDataByName("quantity", item->details.count, i);
  7030. packet->setArrayDataByName("stack_size2", item->details.count, i);
  7031. if (GetVersion() <= 1096)
  7032. packet->setArrayDataByName("description", item->description.c_str(), i);
  7033. }
  7034. if (GetVersion() <= 546) {
  7035. packet->setDataByName("type", 16);
  7036. }
  7037. else {
  7038. packet->setDataByName("type", 96);
  7039. }
  7040. EQ2Packet* outapp = packet->serialize();
  7041. QueuePacket(outapp);
  7042. safe_delete(packet);
  7043. }
  7044. safe_delete(repairable_items);
  7045. }
  7046. }
  7047. void Client::ShowLottoWindow() {
  7048. Spawn* spawn = GetMerchantTransaction();
  7049. if (spawn) {
  7050. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  7051. if (!item_id)
  7052. {
  7053. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  7054. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  7055. return;
  7056. }
  7057. else if (item_id == 0)
  7058. {
  7059. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  7060. return;
  7061. }
  7062. Item* item = master_item_list.GetItem(item_id);
  7063. if (!item) {
  7064. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  7065. return;
  7066. }
  7067. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  7068. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7069. if (packet) {
  7070. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7071. packet->setArrayLengthByName("num_items", 1);
  7072. packet->setArrayDataByName("item_name", item->name.c_str());
  7073. packet->setArrayDataByName("price", item->sell_price);
  7074. packet->setArrayDataByName("item_id", item->details.item_id);
  7075. packet->setArrayDataByName("stack_size", item->details.count);
  7076. packet->setArrayDataByName("icon", item->details.icon);
  7077. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  7078. packet->setArrayDataByName("tier", item->details.tier);
  7079. packet->setArrayDataByName("item_id2", item->details.item_id);
  7080. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  7081. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  7082. item_difficulty = ARROW_COLOR_WHITE;
  7083. item_difficulty -= 6;
  7084. if (item_difficulty < 0)
  7085. item_difficulty *= -1;
  7086. packet->setArrayDataByName("item_difficulty", item_difficulty);
  7087. //if(item->details.count == 1)
  7088. packet->setArrayDataByName("quantity", 0xFFFF);
  7089. //else
  7090. // packet->setArrayDataByName("quantity", item->details.count);
  7091. packet->setArrayDataByName("stack_size2", item->details.count);
  7092. packet->setArrayDataByName("description", item->description.c_str());
  7093. if (GetVersion() <= 546) {
  7094. packet->setDataByName("type", 128);
  7095. }
  7096. else {
  7097. packet->setDataByName("type", 0x00000102);
  7098. }
  7099. QueuePacket(packet->serialize());
  7100. safe_delete(packet);
  7101. }
  7102. }
  7103. }
  7104. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  7105. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  7106. if (packet) {
  7107. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  7108. int32 rolls[6] = { 0 };
  7109. int32 lottery_digits[6] = { 0 };
  7110. int8 num_matches = 0;
  7111. int64 jackpot = 0;
  7112. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  7113. if (!item) {
  7114. return;
  7115. }
  7116. database.DeleteItem(GetCharacterID(), item, 0);
  7117. GetPlayer()->item_list.RemoveItem(item, true);
  7118. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7119. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  7120. if (!winning_numbers) {
  7121. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  7122. variables.AddVariable(winning_numbers);
  7123. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7124. }
  7125. if (strlen(winning_numbers->GetValue()) != 12) {
  7126. winning_numbers->SetValue("231205182236");
  7127. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7128. }
  7129. try {
  7130. for (int32 i = 0; i < 12; i += 2) {
  7131. char num[4];
  7132. strncpy(num, winning_numbers->GetValue() + i, 2);
  7133. lottery_digits[i / 2] = atoi(num);
  7134. }
  7135. }
  7136. catch (...) {
  7137. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  7138. return;
  7139. }
  7140. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  7141. if (!jackpot_var) {
  7142. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  7143. variables.AddVariable(jackpot_var);
  7144. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7145. }
  7146. try {
  7147. jackpot = atoul(jackpot_var->GetValue());
  7148. if (jackpot < 10000)
  7149. jackpot = 10000;
  7150. }
  7151. catch (...) {
  7152. jackpot = 10000;
  7153. }
  7154. char new_jackpot[128] = { 0 };
  7155. sprintf(new_jackpot, "%llu", jackpot + price);
  7156. jackpot_var->SetValue(new_jackpot);
  7157. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7158. world.PickRandomLottoDigits(rolls);
  7159. packet->setDataByName("roll_digit1", rolls[0]);
  7160. packet->setDataByName("roll_digit2", rolls[1]);
  7161. packet->setDataByName("roll_digit3", rolls[2]);
  7162. packet->setDataByName("roll_digit4", rolls[3]);
  7163. packet->setDataByName("roll_digit5", rolls[4]);
  7164. packet->setDataByName("roll_digit6", rolls[5]);
  7165. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  7166. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  7167. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  7168. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  7169. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  7170. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  7171. QueuePacket(packet->serialize());
  7172. safe_delete(packet);
  7173. for (int32 i = 0; i < 6; i++) {
  7174. for (int32 j = 0; j < 6; j++) {
  7175. if (rolls[i] == lottery_digits[j]) {
  7176. num_matches++;
  7177. break;
  7178. }
  7179. }
  7180. }
  7181. char new_jackpot_str[16];
  7182. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  7183. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  7184. if (num_matches == 6) {
  7185. world.PickRandomLottoDigits(lottery_digits);
  7186. for (int32 i = 0; i < 12; i += 2)
  7187. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  7188. winning_numbers->SetValue(new_jackpot_str);
  7189. jackpot_var->SetValue("10000");
  7190. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7191. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7192. }
  7193. }
  7194. }
  7195. void Client::SendGuildCreateWindow() {
  7196. if (GetVersion() <= 546) {
  7197. SimpleMessage(0, "Not implemented on this client...yet?");
  7198. }
  7199. else {
  7200. Spawn* spawn = GetPlayer()->GetTarget();
  7201. if (spawn) {
  7202. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7203. if (packet) {
  7204. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7205. packet->setArrayLengthByName("num_items", 0);
  7206. packet->setDataByName("type", 0x00008000);
  7207. QueuePacket(packet->serialize());
  7208. safe_delete(packet);
  7209. }
  7210. }
  7211. }
  7212. }
  7213. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7214. BuyBackItem* item = new BuyBackItem;
  7215. item->item_id = item_id;
  7216. item->unique_id = unique_id;
  7217. item->price = price;
  7218. item->quantity = quantity;
  7219. item->save_needed = save_needed;
  7220. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7221. buy_back_items.push_back(item);
  7222. if (buy_back_items.size() > 10) {
  7223. safe_delete(buy_back_items.front());
  7224. buy_back_items.pop_front();
  7225. }
  7226. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7227. }
  7228. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7229. return &buy_back_items;
  7230. }
  7231. vector<Item*>* Client::GetRepairableItems() {
  7232. vector<Item*>* repairable_items = new vector<Item*>;
  7233. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7234. map<int32, Item*>* items = player->GetItemList();
  7235. if (equipped_items && equipped_items->size() > 0) {
  7236. for (int32 i = 0; i < equipped_items->size(); i++) {
  7237. Item* item = equipped_items->at(i);
  7238. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7239. repairable_items->push_back(item);
  7240. }
  7241. }
  7242. if (items && items->size() > 0) {
  7243. map<int32, Item*>::iterator itr;
  7244. for (itr = items->begin(); itr != items->end(); itr++) {
  7245. Item* item = itr->second;
  7246. if (item && !item->CheckFlag(NO_REPAIR) && item->generic_info.condition < 100)
  7247. repairable_items->push_back(item);
  7248. }
  7249. }
  7250. safe_delete(equipped_items);
  7251. safe_delete(items);
  7252. return repairable_items;
  7253. }
  7254. vector<Item*>* Client::GetItemsByEffectType(ItemEffectType type, ItemEffectType type2) {
  7255. if(type == NO_EFFECT_TYPE)
  7256. return nullptr;
  7257. vector<Item*>* return_items = new vector<Item*>;
  7258. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7259. map<int32, Item*>* items = player->GetItemList();
  7260. if (equipped_items && equipped_items->size() > 0) {
  7261. for (int32 i = 0; i < equipped_items->size(); i++) {
  7262. Item* item = equipped_items->at(i);
  7263. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7264. return_items->push_back(item);
  7265. }
  7266. }
  7267. if (items && items->size() > 0) {
  7268. map<int32, Item*>::iterator itr;
  7269. for (itr = items->begin(); itr != items->end(); itr++) {
  7270. Item* item = itr->second;
  7271. if (item && (item->effect_type == type || (type2 != NO_EFFECT_TYPE && item->effect_type == type2)))
  7272. return_items->push_back(item);
  7273. }
  7274. }
  7275. safe_delete(equipped_items);
  7276. safe_delete(items);
  7277. return return_items;
  7278. }
  7279. void Client::SendMailList() {
  7280. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7281. if (kiosk_id > 0) {
  7282. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7283. if (p) {
  7284. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7285. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7286. int32 i = 0;
  7287. p->setDataByName("kiosk_id", kiosk_id);
  7288. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7289. while (itr.Next()) {
  7290. Mail* mail = itr->second;
  7291. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7292. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7293. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7294. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7295. p->setArrayDataByName("unknown1", 0x0000, i);
  7296. p->setArrayDataByName("already_read", mail->already_read, i);
  7297. if(mail->expire_time)
  7298. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7299. else
  7300. p->setArrayDataByName("mail_deletion", 0, i);
  7301. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7302. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7303. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7304. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7305. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7306. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7307. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7308. //p->setArrayDataByName("unknown2", 0, i);
  7309. bool successItemAdd = false;
  7310. if(mail->stack || mail->char_item_id)
  7311. {
  7312. Item* item = master_item_list.GetItem(mail->char_item_id);
  7313. if(item)
  7314. {
  7315. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7316. if (version < 860)
  7317. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7318. else if (version < 1193)
  7319. p->setItemArrayDataByName("item", item, player, i);
  7320. else
  7321. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7322. successItemAdd = true;
  7323. }
  7324. }
  7325. if(!successItemAdd)
  7326. {
  7327. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7328. p->setArrayDataByName("end_tag3", 0xFF, i);
  7329. }
  7330. i++;
  7331. }
  7332. // GMs send mail for free!
  7333. if (GetAdminStatus() > 0)
  7334. {
  7335. p->setDataByName("postage_cost", 0);
  7336. p->setDataByName("attachment_cost", 0);
  7337. }
  7338. else
  7339. {
  7340. p->setDataByName("postage_cost", 10);
  7341. p->setDataByName("attachment_cost", 50);
  7342. }
  7343. p->setDataByName("unknown3", 0x01F4);
  7344. p->setDataByName("unknown4", 0x01000000);
  7345. EQ2Packet* pack = p->serialize();
  7346. QueuePacket(pack);
  7347. safe_delete(p);
  7348. }
  7349. }
  7350. else
  7351. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7352. }
  7353. void Client::DisplayMailMessage(int32 mail_id) {
  7354. Mail* mail = player->GetMail(mail_id);
  7355. if (mail) {
  7356. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7357. if (kiosk_id > 0) {
  7358. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7359. if (update) {
  7360. update->setDataByName("action", 0x03);
  7361. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7362. update->setDataByName("packetsubtype", 0xFF);
  7363. QueuePacket(update->serialize());
  7364. safe_delete(update);
  7365. }
  7366. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7367. if (packet) {
  7368. packet->setDataByName("kiosk_id", kiosk_id);
  7369. packet->setDataByName("mail_id", mail->mail_id);
  7370. packet->setDataByName("player_to_id", mail->player_to_id);
  7371. packet->setDataByName("player_from", mail->player_from.c_str());
  7372. packet->setDataByName("subject", mail->subject.c_str());
  7373. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7374. packet->setDataByName("unknown1", 1);
  7375. packet->setDataByName("unknown2", 0);
  7376. packet->setDataByName("lock_report_button", 1);
  7377. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7378. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7379. packet->setDataByName("coin_copper", mail->coin_copper);
  7380. packet->setDataByName("coin_silver", mail->coin_silver);
  7381. packet->setDataByName("coin_gold", mail->coin_gold);
  7382. packet->setDataByName("coin_plat", mail->coin_plat);
  7383. if(mail->stack || mail->char_item_id)
  7384. {
  7385. Item* item = master_item_list.GetItem(mail->char_item_id);
  7386. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7387. if (version < 860)
  7388. packet->setItemByName("item", item, player, 0, -1);
  7389. else if (version < 1193)
  7390. packet->setItemByName("item", item, player, 0, 0);
  7391. else
  7392. packet->setItemByName("item", item, player, 0, 2);
  7393. }
  7394. else
  7395. {
  7396. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7397. packet->setDataByName("end_tag3", 0xFF);
  7398. }
  7399. mail->already_read = true;
  7400. mail->save_needed = true;
  7401. EQ2Packet* pack = packet->serialize();
  7402. QueuePacket(pack);
  7403. safe_delete(packet);
  7404. // trying to update this causes the window not to open
  7405. //SendMailList();
  7406. }
  7407. }
  7408. else
  7409. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7410. }
  7411. }
  7412. /* 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
  7413. packet back to the client before the mail actually sent. */
  7414. void Client::HandleSentMail(EQApplicationPacket* app) {
  7415. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7416. if (packet) {
  7417. packet->LoadPacketData(app->pBuffer, app->size);
  7418. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7419. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7420. vector<int32>* ids = 0;
  7421. MMailWindowMutex.lock();
  7422. if (reply_packet) {
  7423. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7424. if (player_to.length() == 0)
  7425. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7426. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7427. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7428. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7429. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7430. else {
  7431. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7432. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7433. ids = database.GetAllPlayerIDs();
  7434. else
  7435. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7436. }
  7437. else {
  7438. ids = new vector<int32>;
  7439. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7440. }
  7441. if (ids) {
  7442. for (int32 i = 0; i < ids->size(); i++) {
  7443. int32 player_to_id = ids->at(i);
  7444. if (player_to_id > 0) {
  7445. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7446. Mail* mail = new Mail;
  7447. mail->mail_id = 0;
  7448. mail->player_to_id = player_to_id;
  7449. mail->player_from = string(GetPlayer()->GetName());
  7450. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7451. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7452. mail->already_read = 0;
  7453. mail->mail_type = MAIL_TYPE_REGULAR;
  7454. mail->coin_copper = mail_window.coin_copper;
  7455. mail->coin_silver = mail_window.coin_silver;
  7456. mail->coin_gold = mail_window.coin_gold;
  7457. mail->coin_plat = mail_window.coin_plat;
  7458. mail->char_item_id = mail_window.char_item_id;
  7459. mail->stack = mail_window.stack;
  7460. // GM's send mail for free!
  7461. if (GetAdminStatus() > 0)
  7462. {
  7463. mail->postage_cost = 0;
  7464. mail->attachment_cost = 0;
  7465. }
  7466. else
  7467. {
  7468. mail->postage_cost = 10;
  7469. mail->attachment_cost = 50;
  7470. }
  7471. mail->time_sent = Timer::GetUnixTimeStamp();
  7472. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7473. //int16 packettype = packet->getType_int16_ByName("packettype");
  7474. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  7475. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  7476. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  7477. if (postage_cost > 0 || attachment_cost > 0)
  7478. PlaySoundA("coin_cha_ching");*/
  7479. mail->save_needed = false;
  7480. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7481. if (to_client) {
  7482. to_client->GetPlayer()->AddMail(mail);
  7483. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You have unread mail in your mailbox.");
  7484. string popup_text = "You have unread mail!";
  7485. to_client->SendPopupMessage(10, popup_text.c_str(), "", 3, 0xFF, 0xFF, 0xFF);
  7486. }
  7487. database.SavePlayerMail(mail);
  7488. ResetSendMail(false, false);
  7489. }
  7490. else
  7491. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  7492. }
  7493. }
  7494. }
  7495. string players_to = "";
  7496. if (ids) {
  7497. for (int32 i = 0; i < ids->size(); i++) {
  7498. if (ids->at(i) != 0)
  7499. players_to.append(database.GetCharacterName(ids->at(i)));
  7500. if (i < (ids->size() - 1))
  7501. players_to.append(", ");
  7502. }
  7503. }
  7504. reply_packet->setDataByName("player_to", players_to.c_str());
  7505. reply_packet->setDataByName("reply_type", reply_type);
  7506. QueuePacket(reply_packet->serialize());
  7507. safe_delete(reply_packet);
  7508. safe_delete(ids);
  7509. }
  7510. safe_delete(packet);
  7511. MMailWindowMutex.unlock();
  7512. }
  7513. }
  7514. void Client::DeleteMail(int32 mail_id, bool from_database) {
  7515. player->DeleteMail(mail_id, from_database);
  7516. }
  7517. bool Client::AddMailItem(Item* item)
  7518. {
  7519. if(item && (item->CheckFlag(LORE) || item->CheckFlag(STACK_LORE))) {
  7520. Message(CHANNEL_COLOR_CHAT_RELATIONSHIP, "Lore items cannot be mailed.");
  7521. return false;
  7522. }
  7523. bool ret = false;
  7524. if (GetMailTransaction()) {
  7525. MMailWindowMutex.lock();
  7526. if(mail_window.char_item_id == 0)
  7527. {
  7528. mail_window.item = item;
  7529. mail_window.char_item_id = item->details.item_id;
  7530. mail_window.stack = item->details.count;
  7531. ret = true;
  7532. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7533. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7534. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7535. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7536. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7537. if(item)
  7538. {
  7539. packet->setDataByName("stack", mail_window.stack);
  7540. item->stack_count = mail_window.stack;
  7541. if (version < 860)
  7542. packet->setItemByName("item", item, player, 0, -1);
  7543. else if (version < 1193)
  7544. packet->setItemByName("item", item, player, 0, 0);
  7545. else
  7546. packet->setItemByName("item", item, player, 0, 2);
  7547. }
  7548. else
  7549. {
  7550. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7551. packet->setDataByName("end_tag3", 0xFF);
  7552. }
  7553. //packet->setDataByName("packettype", GetItemPacketType(version));
  7554. //packet->setDataByName("packetsubtype", 0xFF);
  7555. //packet->setDataByName("unknown2", 0);
  7556. //packet->PrintPacket();
  7557. QueuePacket(packet->serialize());
  7558. }
  7559. MMailWindowMutex.unlock();
  7560. }
  7561. return ret;
  7562. }
  7563. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7564. bool ret = false;
  7565. if (GetMailTransaction()) {
  7566. MMailWindowMutex.lock();
  7567. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7568. if (packet) {
  7569. if (copper > 0) {
  7570. if (player->RemoveCoins(copper)) {
  7571. mail_window.coin_copper += copper;
  7572. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7573. ret = true;
  7574. }
  7575. }
  7576. else if (silver > 0) {
  7577. if (player->RemoveCoins(silver * 100)) {
  7578. mail_window.coin_silver += silver;
  7579. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7580. ret = true;
  7581. }
  7582. }
  7583. else if (gold > 0) {
  7584. if (player->RemoveCoins(gold * 10000)) {
  7585. mail_window.coin_gold += gold;
  7586. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7587. ret = true;
  7588. }
  7589. }
  7590. else if (plat > 0) {
  7591. if (player->RemoveCoins(plat * 1000000)) {
  7592. mail_window.coin_plat += plat;
  7593. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7594. ret = true;
  7595. }
  7596. }
  7597. if (ret) {
  7598. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7599. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7600. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7601. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7602. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7603. if(item)
  7604. {
  7605. packet->setDataByName("stack", mail_window.stack);
  7606. item->stack_count = mail_window.stack;
  7607. if (version < 860)
  7608. packet->setItemByName("item", item, player, 0, -1);
  7609. else if (version < 1193)
  7610. packet->setItemByName("item", item, player, 0, 0);
  7611. else
  7612. packet->setItemByName("item", item, player, 0, 2);
  7613. }
  7614. else
  7615. {
  7616. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7617. packet->setDataByName("end_tag3", 0xFF);
  7618. }
  7619. //packet->PrintPacket();
  7620. QueuePacket(packet->serialize());
  7621. }
  7622. else
  7623. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7624. safe_delete(packet);
  7625. }
  7626. MMailWindowMutex.unlock();
  7627. }
  7628. else
  7629. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7630. return ret;
  7631. }
  7632. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7633. bool ret = false;
  7634. if (GetMailTransaction()) {
  7635. MMailWindowMutex.lock();
  7636. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7637. if (packet) {
  7638. if (copper > 0) {
  7639. player->AddCoins(copper);
  7640. mail_window.coin_copper -= copper;
  7641. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7642. ret = true;
  7643. }
  7644. else if (silver > 0) {
  7645. player->AddCoins(silver * 100);
  7646. mail_window.coin_silver -= silver;
  7647. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7648. ret = true;
  7649. }
  7650. else if (gold > 0) {
  7651. player->AddCoins(gold * 10000);
  7652. mail_window.coin_gold -= gold;
  7653. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7654. ret = true;
  7655. }
  7656. else if (plat > 0) {
  7657. player->AddCoins(plat * 1000000);
  7658. mail_window.coin_plat -= plat;
  7659. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7660. ret = true;
  7661. }
  7662. if (ret) {
  7663. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7664. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7665. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7666. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7667. packet->setDataByName("stack", 0);
  7668. packet->setDataByName("packettype", 0x2BFE);
  7669. packet->setDataByName("packetsubtype", 0xFF);
  7670. packet->setDataByName("unknown2", 0);
  7671. QueuePacket(packet->serialize());
  7672. }
  7673. safe_delete(packet);
  7674. }
  7675. MMailWindowMutex.unlock();
  7676. }
  7677. else
  7678. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7679. return ret;
  7680. }
  7681. void Client::TakeMailAttachments(int32 mail_id) {
  7682. if (GetMailTransaction()) {
  7683. Mail* mail = player->GetMail(mail_id);
  7684. if (mail) {
  7685. int64 amount = 0;
  7686. if (mail->coin_copper > 0) {
  7687. amount += mail->coin_copper;
  7688. mail->coin_copper = 0;
  7689. }
  7690. if (mail->coin_silver > 0) {
  7691. amount += mail->coin_silver * 100;
  7692. mail->coin_silver = 0;
  7693. }
  7694. if (mail->coin_gold > 0) {
  7695. amount += mail->coin_gold * 10000;
  7696. mail->coin_gold = 0;
  7697. }
  7698. if (mail->coin_plat > 0) {
  7699. amount += mail->coin_plat * 1000000;
  7700. mail->coin_plat = 0;
  7701. }
  7702. if (mail->char_item_id > 0) {
  7703. AddItem(mail->char_item_id, mail->stack);
  7704. mail->char_item_id = 0;
  7705. mail->stack = 0;
  7706. }
  7707. /* 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
  7708. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7709. find it in any packet logs.*/
  7710. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7711. if (packet) {
  7712. packet->setDataByName("unknown", 0x03);
  7713. packet->setDataByName("coin_copper", mail->coin_copper);
  7714. packet->setDataByName("coin_silver", mail->coin_silver);
  7715. packet->setDataByName("coin_gold", mail->coin_gold);
  7716. packet->setDataByName("coin_plat", mail->coin_plat);
  7717. packet->setDataByName("stack", 0);
  7718. packet->setDataByName("packettype", 0x2BFE);
  7719. packet->setDataByName("packetsubtype", 0xFF);
  7720. packet->setDataByName("unknown2", 0);
  7721. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7722. DumpPacket(packet->serialize());
  7723. QueuePacket(packet->serialize());
  7724. safe_delete(packet);
  7725. }*/
  7726. database.SavePlayerMail(mail);
  7727. if (amount > 0)
  7728. player->AddCoins(amount);
  7729. SendMailList();
  7730. }
  7731. }
  7732. else
  7733. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7734. }
  7735. void Client::ResetSendMail(bool cancel, bool needslock) {
  7736. if(cancel && mail_transaction)
  7737. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7738. if(needslock)
  7739. MMailWindowMutex.lock();
  7740. if(cancel)
  7741. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7742. if(!cancel)
  7743. mail_transaction = 0;
  7744. mail_window.coin_copper = 0;
  7745. mail_window.coin_silver = 0;
  7746. mail_window.coin_gold = 0;
  7747. mail_window.coin_plat = 0;
  7748. mail_window.char_item_id = 0;
  7749. mail_window.stack = 0;
  7750. if(mail_window.item){
  7751. if(cancel)
  7752. AddItem(mail_window.item);
  7753. else
  7754. safe_delete(mail_window.item);
  7755. }
  7756. mail_window.item = nullptr;
  7757. if(needslock)
  7758. MMailWindowMutex.unlock();
  7759. }
  7760. bool Client::GateAllowed() {
  7761. ZoneServer* zone = GetCurrentZone();
  7762. if (zone){
  7763. bool cangate = zone->GetCanGate();
  7764. return cangate;
  7765. }
  7766. return false;
  7767. }
  7768. bool Client::BindAllowed() {
  7769. ZoneServer* zone = GetCurrentZone();
  7770. if (zone){
  7771. bool canbind = zone->GetCanBind();
  7772. return canbind;
  7773. }
  7774. return false;
  7775. }
  7776. bool Client::Bind() {
  7777. int canbind = BindAllowed();
  7778. if(canbind == 0) {
  7779. Message(CHANNEL_MERCHANT, "You cannot bind at this location.");
  7780. return false;
  7781. }
  7782. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7783. player->GetPlayerInfo()->SetBindX(player->GetX());
  7784. player->GetPlayerInfo()->SetBindY(player->GetY());
  7785. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7786. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7787. Message(CHANNEL_MERCHANT, "Your spirit has been bound to this location.");
  7788. return true;
  7789. }
  7790. bool Client::Gate(bool is_spell) {
  7791. if (player->GetPlayerInfo()->GetBindZoneID() == 0) {
  7792. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells. You have no bind location set.");
  7793. return false;
  7794. }
  7795. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7796. if (zone) {
  7797. int cangate = GateAllowed();
  7798. if(cangate == 0) {
  7799. SimpleMessage(CHANNEL_MERCHANT, "You can not cast recall spells in this zone.");
  7800. return false;
  7801. }
  7802. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7803. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7804. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7805. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7806. Zone(zone, false, is_spell);
  7807. return true;
  7808. }
  7809. return false;
  7810. }
  7811. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7812. if (!destinations || !spawn) {
  7813. return;
  7814. }
  7815. bool has_map = false;
  7816. if (transport_id > 0)
  7817. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7818. transport_spawn = spawn;
  7819. vector<TransportDestination*> transport_list;
  7820. vector<TransportDestination*>::iterator itr;
  7821. TransportDestination* destination = 0;
  7822. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7823. destination = *itr;
  7824. 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)))
  7825. transport_list.push_back(destination);
  7826. }
  7827. if (transport_list.size() == 0 && destination) {
  7828. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7829. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7830. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7831. else
  7832. {
  7833. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7834. if (app)
  7835. QueuePacket(app);
  7836. }
  7837. }
  7838. else {
  7839. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7840. // determine if this is an instanced zone that already exists
  7841. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7842. if (instance_zone || new_zone) {
  7843. GetPlayer()->SetX(destination->destination_x);
  7844. GetPlayer()->SetY(destination->destination_y);
  7845. GetPlayer()->SetZ(destination->destination_z);
  7846. GetPlayer()->SetHeading(destination->destination_heading);
  7847. if (instance_zone)
  7848. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7849. else
  7850. Zone(new_zone, false, is_spell);
  7851. }
  7852. }
  7853. if (destination->message.length() > 0)
  7854. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7855. }
  7856. else if (transport_list.size() > 0) {
  7857. if (!spawn->IsSoundsDisabled())
  7858. PlaySound("mariner_bell");
  7859. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7860. if (packet) {
  7861. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7862. // Put all the destinations the player can go in a new vector
  7863. vector<TransportDestination*> destinations;
  7864. for (int32 i = 0; i < transport_list.size(); i++) {
  7865. destination = transport_list.at(i);
  7866. // Check min level
  7867. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7868. continue;
  7869. // Check max level
  7870. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7871. continue;
  7872. // Check quest complete
  7873. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7874. continue;
  7875. // Check req quest and step
  7876. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7877. continue;
  7878. // 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
  7879. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7880. packet->setDataByName("current_zone", destination->display_name.c_str());
  7881. packet->setDataByName("current_map_x", destination->map_x);
  7882. packet->setDataByName("current_map_y", destination->map_y);
  7883. }
  7884. else {
  7885. destinations.push_back(destination);
  7886. }
  7887. }
  7888. // Use the new vector to create the packet
  7889. destination = 0;
  7890. packet->setArrayLengthByName("num_destinations", destinations.size());
  7891. for (int32 i = 0; i < destinations.size(); i++) {
  7892. destination = destinations.at(i);
  7893. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7894. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7895. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7896. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7897. packet->setArrayDataByName("cost", destination->cost, i);
  7898. if (has_map) {
  7899. packet->setArrayDataByName("map_x", destination->map_x, i);
  7900. packet->setArrayDataByName("map_y", destination->map_y, i);
  7901. }
  7902. }
  7903. if (has_map)
  7904. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7905. EQ2Packet* app = packet->serialize();
  7906. //DumpPacket(app);
  7907. if (destinations.size() > 0)
  7908. QueuePacket(app);
  7909. safe_delete(packet);
  7910. }
  7911. }
  7912. }
  7913. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7914. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7915. if (packet) {
  7916. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7917. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7918. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7919. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7920. int32 cost = packet->getType_int32_ByName("cost");
  7921. vector<TransportDestination*> destinations;
  7922. TransportDestination* destination = 0;
  7923. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7924. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7925. vector<TransportDestination*>::iterator itr;
  7926. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7927. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7928. destination = *itr;
  7929. break;
  7930. }
  7931. }
  7932. SetTemporaryTransportID(0);
  7933. if (!destination)
  7934. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7935. else {
  7936. if (cost == 0 || player->RemoveCoins(cost)) {
  7937. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7938. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7939. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7940. else
  7941. {
  7942. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7943. if (outapp)
  7944. QueuePacket(outapp);
  7945. }
  7946. }
  7947. else {
  7948. GetPlayer()->SetX(destination->destination_x);
  7949. GetPlayer()->SetY(destination->destination_y);
  7950. GetPlayer()->SetZ(destination->destination_z);
  7951. GetPlayer()->SetHeading(destination->destination_heading);
  7952. // Test if where we're going is an Instanced zone
  7953. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7954. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7955. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7956. Zone(new_zone, false);
  7957. }
  7958. }
  7959. if (destination->message.length() > 0)
  7960. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7961. }
  7962. else
  7963. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7964. }
  7965. }
  7966. safe_delete(packet);
  7967. }
  7968. }
  7969. void Client::SendNewSpells(int8 class_id) {
  7970. if (class_id > 0) {
  7971. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7972. vector<Spell*>::iterator itr;
  7973. Spell* spell = 0;
  7974. bool send_updates = false;
  7975. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7976. spell = *itr;
  7977. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7978. send_updates = true;
  7979. SendSpellUpdate(spell);
  7980. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7981. player->UnlockSpell(spell);
  7982. }
  7983. }
  7984. if (send_updates) {
  7985. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7986. if (outapp)
  7987. QueuePacket(outapp);
  7988. }
  7989. safe_delete(spells);
  7990. }
  7991. }
  7992. void Client::SetItemSearch(vector<Item*>* items) {
  7993. if (items) {
  7994. safe_delete(search_items);
  7995. search_items = items;
  7996. }
  7997. }
  7998. vector<Item*>* Client::GetSearchItems() {
  7999. return search_items;
  8000. }
  8001. void Client::SearchStore(int32 page) {
  8002. if (search_items) {
  8003. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  8004. if (packet) {
  8005. int32 x = page * 8;
  8006. if (search_items->size() > 8) {
  8007. if ((search_items->size() - x) > 8)
  8008. packet->setArrayLengthByName("num_items", 8);
  8009. else
  8010. packet->setArrayLengthByName("num_items", search_items->size() - x);
  8011. }
  8012. else
  8013. packet->setArrayLengthByName("num_items", search_items->size());
  8014. if (search_items->size() > 0) {
  8015. packet->setArrayLengthByName("num_sellers", 1);
  8016. packet->setArrayDataByName("seller_seller_id", 1);
  8017. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  8018. packet->setDataByName("per_page", 8);
  8019. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  8020. packet->setDataByName("page", page);
  8021. Item* item = 0;
  8022. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  8023. for (int32 i = 0; i < limit; i++, x++) {
  8024. if (x >= search_items->size())
  8025. break;
  8026. item = search_items->at(x);
  8027. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8028. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  8029. packet->setArrayDataByName("icon", item->details.icon, i);
  8030. //packet->setArrayDataByName("unknown2b", i, i);
  8031. packet->setArrayDataByName("item_seller_id", 1, i);
  8032. if (item->stack_count == 0)
  8033. packet->setArrayDataByName("quantity", 1, i);
  8034. else
  8035. packet->setArrayDataByName("quantity", item->stack_count, i);
  8036. packet->setArrayDataByName("stack_size", item->stack_count, i);
  8037. std::string tmpStr("");
  8038. tmpStr.append(item->name.c_str());
  8039. tmpStr.append(" (");
  8040. tmpStr.append(std::to_string(item->details.item_id));
  8041. tmpStr.append(")");
  8042. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  8043. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  8044. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  8045. }
  8046. }
  8047. /*EQ2Packet* outapp = packet->serialize();
  8048. DumpPacket(outapp);
  8049. QueuePacket(outapp);*/
  8050. QueuePacket(packet->serialize());
  8051. safe_delete(packet);
  8052. }
  8053. }
  8054. }
  8055. void Client::SetReadyForUpdates() {
  8056. GetPlayer()->SetFullyLoggedIn(true);
  8057. if (!ready_for_updates)
  8058. database.loadCharacterProperties(this);
  8059. ready_for_updates = true;
  8060. }
  8061. void Client::SetReadyForSpawns(bool val) {
  8062. ready_for_spawns = val;
  8063. if (GetPlayer()->GetActivityStatus() > 0) {
  8064. GetPlayer()->SetActivityStatus(0);
  8065. if (GetPlayer()->GetGroupMemberInfo()) {
  8066. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  8067. }
  8068. }
  8069. GetPlayer()->SetActiveReward(false);
  8070. zone_list.CheckFriendZoned(this);
  8071. }
  8072. void Client::SendChatRelationship(int8 type, const char* name) {
  8073. if (!name) {
  8074. return;
  8075. }
  8076. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8077. if (packet) {
  8078. packet->setDataByName("account_id", GetAccountID());
  8079. packet->setDataByName("type", type);
  8080. packet->setArrayLengthByName("num_names", 1);
  8081. packet->setArrayDataByName("name", name);
  8082. if (type == 0) {
  8083. Client* client = zone_list.GetClientByCharName(name);
  8084. if (client) {
  8085. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  8086. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  8087. }
  8088. }
  8089. QueuePacket(packet->serialize());
  8090. safe_delete(packet);
  8091. }
  8092. }
  8093. void Client::SendFriendList() {
  8094. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8095. if (packet) {
  8096. packet->setDataByName("account_id", GetAccountID());
  8097. map<string, int8>::iterator itr;
  8098. map<string, int8>* friends = player->GetFriends();
  8099. if (friends && friends->size() > 0) {
  8100. Client* client = 0;
  8101. vector<string> names;
  8102. for (itr = friends->begin(); itr != friends->end(); itr++) {
  8103. if (itr->second == 2)
  8104. continue;
  8105. names.push_back(itr->first);
  8106. }
  8107. packet->setArrayLengthByName("num_names", names.size());
  8108. for (int32 i = 0; i < names.size(); i++) {
  8109. client = zone_list.GetClientByCharName(names[i]);
  8110. packet->setArrayDataByName("name", names[i].c_str(), i);
  8111. if (client) {
  8112. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  8113. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  8114. }
  8115. }
  8116. }
  8117. QueuePacket(packet->serialize());
  8118. safe_delete(packet);
  8119. }
  8120. }
  8121. void Client::SendIgnoreList() {
  8122. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  8123. if (packet) {
  8124. packet->setDataByName("account_id", GetAccountID());
  8125. packet->setDataByName("type", 2);
  8126. map<string, int8>::iterator itr;
  8127. map<string, int8>* ignored = player->GetIgnoredPlayers();
  8128. if (ignored && ignored->size() > 0) {
  8129. vector<string> names;
  8130. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  8131. if (itr->second == 2)
  8132. continue;
  8133. names.push_back(itr->first);
  8134. }
  8135. packet->setArrayLengthByName("num_names", names.size());
  8136. for (int32 i = 0; i < names.size(); i++)
  8137. packet->setArrayDataByName("name", names[i].c_str(), i);
  8138. }
  8139. QueuePacket(packet->serialize());
  8140. safe_delete(packet);
  8141. }
  8142. }
  8143. void Client::AddWaypoint(string name, int8 type) {
  8144. waypoint_id++;
  8145. WaypointInfo info;
  8146. info.id = waypoint_id;
  8147. info.type = type;
  8148. waypoints[name] = info;
  8149. }
  8150. void Client::SendWaypoints() {
  8151. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8152. if (packet) {
  8153. packet->setArrayLengthByName("num_updates", waypoints.size());
  8154. map<string, WaypointInfo>::iterator itr;
  8155. int16 i = 0;
  8156. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8157. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  8158. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  8159. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  8160. i++;
  8161. }
  8162. packet->setDataByName("unknown", 0xFFFFFFFF);
  8163. QueuePacket(packet->serialize());
  8164. safe_delete(packet);
  8165. }
  8166. }
  8167. void Client::SelectWaypoint(int32 id) {
  8168. string found_name = "";
  8169. map<string, WaypointInfo>::iterator itr;
  8170. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  8171. if (itr->second.id == id) {
  8172. found_name = itr->first;
  8173. break;
  8174. }
  8175. }
  8176. if (found_name.length() > 0) {
  8177. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  8178. ShowPathToTarget(spawn);
  8179. }
  8180. }
  8181. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  8182. if (waypoint_name) {
  8183. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  8184. if (packet) {
  8185. packet->setArrayLengthByName("num_updates", 1);
  8186. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  8187. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  8188. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  8189. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  8190. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  8191. packet->setDataByName("unknown", 0xFFFFFFFF);
  8192. QueuePacket(packet->serialize());
  8193. safe_delete(packet);
  8194. }
  8195. }
  8196. }
  8197. void Client::ClearWaypoint() {
  8198. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8199. if (packet) {
  8200. QueuePacket(packet->serialize());
  8201. safe_delete(packet);
  8202. }
  8203. }
  8204. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  8205. if (current_zone->pathing) {
  8206. if (GetPlayer()->GetMap()) {
  8207. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  8208. return false;
  8209. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  8210. return false;
  8211. auto loc = glm::vec3(x, z, y);
  8212. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  8213. if (new_z != BEST_Z_INVALID) //this is actually y
  8214. y = new_z;
  8215. }
  8216. bool partial = false;
  8217. bool stuck = false;
  8218. PathfinderOptions opts;
  8219. opts.smooth_path = true;
  8220. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  8221. opts.offset = y_offset + 1.0f;
  8222. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  8223. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8224. if (packet) {
  8225. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  8226. packet->setArrayLengthByName("num_points", path.size());
  8227. int i = 0;
  8228. for (auto& node : path)
  8229. {
  8230. packet->setArrayDataByName("x", node.pos.x, i);
  8231. packet->setArrayDataByName("y", node.pos.z, i);
  8232. packet->setArrayDataByName("z", node.pos.y, i);
  8233. packet->setDataByName("waypoint_x", x);
  8234. packet->setDataByName("waypoint_y", y);
  8235. packet->setDataByName("waypoint_z", z);
  8236. i++;
  8237. }
  8238. if (i > 0)
  8239. QueuePacket(packet->serialize());
  8240. safe_delete(packet);
  8241. return (i > 0);
  8242. }
  8243. }
  8244. return false;
  8245. }
  8246. bool Client::ShowPathToTarget(Spawn* spawn) {
  8247. if (spawn) {
  8248. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  8249. }
  8250. return false;
  8251. }
  8252. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  8253. if (waypoint_name) {
  8254. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8255. if (packet) {
  8256. packet->setArrayLengthByName("num_points", 1);
  8257. packet->setArrayDataByName("x", x, 0);
  8258. packet->setArrayDataByName("y", y, 0);
  8259. packet->setArrayDataByName("z", z, 0);
  8260. packet->setDataByName("waypoint_x", x);
  8261. packet->setDataByName("waypoint_y", y);
  8262. packet->setDataByName("waypoint_z", z);
  8263. packet->setDataByName("waypoint_name", waypoint_name);
  8264. packet->setDataByName("unknown", 0);
  8265. QueuePacket(packet->serialize());
  8266. safe_delete(packet);
  8267. }
  8268. }
  8269. }
  8270. void Client::InspectPlayer(Player* player_to_inspect) {
  8271. int source_pvp_alignment = GetPlayer()->GetPVPAlignment();
  8272. int target_pvp_alignment = player_to_inspect->GetPVPAlignment();
  8273. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8274. if(pvp_allowed == true){
  8275. if(source_pvp_alignment != target_pvp_alignment){
  8276. Message(CHANNEL_COLOR_RED, "You can not inspect players of different alignments.");
  8277. return;
  8278. }
  8279. }
  8280. if (player_to_inspect) {
  8281. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  8282. if (packet) {
  8283. packet->setDataByName("unknown", 0);
  8284. packet->setSmallStringByName("name", player_to_inspect->GetName());
  8285. packet->setDataByName("race", player_to_inspect->GetRace());
  8286. packet->setDataByName("gender", player_to_inspect->GetGender());
  8287. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  8288. int16 effective_level = player_to_inspect->GetInfoStruct()->get_effective_level() != 0 ? player_to_inspect->GetInfoStruct()->get_effective_level() : player_to_inspect->GetLevel();
  8289. packet->setDataByName("adventure_level_effective", effective_level);
  8290. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  8291. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  8292. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  8293. packet->setDataByName("health", player_to_inspect->GetHP());
  8294. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  8295. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  8296. packet->setDataByName("power", player_to_inspect->GetPower());
  8297. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  8298. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  8299. packet->setDataByName("mitigation", player_to_inspect->GetInfoStruct()->get_cur_mitigation());
  8300. packet->setDataByName("unknown1", 0);
  8301. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_avoidance_display()*10.0f);
  8302. packet->setDataByName("unknown2", 0);
  8303. packet->setDataByName("mitigation_percentage", 0);
  8304. packet->setDataByName("strength", player_to_inspect->GetStr());
  8305. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  8306. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8307. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8308. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8309. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8310. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8311. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8312. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8313. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8314. packet->setDataByName("unknown4", 0);
  8315. packet->setDataByName("unknown5", 0);
  8316. packet->setDataByName("unknown6", 0);
  8317. packet->setDataByName("unknown7", 0);
  8318. packet->setDataByName("unknown8", 0);
  8319. packet->setDataByName("unknown9", 0);
  8320. packet->setDataByName("unknown10", 0);
  8321. packet->setDataByName("unknown11", 0);
  8322. packet->setDataByName("unknown12", 0);
  8323. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8324. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8325. packet->setDataByName("heat_resist_percentage", 0);
  8326. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8327. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8328. packet->setDataByName("cold_resist_percentage", 0);
  8329. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8330. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8331. packet->setDataByName("magic_resist_percentage", 0);
  8332. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8333. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8334. packet->setDataByName("mental_resist_percentage", 0);
  8335. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8336. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8337. packet->setDataByName("divine_resist_percentage", 0);
  8338. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8339. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8340. packet->setDataByName("disease_resist_percentage", 0);
  8341. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8342. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8343. packet->setDataByName("poison_resist_percentage", 0);
  8344. packet->setArrayLengthByName("num_chars", 0x01FF);
  8345. string biography = player_to_inspect->GetBiography();
  8346. for (size_t i = 0; i < biography.length(); i++)
  8347. packet->setArrayDataByName("biography_char", biography[i], i);
  8348. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  8349. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  8350. if (pw)
  8351. packet->setItemByName("primary", pw, player_to_inspect, 0);
  8352. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  8353. if (sw)
  8354. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  8355. //DumpPacket(packet->serialize());
  8356. QueuePacket(packet->serialize());
  8357. safe_delete(packet);
  8358. }
  8359. }
  8360. }
  8361. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8362. pending_guild_invite.guild = guild;
  8363. pending_guild_invite.invited_by = invited_by;
  8364. }
  8365. void Client::ShowClaimWindow() {
  8366. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8367. if (packet) {
  8368. map<int32, Item*>* items = &master_item_list.items;
  8369. map<int32, Item*>::iterator itr;
  8370. int32 i = 0;
  8371. if (items->size() > 10)
  8372. packet->setArrayLengthByName("num_claim_items", 10);
  8373. else
  8374. packet->setArrayLengthByName("num_claim_items", items->size());
  8375. for (itr = items->begin(); itr != items->end(); itr++) {
  8376. if (i == 10)
  8377. break;
  8378. Item* item = itr->second;
  8379. packet->setArrayDataByName("id", i, i);
  8380. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8381. packet->setArrayDataByName("num_remaining", 5, i);
  8382. packet->setArrayDataByName("one_per_character", 1, i);
  8383. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8384. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8385. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8386. packet->setArrayDataByName("category", "Scott's Shit", i);
  8387. packet->setArrayDataByName("icon", item->details.icon, i);
  8388. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8389. i++;
  8390. }
  8391. packet->setDataByName("unknown3", 1);
  8392. QueuePacket(packet->serialize());
  8393. safe_delete(packet);
  8394. }
  8395. }
  8396. void Client::ShowGuildSearchWindow() {
  8397. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8398. if (packet) {
  8399. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8400. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8401. packet->setArrayLengthByName("num_guilds", guilds->size());
  8402. int32 i = 0;
  8403. while (itr.Next()) {
  8404. Guild* guild = itr.second;
  8405. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8406. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8407. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8408. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8409. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8410. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8411. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8412. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8413. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8414. packet->setArrayDataByName("unknown7", 0x02, i);
  8415. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8416. i++;
  8417. }
  8418. QueuePacket(packet->serialize());
  8419. safe_delete(packet);
  8420. }
  8421. }
  8422. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8423. PacketStruct* packet;
  8424. vector<int8>* slot_data;
  8425. vector<int8>::iterator itr;
  8426. int32 slots = 0;
  8427. assert(item);
  8428. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8429. return;
  8430. }
  8431. slot_data = &item->slot_data;
  8432. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8433. if (version >= 1188)
  8434. slots = *itr;
  8435. else
  8436. slots += (int8)pow(2.0, *itr);
  8437. }
  8438. packet->setDataByName("slot", slots);
  8439. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8440. if (slots == 2) {
  8441. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8442. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8443. }
  8444. else {
  8445. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8446. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8447. }
  8448. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8449. if (slots == 4) {
  8450. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8451. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8452. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8453. }
  8454. else if (slots == 7) {
  8455. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8456. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8457. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8458. }
  8459. else {
  8460. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8461. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8462. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8463. }
  8464. packet->setDataByName("icon", item->details.icon);
  8465. packet->setDataByName("item_id", item->details.item_id);
  8466. packet->setDataByName("item_crc", crc);
  8467. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8468. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8469. packet->setDataByName("unknown5", 0xFF, 9);
  8470. packet->setDataByName("unknown5", 0xFF, 10);
  8471. QueuePacket(packet->serialize());
  8472. safe_delete(packet);
  8473. }
  8474. void Client::SendCollectionList() {
  8475. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8476. map<int32, Collection*>::iterator itr;
  8477. vector<struct CollectionItem*>* collection_items;
  8478. Collection* collection;
  8479. struct CollectionItem* collection_item;
  8480. PacketStruct* packet = 0;
  8481. int16 i = 0, j;
  8482. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8483. return;
  8484. packet->setArrayLengthByName("num_collections", collections->size());
  8485. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8486. collection = itr->second;
  8487. collection_items = collection->GetCollectionItems();
  8488. packet->setArrayDataByName("unknown", 1, i);
  8489. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8490. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8491. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8492. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8493. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8494. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8495. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8496. for (j = 0; j < collection_items->size(); j++) {
  8497. collection_item = collection_items->at(j);
  8498. Item* item = master_item_list.GetItem(collection_item->item);
  8499. if (item) {
  8500. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8501. if (version < 955)
  8502. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8503. else
  8504. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8505. }
  8506. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8507. }
  8508. i++;
  8509. }
  8510. packet->setDataByName("new_collection_flag", 1);
  8511. QueuePacket(packet->serialize());
  8512. safe_delete(packet);
  8513. }
  8514. bool Client::SendCollectionsForItem(Item* item) {
  8515. map<int32, Collection*> collections_to_send;
  8516. map<int32, Collection*>* collections;
  8517. map<int32, Collection*>::iterator itr;
  8518. vector<struct CollectionItem*>* collection_items;
  8519. Collection* collection;
  8520. struct CollectionItem* collection_item;
  8521. PacketStruct* packet;
  8522. int16 i;
  8523. assert(item);
  8524. /* get any collections required by this item that the player already has */
  8525. collections = player->GetCollectionList()->GetCollections();
  8526. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8527. collection = itr->second;
  8528. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8529. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8530. collections_to_send[collection->GetID()] = collection;
  8531. }
  8532. }
  8533. /* get any collections required by this item that the player does not have and send it to the client */
  8534. collections = master_collection_list.GetCollections();
  8535. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8536. collection = itr->second;
  8537. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8538. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8539. return false;
  8540. }
  8541. packet->setArrayLengthByName("num_collections", 1);
  8542. packet->setArrayDataByName("unknown", 1, 0);
  8543. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8544. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8545. packet->setArrayDataByName("completed", 0, 0);
  8546. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8547. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8548. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8549. packet->setArrayDataByName("unknown3", 0x28, 0);
  8550. collection_items = collection->GetCollectionItems();
  8551. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8552. for (i = 0; i < collection_items->size(); i++) {
  8553. collection_item = collection_items->at(i);
  8554. Item* item2 = master_item_list.GetItem(collection_item->item);
  8555. if (item2) {
  8556. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8557. if (version < 955)
  8558. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8559. else
  8560. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8561. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8562. }
  8563. }
  8564. packet->setDataByName("new_collection_flag", 0);
  8565. QueuePacket(packet->serialize());
  8566. safe_delete(packet);
  8567. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8568. collections_to_send[collection->GetID()] = collection;
  8569. }
  8570. }
  8571. /* send the client a list of collections that should be filtered for this item */
  8572. if (collections_to_send.size() > 0) {
  8573. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8574. return false;
  8575. }
  8576. i = 0;
  8577. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8578. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8579. collection = itr->second;
  8580. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8581. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8582. i++;
  8583. }
  8584. packet->setDataByName("item_icon", item->details.icon);
  8585. packet->setDataByName("item_name", item->name.c_str());
  8586. packet->setDataByName("item_id", item->details.item_id);
  8587. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8588. QueuePacket(packet->serialize());
  8589. safe_delete(packet);
  8590. }
  8591. return collections_to_send.size() > 0;
  8592. }
  8593. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8594. Collection* collection;
  8595. struct CollectionItem* collection_item;
  8596. PacketStruct* packet;
  8597. char tmp[200] = { 0 };
  8598. assert(item);
  8599. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8600. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8601. /* get the item struct that represents the item for this collection */
  8602. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8603. SendCollectionList();
  8604. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8605. return;
  8606. }
  8607. /* sanity check */
  8608. if (collection_item->found) {
  8609. SendCollectionList();
  8610. 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());
  8611. return;
  8612. }
  8613. }
  8614. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8615. collection = new Collection(collection);
  8616. /* get the item struct that represents the item for this collection */
  8617. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8618. SendCollectionList();
  8619. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8620. safe_delete(collection);
  8621. return;
  8622. }
  8623. /* add the new collection to the player's collection list */
  8624. if (!player->GetCollectionList()->AddCollection(collection)) {
  8625. SendCollectionList();
  8626. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8627. safe_delete(collection);
  8628. return;
  8629. }
  8630. }
  8631. else {
  8632. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8633. return;
  8634. }
  8635. collection_item->found = 1;
  8636. collection->SetSaveNeeded(true);
  8637. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8638. SendCollectionList();
  8639. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8640. return;
  8641. }
  8642. packet->setDataByName("collection_id", collection_id);
  8643. packet->setDataByName("collection_item_num", collection_item->index);
  8644. packet->setDataByName("add", 1);
  8645. QueuePacket(packet->serialize());
  8646. Item* item2 = master_item_list.GetItem(collection_item->item);
  8647. if (item2) {
  8648. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8649. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8650. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8651. }
  8652. safe_delete(packet);
  8653. RemoveItem(item, 1);
  8654. SendCollectionList();
  8655. }
  8656. void Client::DisplayCollectionComplete(Collection* collection) {
  8657. vector<struct CollectionRewardItem*>* reward_items;
  8658. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8659. struct CollectionRewardItem* reward_item;
  8660. PacketStruct* packet;
  8661. int32 i;
  8662. assert(collection);
  8663. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8664. return;
  8665. }
  8666. reward_items = collection->GetRewardItems();
  8667. selectable_reward_items = collection->GetSelectableRewardItems();
  8668. packet->setDataByName("title", "Quest Reward!");
  8669. packet->setDataByName("name", collection->GetName());
  8670. packet->setDataByName("description", collection->GetCategory());
  8671. packet->setDataByName("level", collection->GetLevel());
  8672. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8673. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8674. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8675. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8676. for (i = 0; i < reward_items->size(); i++) {
  8677. reward_item = reward_items->at(i);
  8678. if(!reward_item->item)
  8679. {
  8680. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8681. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8682. continue;
  8683. }
  8684. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8685. if (version < 860)
  8686. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8687. else if (version < 1193)
  8688. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8689. else
  8690. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8691. }
  8692. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8693. for (i = 0; i < selectable_reward_items->size(); i++) {
  8694. reward_item = selectable_reward_items->at(i);
  8695. if(!reward_item->item)
  8696. {
  8697. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8698. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8699. continue;
  8700. }
  8701. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8702. if (version < 860)
  8703. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8704. else if (version < 1193)
  8705. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8706. else
  8707. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8708. }
  8709. QueuePacket(packet->serialize());
  8710. safe_delete(packet);
  8711. }
  8712. void Client::HandInCollections() {
  8713. map<int32, Collection*>* collections;
  8714. map<int32, Collection*>::iterator itr;
  8715. Collection* collection;
  8716. /* only show 1 collection reward dialog at a time */
  8717. if (player->GetPendingCollectionReward()) {
  8718. return;
  8719. }
  8720. collections = player->GetCollectionList()->GetCollections();
  8721. /* 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
  8722. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8723. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8724. collection = itr->second;
  8725. if (collection->GetIsReadyToTurnIn()) {
  8726. player->SetPendingCollectionReward(collection);
  8727. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  8728. QuestRewardData* data = new QuestRewardData;
  8729. data->quest_id = 0;
  8730. data->is_temporary = false;
  8731. data->description = std::string("");
  8732. data->is_collection = true;
  8733. data->has_displayed = false;
  8734. data->tmp_coin = 0;
  8735. data->tmp_status = 0;
  8736. data->db_saved = false;
  8737. data->db_index = 0;
  8738. quest_pending_reward.push_back(data);
  8739. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  8740. quest_updates = true;
  8741. break;
  8742. }
  8743. }
  8744. if(quest_updates) {
  8745. SaveQuestRewardData(true);
  8746. }
  8747. }
  8748. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8749. vector<struct CollectionRewardItem*>* reward_items;
  8750. vector<struct CollectionRewardItem*>::iterator itr;
  8751. struct CollectionRewardItem* reward_item;
  8752. int16 num_slots_needed;
  8753. int16 num_slots;
  8754. assert(collection);
  8755. reward_items = collection->GetRewardItems();
  8756. num_slots_needed = (int16)reward_items->size();
  8757. if (selectable_item_id > 0)
  8758. num_slots_needed++;
  8759. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8760. if (num_slots < num_slots_needed) {
  8761. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8762. DisplayCollectionComplete(collection);
  8763. return;
  8764. }
  8765. /* add manditory items */
  8766. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8767. reward_item = *itr;
  8768. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8769. }
  8770. /* find and add the selectable item if there's one */
  8771. if (selectable_item_id > 0) {
  8772. reward_items = collection->GetSelectableRewardItems();
  8773. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8774. reward_item = *itr;
  8775. if (reward_item->item->details.item_id == selectable_item_id) {
  8776. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8777. break;
  8778. }
  8779. }
  8780. }
  8781. if (collection->GetRewardXP() > 0) {
  8782. player->AddXP((int32)collection->GetRewardXP());
  8783. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  8784. }
  8785. if (collection->GetRewardCoin() > 0) {
  8786. player->AddCoins(collection->GetRewardCoin());
  8787. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8788. }
  8789. collection->SetCompleted(true);
  8790. //update achievements for completeing collection here
  8791. collection->SetSaveNeeded(true);
  8792. SendCollectionList();
  8793. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8794. player->SetPendingCollectionReward(0);
  8795. RemoveQueuedQuestReward();
  8796. GetPlayer()->SetActiveReward(false);
  8797. HandInCollections();
  8798. }
  8799. void Client::SendRecipeList() {
  8800. PacketStruct* packet = 0;
  8801. if (GetRecipeListSent()) {
  8802. return;
  8803. }
  8804. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8805. return;
  8806. }
  8807. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8808. map<int32, Recipe*>::iterator itr;
  8809. Recipe* recipe;
  8810. int16 i = 0;
  8811. packet->setArrayLengthByName("num_recipes", recipes->size());
  8812. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8813. recipe = itr->second;
  8814. packet->setArrayDataByName("id", recipe->GetID(), i);
  8815. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8816. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8817. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8818. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8819. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8820. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8821. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8822. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8823. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8824. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8825. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8826. i++;
  8827. }
  8828. //packet->PrintPacket();
  8829. //DumpPacket(packet->serialize());
  8830. QueuePacket(packet->serialize());
  8831. safe_delete(packet);
  8832. SetRecipeListSent(true);
  8833. }
  8834. void Client::ShowRecipeBook() {
  8835. PacketStruct* packet = 0;
  8836. Spawn* target = 0;
  8837. if (!(target = player->GetTarget())) {
  8838. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8839. return;
  8840. }
  8841. if (!target->IsObject()) {
  8842. return;
  8843. }
  8844. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8845. return;
  8846. }
  8847. packet->setDataByName("device", target->GetName());
  8848. packet->setDataByName("unknown1", 1);
  8849. if (((Object*)target)->GetDeviceID() > 0) {
  8850. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8851. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8852. packet->setDataByName("unknown2", 8);
  8853. packet->setDataByName("unknown3", deviceID);
  8854. }
  8855. //packet->PrintPacket();
  8856. QueuePacket(packet->serialize());
  8857. safe_delete(packet);
  8858. }
  8859. void Client::SendTitleUpdate() {
  8860. // must call release read lock before leaving function on GetPlayerTitles
  8861. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8862. vector<Title*>::iterator itr;
  8863. Title* title;
  8864. sint32 i = 0;
  8865. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8866. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8867. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8868. if (packet) {
  8869. packet->setArrayLengthByName("num_titles", titles->size());
  8870. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8871. title = *itr;
  8872. packet->setArrayDataByName("title", title->GetName(), i);
  8873. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8874. i++;
  8875. }
  8876. packet->setDataByName("current_prefix", prefix_index);
  8877. packet->setDataByName("current_suffix", suffix_index);
  8878. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8879. #if EQDEBUG >= 9
  8880. packet->PrintPacket();
  8881. #endif
  8882. QueuePacket(packet->serialize());
  8883. safe_delete(packet);
  8884. SendUpdateTitles(prefix_index, suffix_index);
  8885. }
  8886. player->GetPlayerTitles()->ReleaseReadLock();
  8887. }
  8888. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8889. Title* suffix_title = 0;
  8890. Title* prefix_title = 0;
  8891. if (suffix != -1) {
  8892. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8893. if(suffix_title)
  8894. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8895. }
  8896. else
  8897. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8898. if (prefix != -1) {
  8899. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8900. if(prefix_title)
  8901. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8902. }
  8903. else
  8904. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8905. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8906. }
  8907. void Client::SendLanguagesUpdate(int32 id) {
  8908. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8909. list<Language*>::iterator itr;
  8910. Language* language;
  8911. int32 i = 0;
  8912. GetPlayer()->SetCurrentLanguage(id);
  8913. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8914. if (packet) {
  8915. packet->setArrayLengthByName("num_languages", languages->size());
  8916. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8917. language = *itr;
  8918. packet->setArrayDataByName("language_id", language->GetID(), i);
  8919. i++;
  8920. }
  8921. packet->setDataByName("current_language", id);
  8922. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8923. #if EQDEBUG >= 9
  8924. packet->PrintPacket();
  8925. #endif
  8926. QueuePacket(packet->serialize());
  8927. safe_delete(packet);
  8928. }
  8929. }
  8930. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8931. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8932. if (packet) {
  8933. if (pet_name)
  8934. packet->setDataByName("pet_name", pet_name);
  8935. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  8936. packet->setDataByName("protect_master", 1);
  8937. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  8938. packet->setDataByName("protect_self", 1);
  8939. if (player->GetInfoStruct()->get_pet_movement() == 2)
  8940. packet->setDataByName("stay_follow_toggle", 1);
  8941. packet->setDataByName("pet_type", type);
  8942. QueuePacket(packet->serialize());
  8943. }
  8944. safe_delete(packet);
  8945. }
  8946. bool Client::IsCrafting() {
  8947. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8948. }
  8949. void Client::SendBiography() {
  8950. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8951. if (packet) {
  8952. char biography[512];
  8953. if(player->GetInfoStruct()->get_biography().size() < 1)
  8954. {
  8955. safe_delete(packet);
  8956. return;
  8957. }
  8958. else
  8959. {
  8960. int16 size = player->GetInfoStruct()->get_biography().size();
  8961. if(size>511)
  8962. size = 511;
  8963. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  8964. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  8965. }
  8966. packet->setDataByName("biography", biography);
  8967. QueuePacket(packet->serialize());
  8968. }
  8969. safe_delete(packet);
  8970. }
  8971. PendingResurrection* Client::GetCurrentRez() {
  8972. return &current_rez;
  8973. }
  8974. Mutex* Client::GetResurrectMutex() {
  8975. return &m_resurrect;
  8976. }
  8977. void Client::SendResurrectionWindow() {
  8978. Spawn* caster = current_rez.caster;
  8979. if (!caster || !player)
  8980. return;
  8981. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8982. if (!packet)
  8983. return;
  8984. char* tmp = new char[512];
  8985. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8986. packet->setMediumStringByName("text", tmp);
  8987. packet->setMediumStringByName("accept_text", "Yes");
  8988. packet->setMediumStringByName("cancel_text", "No");
  8989. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8990. packet->setMediumStringByName("accept_command", tmp);
  8991. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8992. packet->setMediumStringByName("cancel_command", tmp);
  8993. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8994. QueuePacket(packet->serialize());
  8995. safe_delete(packet);
  8996. safe_delete_array(tmp);
  8997. }
  8998. void Client::AcceptResurrection() {
  8999. Spawn* caster = current_rez.caster;
  9000. if (!player || !caster)
  9001. return;
  9002. if (player->Alive())
  9003. return;
  9004. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  9005. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  9006. SendResurrectionWindow();
  9007. return;
  9008. }
  9009. player->GetZone()->ResurrectSpawn(player, this);
  9010. current_rez.should_delete = true;
  9011. }
  9012. void Client::SetPendingLastName(string last_name) {
  9013. pending_last_name = new string;
  9014. pending_last_name->assign(last_name);
  9015. }
  9016. string* Client::GetPendingLastName() {
  9017. return pending_last_name;
  9018. }
  9019. void Client::RemovePendingLastName() {
  9020. safe_delete(pending_last_name);
  9021. }
  9022. void Client::SendLastNameConfirmation() {
  9023. if (!pending_last_name)
  9024. return;
  9025. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  9026. if (packet) {
  9027. char* text = new char[128];
  9028. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  9029. packet->setDataByName("text", text);
  9030. packet->setDataByName("accept_text", "Yes");
  9031. packet->setDataByName("accept_command", "confirmedlastname");
  9032. packet->setDataByName("cancel_text", "No");
  9033. packet->setDataByName("max_length", 50);
  9034. packet->setDataByName("unknown4", 1);
  9035. packet->setDataByName("unknown5", 1);
  9036. QueuePacket(packet->serialize());
  9037. safe_delete(packet);
  9038. safe_delete_array(text);
  9039. }
  9040. }
  9041. void Client::AddQuestTimer(int32 quest_id) {
  9042. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9043. quest_timers.push_back(quest_id);
  9044. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9045. }
  9046. void Client::RemoveQuestTimer(int32 quest_id) {
  9047. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  9048. vector<int32>::iterator itr;
  9049. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  9050. if ((*itr) == quest_id) {
  9051. quest_timers.erase(itr);
  9052. break;
  9053. }
  9054. }
  9055. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  9056. }
  9057. void Client::SavePlayerImages() {
  9058. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  9059. // Save the paperdoll image if the server allows it
  9060. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  9061. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9062. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  9063. // Save the head shot if the server allows it
  9064. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  9065. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9066. // Send the head shot to the login server
  9067. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  9068. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  9069. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  9070. memset(packet->pBuffer, 0, size);
  9071. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  9072. pic->account_id = GetAccountID();
  9073. pic->char_id = GetCharacterID();
  9074. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  9075. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  9076. loginserver.SendPacket(packet);
  9077. safe_delete(packet);
  9078. }
  9079. }
  9080. safe_delete_array(incoming_paperdoll.image_bytes);
  9081. incoming_paperdoll.current_size_bytes = 0;
  9082. }
  9083. void Client::EndAutoMount() {
  9084. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9085. if (packet) {
  9086. packet->setDataByName("parameter1", 128);
  9087. packet->setDataByName("parameter2", 64);
  9088. packet->setDataByName("value", 1);
  9089. QueuePacket(packet->serialize());
  9090. safe_delete(packet);
  9091. }
  9092. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  9093. if (packet) {
  9094. packet->setDataByName("parameter3", 4);
  9095. packet->setDataByName("parameter5", 2);
  9096. packet->setDataByName("value", 0);
  9097. QueuePacket(packet->serialize());
  9098. safe_delete(packet);
  9099. }
  9100. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  9101. if (packet) {
  9102. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  9103. QueuePacket(packet->serialize());
  9104. safe_delete(packet);
  9105. }
  9106. on_auto_mount = false;
  9107. player->SetMount(((Player*)player)->GetTempMount());
  9108. EQ2_Color mount_color = player->GetTempMountColor();
  9109. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  9110. player->SetMountColor(&mount_color);
  9111. player->SetMountSaddleColor(&saddle_color);
  9112. player->SetTempMount(0);
  9113. }
  9114. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  9115. const char* spawn_script = spawn->GetSpawnScript();
  9116. bool should_use_spawn = true;
  9117. if (spawn_script) {
  9118. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  9119. if (state) {
  9120. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  9121. if (state_mutex)
  9122. state_mutex->writelock(__FUNCTION__, __LINE__);
  9123. lua_getglobal(state, "can_use_command");
  9124. if (lua_isfunction(state, -1)) {
  9125. lua_interface->SetSpawnValue(state, spawn);
  9126. lua_interface->SetSpawnValue(state, GetPlayer());
  9127. lua_interface->SetStringValue(state, command ? command : "");
  9128. if (lua_pcall(state, 3, 1, 0) == 0) {
  9129. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  9130. }
  9131. }
  9132. lua_interface->ResetFunctionStack(state);
  9133. if (state_mutex)
  9134. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  9135. }
  9136. }
  9137. return should_use_spawn;
  9138. }
  9139. bool Client::IsCurrentTransmuteID(int32 req_id) {
  9140. return req_id == transmuteID;
  9141. }
  9142. void Client::SetTransmuteID(int32 trans_id) {
  9143. transmuteID = trans_id;
  9144. }
  9145. int32 Client::GetTransmuteID() {
  9146. return transmuteID;
  9147. }
  9148. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  9149. {
  9150. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  9151. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  9152. if (zar)
  9153. {
  9154. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  9155. if (database.IsActiveQuery(charID))
  9156. {
  9157. delayedLogin = true;
  9158. delayedAccountID = account_id;
  9159. delayedAccessKey = access_code;
  9160. delayTimer.Start(500);
  9161. 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);
  9162. return true;
  9163. }
  9164. delayedLogin = false;
  9165. delayTimer.Disable();
  9166. firstlogin = zar->isFirstLogin();
  9167. 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);
  9168. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  9169. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  9170. GetPlayer()->vis_changed = false;
  9171. GetPlayer()->info_changed = false;
  9172. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  9173. if (pvp_allowed)
  9174. this->GetPlayer()->SetAttackable(1);
  9175. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  9176. Client* client = zone_list.GetClientByCharName(player->GetName());
  9177. if (client) {
  9178. if (client->getConnection())
  9179. client->getConnection()->SendDisconnect(true);
  9180. if (client->GetCurrentZone() && !client->IsZoning()) {
  9181. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  9182. if (client->GetVersion() == version) {
  9183. client->DisableSave();
  9184. client->ReplaceGroupClient(this);
  9185. Player* current_player = GetPlayer();
  9186. SetPlayer(client->GetPlayer());
  9187. GetPlayer()->SetClient(this);
  9188. GetPlayer()->SetReturningFromLD(true);
  9189. SetCurrentZone(GetPlayer()->GetZone());
  9190. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  9191. client->SetPlayer(current_player);
  9192. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  9193. GetPlayer()->ResetSavedSpawns();
  9194. }
  9195. ZoneServer* tmpZone = client->GetCurrentZone();
  9196. tmpZone->RemoveClientImmediately(client);
  9197. }
  9198. }
  9199. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  9200. if (!GetCurrentZone()) {
  9201. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  9202. ClientPacketFunctions::SendLoginDenied(this);
  9203. }
  9204. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  9205. getConnection()->SetClientVersion(version);
  9206. GetCurrentZone()->SetSpawnStructs(this);
  9207. connected_to_zone = true;
  9208. client_list.Remove(this); //remove from master client list
  9209. GetCurrentZone()->AddClient(this); //add to zones client list
  9210. zone_list.AddClientToMap(player->GetName(), this);
  9211. // 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.
  9212. new_client_login = true;
  9213. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  9214. if (zone_script && lua_interface)
  9215. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  9216. }
  9217. else {
  9218. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  9219. ClientPacketFunctions::SendLoginDenied(this);
  9220. return false;
  9221. }
  9222. }
  9223. else {
  9224. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  9225. ClientPacketFunctions::SendLoginDenied(this);
  9226. }
  9227. zone_auth.RemoveAuth(zar);
  9228. }
  9229. else
  9230. {
  9231. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  9232. Disconnect();
  9233. }
  9234. return true;
  9235. }
  9236. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  9237. if (!IsReadyForUpdates())
  9238. return;
  9239. map<int32, SpawnData> info_changes;
  9240. map<int32, SpawnData> pos_changes;
  9241. map<int32, SpawnData> vis_changes;
  9242. map<int32, SpawnData> empty_changes;
  9243. int32 info_size = 0;
  9244. int32 pos_size = 0;
  9245. int32 vis_size = 0;
  9246. int count = 0;
  9247. for (const auto& spawn : spawns) {
  9248. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  9249. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  9250. continue;
  9251. if (spawn->vis_changed)
  9252. {
  9253. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9254. if (vis_change) {
  9255. SpawnData data;
  9256. data.spawn = spawn;
  9257. data.data = vis_change;
  9258. data.size = spawn->vis_packet_size;
  9259. map<int32, SpawnData> tmp_vis_changes;
  9260. tmp_vis_changes[index] = data;
  9261. map<int32, SpawnData> tmp_info_changes;
  9262. map<int32, SpawnData> tmp_pos_changes;
  9263. int32 tmp_info_size = 0;
  9264. int32 tmp_pos_size = 0;
  9265. if (spawn->info_changed) {
  9266. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9267. if (info_change) {
  9268. SpawnData data;
  9269. data.spawn = spawn;
  9270. data.data = info_change;
  9271. data.size = spawn->info_packet_size;
  9272. tmp_info_size = data.size;
  9273. tmp_info_changes[index] = data;
  9274. }
  9275. }
  9276. if (spawn->position_changed) {
  9277. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9278. if (pos_change) {
  9279. SpawnData data;
  9280. data.spawn = spawn;
  9281. data.data = pos_change;
  9282. data.size = spawn->pos_packet_size;
  9283. tmp_pos_size = data.size;
  9284. tmp_pos_changes[index] = data;
  9285. }
  9286. }
  9287. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  9288. for (auto& kv : tmp_info_changes) {
  9289. safe_delete_array(kv.second.data);
  9290. }
  9291. for (auto& kv : tmp_pos_changes) {
  9292. safe_delete_array(kv.second.data);
  9293. }
  9294. for (auto& kv : tmp_vis_changes) {
  9295. safe_delete_array(kv.second.data);
  9296. }
  9297. continue;
  9298. }
  9299. }
  9300. if (spawn->info_changed) {
  9301. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9302. if (info_change) {
  9303. SpawnData data;
  9304. data.spawn = spawn;
  9305. data.data = info_change;
  9306. data.size = spawn->info_packet_size;
  9307. info_size += spawn->info_packet_size;
  9308. info_changes[index] = data;
  9309. }
  9310. count++;
  9311. }
  9312. if (spawn->position_changed) {
  9313. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9314. if (pos_change) {
  9315. SpawnData data;
  9316. data.spawn = spawn;
  9317. data.data = pos_change;
  9318. data.size = spawn->pos_packet_size;
  9319. pos_size += spawn->pos_packet_size;
  9320. pos_changes[index] = data;
  9321. }
  9322. count++;
  9323. }
  9324. if (spawn->vis_changed) {
  9325. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9326. if (vis_change) {
  9327. SpawnData data;
  9328. data.spawn = spawn;
  9329. data.data = vis_change;
  9330. data.size = spawn->vis_packet_size;
  9331. vis_size += spawn->vis_packet_size;
  9332. vis_changes[index] = data;
  9333. }
  9334. count++;
  9335. }
  9336. }
  9337. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9338. return;
  9339. }
  9340. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9341. for (auto& kv : info_changes) {
  9342. safe_delete_array(kv.second.data);
  9343. }
  9344. for (auto& kv : pos_changes) {
  9345. safe_delete_array(kv.second.data);
  9346. }
  9347. for (auto& kv : vis_changes) {
  9348. safe_delete_array(kv.second.data);
  9349. }
  9350. }
  9351. 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)
  9352. {
  9353. static const int8 oversized = 255;
  9354. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9355. int32 size = info_size + pos_size + vis_size + 8;
  9356. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9357. size += 3;
  9358. size += CheckOverLoadSize(info_size);
  9359. size += CheckOverLoadSize(pos_size);
  9360. size += CheckOverLoadSize(vis_size);
  9361. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9362. size += 2;
  9363. }
  9364. uchar* tmp = new uchar[size];
  9365. uchar* ptr = tmp;
  9366. memset(tmp, 0, size);
  9367. if (version <= 283) {
  9368. if (size >= 255) {
  9369. size -= 3;
  9370. memcpy(ptr, &oversized, sizeof(int8));
  9371. ptr += sizeof(int8);
  9372. memcpy(ptr, &size, sizeof(int16));
  9373. ptr += sizeof(int16);
  9374. size += 3;
  9375. }
  9376. else {
  9377. size -= 1;
  9378. memcpy(ptr, &size, sizeof(int8));
  9379. ptr += sizeof(int8);
  9380. size += 1;
  9381. }
  9382. }
  9383. else {
  9384. size -= 4;
  9385. memcpy(ptr, &size, sizeof(int32));
  9386. ptr += sizeof(int32);
  9387. size += 4;
  9388. }
  9389. memcpy(ptr, &oversized, sizeof(int8));
  9390. ptr += sizeof(int8);
  9391. memcpy(ptr, &opcode_val, sizeof(int16));
  9392. ptr += sizeof(int16);
  9393. int32 current_time = Timer::GetCurrentTime2();
  9394. memcpy(ptr, &current_time, sizeof(int32));
  9395. ptr += sizeof(int32);
  9396. ptr += DoOverLoad(info_size, ptr);
  9397. for (const auto& kv : info_changes) {
  9398. auto info = kv.second;
  9399. memcpy(ptr, info.data, info.size);
  9400. ptr += info.size;
  9401. }
  9402. ptr += DoOverLoad(pos_size, ptr);
  9403. for (const auto& kv : pos_changes) {
  9404. auto pos = kv.second;
  9405. memcpy(ptr, pos.data, pos.size);
  9406. ptr += pos.size;
  9407. }
  9408. ptr += DoOverLoad(vis_size, ptr);
  9409. for (const auto& kv : vis_changes) {
  9410. auto vis = kv.second;
  9411. memcpy(ptr, vis.data, vis.size);
  9412. ptr += vis.size;
  9413. }
  9414. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9415. if (packet) {
  9416. /*char blah[64];
  9417. snprintf(blah, 64, "Sending %i", current_time);
  9418. SimpleMessage(4, blah);*/
  9419. QueuePacket(packet);
  9420. }
  9421. delete[] tmp;
  9422. }
  9423. void Client::SendHailCommand(Spawn* spawn)
  9424. {
  9425. // hardcoded 'hail' entity commands
  9426. switch (spawn->secondary_command_list_id)
  9427. {
  9428. case 9:
  9429. case 1262:
  9430. case 1265:
  9431. case 1267:
  9432. {
  9433. EQ2_16BitString* command = new EQ2_16BitString();
  9434. command->data = "";
  9435. command->size = 0;
  9436. commands.Process(COMMAND_HAIL, command, this, spawn);
  9437. safe_delete(command);
  9438. break;
  9439. }
  9440. }
  9441. }
  9442. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9443. {
  9444. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9445. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9446. if (packet) {
  9447. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9448. packet->setMediumStringByName("command_name", command);
  9449. packet->setDataByName("distance", distance);
  9450. QueuePacket(packet->serialize());
  9451. safe_delete(packet);
  9452. }
  9453. }
  9454. }
  9455. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9456. {
  9457. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9458. return false;
  9459. if (command == "house_spawn_examine")
  9460. {
  9461. uint32 itemID = spawn->GetPickupItemID();
  9462. if (itemID)
  9463. {
  9464. Item* item = master_item_list.GetItem(itemID);
  9465. if (item)
  9466. {
  9467. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9468. //DumpPacket(app);
  9469. QueuePacket(app);
  9470. }
  9471. }
  9472. return true;
  9473. }
  9474. return false;
  9475. }
  9476. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9477. {
  9478. if (GetTempPlacementSpawn())
  9479. {
  9480. Spawn* tmp = GetTempPlacementSpawn();
  9481. int32 spawn_group_id = database.GetNextSpawnLocation();
  9482. tmp->SetSpawnLocationID(spawn_group_id);
  9483. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9484. int32 spawnDBID = 0;
  9485. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9486. {
  9487. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9488. tmp->SetDatabaseID(spawnDBID);
  9489. }
  9490. else
  9491. {
  9492. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9493. if (spawnDBID)
  9494. {
  9495. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9496. tmp->SetDatabaseID(spawnDBID);
  9497. }
  9498. }
  9499. tmp->SetX(place_object->getType_float_ByName("x"));
  9500. tmp->SetY(place_object->getType_float_ByName("y"));
  9501. tmp->SetZ(place_object->getType_float_ByName("z"));
  9502. tmp->SetHeading(newHeading);
  9503. tmp->SetSpawnOrigX(tmp->GetX());
  9504. tmp->SetSpawnOrigY(tmp->GetY());
  9505. tmp->SetSpawnOrigZ(tmp->GetZ());
  9506. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9507. database.SaveSpawnInfo(tmp);
  9508. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9509. if (!spawnDBID)
  9510. {
  9511. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9512. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  9513. }
  9514. return true;
  9515. }
  9516. return false;
  9517. }
  9518. bool Client::PopulateHouseSpawnFinalize()
  9519. {
  9520. if (GetTempPlacementSpawn())
  9521. {
  9522. Spawn* tmp = GetTempPlacementSpawn();
  9523. GetCurrentZone()->AddSpawn(tmp);
  9524. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9525. SetTempPlacementSpawn(nullptr);
  9526. int32 uniqueID = GetPlacementUniqueItemID();
  9527. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9528. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9529. tmp->SetPickupUniqueItemID(uniqueID);
  9530. if (uniqueItem)
  9531. {
  9532. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9533. {
  9534. Query query;
  9535. 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);
  9536. }
  9537. if(lua_interface->RunItemScript(uniqueItem->GetItemScript(), "placed", uniqueItem, GetPlayer(), tmp))
  9538. {
  9539. uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9540. }
  9541. if(uniqueItem) {
  9542. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9543. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9544. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9545. }
  9546. SetPlacementUniqueItemID(0);
  9547. }
  9548. return true;
  9549. }
  9550. return false;
  9551. }
  9552. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9553. {
  9554. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9555. packet->setDataByName("placement_mode", placementMode);
  9556. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9557. packet->setDataByName("model_type", spawn->GetModelType());
  9558. packet->setDataByName("unknown", 1); //size
  9559. packet->setDataByName("unknown2", 1); //size 2
  9560. packet->setDataByName("unknown2", .5, 1); //size 3
  9561. packet->setDataByName("unknown2", 3, 2);
  9562. packet->setDataByName("unknown2", unknown2_3, 3);
  9563. packet->setDataByName("max_distance", 500);
  9564. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9565. QueuePacket(packet->serialize());
  9566. safe_delete(packet);
  9567. }
  9568. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9569. {
  9570. SetPendingFlightPath(path_id);
  9571. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9572. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9573. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9574. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9575. if (packet) {
  9576. QueuePacket(packet->serialize());
  9577. safe_delete(packet);
  9578. }
  9579. if (mount_id)
  9580. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9581. }
  9582. void Client::SendShowBook(Spawn* sender, string title, int8 language, int8 num_pages, ...)
  9583. {
  9584. if (!sender)
  9585. {
  9586. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9587. return;
  9588. }
  9589. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9590. if (!packet) {
  9591. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9592. return;
  9593. }
  9594. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9595. packet->setDataByName("book_title", title.c_str());
  9596. packet->setDataByName("book_type", "simple");
  9597. packet->setDataByName("unknown2", 1);
  9598. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9599. packet->setDataByName("language", language);
  9600. if (GetVersion() > 546)
  9601. packet->setDataByName("unknown5", 1, 4);
  9602. packet->setArrayLengthByName("num_pages", num_pages);
  9603. va_list args;
  9604. va_start(args, num_pages);
  9605. std::string endString("");
  9606. for (int8 p = 0; p < num_pages; p++)
  9607. {
  9608. std::string page = va_arg(args, string);
  9609. switch (GetVersion())
  9610. {
  9611. // release client
  9612. case 283:
  9613. {
  9614. endString.append(page);
  9615. break;
  9616. }
  9617. // DoF trial
  9618. case 546:
  9619. {
  9620. if (p == 0)
  9621. packet->setDataByName("cover_page", page.c_str());
  9622. else
  9623. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9624. break;
  9625. }
  9626. // all other clients
  9627. default:
  9628. {
  9629. packet->setArrayDataByName("page_text", page.c_str(), p);
  9630. break;
  9631. }
  9632. }
  9633. }
  9634. if (GetVersion() == 283)
  9635. {
  9636. packet->setDataByName("page_text", endString.c_str());
  9637. }
  9638. va_end(args);
  9639. QueuePacket(packet->serialize());
  9640. safe_delete(packet);
  9641. }
  9642. void Client::SendShowBook(Spawn* sender, string title, int8 language, vector<Item::BookPage*> pages)
  9643. {
  9644. if (!sender)
  9645. {
  9646. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9647. return;
  9648. }
  9649. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9650. if (!packet) {
  9651. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9652. return;
  9653. }
  9654. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9655. packet->setDataByName("book_title", title.c_str());
  9656. packet->setDataByName("book_type", "simple");
  9657. packet->setDataByName("unknown2", 1);
  9658. if(language > 0 && !GetPlayer()->HasLanguage(language))
  9659. packet->setDataByName("language", language);
  9660. if (GetVersion() > 546)
  9661. packet->setDataByName("unknown5", 1, 4);
  9662. packet->setArrayLengthByName("num_pages", pages.size());
  9663. std::string endString("");
  9664. for (int8 p = 0; p < pages.size(); p++)
  9665. {
  9666. Item::BookPage* page = pages[p];
  9667. std::string pageText = string(page->page_text.data);
  9668. switch (GetVersion())
  9669. {
  9670. // release client
  9671. case 283:
  9672. {
  9673. endString.append(pageText);
  9674. break;
  9675. }
  9676. // DoF trial
  9677. case 546:
  9678. {
  9679. if (p == 0)
  9680. packet->setDataByName("cover_page", pageText.c_str());
  9681. else
  9682. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9683. break;
  9684. }
  9685. // all other clients
  9686. default:
  9687. {
  9688. int8 valign = int8(page->valign);
  9689. int8 halign = int8(page->halign);
  9690. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9691. packet->setArrayDataByName("page_text_valign", valign, p);
  9692. packet->setArrayDataByName("page_text_halign", halign, p);
  9693. break;
  9694. }
  9695. }
  9696. }
  9697. if (GetVersion() == 283)
  9698. {
  9699. packet->setDataByName("page_text", endString.c_str());
  9700. }
  9701. QueuePacket(packet->serialize());
  9702. safe_delete(packet);
  9703. }
  9704. void Client::ReplaceGroupClient(Client* new_client)
  9705. {
  9706. if (this->GetPlayer()->GetGroupMemberInfo())
  9707. {
  9708. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9709. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9710. if(group)
  9711. {
  9712. group->MGroupMembers.writelock();
  9713. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9714. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9715. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9716. group->MGroupMembers.releasewritelock();
  9717. }
  9718. else
  9719. {
  9720. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9721. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9722. this->GetPlayer()->SetGroupMemberInfo(0);
  9723. }
  9724. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9725. }
  9726. }
  9727. void Client::TempRemoveGroup()
  9728. {
  9729. if (this->GetPlayer()->GetGroupMemberInfo())
  9730. {
  9731. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9732. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9733. if(group)
  9734. {
  9735. group->MGroupMembers.writelock();
  9736. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9737. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9738. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9739. this->GetPlayer()->SetGroupMemberInfo(0);
  9740. group->MGroupMembers.releasewritelock();
  9741. group->RemoveClientReference(this);
  9742. }
  9743. else
  9744. {
  9745. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9746. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9747. this->GetPlayer()->SetGroupMemberInfo(0);
  9748. }
  9749. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9750. }
  9751. }
  9752. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9753. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9754. {
  9755. Mail mail;
  9756. memset(&mail,0,sizeof(Mail));
  9757. mail.player_to_id = charID;
  9758. mail.player_from = fromName;
  9759. mail.subject = subjectName;
  9760. mail.mail_body = mailBody;
  9761. mail.mail_type = mailType;
  9762. mail.coin_copper = copper;
  9763. mail.coin_silver = silver;
  9764. mail.coin_gold = gold;
  9765. mail.coin_plat = platinum;
  9766. mail.char_item_id = item_id;
  9767. mail.stack = stack_size;
  9768. mail.time_sent = time_sent;
  9769. mail.expire_time = expire_time;
  9770. database.SavePlayerMail(&mail);
  9771. }
  9772. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9773. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9774. {
  9775. Mail* mail = new Mail();
  9776. mail->player_to_id = GetCharacterID();
  9777. mail->player_from = fromName;
  9778. mail->subject = subjectName;
  9779. mail->mail_body = mailBody;
  9780. mail->mail_type = mailType;
  9781. mail->coin_copper = copper;
  9782. mail->coin_silver = silver;
  9783. mail->coin_gold = gold;
  9784. mail->coin_plat = platinum;
  9785. mail->char_item_id = item_id;
  9786. mail->stack = stack_size;
  9787. mail->time_sent = time_sent;
  9788. mail->expire_time = expire_time;
  9789. mail->postage_cost = 0;
  9790. mail->save_needed = 1;
  9791. mail->already_read = 0;
  9792. database.SavePlayerMail(mail);
  9793. GetPlayer()->AddMail(mail);
  9794. }
  9795. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9796. {
  9797. if(slot < NUM_SLOTS)
  9798. {
  9799. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9800. if (app)
  9801. QueuePacket(app);
  9802. }
  9803. else
  9804. {
  9805. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9806. if (outapp)
  9807. QueuePacket(outapp);
  9808. }
  9809. }
  9810. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9811. {
  9812. if(spawn_player_id < 1)
  9813. return;
  9814. MQueueStateCmds.writelock();
  9815. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9816. MQueueStateCmds.releasewritelock();
  9817. }
  9818. void Client::ProcessStateCommands()
  9819. {
  9820. if(!IsReadyForUpdates())
  9821. return;
  9822. MQueueStateCmds.writelock();
  9823. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9824. for(; itr != queued_state_commands.end(); itr++)
  9825. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9826. queued_state_commands.clear();
  9827. MQueueStateCmds.releasewritelock();
  9828. }
  9829. void Client::PurgeItem(Item* item)
  9830. {
  9831. MConversation.writelock();
  9832. map<int32, Item*>::iterator itr;
  9833. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9834. {
  9835. if ( itr->second == item )
  9836. {
  9837. conversation_items.erase(itr);
  9838. break;
  9839. }
  9840. }
  9841. MConversation.releasewritelock();
  9842. }
  9843. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9844. {
  9845. if(GetPlayer()->StopSaveSpellEffects())
  9846. return;
  9847. if(item) {
  9848. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9849. if(item->GetItemScript() && lua_interface){
  9850. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9851. if (slot == 22)
  9852. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9853. else
  9854. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9855. }
  9856. if (item->details.count > 1) {
  9857. item->details.count -= 1;
  9858. item->save_needed = true;
  9859. }
  9860. else {
  9861. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9862. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9863. }
  9864. GetPlayer()->SetCharSheetChanged(true);
  9865. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9866. }
  9867. }
  9868. void Client::AwardCoins(int64 total_coins, std::string reason)
  9869. {
  9870. if (total_coins > 0) {
  9871. player->AddCoins(total_coins);
  9872. PlaySound("coin_cha_ching");
  9873. char tmp[64] = { 0 };
  9874. string message = "You receive ";
  9875. int32 val = 0;
  9876. if (total_coins >= 1000000) {
  9877. val = total_coins / 1000000;
  9878. total_coins -= 1000000 * val;
  9879. sprintf(tmp, "%u Platinum ", val);
  9880. message.append(tmp);
  9881. memset(tmp, 0, 64);
  9882. }
  9883. if (total_coins >= 10000) {
  9884. val = total_coins / 10000;
  9885. total_coins -= 10000 * val;
  9886. sprintf(tmp, "%u Gold ", val);
  9887. message.append(tmp);
  9888. memset(tmp, 0, 64);
  9889. }
  9890. if (total_coins >= 100) {
  9891. val = total_coins / 100;
  9892. total_coins -= 100 * val;
  9893. sprintf(tmp, "%u Silver ", val);
  9894. message.append(tmp);
  9895. memset(tmp, 0, 64);
  9896. }
  9897. if (total_coins > 0) {
  9898. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9899. message.append(tmp);
  9900. }
  9901. message.append(reason);
  9902. int8 type = CHANNEL_LOOT;
  9903. SimpleMessage(type, message.c_str());
  9904. }
  9905. }
  9906. void Client::TriggerSpellSave()
  9907. {
  9908. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  9909. // default to not have some bogus value in the rule
  9910. if(interval < 1)
  9911. interval = 100;
  9912. MSaveSpellStateMutex.lock();
  9913. if(!save_spell_state_timer.Enabled())
  9914. {
  9915. save_spell_state_time_bucket = 0;
  9916. save_spell_state_timer.Start(interval, true);
  9917. }
  9918. else
  9919. {
  9920. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  9921. save_spell_state_time_bucket += elapsed_time;
  9922. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  9923. // default to not have some bogus value in the rule
  9924. if(save_wait_cap < interval)
  9925. save_wait_cap = interval+1;
  9926. if(save_spell_state_time_bucket >= save_wait_cap)
  9927. {
  9928. // save immediately and disable timer
  9929. GetPlayer()->SaveSpellEffects();
  9930. save_spell_state_timer.Disable();
  9931. }
  9932. }
  9933. MSaveSpellStateMutex.unlock();
  9934. }
  9935. void Client::UpdateSentSpellList() {
  9936. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  9937. std::map<int32, int32>::iterator itr;
  9938. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  9939. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  9940. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  9941. QueuePacket(app);
  9942. }
  9943. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  9944. }
  9945. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  9946. tempPlacementSpawn = tmp;
  9947. hasSentTempPlacementSpawn = false;
  9948. if(tempPlacementSpawn)
  9949. temp_placement_timer.Start();
  9950. else
  9951. temp_placement_timer.Disable();
  9952. }
  9953. void Client::SetPlayer(Player* new_player) {
  9954. if (player && player != new_player)
  9955. zone_list.RemoveClientFromMap(player->GetName(), this);
  9956. player = new_player;
  9957. player->SetClient(this);
  9958. }
  9959. bool Client::UseItem(Item* item, Spawn* target) {
  9960. if (item && item->GetItemScript()) {
  9961. int16 item_index = item->details.index;
  9962. if(!item->CheckFlag2(INDESTRUCTABLE) && item->generic_info.condition == 0) {
  9963. SimpleMessage(CHANNEL_COLOR_RED, "This item is broken and must be repaired at a mender before it can be used");
  9964. }
  9965. else if (item->CheckFlag(EVIL_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_EVIL) {
  9966. Message(0, "%s requires an evil race.", item->name.c_str());
  9967. }
  9968. else if (item->CheckFlag(GOOD_ONLY) && GetPlayer()->GetAlignment() != ALIGNMENT_GOOD) {
  9969. Message(0, "%s requires a good race.", item->name.c_str());
  9970. }
  9971. else if (item->generic_info.max_charges == 0 || item->generic_info.max_charges == 0xFFFF) {
  9972. lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target);
  9973. return true;
  9974. }
  9975. else {
  9976. if (item->details.count > 0) {
  9977. std::string itemName = string(item->name);
  9978. int32 item_id = item->details.item_id;
  9979. sint64 flags = 0;
  9980. if(lua_interface->RunItemScript(item->GetItemScript(), "used", item, player, target, &flags) && flags >= 0)
  9981. {
  9982. //reobtain item make sure it wasn't removed
  9983. item = player->item_list.GetItemFromIndex(item_index);
  9984. if(!item) {
  9985. 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);
  9986. return true;
  9987. }
  9988. else if(!item->generic_info.display_charges && item->generic_info.max_charges == 1) {
  9989. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  9990. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  9991. return true;
  9992. }
  9993. else
  9994. {
  9995. item->details.count--; // charges
  9996. item->save_needed = true;
  9997. QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  9998. if(!item->details.count) {
  9999. Message(CHANNEL_NARRATIVE, "%s is out of charges. It has been removed.", item->name.c_str());
  10000. RemoveItem(item, 1); // end of a set of charges OR an item that uses a stack count of actual item quantity
  10001. }
  10002. return true;
  10003. }
  10004. }
  10005. else {
  10006. 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);
  10007. return true;
  10008. }
  10009. }
  10010. else
  10011. {
  10012. //reobtain item make sure it wasn't removed
  10013. item = player->item_list.GetItemFromIndex(item_index);
  10014. SimpleMessage(CHANNEL_COLOR_YELLOW, "Item is out of charges.");
  10015. if(item) {
  10016. 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);
  10017. }
  10018. }
  10019. }
  10020. }
  10021. return false;
  10022. }
  10023. void Client::SendPlayFlavor(Spawn* spawn, int8 language, VoiceOverStruct* non_garble,
  10024. VoiceOverStruct* garble, bool success, bool garble_success) {
  10025. VoiceOverStruct* resStruct = nullptr;
  10026. if(language == 0 || GetPlayer()->HasLanguage(language)) {
  10027. if(success) {
  10028. resStruct = non_garble;
  10029. }
  10030. }
  10031. else if(garble_success) {
  10032. resStruct = garble;
  10033. }
  10034. if(resStruct) {
  10035. 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);
  10036. }
  10037. }
  10038. void Client::SaveQuestRewardData(bool force_refresh) {
  10039. Query query;
  10040. if(force_refresh) {
  10041. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_rewards where char_id = %u",
  10042. GetCharacterID());
  10043. query.AddQueryAsync(GetCharacterID(), &database, Q_DELETE, "delete from character_quest_temporary_rewards where char_id = %u",
  10044. GetCharacterID());
  10045. }
  10046. vector<QuestRewardData*>::iterator itr;
  10047. vector<QuestRewardData*> tmp_quest_rewards;
  10048. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  10049. int index = 0;
  10050. for (itr = quest_pending_reward.begin(); itr != quest_pending_reward.end(); itr++) {
  10051. int32 questID = (*itr)->quest_id;
  10052. if(!(*itr)->db_saved || force_refresh) {
  10053. 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')",
  10054. 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());
  10055. (*itr)->db_saved = true;
  10056. (*itr)->db_index = index;
  10057. if((*itr)->is_temporary) {
  10058. std::vector<int32> items;
  10059. Quest* quest = GetPlayer()->GetAnyQuest(questID);
  10060. if(quest) {
  10061. quest->GetTmpRewardItemsByID(&items);
  10062. if(!force_refresh && items.size() > 0) {
  10063. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "delete from character_quest_temporary_rewards where char_id = %u and quest_id = %u",
  10064. GetCharacterID(), questID);
  10065. }
  10066. for(int i=0;i<items.size();i++) {
  10067. query.AddQueryAsync(GetCharacterID(), &database, Q_REPLACE, "replace into character_quest_temporary_rewards (char_id, quest_id, item_id) values(%u, %u, %u)",
  10068. GetCharacterID(), questID, items[i]);
  10069. }
  10070. }
  10071. }
  10072. }
  10073. index++;
  10074. }
  10075. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  10076. }
  10077. void Client::UpdateCharacterRewardData(QuestRewardData* data) {
  10078. if(!data)
  10079. return;
  10080. if(data->db_saved) {
  10081. Query query;
  10082. 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",
  10083. 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);
  10084. }
  10085. }