client.cpp 371 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709
  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. player_pos_changed = false;
  140. ++numclients;
  141. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  142. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  143. remove_from_list = false;
  144. new_client_login = false;
  145. UpdateWindowTitle(0);
  146. num_active_failures = 0;
  147. player = new Player();
  148. player->SetClient(this);
  149. combine_spawn = 0;
  150. lua_debug = false;
  151. ready_for_spawns = false;
  152. ready_for_updates = false;
  153. lua_debug_timer.Disable();
  154. transport_spawn = 0;
  155. MBuyBack.SetName("Client::MBuyBack");
  156. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  157. MDeletePlayer.SetName("Client::MDeletePlayer");
  158. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  159. search_items = 0;
  160. version = 0;
  161. next_conversation_id = 0;
  162. pending_guild_invite.guild = 0;
  163. pending_guild_invite.invited_by = 0;
  164. m_recipeListSent = false;
  165. m_resurrect.SetName("Client::m_resurrect");
  166. current_rez.expire_timer = 0;
  167. current_rez.should_delete = true;
  168. pending_last_name = 0;
  169. should_target = false;
  170. initial_spawns_sent = false;
  171. MQuestTimers.SetName("Client::quest_timers");
  172. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  173. on_auto_mount = false;
  174. should_load_spells = true;
  175. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  176. delayedLogin = false;
  177. delayedAccountID = 0;
  178. delayedAccessKey = 0;
  179. delayTimer.Disable();
  180. tempPlacementSpawn = nullptr;
  181. placement_unique_item_id = 0;
  182. SetHasOwnerOrEditAccess(false);
  183. temporary_transport_id = 0;
  184. rejoin_group_id = 0;
  185. lastRegionRemapTime = 0;
  186. regionDebugMessaging = false;
  187. client_reloading_zone = false;
  188. last_saved_timestamp = 0;
  189. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  190. MConversation.SetName("Client::MConversation");
  191. save_spell_state_timer.Disable();
  192. save_spell_state_time_bucket = 0;
  193. player_loading_complete = false;
  194. MItemDetails.SetName("Client::MItemDetails");
  195. MSpellDetails.SetName("Client::MSpellDetails");
  196. hasSentTempPlacementSpawn = false;
  197. spawn_removal_timer.Start();
  198. disable_save = false;
  199. }
  200. Client::~Client() {
  201. RemoveClientFromZone();
  202. //let the stream factory know were done with this stream
  203. if (eqs) {
  204. eqs->Close();
  205. try {
  206. eqs->ReleaseFromUse();
  207. }
  208. catch (...) {}
  209. }
  210. eqs = NULL;
  211. //safe_delete(autobootup_timeout);
  212. safe_delete(CLE_keepalive_timer);
  213. safe_delete(connect);
  214. --numclients;
  215. UpdateWindowTitle(0);
  216. }
  217. void Client::RemoveClientFromZone() {
  218. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  219. Spawn* tmp = GetTempPlacementSpawn();
  220. SetTempPlacementSpawn(nullptr);
  221. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  222. }
  223. if(player && player->GetZone())
  224. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  225. if (current_zone && player) {
  226. if (player->GetGroupMemberInfo())
  227. {
  228. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  229. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  230. else
  231. TempRemoveGroup();
  232. }
  233. world.GetGroupManager()->ClearPendingInvite(player);
  234. }
  235. if (lua_interface)
  236. lua_interface->RemoveDebugClients(this);
  237. if (player)
  238. zone_list.RemoveClientFromMap(player->GetName(), this);
  239. safe_delete(camp_timer);
  240. safe_delete(search_items);
  241. safe_delete(current_rez.expire_timer);
  242. safe_delete(pending_last_name);
  243. safe_delete_array(incoming_paperdoll.image_bytes);
  244. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  245. if (player && !player->GetPendingDeletion())
  246. safe_delete(player);
  247. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  248. }
  249. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  250. if (eqs) {
  251. if (!eqs->CheckActive()) {
  252. client_list.Remove(this);
  253. eqs = 0;
  254. }
  255. }
  256. if (app && eqs && version > 0)
  257. eqs->EQ2QueuePacket(app, attemptedCombine);
  258. else {
  259. safe_delete(app);
  260. }
  261. }
  262. void Client::PopulateSkillMap() {
  263. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  264. if (app)
  265. QueuePacket(app);
  266. else {
  267. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  268. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  269. }
  270. }
  271. void Client::SendLoginInfo() {
  272. if(GetPlayer()->IsReturningFromLD())
  273. firstlogin = true;
  274. if (firstlogin) {
  275. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  276. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  277. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  278. PopulateSkillMap();
  279. // 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!
  280. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  281. }
  282. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  283. database.ToggleCharacterOnline(this, 1);
  284. int32 count = 0;
  285. if(!GetPlayer()->IsReturningFromLD())
  286. {
  287. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  288. count = database.LoadCharacterSkills(GetCharacterID(), player);
  289. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  290. count = database.LoadCharacterSpells(GetCharacterID(), player);
  291. }
  292. else
  293. {
  294. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  295. }
  296. // get the latest character starting skills / spells, may have been updated after character creation
  297. world.SyncCharacterAbilities(this);
  298. if(!GetPlayer()->IsReturningFromLD())
  299. {
  300. count = database.LoadCharacterTitles(GetCharacterID(), player);
  301. if (count == 0) {
  302. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  303. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  304. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  305. }
  306. }
  307. if(!GetPlayer()->IsReturningFromLD())
  308. {
  309. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  310. if (count == 0)
  311. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  312. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  313. if (count == 0)
  314. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  315. }
  316. ClientPacketFunctions::SendLoginAccepted(this);
  317. ClientPacketFunctions::SendAbilities ( this );
  318. ClientPacketFunctions::SendCommandNamePacket(this);
  319. ClientPacketFunctions::SendQuickBarInit(this);
  320. // we only need to send the MOTD if it is the first time the person is logging in.
  321. if (firstlogin) {
  322. ClientPacketFunctions::SendMOTD(this);
  323. ClientPacketFunctions::SendCharacterMacros(this);
  324. zone_list.CheckFriendList(this);
  325. }
  326. if(!GetPlayer()->IsReturningFromLD())
  327. {
  328. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  329. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  330. {
  331. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  332. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  333. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  334. }
  335. database.LoadPlayerFactions(this);
  336. database.LoadCharacterQuests(this);
  337. database.LoadPlayerMail(this);
  338. }
  339. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  340. SendQuestJournal(true, 0, false);
  341. if (version > 546) // right version? possibly not!
  342. master_aa_list.DisplayAA(this, 0, 3);
  343. if (version > 283)
  344. SendCollectionList();
  345. SendBiography();
  346. map<int32, Quest*>::iterator itr;
  347. Quest* quest = 0;
  348. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  349. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  350. quest = itr->second;
  351. if (quest->IsTracked()) {
  352. quest->SetTracked(false);
  353. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  354. quest->SetTracked(true);
  355. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  356. }
  357. }
  358. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  359. // SendAchievementsList();
  360. /*Guild* guild = player->GetGuild();
  361. if (guild) {
  362. guild->UpdateGuildMemberInfo(GetPlayer());
  363. if (firstlogin)
  364. guild->SendGuildMOTD(this);
  365. guild->SendGuildUpdate(this);
  366. guild->SendGuildMember(GetPlayer(), firstlogin);
  367. guild->SendGuildEventList(this);
  368. guild->SendGuildBankEventList(this);
  369. guild->SendAllGuildEvents(this);
  370. guild->SendGuildMemberList(this);
  371. }*/
  372. if (version > 283) {
  373. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  374. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  375. if (outapp) {
  376. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  377. //DumpPacket(outapp);
  378. QueuePacket(outapp);
  379. }
  380. }
  381. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  382. ClientPacketFunctions::SendCommandList(this);
  383. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  384. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  385. ClientPacketFunctions::SendInstanceList(this);
  386. SendZoneInfo();
  387. /*Spell* spell = 0;
  388. vector<QuickBarItem*>::iterator itr;
  389. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  390. if((*itr)->type == 1){
  391. spell = master_spell_list.GetSpell((*itr)->id);
  392. if(spell)
  393. QueuePacket(spell->serialize(this, false, 0x20));
  394. }
  395. }*/
  396. }
  397. void Client::SendPlayerDeathWindow()
  398. {
  399. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  400. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  401. vector<RevivePoint*>::iterator itr;
  402. if (results && results->size() > 0)
  403. {
  404. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  405. if (packet)
  406. {
  407. packet->setArrayLengthByName("location_count", results->size());
  408. RevivePoint* point = 0;
  409. int32 i = 0;
  410. for (itr = results->begin(); itr != results->end(); itr++, i++)
  411. {
  412. point = *itr;
  413. if (point)
  414. {
  415. packet->setArrayDataByName("location_id", point->id, i);
  416. //zone_name = database.GetZoneName(point->zone_id);
  417. string zone_name = database.GetZoneDescription(point->zone_id);
  418. if (zone_name.length() > 0)
  419. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  420. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  421. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  422. }
  423. if (point->id == 0xFFFFFFFF)//tmp location
  424. safe_delete(point);
  425. }
  426. // done with the revive points so lets free up the pointer
  427. safe_delete(results);
  428. #if EQDEBUG >= 3
  429. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  430. packet->PrintPacket();
  431. #endif
  432. EQ2Packet* outapp = packet->serialize();
  433. QueuePacket(outapp);
  434. safe_delete(packet);
  435. }
  436. }
  437. }
  438. void Client::DisplayDeadWindow()
  439. {
  440. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  441. player->SetHP(0);
  442. player->SetPower(0);
  443. GetCurrentZone()->TriggerCharSheetTimer();
  444. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  445. if (packet)
  446. {
  447. packet->setDataByName("parameter1", 8);
  448. packet->setDataByName("value", 1);
  449. QueuePacket(packet->serialize());
  450. packet->setDataByName("parameter1", 16);
  451. QueuePacket(packet->serialize());
  452. safe_delete(packet);
  453. }
  454. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  455. if (packet)
  456. {
  457. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  458. QueuePacket(packet->serialize());
  459. safe_delete(packet);
  460. }
  461. SendPlayerDeathWindow();
  462. }
  463. void Client::HandlePlayerRevive(int32 point_id)
  464. {
  465. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  466. if (packet)
  467. {
  468. packet->setDataByName("parameter1", 8);
  469. QueuePacket(packet->serialize());
  470. packet->setDataByName("parameter1", 16);
  471. QueuePacket(packet->serialize());
  472. safe_delete(packet);
  473. }
  474. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  475. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  476. if (packet)
  477. {
  478. QueuePacket(packet->serialize());
  479. safe_delete(packet);
  480. }
  481. float origX, origY, origZ, origHeading = 0.0f;
  482. origX = player->GetX();
  483. origY = player->GetY();
  484. origZ = player->GetZ();
  485. origHeading = player->GetHeading();
  486. ZoneServer* originalZone = GetCurrentZone();
  487. int32 origGridID = GetPlayer()->appearance.pos.grid_id;
  488. float x, y, z, heading;
  489. RevivePoint* revive_point = 0;
  490. if (point_id != 0xFFFFFFFF)
  491. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  492. string zone_desc;
  493. const char* location_name = "Unknown";
  494. //revive at zone safe coords
  495. if (!revive_point)
  496. {
  497. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  498. x = GetCurrentZone()->GetSafeX();
  499. y = GetCurrentZone()->GetSafeY();
  500. z = GetCurrentZone()->GetSafeZ();
  501. heading = GetCurrentZone()->GetSafeHeading();
  502. zone_desc = GetCurrentZone()->GetZoneDescription();
  503. location_name = "Zone Safe Point";
  504. Zone(GetCurrentZone()->GetZoneName(), false);
  505. }
  506. else
  507. {
  508. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  509. x = revive_point->x;
  510. y = revive_point->y;
  511. z = revive_point->z;
  512. heading = revive_point->heading;
  513. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  514. location_name = revive_point->location_name.c_str();
  515. Zone(GetCurrentZone()->GetZoneName(), false);
  516. }
  517. player->SetResurrecting(true);
  518. player->SetX(x);
  519. player->SetY(y);
  520. player->SetZ(z);
  521. player->SetHeading(heading);
  522. player->SetHP(player->GetTotalHP());
  523. player->SetPower(player->GetTotalPower());
  524. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  525. zone_desc.c_str(),
  526. player->GetX(),
  527. player->GetY(),
  528. player->GetZ(),
  529. player->GetHeading(),
  530. player->GetHP(),
  531. player->GetPower(),
  532. location_name);
  533. //player->ClearEverything();
  534. Save();
  535. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  536. {
  537. string zone_name = database.GetZoneName(revive_point->zone_id);
  538. if (zone_name.length() == 0)
  539. {
  540. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  541. x = GetCurrentZone()->GetSafeX();
  542. y = GetCurrentZone()->GetSafeY();
  543. z = GetCurrentZone()->GetSafeZ();
  544. heading = GetCurrentZone()->GetSafeHeading();
  545. location_name = "Zone Safe Point";
  546. }
  547. else
  548. {
  549. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  550. location_name = revive_point->location_name.c_str();
  551. player->ClearEverything();
  552. Zone(zone_name.c_str(), false);
  553. }
  554. }
  555. zone_desc = GetCurrentZone()->GetZoneDescription();
  556. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  557. player->SetSpawnType(4);
  558. if (version > 283) {
  559. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  560. if (packet)
  561. {
  562. QueuePacket(packet->serialize());
  563. safe_delete(packet);
  564. }
  565. }
  566. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  567. if (packet)
  568. {
  569. packet->setDataByName("x", x);
  570. packet->setDataByName("y", y);
  571. packet->setDataByName("z", z);
  572. QueuePacket(packet->serialize());
  573. safe_delete(packet);
  574. }
  575. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  576. if (packet)
  577. {
  578. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  579. packet->setDataByName("speed", 32);
  580. packet->setDataByName("unknown2", 0);
  581. //DoF Merge: old value and speed wasn't included
  582. //packet->setDataByName("unknown2", 255);
  583. QueuePacket(packet->serialize());
  584. safe_delete(packet);
  585. }
  586. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  587. if (packet)
  588. {
  589. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  590. QueuePacket(packet->serialize());
  591. safe_delete(packet);
  592. }
  593. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  594. {
  595. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  596. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  597. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  598. originalZone->RemoveSpawn(player, false, true, true, true, true);
  599. originalZone->AddSpawn(shard);
  600. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  601. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  602. }
  603. m_resurrect.writelock(__FUNCTION__, __LINE__);
  604. if (current_rez.active)
  605. current_rez.should_delete = true;
  606. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  607. }
  608. void Client::SendCharInfo() {
  609. EQ2Packet* app;
  610. if(IsReloadingZone()){
  611. SetReloadingZone(false);
  612. }
  613. player->SetEquippedItemAppearances();
  614. ClientPacketFunctions::SendCharacterData(this);
  615. SendCharPOVGhost();
  616. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  617. if (packet) {
  618. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  619. packet->setDataByName("size", .56);
  620. packet->setDataByName("unknown2", 255);
  621. packet->setDataByName("speed", player->GetSpeed());
  622. packet->setDataByName("air_speed", player->GetAirSpeed());
  623. EQ2Packet* app = packet->serialize();
  624. QueuePacket(app);
  625. safe_delete(packet);
  626. }
  627. if (version <= 283) {
  628. //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
  629. Sleep(2000);
  630. }
  631. //sending bad spawn packet?
  632. //SendAchievementsList();
  633. ClientPacketFunctions::SendCharacterSheet(this);
  634. ClientPacketFunctions::SendTraitList(this);// moved from below
  635. ClientPacketFunctions::SendAbilities(this);
  636. ClientPacketFunctions::SendSkillBook(this);
  637. if (!IsReloadingZone() && !player->IsResurrecting()) {
  638. if(GetVersion() > 546) //we will send this later on for 546 and below
  639. ClientPacketFunctions::SendUpdateSpellBook(this);
  640. }
  641. else {
  642. player->SetResurrecting(false);
  643. }
  644. ClientPacketFunctions::SendLoginCommandMessages(this);
  645. GetCurrentZone()->AddSpawn(player);
  646. //SendCollectionList();
  647. Guild* guild = player->GetGuild();
  648. if (guild)
  649. guild->GuildMemberLogin(this, firstlogin);
  650. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  651. if (app) {
  652. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  653. //DumpPacket(app);
  654. QueuePacket(app);
  655. }
  656. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  657. if (app) {
  658. QueuePacket(app);
  659. }
  660. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  661. if (app) {
  662. QueuePacket(app);
  663. }
  664. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  665. if (items && items->size() > 0) {
  666. for (int32 i = 0; i < items->size(); i++) {
  667. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  668. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  669. //DumpPacket(outapp);
  670. QueuePacket(outapp);
  671. }
  672. }
  673. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  674. QueuePacket(app);
  675. safe_delete(items);
  676. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  677. if (items && items->size() > 0) {
  678. for (int32 i = 0; i < items->size(); i++)
  679. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  680. }
  681. safe_delete(items);
  682. if (version > 283) {
  683. SendTitleUpdate();
  684. }
  685. GetPlayer()->ChangePrimaryWeapon();
  686. GetPlayer()->ChangeSecondaryWeapon();
  687. GetPlayer()->ChangeRangedWeapon();
  688. if(!GetPlayer()->IsReturningFromLD()) {
  689. database.LoadBuyBacks(this);
  690. }
  691. if (version > 546)
  692. master_aa_list.DisplayAA(this, 0, 0);
  693. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  694. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  695. string zone_motd_send = "Zone MOTD: " + zone_motd;
  696. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  697. }
  698. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  699. if (zone_script && lua_interface)
  700. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  701. this->client_zoning = false;
  702. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  703. GetCurrentZone()->AddDamagedSpawn(player);
  704. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  705. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  706. if (firstlogin)
  707. firstlogin = false;
  708. player->ClearProcs();
  709. items = player->GetEquippedItemList();
  710. if (items && items->size() > 0) {
  711. for (int32 i = 0; i < items->size(); i++) {
  712. Item* item = items->at(i);
  713. if (item && item->GetItemScript() && lua_interface)
  714. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  715. }
  716. }
  717. //Allow this player to change their last name if they meet the level requirement
  718. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  719. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  720. safe_delete(items);
  721. if (!player->Alive())
  722. DisplayDeadWindow();
  723. ClientPacketFunctions::SendLocalizedTextMessage(this);
  724. if (GetCurrentZone()->GetInstanceID())
  725. {
  726. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  727. if (ph) {
  728. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  729. string name = string(GetPlayer()->GetName());
  730. if (name.compare(ph->player_name) == 0)
  731. SetHasOwnerOrEditAccess(true);
  732. }
  733. }
  734. if (version > 546)
  735. ClientPacketFunctions::SendHousingList(this);
  736. bool groupMentor = false;
  737. GetPlayer()->group_id = rejoin_group_id;
  738. if(!world.RejoinGroup(this, rejoin_group_id))
  739. GetPlayer()->group_id = 0;
  740. else
  741. {
  742. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  743. if(ent && ent->IsPlayer())
  744. {
  745. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  746. groupMentor = true;
  747. }
  748. }
  749. if(!groupMentor)
  750. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  751. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  752. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  753. GetPlayer()->SetSaveSpellEffects(false);
  754. GetPlayer()->SetCharSheetChanged(true);
  755. GetPlayer()->SetReturningFromLD(false);
  756. }
  757. void Client::SendZoneSpawns() {
  758. //Allows us to place spawns almost anywhere
  759. if (version > 283) {
  760. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  761. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  762. QueuePacket(app);
  763. }
  764. ClientPacketFunctions::SendSkillSlotMappings(this);
  765. ClientPacketFunctions::SendGameWorldTime(this);
  766. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  767. }
  768. void Client::SendCharPOVGhost() {
  769. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  770. if (set_pov) {
  771. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  772. EQ2Packet* app_pov = set_pov->serialize();
  773. QueuePacket(app_pov);
  774. safe_delete(set_pov);
  775. }
  776. }
  777. void Client::SendZoneInfo() {
  778. ZoneServer* zone = GetCurrentZone();
  779. if (zone) {
  780. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  781. QueuePacket(packet);
  782. if (version > 283) {
  783. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  784. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  785. #if EQDEBUG >= 9
  786. fog_packet->PrintPacket();
  787. #endif
  788. if (fog_packet) {
  789. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  790. QueuePacket(fog_packet->serialize());
  791. safe_delete(fog_packet);
  792. }
  793. zone->SendFlightPathsPackets(this);
  794. }
  795. }
  796. /*
  797. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  798. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  799. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  800. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  801. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  802. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  803. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  804. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  805. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  806. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  807. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  808. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  809. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  810. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  811. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  812. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  813. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  814. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  815. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  816. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  817. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  818. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  819. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  820. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  821. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  822. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  823. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  824. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  825. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  826. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  827. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  828. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  829. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  830. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  831. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  832. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  833. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  834. QueuePacket(appA);
  835. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  836. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  837. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  838. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  839. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  840. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  841. QueuePacket(appB);
  842. */
  843. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  844. SendFriendList();
  845. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  846. SendIgnoreList();
  847. }
  848. void Client::SendDefaultGroupOptions() {
  849. /*
  850. 0 - loot method
  851. 1 - loot items rarity
  852. 2 - Auto split coin
  853. 4 - default yell method
  854. 6 - group autolock
  855. 7 - solo autolock
  856. */
  857. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  858. if (default_options) {
  859. default_options->setDataByName("loot_method", 1);
  860. default_options->setDataByName("loot_items_rarity", 1);
  861. default_options->setDataByName("auto_split_coin", 1);
  862. default_options->setDataByName("default_yell_method", 1);
  863. EQ2Packet* app7 = default_options->serialize();
  864. QueuePacket(app7);
  865. safe_delete(default_options);
  866. }
  867. }
  868. bool Client::HandlePacket(EQApplicationPacket* app) {
  869. bool ret = true;
  870. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  871. //DumpPacket(app);
  872. #if EQDEBUG >= 9
  873. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  874. DumpPacket(app, true);
  875. #endif
  876. EmuOpcode opcode = app->GetOpcode();
  877. #if EQDEBUG >= 9
  878. const char* name = app->GetOpcodeName();
  879. if (name)
  880. cout << name;
  881. else
  882. cout << "Unknown";
  883. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  884. DumpPacket(app);
  885. #endif
  886. //if (opcode != OP_UpdatePositionMsg) {
  887. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  888. //}
  889. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  890. {
  891. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  892. }
  893. switch (opcode) {
  894. case _maxEmuOpcode:
  895. break;
  896. case OP_LoginByNumRequestMsg: {
  897. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  898. PacketStruct* request;
  899. request = configReader.getStruct("LoginByNumRequest", 1);
  900. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  901. // test the original location of Version for clients older than 1212
  902. version = request->getType_int16_ByName("version");
  903. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  904. // must be new client data version method, re-fetch the packet
  905. safe_delete(request);
  906. request = configReader.getStruct("LoginByNumRequest", 1208);
  907. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  908. // Xinux suggests using an INT16 here. Our first new version = 57000
  909. version = request->getType_int16_ByName("version");
  910. }
  911. else {
  912. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  913. break;
  914. }
  915. }
  916. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  917. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  918. ClientPacketFunctions::SendLoginDenied(this);
  919. return false;
  920. }
  921. int32 account_id = request->getType_int32_ByName("account_id");
  922. int32 access_code = request->getType_int32_ByName("access_code");
  923. if (!HandleNewLogin(account_id, access_code))
  924. return false;
  925. }
  926. safe_delete(request);
  927. break;
  928. }
  929. case OP_SysClient: {
  930. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  931. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  932. SetReadyForUpdates();
  933. ProcessStateCommands();
  934. break;
  935. }
  936. case OP_MapRequest: {
  937. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  938. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  939. if (packet && app->size > 2 && GetCurrentZone()) {
  940. packet->LoadPacketData(app->pBuffer, app->size);
  941. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  942. if (fog_packet) {
  943. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  944. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  945. fog_packet->setDataByName("unknown1", 1);
  946. fog_packet->setDataByName("unknown3", 1);
  947. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  948. //fog_packet->PrintPacket();
  949. QueuePacket(fog_packet->serialize());
  950. safe_delete(fog_packet);
  951. }
  952. safe_delete(packet);
  953. }
  954. break;
  955. }
  956. case OP_RequestCampMsg: {
  957. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  958. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  959. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  960. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  961. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  962. request->getType_int8_ByName("quit"),
  963. request->getType_int8_ByName("camp_desktop"),
  964. request->getType_int16_ByName("camp_char_select"),
  965. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  966. //DumpPacket(app->pBuffer, app->size);
  967. //request->PrintPacket();
  968. if (!camp_timer) {
  969. int16 camp_time = 20; // default if rule cannot be found
  970. if (GetAdminStatus() >= 100)
  971. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  972. else
  973. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  974. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  975. if (response) {
  976. bool disconnect = false;
  977. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  978. // Command: /camp desktop
  979. // Command: /quit
  980. response->setDataByName("camp_desktop", 1);
  981. disconnect = true;
  982. }
  983. else {
  984. // Command: /camp
  985. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  986. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  987. response->setDataByName("seconds", camp_time);
  988. }
  989. camp_timer = new Timer(camp_time * 1000);
  990. camp_timer->Enable();
  991. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  992. // /camp {char_name}
  993. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  994. }
  995. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  996. // /camp (go back to char selection screen)
  997. response->setDataByName("char_name", " ");
  998. response->setDataByName("camp_char_select", 1);
  999. }
  1000. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1001. response->getType_int8_ByName("seconds"),
  1002. response->getType_int8_ByName("camp_desktop"),
  1003. response->getType_int8_ByName("camp_char_select"),
  1004. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1005. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1006. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1007. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1008. //response->PrintPacket();
  1009. QueuePacket(response->serialize());
  1010. safe_delete(response);
  1011. if (disconnect)
  1012. Disconnect();
  1013. }
  1014. }
  1015. }
  1016. safe_delete(request);
  1017. break;
  1018. }
  1019. case OP_StoodMsg: {
  1020. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1021. if (camp_timer)
  1022. {
  1023. // JA: clear camping flag
  1024. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1025. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1026. safe_delete(camp_timer);
  1027. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1028. QueuePacket(outapp);
  1029. }
  1030. player->SetTempVisualState(0);
  1031. break;
  1032. }
  1033. case OP_StandMsg: {
  1034. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1035. if (camp_timer)
  1036. {
  1037. // JA: clear camping flag
  1038. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1039. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1040. safe_delete(camp_timer);
  1041. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1042. QueuePacket(outapp);
  1043. }
  1044. player->SetTempVisualState(539);
  1045. break;
  1046. }
  1047. case OP_SitMsg: {
  1048. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1049. player->SetTempVisualState(538);
  1050. break;
  1051. }
  1052. case OP_SatMsg: {
  1053. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1054. player->SetTempVisualState(540);
  1055. break;
  1056. }
  1057. case OP_QuestJournalOpenMsg:
  1058. case OP_QuestJournalInspectMsg: {
  1059. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1060. if (app->size < sizeof(int32))
  1061. break;
  1062. int32 quest_id = 0;
  1063. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1064. Quest* quest = GetActiveQuest(quest_id);
  1065. if (quest)
  1066. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1067. else {
  1068. quest = player->GetCompletedQuest(quest_id);
  1069. if (quest)
  1070. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1071. }
  1072. break;
  1073. }
  1074. case OP_QuestJournalSetVisibleMsg: {
  1075. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1076. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1077. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1078. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1079. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1080. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1081. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1082. if (player_quests) {
  1083. if (player_quests->count(quest_id) > 0)
  1084. player_quests->at(quest_id)->SetHidden(hidden);
  1085. else
  1086. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1087. }
  1088. else
  1089. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1090. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1091. safe_delete(packet);
  1092. }
  1093. break;
  1094. }
  1095. case OP_MacroUpdateMsg: {
  1096. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1097. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1098. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1099. vector<string>* update = new vector<string>;
  1100. int8 number = macro_update->getType_int8_ByName("number");
  1101. int16 icon = macro_update->getType_int16_ByName("icon");
  1102. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1103. int8 count = macro_update->getType_int8_ByName("macro_count");
  1104. if (GetVersion() <= 283) {
  1105. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1106. }
  1107. else {
  1108. for (int8 i = 0; i < count; i++) {
  1109. char tmp_command[15] = { 0 };
  1110. sprintf(tmp_command, "command_%i", i);
  1111. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1112. }
  1113. }
  1114. if (name.length() == 0)
  1115. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1116. else
  1117. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1118. safe_delete(update);
  1119. safe_delete(macro_update);
  1120. }
  1121. break;
  1122. }
  1123. case OP_DialogSelectMsg: {
  1124. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1125. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1126. if (packet) {
  1127. packet->LoadPacketData(app->pBuffer, app->size);
  1128. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1129. int32 response_index = packet->getType_int32_ByName("response");
  1130. if (GetCurrentZone()) {
  1131. MConversation.readlock();
  1132. Spawn* spawn = conversation_spawns[conversation_id];
  1133. Item* item = conversation_items[conversation_id];
  1134. MConversation.releasereadlock();
  1135. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1136. if (spawn)
  1137. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1138. else if (item && lua_interface && item->GetItemScript())
  1139. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1140. else
  1141. CloseDialog(conversation_id);
  1142. }
  1143. else
  1144. CloseDialog(conversation_id);
  1145. }
  1146. safe_delete(packet);
  1147. }
  1148. break;
  1149. }
  1150. case OP_CancelMoveObjectModeMsg: {
  1151. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1152. if (GetTempPlacementSpawn())
  1153. {
  1154. Spawn* tmp = GetTempPlacementSpawn();
  1155. SetTempPlacementSpawn(nullptr);
  1156. SetPlacementUniqueItemID(0);
  1157. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1158. break; // break out early if we are tied to a temp spawn
  1159. }
  1160. // if we are moving some other object? other use-cases not covered
  1161. break;
  1162. }
  1163. case OP_PositionMoveableObject: {
  1164. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1165. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1166. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1167. Spawn* spawn = 0;
  1168. if (GetTempPlacementSpawn())
  1169. spawn = GetTempPlacementSpawn();
  1170. else
  1171. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1172. if (!spawn) {
  1173. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1174. break;
  1175. }
  1176. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1177. {
  1178. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1179. break;
  1180. }
  1181. // handles instantiation logic + adding to zone of a new house object
  1182. PopulateHouseSpawn(place_object);
  1183. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1184. char query[256];
  1185. switch (GetSpawnPlacementMode())
  1186. {
  1187. case ServerSpawnPlacementMode::OPEN_HEADING:
  1188. {
  1189. if (spawn && spawn->IsWidget())
  1190. {
  1191. Widget* widget = (Widget*)spawn;
  1192. widget->SetOpenHeading(newHeading);
  1193. widget->SetIncludeHeading(true);
  1194. spawn->position_changed = true;
  1195. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1196. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1197. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1198. }
  1199. else
  1200. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1201. break;
  1202. }
  1203. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1204. {
  1205. if (spawn && spawn->IsWidget())
  1206. {
  1207. Widget* widget = (Widget*)spawn;
  1208. widget->SetClosedHeading(newHeading);
  1209. widget->SetIncludeHeading(true);
  1210. spawn->position_changed = true;
  1211. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1212. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1213. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1214. if (spawn->GetSpawnLocationID())
  1215. {
  1216. Query query;
  1217. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1218. }
  1219. }
  1220. else
  1221. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1222. break;
  1223. }
  1224. default:
  1225. {
  1226. spawn->SetX(place_object->getType_float_ByName("x"));
  1227. spawn->SetY(place_object->getType_float_ByName("y"));
  1228. spawn->SetZ(place_object->getType_float_ByName("z"));
  1229. spawn->SetHeading(newHeading);
  1230. spawn->SetSpawnOrigX(spawn->GetX());
  1231. spawn->SetSpawnOrigY(spawn->GetY());
  1232. spawn->SetSpawnOrigZ(spawn->GetZ());
  1233. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1234. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1235. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1236. else if (spawn->GetSpawnLocationID() > 0)
  1237. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1238. }
  1239. }
  1240. PopulateHouseSpawnFinalize();
  1241. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1242. safe_delete(place_object);
  1243. }
  1244. break;
  1245. }
  1246. case OP_CampAbortedMsg: {
  1247. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1248. if (camp_timer)
  1249. {
  1250. // JA: clear camping flag
  1251. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1252. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1253. safe_delete(camp_timer);
  1254. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1255. QueuePacket(outapp);
  1256. }
  1257. break;
  1258. }
  1259. case OP_DoneLoadingUIResourcesMsg: {
  1260. ClientPacketFunctions::SendUpdateSpellBook(this);
  1261. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1262. QueuePacket(app);
  1263. if(!player_loading_complete)
  1264. {
  1265. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1266. if (zone_script && lua_interface)
  1267. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1268. player_loading_complete = true;
  1269. }
  1270. break;
  1271. }
  1272. case OP_DoneLoadingZoneResourcesMsg: {
  1273. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1274. SendZoneSpawns();
  1275. break;
  1276. }
  1277. case OP_DefaultGroupOptionsRequestMsg: {
  1278. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1279. SendDefaultGroupOptions();
  1280. break;
  1281. }
  1282. case OP_DoneLoadingEntityResourcesMsg: {
  1283. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1284. if (!IsReadyForSpawns())
  1285. SetReadyForSpawns(true);
  1286. SendCharInfo();
  1287. pos_update.Start();
  1288. quest_pos_timer.Start();
  1289. break;
  1290. }
  1291. case OP_LootItemsRequestMsg: {
  1292. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1293. HandleLoot(app);
  1294. break;
  1295. }
  1296. case OP_WaypointSelectMsg: {
  1297. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1298. if (packet) {
  1299. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1300. int32 selection = packet->getType_int32_ByName("selection");
  1301. if (selection > 0) {
  1302. SelectWaypoint(selection);
  1303. }
  1304. }
  1305. }
  1306. break;
  1307. }
  1308. case OP_KnowledgeWindowSlotMappingMsg: {
  1309. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1310. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1311. if (packet) {
  1312. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1313. int num_updates = packet->getType_int16_ByName("spell_count");
  1314. int32 spell_id = 0;
  1315. int16 slot_id = 0;
  1316. char tmp_spell_id[15];
  1317. char tmp_slot[15];
  1318. for (int i = 0; i < num_updates; i++) {
  1319. memset(tmp_spell_id, 0, 15);
  1320. memset(tmp_slot, 0, 15);
  1321. sprintf(tmp_spell_id, "spell_id_%i", i);
  1322. sprintf(tmp_slot, "slot_id_%i", i);
  1323. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1324. if (spell_id > 0) {
  1325. slot_id = packet->getType_int16_ByName(tmp_slot);
  1326. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1327. if (spell && spell->slot != slot_id) {
  1328. spell->slot = slot_id;
  1329. spell->save_needed = true;
  1330. }
  1331. }
  1332. }
  1333. }
  1334. safe_delete(packet);
  1335. }
  1336. //SendKnowledgeWindowSlot();
  1337. break;
  1338. }
  1339. case OP_ReadyToZoneMsg: {
  1340. if (!IsReadyForSpawns())
  1341. {
  1342. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1343. }
  1344. else
  1345. {
  1346. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1347. if (client_zoning)
  1348. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1349. else
  1350. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1351. Disconnect();
  1352. }
  1353. break;
  1354. }
  1355. case OP_ClientFellMsg: {
  1356. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1357. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1358. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1359. float height = request->getType_float_ByName("height");
  1360. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1361. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1362. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1363. break;
  1364. }*/
  1365. float safe_height = 13.0f;
  1366. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1367. GetPlayer()->MStats.lock();
  1368. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1369. GetPlayer()->MStats.unlock();
  1370. if (skill)
  1371. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1372. if (height > safe_height) {
  1373. int16 damage = (int16)ceil((height - safe_height) * 125);
  1374. if (height >= 80)
  1375. damage = 30000;
  1376. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1377. if (damage > 0) {
  1378. GetPlayer()->TakeDamage(damage);
  1379. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1380. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1381. if (!GetPlayer()->GetInvulnerable())
  1382. GetPlayer()->SetCharSheetChanged(true);
  1383. 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);
  1384. if (GetPlayer()->GetHP() == 0) {
  1385. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1386. }
  1387. }
  1388. }
  1389. safe_delete(request);
  1390. }
  1391. break;
  1392. }
  1393. case OP_MapFogDataUpdateMsg: {
  1394. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1395. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1396. break;
  1397. }
  1398. case OP_SelectZoneTeleporterDestinatio: {
  1399. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1400. ProcessTeleportLocation(app);
  1401. break;
  1402. }
  1403. case OP_SendLatestRequestMsg: {
  1404. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1405. uchar blah25[] = { 0x01 };
  1406. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1407. QueuePacket(app25);
  1408. break;
  1409. }
  1410. case OP_ShowCreateFromRecipeUIMsg: {
  1411. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1412. break;
  1413. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1414. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1415. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1416. QueuePacket(app);
  1417. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1418. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1419. QueuePacket(app);
  1420. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1421. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1422. ,0xff,0xff,0xff};
  1423. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1424. QueuePacket(app);
  1425. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1426. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1427. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1428. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1429. QueuePacket(app);
  1430. uchar blah5[] ={0x00,0x00};
  1431. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1432. QueuePacket(app);
  1433. break;*/
  1434. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1435. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1436. //QueuePacket(app);
  1437. }
  1438. case OP_BeginItemCreationMsg: {
  1439. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1440. //DumpPacket(app->pBuffer, app->size);
  1441. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1442. if (packet) {
  1443. packet->LoadPacketData(app->pBuffer, app->size);
  1444. int32 item = 0;
  1445. vector<int32> items;
  1446. char tmp_item_id[20];
  1447. item = packet->getType_int32_ByName("primary_component_id");
  1448. if (item > 0)
  1449. items.push_back(item);
  1450. item = 0;
  1451. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1452. for (int8 i = 0; i < build_components; i++) {
  1453. memset(tmp_item_id, 0, 20);
  1454. sprintf(tmp_item_id, "component_id_%i", i);
  1455. item = packet->getType_int32_ByName(tmp_item_id);
  1456. if (item > 0)
  1457. items.push_back(item);
  1458. item = 0;
  1459. }
  1460. item = packet->getType_int32_ByName("fuel_id");
  1461. if (item > 0)
  1462. items.push_back(item);
  1463. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1464. safe_delete(packet);
  1465. }
  1466. break;
  1467. }
  1468. case OP_StopItemCreationMsg: {
  1469. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1470. //DumpPacket(app->pBuffer, app->size);
  1471. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1472. break;
  1473. }
  1474. case OP_SignalMsg: {
  1475. PacketStruct* packet = configReader.getStruct("WS_Signal", GetVersion());
  1476. if (packet) {
  1477. packet->LoadPacketData(app->pBuffer, app->size);
  1478. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1479. if (str.size > 0) {
  1480. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1481. SetReadyForUpdates();
  1482. GetPlayer()->SendSpawnChanges(true);
  1483. }
  1484. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1485. if (zone_script && lua_interface)
  1486. {
  1487. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1488. }
  1489. }
  1490. }
  1491. break;
  1492. }
  1493. case OP_EntityVerbsRequestMsg: {
  1494. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1495. HandleVerbRequest(app);
  1496. break;
  1497. }
  1498. case OP_EntityVerbsVerbMsg: {
  1499. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1500. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1501. if (packet) {
  1502. packet->LoadPacketData(app->pBuffer, app->size);
  1503. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1504. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1505. Spawn* spawn = player->GetTarget();
  1506. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1507. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1508. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1509. {
  1510. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1511. if (spawn->IsGroundSpawn())
  1512. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1513. else if (spawn->IsObject())
  1514. ((Object*)spawn)->HandleUse(this, command);
  1515. else if (spawn->IsWidget())
  1516. ((Widget*)spawn)->HandleUse(this, command);
  1517. else if (spawn->IsSign())
  1518. ((Sign*)spawn)->HandleUse(this, command);
  1519. }
  1520. }
  1521. }
  1522. else {
  1523. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1524. if (command.size > 0) {
  1525. string command_name = command.data;
  1526. if (command_name.find(" ") < 0xFFFFFFFF) {
  1527. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1528. string::size_type pos = command_name.find(" ");
  1529. while(pos != string::npos){
  1530. command_name.replace(pos, 1, "_");
  1531. pos = command_name.find(" ");
  1532. }
  1533. }
  1534. else
  1535. command_name = command_name.substr(0, command_name.find(" "));
  1536. }
  1537. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1538. if (handler != 0xFFFFFFFF) {
  1539. if (command.data == command_name) {
  1540. command.data = "";
  1541. command.size = 0;
  1542. }
  1543. else {
  1544. command.data = command.data.substr(command.data.find(" ") + 1);
  1545. command.size = command.data.length();
  1546. }
  1547. commands.Process(handler, &command, this);
  1548. }
  1549. else {
  1550. if (spawn && spawn->IsNPC()) {
  1551. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1552. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1553. command_name = command.data;
  1554. string::size_type pos = command_name.find(" ");
  1555. while (pos != string::npos) {
  1556. command_name.replace(pos, 1, "_");
  1557. pos = command_name.find(" ");
  1558. }
  1559. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1560. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1561. }
  1562. }
  1563. }
  1564. }
  1565. else
  1566. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1567. }
  1568. }
  1569. }
  1570. safe_delete(packet);
  1571. }
  1572. break;
  1573. }
  1574. case OP_SkillInfoRequest: {
  1575. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1576. HandleSkillInfoRequest(app);
  1577. break;
  1578. }
  1579. case OP_UpdateTargetMsg: {
  1580. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1581. int16 index = 0;
  1582. memcpy(&index, app->pBuffer, sizeof(int16));
  1583. if (index == 0xFFFF)
  1584. GetPlayer()->SetTarget(0);
  1585. else {
  1586. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1587. if(spawn)
  1588. GetPlayer()->SetTarget(spawn);
  1589. else {
  1590. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1591. }
  1592. }
  1593. if (GetPlayer()->GetTarget())
  1594. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1595. //player->SetTarget((int16*)app->pBuffer);
  1596. break;
  1597. }
  1598. case OP_ExamineInfoRequestMsg: {
  1599. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1600. HandleExamineInfoRequest(app);
  1601. break;
  1602. }
  1603. case OP_QuickbarUpdateMsg:
  1604. //case OP_QuickbarAddMsg:
  1605. {
  1606. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1607. HandleQuickbarUpdateRequest(app);
  1608. break;
  1609. }
  1610. case OP_PredictionUpdateMsg: {
  1611. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1612. if (version <= 546) {
  1613. int8 offset = 9;
  1614. if (app->pBuffer[0] == 0xFF)
  1615. offset += 2;
  1616. if (app->size > offset) {
  1617. if (player->IsCasting()) {
  1618. float distance = 0;
  1619. float x = player->GetX();
  1620. float y = player->GetY();
  1621. float z = player->GetZ();
  1622. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1623. distance = player->GetDistance(x, y, z, false);
  1624. if (distance > .5)
  1625. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1626. }
  1627. else
  1628. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1629. player_pos_changed = true;
  1630. //DumpPacket(app);
  1631. }
  1632. }
  1633. else {
  1634. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1635. QueuePacket(app);
  1636. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1637. }
  1638. break;
  1639. }
  1640. case OP_RemoteCmdMsg: {
  1641. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1642. if (app->size > 0) {
  1643. EQ2_CommandString remote(app->pBuffer, app->size);
  1644. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1645. #if EQDEBUG >= 9
  1646. DumpPacket(app);
  1647. #endif
  1648. commands.Process(remote.handler, &remote.command, this);
  1649. }
  1650. else //bad client, disconnect
  1651. Disconnect();
  1652. break;
  1653. }
  1654. case OP_CancelSpellCast: {
  1655. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1656. current_zone->Interrupted(player, 0, 0, true);
  1657. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1658. break;
  1659. }
  1660. case OP_UpdatePositionMsg: {
  1661. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1662. int8 offset = 13;
  1663. if (app->pBuffer[0] == 0xFF)
  1664. offset += 2;
  1665. if (app->size > offset) {
  1666. if (player->IsCasting()) {
  1667. float distance = 0;
  1668. float x = player->GetX();
  1669. float y = player->GetY();
  1670. float z = player->GetZ();
  1671. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1672. distance = player->GetDistance(x, y, z, false);
  1673. if (distance > .5)
  1674. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1675. }
  1676. else
  1677. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1678. player_pos_changed = true;
  1679. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1680. //DumpPacket(app);
  1681. }
  1682. break;
  1683. }
  1684. case OP_MailSendMessageMsg: {
  1685. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1686. HandleSentMail(app);
  1687. break;
  1688. }
  1689. case OP_StopTrackingMsg: {
  1690. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1691. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1692. break;
  1693. }
  1694. case OP_BeginTrackingMsg: {
  1695. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1696. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1697. if (packet) {
  1698. packet->LoadPacketData(app->pBuffer, app->size);
  1699. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1700. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1701. if (spawn) {
  1702. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1703. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1704. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1705. }
  1706. safe_delete(packet);
  1707. }
  1708. break;
  1709. }
  1710. case OP_BioUpdateMsg: {
  1711. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1712. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1713. if (packet) {
  1714. packet->LoadPacketData(app->pBuffer, app->size);
  1715. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1716. safe_delete(packet);
  1717. }
  1718. break;
  1719. }
  1720. case OP_RewardPackMsg: {
  1721. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1722. /* 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
  1723. when we come across it (scatman) */
  1724. const char* name = app->GetOpcodeName();
  1725. if (name)
  1726. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1727. else
  1728. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1729. //DumpPacket(app);
  1730. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1731. if (packet) {
  1732. packet->LoadPacketData(app->pBuffer, app->size);
  1733. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1734. /* Player has contacted a guild recruiter */
  1735. if (recruiter_name.length() > 0) {
  1736. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1737. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1738. if (recruiter && guild) {
  1739. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1740. 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()));
  1741. recruiter->PlaySound("ui_guild_page");
  1742. }
  1743. }
  1744. /* New picture taken for guild recruiting */
  1745. else {
  1746. //DumpPacket(app->pBuffer, app->size);
  1747. int32 guild_id = 0;
  1748. int16 picture_data_size = 0;
  1749. unsigned char* recruiter_picture_data = 0;
  1750. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1751. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1752. Guild* guild = guild_list.GetGuild(guild_id);
  1753. if (guild) {
  1754. GuildMember* gm = guild->GetGuildMember(player);
  1755. if (gm) {
  1756. safe_delete_array(gm->recruiter_picture_data);
  1757. recruiter_picture_data = new unsigned char[picture_data_size];
  1758. for (int16 i = 0; i < picture_data_size; i++)
  1759. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1760. gm->recruiter_picture_data = recruiter_picture_data;
  1761. gm->recruiter_picture_data_size = picture_data_size;
  1762. guild->SetMemberSaveNeeded(true);
  1763. }
  1764. }
  1765. }
  1766. safe_delete(packet);
  1767. }
  1768. break;
  1769. }
  1770. case OP_PetOptions: {
  1771. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1772. Spawn* target = player->GetTarget();
  1773. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1774. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1775. bool change = false;
  1776. packet->LoadPacketData(app->pBuffer, app->size);
  1777. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1778. if (strlen(name.c_str()) != 0) {
  1779. target->SetName(name.c_str());
  1780. player->GetInfoStruct()->set_pet_name(name);
  1781. GetCurrentZone()->SendUpdateTitles(target);
  1782. change = true;
  1783. }
  1784. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1785. // Check protect self setting and update if needed
  1786. if (packet->getType_int8_ByName("protect_self") == 1) {
  1787. if ((pet_behavior & 2) == 0) {
  1788. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1789. change = true;
  1790. }
  1791. }
  1792. else {
  1793. if ((pet_behavior & 2) != 0) {
  1794. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1795. change = true;
  1796. }
  1797. }
  1798. // Check protect master setting and update if needed
  1799. if (packet->getType_int8_ByName("protect_master") == 1) {
  1800. if ((pet_behavior & 1) == 0) {
  1801. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1802. change = true;
  1803. }
  1804. }
  1805. else {
  1806. if ((pet_behavior & 1) != 0) {
  1807. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1808. change = true;
  1809. }
  1810. }
  1811. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1812. // Check stay/follow setting and update if needed
  1813. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1814. if (pet_movement != 2) {
  1815. player->GetInfoStruct()->set_pet_movement(2);
  1816. change = true;
  1817. }
  1818. }
  1819. else {
  1820. if (pet_movement != 1) {
  1821. player->GetInfoStruct()->set_pet_movement(1);
  1822. change = true;
  1823. }
  1824. }
  1825. // Ranged/Melee settings are not implemented yet
  1826. if (change)
  1827. player->SetCharSheetChanged(true);
  1828. safe_delete(packet);
  1829. }
  1830. break;
  1831. }
  1832. case OP_RecipeBook: {
  1833. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1834. SendRecipeList();
  1835. break;
  1836. }
  1837. case OP_BuyPlayerHouseMsg: {
  1838. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1839. DumpPacket(app);
  1840. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1841. if (packet) {
  1842. packet->LoadPacketData(app->pBuffer, app->size);
  1843. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1844. if (hz) {
  1845. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1846. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1847. if (houses.size() > 24)
  1848. {
  1849. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1850. safe_delete(packet);
  1851. break;
  1852. }
  1853. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1854. {
  1855. std::string req = "You must be of ";
  1856. if (hz->alignment == 1)
  1857. req.append("Good");
  1858. else
  1859. req.append("Evil");
  1860. req.append(" alignment to purchase this house");
  1861. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1862. safe_delete(packet);
  1863. break;
  1864. }
  1865. int32 status_req = hz->upkeep_status + hz->cost_status;
  1866. int32 available_status = player->GetInfoStruct()->get_status_points();
  1867. if (status_req <= available_status &&
  1868. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1869. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1870. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1871. {
  1872. player->GetInfoStruct()->subtract_status_points(status_req);
  1873. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1874. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1875. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1876. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1877. //ClientPacketFunctions::SendHousingList(this);
  1878. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1879. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1880. PlaySound("coin_cha_ching");
  1881. }
  1882. else
  1883. {
  1884. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1885. PlaySound("buy_failed");
  1886. }
  1887. }
  1888. }
  1889. safe_delete(packet);
  1890. break;
  1891. }
  1892. case OP_EnterHouseMsg: {
  1893. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1894. DumpPacket(app);
  1895. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1896. if (packet) {
  1897. packet->LoadPacketData(app->pBuffer, app->size);
  1898. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1899. if (ph) {
  1900. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1901. if (hz) {
  1902. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1903. if (house) {
  1904. Zone(house, true);
  1905. }
  1906. }
  1907. }
  1908. }
  1909. safe_delete(packet);
  1910. break;
  1911. }
  1912. case OP_PayHouseUpkeepMsg: {
  1913. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1914. DumpPacket(app);
  1915. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1916. if (packet) {
  1917. packet->LoadPacketData(app->pBuffer, app->size);
  1918. int64 houseID = packet->getType_int64_ByName("house_id");
  1919. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1920. if (ph)
  1921. {
  1922. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1923. if (!hz)
  1924. {
  1925. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1926. safe_delete(packet);
  1927. break;
  1928. }
  1929. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1930. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1931. {
  1932. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1933. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1934. {
  1935. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1936. PlaySound("buy_failed");
  1937. safe_delete(packet);
  1938. break;
  1939. }
  1940. }
  1941. bool escrowChange = false;
  1942. int64 statusReq = hz->upkeep_status;
  1943. int64 tmpRecoverStatus = 0;
  1944. if(ph->escrow_status && statusReq >= ph->escrow_status )
  1945. {
  1946. escrowChange = true;
  1947. tmpRecoverStatus = ph->escrow_status;
  1948. statusReq -= ph->escrow_status;
  1949. ph->escrow_status = 0;
  1950. }
  1951. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  1952. {
  1953. escrowChange = true;
  1954. ph->escrow_status -= statusReq;
  1955. tmpRecoverStatus = statusReq;
  1956. statusReq = 0;
  1957. }
  1958. int64 coinReq = hz->upkeep_coin;
  1959. int64 tmpRecoverCoins = 0;
  1960. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1961. {
  1962. escrowChange = true;
  1963. tmpRecoverCoins = ph->escrow_coins;
  1964. coinReq -= ph->escrow_coins;
  1965. ph->escrow_coins = 0;
  1966. }
  1967. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1968. {
  1969. escrowChange = true;
  1970. // more than enough in escrow, subtract and make our cost 0!
  1971. ph->escrow_coins -= coinReq;
  1972. tmpRecoverCoins = coinReq;
  1973. coinReq = 0;
  1974. }
  1975. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  1976. if(!statusReq || (statusReq && statusReq <= available_status_points))
  1977. {
  1978. if(coinReq && player->RemoveCoins(coinReq))
  1979. coinReq = 0;
  1980. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  1981. statusReq = 0;
  1982. }
  1983. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  1984. {
  1985. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1986. if (escrowChange)
  1987. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  1988. ph->upkeep_due = upkeep_due;
  1989. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1990. //ClientPacketFunctions::SendHousingList(this);
  1991. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1992. PlaySound("coin_cha_ching");
  1993. }
  1994. else
  1995. {
  1996. // recover the escrow we were going to use but could not spend due to lack of funds
  1997. if (tmpRecoverCoins)
  1998. ph->escrow_coins += tmpRecoverCoins;
  1999. if(tmpRecoverStatus)
  2000. ph->escrow_status += tmpRecoverStatus;
  2001. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2002. PlaySound("buy_failed");
  2003. }
  2004. }
  2005. else
  2006. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2007. }
  2008. safe_delete(packet);
  2009. break;
  2010. }
  2011. case OP_ExitHouseMsg: {
  2012. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2013. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2014. if (instance_id > 0) {
  2015. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2016. if (ph) {
  2017. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2018. if (hz) {
  2019. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2020. // determine if this is an instanced zone that already exists
  2021. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2022. if (instance_zone || new_zone) {
  2023. GetPlayer()->SetX(hz->exit_x);
  2024. GetPlayer()->SetY(hz->exit_y);
  2025. GetPlayer()->SetZ(hz->exit_z);
  2026. GetPlayer()->SetHeading(hz->exit_heading);
  2027. if (instance_zone)
  2028. Zone(instance_zone->GetInstanceID(), false, true);
  2029. else
  2030. Zone(new_zone, false);
  2031. }
  2032. }
  2033. }
  2034. }
  2035. DumpPacket(app);
  2036. break;
  2037. }
  2038. case OP_QuestJournalWaypointMsg: {
  2039. //DumpPacket(app);
  2040. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2041. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2042. if (packet) {
  2043. packet->LoadPacketData(app->pBuffer, app->size);
  2044. int32 quests = packet->getType_int32_ByName("num_quests");
  2045. if (quests > 100) // just picking a number higher than max allowed
  2046. {
  2047. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2048. break;
  2049. }
  2050. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2051. for (int32 i = 0; i < quests; i++) {
  2052. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2053. if (id == 0)
  2054. continue;
  2055. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2056. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2057. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2058. if (player->player_quests.count(id) > 0) {
  2059. player->player_quests[id]->SetTracked(tracked);
  2060. player->player_quests[id]->SetSaveNeeded(true);
  2061. }
  2062. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2063. }
  2064. safe_delete(packet);
  2065. }
  2066. break;
  2067. }
  2068. case OP_PaperdollImage: {
  2069. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2070. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2071. //First check if this is a new image... delete an existing partial image if one exists
  2072. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2073. if (packet_index == 0) {
  2074. safe_delete_array(incoming_paperdoll.image_bytes);
  2075. incoming_paperdoll.last_received_packet_index = 0;
  2076. incoming_paperdoll.current_size_bytes = 0;
  2077. }
  2078. //return if this packet is not the one we are expecting...
  2079. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2080. safe_delete(packet);
  2081. break;
  2082. }
  2083. //Check how many packets we're supposed to be receiving for this/these images
  2084. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2085. //Check the image type, if this is a new type in the same series of packets we have a new image
  2086. int8 img_type = packet->getType_int8_ByName("image_type");
  2087. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2088. //We have a new image. Save the old data and clear before continuing
  2089. SavePlayerImages();
  2090. }
  2091. incoming_paperdoll.image_type = img_type;
  2092. //Get the size of the image data in this packet
  2093. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2094. if (image_size <= 0 || image_size > 1048576) {
  2095. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2096. safe_delete(packet);
  2097. break;
  2098. }
  2099. //Create a new array
  2100. int32 new_image_size = image_size;
  2101. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2102. if (incoming_paperdoll.image_bytes) {
  2103. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2104. safe_delete_array(incoming_paperdoll.image_bytes);
  2105. }
  2106. //variable i should be the index in the packet of the first PNG file byte
  2107. vector<DataStruct*>* d_structs = packet->getStructs();
  2108. vector<DataStruct*>::iterator itr;
  2109. int32 i = 0;
  2110. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2111. DataStruct* ds = (*itr);
  2112. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2113. i += ds->GetDataSizeInBytes();
  2114. else
  2115. break;
  2116. }
  2117. //Return if this packet is bad and we would read out of bounds
  2118. if (app->size - i < new_image_size) {
  2119. safe_delete(packet);
  2120. safe_delete_array(new_image);
  2121. break;
  2122. }
  2123. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2124. memcpy(tmp, app->pBuffer + i, new_image_size);
  2125. incoming_paperdoll.current_size_bytes += new_image_size;
  2126. incoming_paperdoll.image_bytes = new_image;
  2127. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2128. if (incoming_paperdoll.image_num_packets == 1 ||
  2129. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2130. SavePlayerImages();
  2131. }
  2132. incoming_paperdoll.last_received_packet_index = packet_index;
  2133. }
  2134. safe_delete(packet);
  2135. */
  2136. break;
  2137. }
  2138. case OP_ReadyForTakeOffMsg:
  2139. {
  2140. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2141. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2142. if (GetPendingFlightPath() > 0) {
  2143. if (index != -1) {
  2144. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2145. if (packet) {
  2146. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2147. packet->setDataByName("path_id", index);
  2148. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2149. QueuePacket(packet->serialize());
  2150. safe_delete(packet);
  2151. on_auto_mount = true;
  2152. }
  2153. }
  2154. else {
  2155. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2156. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2157. EndAutoMount();
  2158. }
  2159. SetPendingFlightPath(0);
  2160. }
  2161. else
  2162. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2163. break;
  2164. }
  2165. case OP_EarlyLandingRequestMsg:
  2166. {
  2167. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2168. EndAutoMount();
  2169. break;
  2170. }
  2171. case OP_SubmitCharCust:
  2172. {
  2173. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2174. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2175. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2176. int8 type = packet->getType_int8_ByName("type");
  2177. if (type == 0) {
  2178. if (player->custNPC) {
  2179. player->custNPCTarget->CustomizeAppearance(packet);
  2180. current_zone->SendSpawnChanges(player->custNPCTarget);
  2181. }
  2182. else {
  2183. player->CustomizeAppearance(packet);
  2184. current_zone->SendSpawnChanges(player);
  2185. }
  2186. }
  2187. }
  2188. if (player->custNPC) {
  2189. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2190. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2191. if (player->custNPCTarget->IsBot())
  2192. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2193. player->custNPC = false;
  2194. player->custNPCTarget = 0;
  2195. player->changed = true;
  2196. player->info_changed = true;
  2197. current_zone->SendSpawnChanges(player, this);
  2198. }
  2199. break;
  2200. }
  2201. default: {
  2202. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2203. const char* name = app->GetOpcodeName();
  2204. if (name)
  2205. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2206. else
  2207. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2208. //DumpPacket(app);
  2209. }
  2210. }
  2211. if (!eqs || !eqs->CheckActive()) {
  2212. return false;
  2213. }
  2214. return ret;
  2215. }
  2216. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2217. if (!item) {
  2218. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2219. return false;
  2220. }
  2221. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2222. if (player->item_list.AssignItemToFreeSlot(item)) {
  2223. int8 type = CHANNEL_LOOT;
  2224. if (entity) {
  2225. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2226. }
  2227. else {
  2228. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2229. }
  2230. Guild* guild = player->GetGuild();
  2231. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2232. char adjective[32];
  2233. int8 type;
  2234. memset(adjective, 0, sizeof(adjective));
  2235. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2236. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2237. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2238. }
  2239. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2240. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2241. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2242. }
  2243. else {
  2244. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2245. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2246. }
  2247. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2248. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2249. }
  2250. if (item->GetItemScript() && lua_interface)
  2251. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2252. CheckPlayerQuestsItemUpdate(item);
  2253. return true;
  2254. }
  2255. else
  2256. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2257. }
  2258. else
  2259. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2260. return false;
  2261. }
  2262. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2263. if (!entity) {
  2264. return false;
  2265. }
  2266. Item* item = entity->LootItem(item_id);
  2267. bool success = false;
  2268. success = HandleLootItem(entity, item);
  2269. if(!success)
  2270. entity->AddLootItem(item);
  2271. return success;
  2272. }
  2273. void Client::HandleLoot(EQApplicationPacket* app) {
  2274. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2275. if (packet) {
  2276. packet->LoadPacketData(app->pBuffer, app->size);
  2277. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2278. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2279. safe_delete(packet);
  2280. int32 item_id = 0;
  2281. Item* item = 0;
  2282. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2283. if (player->HasPendingLootItems(loot_id)) {
  2284. Item* master_item = 0;
  2285. if (loot_all) {
  2286. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2287. if (items) {
  2288. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2289. master_item = items->at(i);
  2290. if (master_item) {
  2291. item = new Item(master_item);
  2292. if (item) {
  2293. loot_all = HandleLootItem(0, item);
  2294. if (loot_all)
  2295. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2296. }
  2297. }
  2298. }
  2299. safe_delete(items);
  2300. }
  2301. }
  2302. else {
  2303. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2304. if (packet) {
  2305. packet->LoadPacketData(app->pBuffer, app->size);
  2306. item_id = packet->getType_int32_ByName("item_id");
  2307. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2308. if (items) {
  2309. for (int32 i = 0; i < items->size(); i++) {
  2310. master_item = items->at(i);
  2311. if (master_item && master_item->details.item_id == item_id) {
  2312. item = new Item(master_item);
  2313. if (item && HandleLootItem(0, item))
  2314. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2315. break;
  2316. }
  2317. }
  2318. safe_delete(items);
  2319. }
  2320. safe_delete(packet);
  2321. }
  2322. }
  2323. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2324. if (outapp)
  2325. QueuePacket(outapp);
  2326. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2327. }
  2328. else {
  2329. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2330. if (loot_all) {
  2331. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2332. loot_all = HandleLootItem(spawn, item_id);
  2333. }
  2334. }
  2335. else {
  2336. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2337. if (packet) {
  2338. packet->LoadPacketData(app->pBuffer, app->size);
  2339. item_id = packet->getType_int32_ByName("item_id");
  2340. HandleLootItem(spawn, item_id);
  2341. safe_delete(packet);
  2342. }
  2343. }
  2344. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2345. if (outapp)
  2346. QueuePacket(outapp);
  2347. Loot(spawn);
  2348. if (!spawn->HasLoot()) {
  2349. CloseLoot(loot_id);
  2350. if (spawn->IsNPC())
  2351. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2352. }
  2353. }
  2354. else {
  2355. if (!spawn) {
  2356. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2357. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2358. }
  2359. else
  2360. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2361. }
  2362. }
  2363. }
  2364. }
  2365. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2366. PacketStruct* request = 0;
  2367. // cout << "Request: \n";
  2368. // DumpPacket(app);
  2369. switch (app->pBuffer[0]) {
  2370. case 0: { //items
  2371. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2372. if (request) {
  2373. request->LoadPacketData(app->pBuffer, app->size);
  2374. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2375. if (!item)
  2376. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2377. if (item) {
  2378. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2379. if (response) {
  2380. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2381. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2382. response->setSmallStringByName("name", item->name.c_str());
  2383. EQ2Packet* app2 = response->serialize();
  2384. //DumpPacket(app2);
  2385. QueuePacket(app2);
  2386. safe_delete(response);
  2387. }
  2388. }
  2389. }
  2390. break;
  2391. }
  2392. case 2: {//spells
  2393. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2394. if (request) {
  2395. request->LoadPacketData(app->pBuffer, app->size);
  2396. int32 id = request->getType_int32_ByName("id");
  2397. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2398. Spell* spell = master_spell_list.GetSpell(id, tier);
  2399. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2400. if (response) {
  2401. response->setDataByName("request_type", 2);
  2402. response->setDataByName("unique_id", tier);
  2403. response->setDataByName("id", id);
  2404. if (spell)
  2405. response->setSmallStringByName("name", spell->GetName());
  2406. else
  2407. response->setSmallStringByName("name", "Unknown Spell");
  2408. EQ2Packet* app2 = response->serialize();
  2409. // DumpPacket(app2);
  2410. QueuePacket(app2);
  2411. safe_delete(response);
  2412. }
  2413. }
  2414. break;
  2415. }
  2416. default: {
  2417. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2418. }
  2419. }
  2420. safe_delete(request);
  2421. }
  2422. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2423. PacketStruct* request = 0;
  2424. if (!app || app->size == 0)
  2425. return;
  2426. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2427. //DumpPacket(app);
  2428. int8 type = app->pBuffer[0];
  2429. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2430. if (version <= 283) {
  2431. if (type == 1)
  2432. type = 4;
  2433. else if (type == 2)
  2434. type = 5;
  2435. }
  2436. if (type == 3) {
  2437. Spell* spell = 0;
  2438. bool trait_display;
  2439. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2440. if (!request) {
  2441. return;
  2442. }
  2443. request->LoadPacketData(app->pBuffer, app->size);
  2444. int32 id = request->getType_int32_ByName("id");
  2445. int32 tier = request->getType_int32_ByName("tier");
  2446. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2447. bool display = true;
  2448. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2449. display = false;
  2450. else if (version <= 546)
  2451. display = request->getType_int8_ByName("display");
  2452. else if (version > 546)
  2453. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2454. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2455. if (trait_tier != 0xFFFFFFFF) {
  2456. spell = master_spell_list.GetSpell(id, trait_tier);
  2457. if (!spell) {
  2458. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2459. }
  2460. trait_display = true;
  2461. }
  2462. else {
  2463. spell = master_spell_list.GetSpell(id, tier);
  2464. trait_display = false;
  2465. }
  2466. // if we can't find it on the master spell list, see if it is a custom spell
  2467. if (!spell)
  2468. {
  2469. lua_interface->FindCustomSpellLock();
  2470. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2471. if (tmpSpell)
  2472. spell = tmpSpell->spell;
  2473. lua_interface->FindCustomSpellUnlock();
  2474. }
  2475. if (spell && !CountSentSpell(id, tier)) {
  2476. if (!spell->IsCopiedSpell())
  2477. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2478. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2479. //DumpPacket(app);
  2480. QueuePacket(app);
  2481. }
  2482. }
  2483. else if (type == 0) {
  2484. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2485. if (!request) {
  2486. return;
  2487. }
  2488. request->LoadPacketData(app->pBuffer, app->size);
  2489. int32 id = request->getType_int32_ByName("id");
  2490. Item* item = 0;
  2491. // translate from unique id to spawn id for houses
  2492. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2493. bool wasSpawn = false;
  2494. if (spawn)
  2495. {
  2496. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2497. if (item)
  2498. {
  2499. wasSpawn = true;
  2500. item = new Item(item);
  2501. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2502. }
  2503. }
  2504. if (!item)
  2505. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2506. if (!item)
  2507. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2508. if (!item)
  2509. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2510. if (!item)
  2511. item = master_item_list.GetItem(id);
  2512. if (item) {// && sent_item_details.count(id) == 0){
  2513. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2514. sent_item_details[id] = true;
  2515. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2516. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2517. //DumpPacket(app);
  2518. QueuePacket(app);
  2519. if (wasSpawn)
  2520. delete item;
  2521. }
  2522. else {
  2523. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2524. DumpPacket(app);
  2525. }
  2526. }
  2527. else if (type == 1) {
  2528. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2529. if (!request) {
  2530. return;
  2531. }
  2532. request->LoadPacketData(app->pBuffer, app->size);
  2533. int32 id = request->getType_int32_ByName("id");
  2534. int32 unique_id = request->getType_int32_ByName("unique_id");
  2535. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2536. if (!item)
  2537. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2538. if (!item)
  2539. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2540. if (!item)
  2541. item = master_item_list.GetItem(id);
  2542. if (item) {
  2543. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2544. sent_item_details[id] = true;
  2545. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2546. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2547. //DumpPacket(app);
  2548. QueuePacket(app);
  2549. }
  2550. else {
  2551. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2552. DumpPacket(app);
  2553. }
  2554. }
  2555. else if (type == 2) {
  2556. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2557. if (!request) {
  2558. return;
  2559. }
  2560. request->LoadPacketData(app->pBuffer, app->size);
  2561. int32 id = request->getType_int32_ByName("item_id");
  2562. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2563. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2564. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2565. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2566. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2567. //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);
  2568. Item* item = master_item_list.GetItem(id);
  2569. if (item) {
  2570. //only display popup for non merchant links
  2571. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2572. //DumpPacket(app);
  2573. QueuePacket(app);
  2574. }
  2575. else {
  2576. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2577. DumpPacket(app);
  2578. }
  2579. }
  2580. else if (type == 4) { //spell effect
  2581. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2582. if (!request) {
  2583. return;
  2584. }
  2585. request->LoadPacketData(app->pBuffer, app->size);
  2586. int32 id = request->getType_int32_ByName("id");
  2587. int16 display = request->getType_int8_ByName("partial_info");
  2588. SpellEffects* effect = player->GetSpellEffect(id);
  2589. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2590. if (effect) {
  2591. int8 tier = effect->tier;
  2592. Spell* spell = master_spell_list.GetSpell(id, tier);
  2593. // if we can't find it on the master spell list, see if it is a custom spell
  2594. if (!spell)
  2595. {
  2596. lua_interface->FindCustomSpellLock();
  2597. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2598. EQ2Packet* pack = 0;
  2599. if (tmpSpell)
  2600. spell = tmpSpell->spell;
  2601. lua_interface->FindCustomSpellUnlock();
  2602. }
  2603. if (spell && !CountSentSpell(id, tier)) {
  2604. if (!spell->IsCopiedSpell())
  2605. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2606. int8 type = 0;
  2607. if (version <= 283)
  2608. type = 1;
  2609. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2610. //DumpPacket(app);
  2611. QueuePacket(app);
  2612. }
  2613. }
  2614. }
  2615. else if (type == 5) { // recipe info
  2616. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2617. if (!request)
  2618. return;
  2619. request->LoadPacketData(app->pBuffer, app->size);
  2620. int32 id = request->getType_int32_ByName("unknown_id");
  2621. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2622. if (recipe) {
  2623. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2624. //DumpPacket(app);
  2625. QueuePacket(app);
  2626. }
  2627. }
  2628. else if (type == 6) { // AA spell info
  2629. Spell* spell = 0;
  2630. //Spell* spell2 = 0;
  2631. //AltAdvanceData* data = 0;
  2632. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2633. if (!request)
  2634. return;
  2635. request->LoadPacketData(app->pBuffer, app->size);
  2636. int32 id = request->getType_int32_ByName("id");
  2637. int32 tier = GetPlayer()->GetSpellTier(id);
  2638. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2639. //data = master_aa_list.GetAltAdvancement(id);
  2640. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2641. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2642. spell = master_spell_list.GetSpell(id, tier);
  2643. if (!spell)
  2644. spell = master_spell_list.GetSpell(id, 1);
  2645. if (!spell)
  2646. {
  2647. lua_interface->FindCustomSpellLock();
  2648. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2649. if (tmpSpell)
  2650. spell = tmpSpell->spell;
  2651. lua_interface->FindCustomSpellUnlock();
  2652. }
  2653. if (!spell)
  2654. {
  2655. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2656. return;
  2657. }
  2658. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2659. if (!spell->IsCopiedSpell())
  2660. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2661. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2662. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2663. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2664. //DumpPacket(app);
  2665. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2666. QueuePacket(app);
  2667. //}
  2668. }
  2669. else {
  2670. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2671. DumpPacket(app);
  2672. }
  2673. safe_delete(request);
  2674. }
  2675. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2676. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2677. if (request) {
  2678. request->LoadPacketData(app->pBuffer, app->size);
  2679. int32 id = request->getType_int32_ByName("id");
  2680. int32 bar = request->getType_int32_ByName("hotbar_number");
  2681. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2682. int32 type = request->getType_int32_ByName("type");
  2683. int8 tier = request->getType_int32_ByName("unique_id");
  2684. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2685. Spell* spell = 0;
  2686. if (type == 0xFFFFFFFF)
  2687. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2688. else {
  2689. if (type == QUICKBAR_NORMAL)
  2690. spell = master_spell_list.GetSpell(id, tier);
  2691. if (spell)
  2692. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2693. else
  2694. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2695. }
  2696. safe_delete(request);
  2697. }
  2698. }
  2699. bool Client::Process(bool zone_process) {
  2700. if (!eqs) {
  2701. return false;
  2702. }
  2703. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2704. return true;
  2705. }
  2706. if (new_client_login) {
  2707. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2708. SendLoginInfo();
  2709. new_client_login = false;
  2710. }
  2711. bool ret = true;
  2712. sockaddr_in to;
  2713. memset((char*)&to, 0, sizeof(to));
  2714. to.sin_family = AF_INET;
  2715. to.sin_port = port;
  2716. to.sin_addr.s_addr = ip;
  2717. /************ Get all packets from packet manager out queue and process them ************/
  2718. EQApplicationPacket* app = 0;
  2719. if (eqs && !eqs->CheckActive()) {
  2720. num_active_failures++;
  2721. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2722. if (num_active_failures > 100) {
  2723. return false;
  2724. }
  2725. return true;
  2726. }
  2727. while (ret && eqs && (app = eqs->PopPacket())) {
  2728. ret = HandlePacket(app);
  2729. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2730. delete app;
  2731. }
  2732. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2733. player->ApplyPassiveSpells();
  2734. //database.LoadCharacterActiveSpells(player);
  2735. player->UnlockAllSpells(true);
  2736. should_load_spells = false;
  2737. }
  2738. if(spawn_removal_timer.Check() && GetPlayer()) {
  2739. GetPlayer()->CheckSpawnRemovalQueue();
  2740. }
  2741. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2742. {
  2743. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2744. return false;
  2745. }
  2746. if (quest_updates) {
  2747. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2748. ProcessQuestUpdates();
  2749. }
  2750. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2751. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2752. CheckQuestQueue();
  2753. }
  2754. MSaveSpellStateMutex.lock();
  2755. if(save_spell_state_timer.Check())
  2756. {
  2757. save_spell_state_timer.Disable();
  2758. GetPlayer()->SaveSpellEffects();
  2759. }
  2760. MSaveSpellStateMutex.unlock();
  2761. if (temp_placement_timer.Check()) {
  2762. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2763. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2764. hasSentTempPlacementSpawn = true;
  2765. temp_placement_timer.Disable();
  2766. }
  2767. }
  2768. if (pos_update.Check())
  2769. {
  2770. ProcessStateCommands();
  2771. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2772. if(GetPlayer()->GetRegionMap())
  2773. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2774. if(player_pos_changed && IsReadyForUpdates()) {
  2775. //GetPlayer()->CalculateLocation();
  2776. client_list.CheckPlayersInvisStatus(this);
  2777. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2778. player_pos_changed = false;
  2779. GetCurrentZone()->CheckTransporters(this);
  2780. if(GetPlayer()->GetRegionMap())
  2781. {
  2782. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2783. {
  2784. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2785. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2786. }
  2787. else
  2788. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2789. }
  2790. }
  2791. }
  2792. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2793. lua_interface->UpdateDebugClients(this);
  2794. if (quest_pos_timer.Check())
  2795. CheckPlayerQuestsLocationUpdate();
  2796. if (player->GetSkills()->HasSkillUpdates()) {
  2797. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2798. if (skills) {
  2799. Skill* skill = 0;
  2800. vector<Skill*>::iterator itr;
  2801. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2802. skill = *itr;
  2803. SkillChanged(skill, skill->previous_val, skill->current_val);
  2804. }
  2805. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2806. if (app) QueuePacket(app);
  2807. safe_delete(skills);
  2808. }
  2809. }
  2810. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2811. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2812. safe_delete(current_rez.expire_timer);
  2813. current_rez.expire_timer = 0;
  2814. current_rez.active = false;
  2815. current_rez.caster = 0;
  2816. current_rez.crit = false;
  2817. current_rez.crit_mod = 0;
  2818. current_rez.expire_timer = 0;
  2819. current_rez.heal_name = "";
  2820. current_rez.hp_perc = 0;
  2821. current_rez.mp_perc = 0;
  2822. current_rez.no_calcs = false;
  2823. current_rez.range = 0;
  2824. current_rez.should_delete = false;
  2825. current_rez.spell_name = "";
  2826. current_rez.spell_visual = 0;
  2827. current_rez.subspell = 0;
  2828. }
  2829. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2830. // Quest timers
  2831. Quest* failed_step = 0;
  2832. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2833. if (quest_timers.size() > 0) {
  2834. vector<int32>::iterator itr;
  2835. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2836. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2837. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2838. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2839. Quest* quest = player_quests->at(*itr);
  2840. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2841. failed_step = quest;
  2842. break;
  2843. }
  2844. }
  2845. else {
  2846. itr = quest_timers.erase(itr);
  2847. break;
  2848. }
  2849. }
  2850. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  2851. }
  2852. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2853. if (failed_step)
  2854. failed_step->StepFailed(failed_step->GetTimerStep());
  2855. if (player->ControlFlagsChanged())
  2856. player->SendControlFlagUpdates(this);
  2857. if (camp_timer && camp_timer->Check()) {
  2858. ResetSendMail();
  2859. if(getConnection())
  2860. getConnection()->SendDisconnect(false);
  2861. safe_delete(camp_timer);
  2862. ret = false;
  2863. }
  2864. if (!eqs || (eqs && !eqs->CheckActive()))
  2865. ret = false;
  2866. // redundant to client disconnect
  2867. // if(!ret)
  2868. // Save();
  2869. return ret;
  2870. }
  2871. ClientList::ClientList() {
  2872. MClients.SetName("ClientList::MClients");
  2873. }
  2874. ClientList::~ClientList() {
  2875. }
  2876. void ClientList::ReloadQuests() {
  2877. list<Client*>::iterator client_iter;
  2878. Client* client = 0;
  2879. MClients.readlock(__FUNCTION__, __LINE__);
  2880. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2881. client = *client_iter;
  2882. if (client)
  2883. client->ReloadQuests();
  2884. }
  2885. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2886. }
  2887. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2888. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2889. return;
  2890. list<Client*>::iterator client_iter;
  2891. Client* client = 0;
  2892. MClients.readlock(__FUNCTION__, __LINE__);
  2893. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2894. client = *client_iter;
  2895. if (client == owner || client->GetPlayer() == NULL)
  2896. continue;
  2897. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2898. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2899. }
  2900. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2901. }
  2902. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2903. list<Client*>::iterator client_iter;
  2904. Client* client = 0;
  2905. MClients.readlock(__FUNCTION__, __LINE__);
  2906. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2907. client = *client_iter;
  2908. if (!client->GetPlayer())
  2909. continue;
  2910. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2911. }
  2912. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2913. }
  2914. int32 ClientList::Count() {
  2915. return client_list.size();
  2916. }
  2917. void ClientList::Add(Client* client) {
  2918. MClients.writelock(__FUNCTION__, __LINE__);
  2919. client_list.push_back(client);
  2920. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2921. }
  2922. Client* ClientList::FindByAccountID(int32 account_id) {
  2923. list<Client*>::iterator client_iter;
  2924. Client* client = 0;
  2925. Client* ret = 0;
  2926. MClients.readlock(__FUNCTION__, __LINE__);
  2927. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2928. client = *client_iter;
  2929. if (client->GetAccountID() == account_id) {
  2930. ret = client;
  2931. break;
  2932. }
  2933. }
  2934. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2935. return ret;
  2936. }
  2937. Client* ClientList::FindByName(char* charName) {
  2938. list<Client*>::iterator client_iter;
  2939. Client* client = 0;
  2940. Client* ret = 0;
  2941. MClients.readlock(__FUNCTION__, __LINE__);
  2942. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2943. client = *client_iter;
  2944. if (!client || !client->GetPlayer())
  2945. continue;
  2946. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2947. ret = client;
  2948. break;
  2949. }
  2950. }
  2951. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2952. return ret;
  2953. }
  2954. Client* ClientList::Get(int32 ip, int16 port) {
  2955. list<Client*>::iterator client_iter;
  2956. Client* client = 0;
  2957. Client* ret = 0;
  2958. MClients.readlock(__FUNCTION__, __LINE__);
  2959. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2960. client = *client_iter;
  2961. if (client->GetIP() == ip && client->GetPort() == port) {
  2962. ret = client;
  2963. break;
  2964. }
  2965. }
  2966. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2967. return ret;
  2968. }
  2969. void ClientList::Process() {
  2970. list<Client*>::iterator client_iter;
  2971. list<Client*>::iterator erase_iter;
  2972. Client* client = 0;
  2973. MClients.readlock(__FUNCTION__, __LINE__);
  2974. erase_iter = client_list.end();
  2975. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2976. client = *client_iter;
  2977. // have a sanity check because the client list can sometimes obtain null client pointers
  2978. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  2979. erase_iter = client_iter;
  2980. break;
  2981. }
  2982. }
  2983. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2984. if (erase_iter != client_list.end()) {
  2985. client = *erase_iter;
  2986. MClients.writelock(__FUNCTION__, __LINE__);
  2987. client_list.erase(erase_iter);
  2988. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2989. if (client && !client->remove_from_list) {
  2990. struct in_addr in;
  2991. in.s_addr = client->GetIP();
  2992. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2993. safe_delete(client);
  2994. }
  2995. }
  2996. }
  2997. void ClientList::RemoveConnection(EQStream* eqs) {
  2998. Client* client;
  2999. if (eqs) {
  3000. list<Client*>::iterator client_iter;
  3001. MClients.readlock(__FUNCTION__, __LINE__);
  3002. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3003. client = *client_iter;
  3004. if (client->getConnection() == eqs)
  3005. client->Disconnect(true);
  3006. }
  3007. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3008. }
  3009. }
  3010. bool ClientList::ContainsStream(EQStream* eqs) {
  3011. if (!eqs) {
  3012. return false;
  3013. }
  3014. list<Client*>::iterator client_iter;
  3015. bool ret = false;
  3016. MClients.readlock(__FUNCTION__, __LINE__);
  3017. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3018. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3019. ret = true;
  3020. break;
  3021. }
  3022. }
  3023. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3024. return ret;
  3025. }
  3026. void ClientList::Remove(Client* client, bool remove_data) {
  3027. client->remove_from_list = true;
  3028. if (remove_data) {
  3029. safe_delete(client);
  3030. }
  3031. }
  3032. void Client::SetCurrentZone(int32 id) {
  3033. if (current_zone) {
  3034. //current_zone->GetCombat()->RemoveHate(player);
  3035. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3036. }
  3037. SetCurrentZone(zone_list.Get(id));
  3038. }
  3039. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3040. if (current_zone) {
  3041. //current_zone->GetCombat()->RemoveHate(player);
  3042. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3043. }
  3044. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3045. }
  3046. ZoneServer* Client::GetCurrentZone() {
  3047. return current_zone;
  3048. }
  3049. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3050. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3051. if (channel_type == CHANNEL_LOOT)
  3052. return CHANNEL_COLOR_NEW_LOOT;
  3053. }
  3054. else if (GetVersion() >= 973) {
  3055. if (channel_type == CHANNEL_LOOT)
  3056. return CHANNEL_COLOR_NEWEST_LOOT;
  3057. }
  3058. if (GetVersion() <= 283) {
  3059. if (channel_type <=12)
  3060. return channel_type;
  3061. switch (channel_type) {
  3062. case CHANNEL_GROUP_CHAT:
  3063. case CHANNEL_GROUP_SAY:
  3064. case CHANNEL_RAID_SAY:
  3065. case CHANNEL_GUILD_CHAT:
  3066. case CHANNEL_GUILD_SAY:
  3067. case CHANNEL_OFFICER_SAY:
  3068. case CHANNEL_GUILD_MOTD:
  3069. return channel_type - 1;
  3070. case CHANNEL_PRIVATE_CHAT:
  3071. case CHANNEL_NONPLAYER_TELL:
  3072. return channel_type - 5;
  3073. case CHANNEL_PRIVATE_TELL:
  3074. case CHANNEL_TELL_FROM_CS:
  3075. return channel_type - 6;
  3076. case CHANNEL_CHAT_CHANNEL_TEXT:
  3077. case CHANNEL_OUT_OF_CHARACTER:
  3078. case CHANNEL_AUCTION:
  3079. case CHANNEL_CUSTOM_CHANNEL:
  3080. case CHANNEL_CHARACTER_TEXT:
  3081. case CHANNEL_REWARD:
  3082. case CHANNEL_DEATH:
  3083. case CHANNEL_PET_CHAT:
  3084. case CHANNEL_SKILL:
  3085. return channel_type - 7;
  3086. case CHANNEL_SPELLS:
  3087. case CHANNEL_YOU_CAST:
  3088. case CHANNEL_YOU_FAIL:
  3089. return channel_type - 8;
  3090. case CHANNEL_FRIENDLY_CAST:
  3091. case CHANNEL_FRIENDLY_FAIL:
  3092. case CHANNEL_OTHER_CAST:
  3093. case CHANNEL_OTHER_FAIL:
  3094. case CHANNEL_HOSTILE_CAST:
  3095. case CHANNEL_HOSTILE_FAIL:
  3096. case CHANNEL_WORN_OFF:
  3097. case CHANNEL_SPELLS_OTHER:
  3098. return channel_type - 9;
  3099. case CHANNEL_COMBAT:
  3100. return channel_type - 15;
  3101. case CHANNEL_HEROIC_OPPORTUNITY:
  3102. case CHANNEL_NON_MELEE_DAMAGE:
  3103. case CHANNEL_DAMAGE_SHIELD:
  3104. return channel_type - 16;
  3105. case CHANNEL_MELEE_COMBAT:
  3106. case CHANNEL_WARNINGS:
  3107. case CHANNEL_YOU_HIT:
  3108. case CHANNEL_YOU_MISS:
  3109. case CHANNEL_ATTACKER_HITS:
  3110. case CHANNEL_ATTACKER_MISSES:
  3111. return channel_type - 18;
  3112. case CHANNEL_OTHER_HIT:
  3113. case CHANNEL_OTHER_MISSES:
  3114. case CHANNEL_CRITICAL_HIT:
  3115. return channel_type - 22;
  3116. case CHANNEL_OTHER:
  3117. case CHANNEL_MONEY_SPLIT:
  3118. case CHANNEL_LOOT:
  3119. return channel_type - 30;
  3120. case CHANNEL_COMMAND_TEXT:
  3121. case CHANNEL_BROADCAST:
  3122. case CHANNEL_WHO:
  3123. case CHANNEL_COMMANDS:
  3124. case CHANNEL_MERCHANT:
  3125. case CHANNEL_MERCHANT_BUY_SELL:
  3126. case CHANNEL_CONSIDER_MESSAGE:
  3127. case CHANNEL_CON_MINUS_2:
  3128. case CHANNEL_CON_MINUS_1:
  3129. case CHANNEL_CON_0:
  3130. case CHANNEL_CON_1:
  3131. case CHANNEL_CON_2:
  3132. return channel_type - 31;
  3133. default: {
  3134. return CHANNEL_DEFAULT;
  3135. }
  3136. }
  3137. }
  3138. else if (GetVersion() <= 546) {
  3139. if (channel_type < 20)
  3140. return channel_type;
  3141. switch (channel_type) {
  3142. case CHANNEL_GUILD_MOTD:
  3143. case CHANNEL_GUILD_MEMBER_ONLINE:
  3144. case CHANNEL_GUILD_EVENT:
  3145. return channel_type + 1;
  3146. case CHANNEL_PRIVATE_CHAT:
  3147. case CHANNEL_NONPLAYER_TELL:
  3148. return channel_type - 1;
  3149. case CHANNEL_PRIVATE_TELL:
  3150. case CHANNEL_TELL_FROM_CS:
  3151. case CHANNEL_ARENA:
  3152. case CHANNEL_CHAT_CHANNEL_TEXT:
  3153. case CHANNEL_OUT_OF_CHARACTER:
  3154. case CHANNEL_AUCTION:
  3155. case CHANNEL_CUSTOM_CHANNEL:
  3156. case CHANNEL_CHARACTER_TEXT:
  3157. case CHANNEL_REWARD:
  3158. case CHANNEL_DEATH:
  3159. case CHANNEL_PET_CHAT:
  3160. case CHANNEL_SKILL:
  3161. case CHANNEL_FACTION:
  3162. case CHANNEL_SPELLS:
  3163. case CHANNEL_YOU_CAST:
  3164. case CHANNEL_YOU_FAIL:
  3165. return channel_type - 2;
  3166. case CHANNEL_FRIENDLY_CAST:
  3167. case CHANNEL_FRIENDLY_FAIL:
  3168. case CHANNEL_OTHER_CAST:
  3169. case CHANNEL_OTHER_FAIL:
  3170. case CHANNEL_HOSTILE_CAST:
  3171. case CHANNEL_HOSTILE_FAIL:
  3172. case CHANNEL_WORN_OFF:
  3173. case CHANNEL_SPELLS_OTHER:
  3174. case CHANNEL_HEAL_SPELLS:
  3175. case CHANNEL_HEALS:
  3176. case CHANNEL_FRIENDLY_HEALS:
  3177. case CHANNEL_OTHER_HEALS:
  3178. case CHANNEL_HOSTILE_HEALS:
  3179. return channel_type - 3;
  3180. case CHANNEL_COMBAT:
  3181. case CHANNEL_GENERAL_COMBAT:
  3182. case CHANNEL_HEROIC_OPPORTUNITY:
  3183. case CHANNEL_NON_MELEE_DAMAGE:
  3184. case CHANNEL_DAMAGE_SHIELD:
  3185. case CHANNEL_WARD:
  3186. return channel_type - 4;
  3187. case CHANNEL_MELEE_COMBAT:
  3188. case CHANNEL_WARNINGS:
  3189. case CHANNEL_YOU_HIT:
  3190. case CHANNEL_YOU_MISS:
  3191. case CHANNEL_ATTACKER_HITS:
  3192. case CHANNEL_ATTACKER_MISSES:
  3193. case CHANNEL_YOUR_PET_HITS:
  3194. case CHANNEL_YOUR_PET_MISSES:
  3195. case CHANNEL_ATTACKER_HITS_PET:
  3196. case CHANNEL_ATTACKER_MISSES_PET:
  3197. case CHANNEL_OTHER_HIT:
  3198. case CHANNEL_OTHER_MISSES:
  3199. return channel_type - 5;
  3200. case CHANNEL_OTHER:
  3201. case CHANNEL_MONEY_SPLIT:
  3202. case CHANNEL_LOOT:
  3203. return channel_type - 14;
  3204. case CHANNEL_COMMAND_TEXT:
  3205. case CHANNEL_BROADCAST:
  3206. case CHANNEL_WHO:
  3207. case CHANNEL_COMMANDS:
  3208. case CHANNEL_MERCHANT:
  3209. case CHANNEL_MERCHANT_BUY_SELL:
  3210. case CHANNEL_CONSIDER_MESSAGE:
  3211. case CHANNEL_CON_MINUS_2:
  3212. case CHANNEL_CON_MINUS_1:
  3213. case CHANNEL_CON_0:
  3214. case CHANNEL_CON_1:
  3215. case CHANNEL_CON_2:
  3216. case CHANNEL_TRADESKILLS:
  3217. case CHANNEL_HARVESTING:
  3218. case CHANNEL_HARVESTING_WARNINGS:
  3219. return channel_type - 15;
  3220. default: {
  3221. return CHANNEL_DEFAULT;
  3222. }
  3223. }
  3224. }
  3225. else {
  3226. switch (channel_type) {
  3227. default: {
  3228. return channel_type;
  3229. }
  3230. }
  3231. }
  3232. return channel_type;
  3233. }
  3234. void Client::HandleTellMessage(Client* from, const char* message) {
  3235. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3236. return;
  3237. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3238. if (packet) {
  3239. packet->setDataByName("from", from->GetPlayer()->GetName());
  3240. packet->setDataByName("to", GetPlayer()->GetName());
  3241. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3242. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3243. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3244. packet->setDataByName("unknown2", 1, 1);
  3245. packet->setDataByName("show_bubble", 1);
  3246. packet->setDataByName("understood", 1);
  3247. packet->setDataByName("time", 2);
  3248. packet->setMediumStringByName("message", message);
  3249. EQ2Packet* outpacket = packet->serialize();
  3250. QueuePacket(outpacket);
  3251. safe_delete(packet);
  3252. }
  3253. }
  3254. void Client::SimpleMessage(int8 color, const char* message) {
  3255. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3256. if (command_packet) {
  3257. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3258. command_packet->setMediumStringByName("text", message);
  3259. command_packet->setDataByName("unknown02", 0x00ff);
  3260. EQ2Packet* outapp = command_packet->serialize();
  3261. QueuePacket(outapp);
  3262. safe_delete(command_packet);
  3263. }
  3264. }
  3265. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3266. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3267. if (packet) {
  3268. int8 xxx = spell->GetSpellData()->is_aa;
  3269. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3270. packet->setDataByName("spell_id", spell->GetSpellID());
  3271. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3272. packet->setDataByName("spell_name", spell->GetName());
  3273. if(add_silently)
  3274. packet->setDataByName("add_silently", 1);
  3275. if(add_to_hotbar)
  3276. packet->setDataByName("add_to_hotbar", 1);
  3277. packet->setDataByName("unknown", xxx);
  3278. packet->setDataByName("display_spell_tier", 1);
  3279. packet->setDataByName("unknown3", 1);
  3280. packet->setDataByName("tier", spell->GetSpellTier());
  3281. packet->setDataByName("icon", spell->GetSpellIcon());
  3282. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3283. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3284. //packet->PrintPacket();
  3285. EQ2Packet* outapp = packet->serialize();
  3286. //DumpPacket(outapp);
  3287. QueuePacket(outapp);
  3288. safe_delete(packet);
  3289. }
  3290. }
  3291. void Client::Message(int8 type, const char* message, ...) {
  3292. va_list argptr;
  3293. char buffer[4096];
  3294. va_start(argptr, message);
  3295. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3296. va_end(argptr);
  3297. SimpleMessage(type, buffer);
  3298. }
  3299. void Client::Disconnect(bool send_disconnect)
  3300. {
  3301. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3302. this->Save();
  3303. this->GetPlayer()->WritePlayerStatistics();
  3304. SetConnected(false);
  3305. if (send_disconnect && getConnection())
  3306. getConnection()->SendDisconnect(true);
  3307. eqs = 0;
  3308. }
  3309. bool Client::Summon(const char* search_name) {
  3310. Spawn* target = 0;
  3311. if (search_name || GetPlayer()->GetTarget()) {
  3312. Client* search_client = 0;
  3313. if (search_name) {
  3314. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3315. if (target && target->IsPlayer())
  3316. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3317. if (!target) {
  3318. search_client = zone_list.GetClientByCharName(string(search_name));
  3319. if (search_client)
  3320. target = search_client->GetPlayer();
  3321. }
  3322. }
  3323. else
  3324. target = GetPlayer()->GetTarget();
  3325. if (target && target != GetPlayer()) {
  3326. target->SetX(GetPlayer()->GetX());
  3327. target->SetY(GetPlayer()->GetY());
  3328. target->SetZ(GetPlayer()->GetZ());
  3329. target->SetHeading(GetPlayer()->GetHeading());
  3330. if (!target->IsPlayer()) {
  3331. target->SetSpawnOrigX(target->GetX());
  3332. target->SetSpawnOrigY(target->GetY());
  3333. target->SetSpawnOrigZ(target->GetZ());
  3334. target->SetSpawnOrigHeading(target->GetHeading());
  3335. }
  3336. target->SetLocation(GetPlayer()->GetLocation());
  3337. }
  3338. else if (target)
  3339. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3340. if (search_client && search_client != this) {
  3341. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3342. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3343. if (search_client->GetCurrentZone() != GetCurrentZone())
  3344. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3345. else {
  3346. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3347. if (app)
  3348. search_client->QueuePacket(app);
  3349. }
  3350. }
  3351. }
  3352. if (!target)
  3353. return false;
  3354. else
  3355. return true;
  3356. }
  3357. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3358. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3359. if(instanceType < 1)
  3360. return std::string("");
  3361. ZoneServer* instance_zone = nullptr;
  3362. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3363. if (data) {
  3364. // If lockout instances check to see if we are locked out
  3365. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3366. int32 time = 0;
  3367. // Check success timer
  3368. if (data->last_success_timestamp > 0) {
  3369. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3370. // Timer has not expired yet can't re enter
  3371. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3372. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3373. }
  3374. }
  3375. // Check failure timer
  3376. if (data->last_failure_timestamp > 0) {
  3377. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3378. // Timer has not expired yet
  3379. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3380. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3381. }
  3382. }
  3383. // Time > 0 then we are locked out, make the message and send it and return true
  3384. if (time > 0) {
  3385. string time_msg = "";
  3386. int16 hour;
  3387. int8 min;
  3388. int8 sec;
  3389. hour = time / 3600;
  3390. time = time % 3600;
  3391. min = time / 60;
  3392. time = time % 60;
  3393. sec = time;
  3394. if (hour > 0) {
  3395. char temp[10];
  3396. snprintf(temp, 9," %i", hour);
  3397. time_msg.append(temp);
  3398. time_msg.append(" hour");
  3399. time_msg.append((hour > 1) ? "s" : "");
  3400. }
  3401. if (min > 0) {
  3402. char temp[5];
  3403. snprintf(temp, 4," %i", min);
  3404. time_msg.append(temp);
  3405. time_msg.append(" minute");
  3406. time_msg.append((min > 1) ? "s" : "");
  3407. }
  3408. // Only add seconds if minutes and hours are 0
  3409. if (hour == 0 && min == 0 && sec > 0) {
  3410. char temp[5];
  3411. snprintf(temp, 4," %i", sec);
  3412. time_msg.append(temp);
  3413. time_msg.append(" second");
  3414. time_msg.append((sec > 1) ? "s" : "");
  3415. }
  3416. if(displayClient)
  3417. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3418. return time_msg;
  3419. }
  3420. }
  3421. }
  3422. return std::string("");
  3423. }
  3424. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3425. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3426. if(instanceType < 1)
  3427. return nullptr;
  3428. ZoneServer* instance_zone = nullptr;
  3429. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3430. if (data) {
  3431. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3432. // If lockout instances check to see if we are locked out
  3433. if (lockoutTime.length() > 0) {
  3434. return nullptr;
  3435. }
  3436. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3437. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3438. // 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
  3439. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3440. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3441. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3442. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3443. }
  3444. else
  3445. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3446. data->instance_id = instance_zone->GetInstanceID();
  3447. }
  3448. }
  3449. return instance_zone;
  3450. }
  3451. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3452. ZoneServer* instance_zone = NULL;
  3453. int8 instanceType = 0;
  3454. // determine if this is a group instanced zone that already exists
  3455. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3456. if (instance_zone != NULL)
  3457. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3458. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3459. {
  3460. // best to check if we already have our own instance!
  3461. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3462. {
  3463. switch (instanceType)
  3464. {
  3465. case SOLO_LOCKOUT_INSTANCE:
  3466. case GROUP_LOCKOUT_INSTANCE:
  3467. case RAID_LOCKOUT_INSTANCE:
  3468. {
  3469. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3470. if (instance_zone) {
  3471. // 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
  3472. // so delete `instances` entry for the zone when it shuts down.
  3473. 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());
  3474. if (db_id > 0)
  3475. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3476. }
  3477. break;
  3478. }
  3479. case SOLO_PERSIST_INSTANCE:
  3480. case GROUP_PERSIST_INSTANCE:
  3481. case RAID_PERSIST_INSTANCE:
  3482. {
  3483. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3484. if (instance_zone) {
  3485. 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());
  3486. if (db_id > 0)
  3487. 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()));
  3488. }
  3489. break;
  3490. }
  3491. case PUBLIC_INSTANCE:
  3492. case TRADESKILL_INSTANCE:
  3493. {
  3494. // if its public/tradeskill, look for a public already setup
  3495. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3496. if (instance_zone) {
  3497. // Check the current population against the max population, if greater or equal start a new version
  3498. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3499. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3500. }
  3501. else
  3502. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3503. break;
  3504. }
  3505. case PERSONAL_HOUSE_INSTANCE:
  3506. case GUILD_HOUSE_INSTANCE:
  3507. {
  3508. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3509. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3510. // with the OP_EnterHouseMsg opcode
  3511. break;
  3512. }
  3513. case QUEST_INSTANCE:
  3514. {
  3515. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3516. break;
  3517. /*
  3518. 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`;
  3519. */
  3520. }
  3521. default:
  3522. {
  3523. // NONE
  3524. }
  3525. }
  3526. }
  3527. if (instance_zone != NULL)
  3528. Zone(instance_zone, zone_coords_valid);
  3529. }
  3530. if (instance_zone != NULL)
  3531. return true;
  3532. else
  3533. return false;
  3534. }
  3535. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3536. Spawn* target = 0;
  3537. if (search_name || GetPlayer()->GetTarget()) {
  3538. Client* search_client = 0;
  3539. if (search_name) {
  3540. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3541. if (!target) {
  3542. search_client = zone_list.GetClientByCharName(search_name);
  3543. if (search_client)
  3544. target = search_client->GetPlayer();
  3545. }
  3546. if (target)
  3547. GetPlayer()->SetTarget(target);
  3548. }
  3549. else
  3550. target = GetPlayer()->GetTarget();
  3551. if (target && target != GetPlayer()) {
  3552. GetPlayer()->SetX(target->GetX());
  3553. GetPlayer()->SetY(target->GetY());
  3554. GetPlayer()->SetZ(target->GetZ());
  3555. GetPlayer()->SetHeading(target->GetHeading());
  3556. GetPlayer()->SetLocation(target->GetLocation());
  3557. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3558. }
  3559. else if (target)
  3560. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3561. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3562. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3563. else if (target) {
  3564. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3565. if (app)
  3566. QueuePacket(app);
  3567. }
  3568. }
  3569. if (!target)
  3570. return false;
  3571. else
  3572. return true;
  3573. }
  3574. bool Client::CheckZoneAccess(const char* zoneName) {
  3575. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3576. ZoneServer* zone = zone_list.Get(zoneName, false);
  3577. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3578. if (zone && zone->GetZoneLockState())
  3579. {
  3580. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3581. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3582. return false;
  3583. }
  3584. sint16 zoneMinStatus = 0;
  3585. int16 zoneMinLevel = 0;
  3586. int16 zoneMaxLevel = 0;
  3587. int16 zoneMinVersion = 0;
  3588. if (!zone)
  3589. {
  3590. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3591. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3592. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3593. return true;
  3594. }
  3595. }
  3596. else
  3597. {
  3598. zoneMinStatus = zone->GetMinimumStatus();
  3599. zoneMinLevel = zone->GetMinimumLevel();
  3600. zoneMaxLevel = zone->GetMaximumLevel();
  3601. zoneMinVersion = zone->GetMinimumVersion();
  3602. }
  3603. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3604. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3605. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3606. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3607. {
  3608. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3609. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3610. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3611. return false;
  3612. }
  3613. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3614. {
  3615. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3616. {
  3617. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3618. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3619. return false;
  3620. }
  3621. }
  3622. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3623. {
  3624. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3625. {
  3626. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3627. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3628. return false;
  3629. }
  3630. }
  3631. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3632. {
  3633. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3634. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3635. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3636. {
  3637. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3638. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3639. return false;
  3640. }
  3641. }
  3642. return true;
  3643. }
  3644. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3645. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3646. }
  3647. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3648. if (!new_zone) {
  3649. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3650. return;
  3651. }
  3652. client_zoning = true;
  3653. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3654. player->SetResurrecting(true);
  3655. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3656. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3657. MSaveSpellStateMutex.lock();
  3658. player->SaveSpellEffects();
  3659. player->SetSaveSpellEffects(true);
  3660. MSaveSpellStateMutex.unlock();
  3661. ResetSendMail();
  3662. // Remove players pet from zone if there is one
  3663. ((Entity*)player)->DismissAllPets();
  3664. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3665. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3666. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3667. SetCurrentZone(new_zone);
  3668. if (player->GetGroupMemberInfo())
  3669. {
  3670. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3671. player->UpdateGroupMemberInfo();
  3672. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3673. }
  3674. // block out the member info for the group
  3675. TempRemoveGroup();
  3676. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3677. if (set_coords)
  3678. {
  3679. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3680. __FUNCTION__,
  3681. GetCurrentZone()->GetSafeX(),
  3682. GetCurrentZone()->GetSafeY(),
  3683. GetCurrentZone()->GetSafeZ(),
  3684. GetCurrentZone()->GetSafeHeading(),
  3685. new_zone->GetZoneName()
  3686. );
  3687. player->SetX(GetCurrentZone()->GetSafeX());
  3688. player->SetY(GetCurrentZone()->GetSafeY());
  3689. player->SetZ(GetCurrentZone()->GetSafeZ());
  3690. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3691. }
  3692. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3693. Save();
  3694. char* new_zone_ip = 0;
  3695. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3696. new_zone_ip = net.GetInternalWorldAddress();
  3697. else
  3698. new_zone_ip = net.GetWorldAddress();
  3699. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3700. int32 key = Timer::GetUnixTimeStamp();
  3701. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3702. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3703. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3704. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3705. if (version > 283) {
  3706. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3707. if (packet)
  3708. {
  3709. QueuePacket(packet->serialize());
  3710. safe_delete(packet);
  3711. }
  3712. }
  3713. }
  3714. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3715. {
  3716. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3717. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3718. }
  3719. float Client::DistanceFrom(Client* client) {
  3720. float ret = 0;
  3721. if (client && client != this) {
  3722. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3723. ret = sqrt(ret);
  3724. }
  3725. return ret;
  3726. }
  3727. void Client::DetermineCharacterUpdates() {
  3728. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3729. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3730. cdu->account_id = GetAccountID();
  3731. cdu->char_id = GetCharacterID();
  3732. int32 timestamp = Timer::GetUnixTimeStamp();
  3733. int8 flag = GetTimeStampFlag();
  3734. if (flag & LEVEL_UPDATE_FLAG)
  3735. {
  3736. cdu->update_field = LEVEL_UPDATE_FLAG;
  3737. cdu->update_data = player->GetLevel();
  3738. loginserver.SendPacket(outpack);
  3739. }
  3740. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3741. if (flag & CLASS_UPDATE_FLAG)
  3742. {
  3743. cdu->update_field = CLASS_UPDATE_FLAG;
  3744. cdu->update_data = player->GetAdventureClass();
  3745. loginserver.SendPacket(outpack);
  3746. }
  3747. if (flag & GENDER_UPDATE_FLAG)
  3748. {
  3749. cdu->update_field = GENDER_UPDATE_FLAG;
  3750. cdu->update_data = player->GetGender();
  3751. loginserver.SendPacket(outpack);
  3752. }
  3753. if (flag & DELETE_UPDATE_FLAG) {
  3754. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3755. }
  3756. safe_delete(outpack); // Zone, armor and name use a different structure
  3757. if (flag & RACE_UPDATE_FLAG)
  3758. {
  3759. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3760. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3761. ru->account_id = GetAccountID();
  3762. ru->char_id = GetCharacterID();
  3763. ru->race = player->GetRace();
  3764. ru->model_type = player->GetModelType();
  3765. loginserver.SendPacket(outpack);
  3766. safe_delete(outpack);
  3767. }
  3768. if (flag & ZONE_UPDATE_FLAG) {
  3769. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3770. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3771. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3772. czu->account_id = GetAccountID();
  3773. czu->char_id = GetCharacterID();
  3774. czu->zone_id = GetCurrentZone()->GetZoneID();
  3775. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3776. czu->zone_length = strlen(zone_file);
  3777. if (czu->zone_length > 64)
  3778. czu->zone_length = 64;
  3779. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3780. loginserver.SendPacket(outpack);
  3781. safe_delete(outpack);
  3782. }
  3783. if (flag & ARMOR_UPDATE_FLAG) {
  3784. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3785. }
  3786. if (flag & NAME_UPDATE_FLAG) {
  3787. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3788. }
  3789. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3790. }
  3791. void Client::Save() {
  3792. if (GetCharacterID() == 0)
  3793. return;
  3794. if (current_zone) {
  3795. DetermineCharacterUpdates();
  3796. UpdateCharacterInstances();
  3797. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3798. database.Save(this);
  3799. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3800. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3801. GetPlayer()->ResetQuickbarNeeded();
  3802. }
  3803. database.SaveItems(this);
  3804. database.SaveBuyBacks(this);
  3805. GetPlayer()->SaveHistory();
  3806. GetPlayer()->SaveLUAHistory();
  3807. MSaveSpellStateMutex.lock();
  3808. GetPlayer()->SaveSpellEffects();
  3809. MSaveSpellStateMutex.unlock();
  3810. }
  3811. }
  3812. void Client::UpdateCharacterInstances() {
  3813. if (GetPlayer() != NULL)
  3814. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3815. /*if ( GetPlayer() != NULL )
  3816. {
  3817. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3818. // to use for applying the update to each instances timer
  3819. int32 lastSaveTS = GetLastSavedTimeStamp();
  3820. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3821. int32 diffTS = newSaveTS - lastSaveTS;
  3822. // update instance timers
  3823. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3824. // update with the new timestamp and save the db
  3825. this->SetLastSavedTimeStamp(newSaveTS);
  3826. }*/
  3827. }
  3828. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3829. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3830. if (packet) {
  3831. packet->LoadPacketData(app->pBuffer, app->size);
  3832. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3833. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3834. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3835. vector<EntityCommand*> commands;
  3836. vector<EntityCommand*> delete_commands;
  3837. if (out && spawn) {
  3838. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3839. {
  3840. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3841. if (!spawn->primary_command_list[i]->default_allow_list)
  3842. {
  3843. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3844. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3845. continue;
  3846. }
  3847. else
  3848. {
  3849. // default is allow list, only deny if added to the list as deny (false itr second)
  3850. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3851. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3852. continue;
  3853. }
  3854. commands.push_back(spawn->primary_command_list[i]);
  3855. }
  3856. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3857. commands.push_back(spawn->secondary_command_list[i]);
  3858. if (spawn->IsPlayer()) {
  3859. if (player->IsFriend(spawn->GetName()))
  3860. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3861. else
  3862. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3863. if (player->IsIgnored(spawn->GetName()))
  3864. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3865. else
  3866. {
  3867. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3868. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3869. }
  3870. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3871. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3872. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3873. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3874. }
  3875. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  3876. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  3877. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  3878. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  3879. }
  3880. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3881. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3882. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3883. }
  3884. out->setDataByName("spawn_id", spawn_id);
  3885. out->setArrayLengthByName("num_verbs", commands.size());
  3886. for (int32 i = 0; i < commands.size(); i++) {
  3887. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3888. out->setArrayDataByName("distance", commands[i]->distance, i);
  3889. if (commands[i]->error_text.length() == 0)
  3890. out->setArrayAddToPacketByName("error", false, i);
  3891. else {
  3892. out->setArrayDataByName("display_error", 1, i);
  3893. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3894. }
  3895. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3896. }
  3897. EQ2Packet* outapp = out->serialize();
  3898. //DumpPacket(outapp);
  3899. QueuePacket(outapp);
  3900. safe_delete(out);
  3901. for (int32 i = 0; i < delete_commands.size(); i++) {
  3902. safe_delete(delete_commands[i]);
  3903. }
  3904. }
  3905. safe_delete(packet);
  3906. }
  3907. }
  3908. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3909. if (previous_value != new_value) {
  3910. 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);
  3911. char tmp[200] = { 0 };
  3912. 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);
  3913. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  3914. }
  3915. }
  3916. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3917. {
  3918. /* JA notes on the unknown:
  3919. 2 = ding glimmer
  3920. 16 = Achievement Unlocked
  3921. 6 no longer does anything
  3922. */
  3923. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3924. if (packet) {
  3925. packet->setDataByName("unknown", unknown);
  3926. packet->setMediumStringByName("text", text);
  3927. if (type && strlen(type) > 0)
  3928. packet->setMediumStringByName("message_type", type);
  3929. packet->setDataByName("size", size);
  3930. packet->setDataByName("red", red);
  3931. packet->setDataByName("green", green);
  3932. packet->setDataByName("blue", blue);
  3933. QueuePacket(packet->serialize());
  3934. safe_delete(packet);
  3935. }
  3936. }
  3937. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3938. if (new_level < 1) {
  3939. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3940. return;
  3941. }
  3942. if (player->GetLevel() != new_level) {
  3943. player->SetLevel(new_level);
  3944. if (player->GetGroupMemberInfo()) {
  3945. player->UpdateGroupMemberInfo();
  3946. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3947. }
  3948. }
  3949. if (new_level > old_level) {
  3950. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3951. }
  3952. if (player->GetPet()) {
  3953. NPC* pet = (NPC*)player->GetPet();
  3954. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3955. pet->SetLevel(new_level);
  3956. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3957. if (command_packet) {
  3958. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3959. command_packet->setDataByName("anim_type", 1753);
  3960. QueuePacket(command_packet->serialize());
  3961. safe_delete(command_packet);
  3962. }
  3963. }
  3964. }
  3965. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3966. if (level_update) {
  3967. level_update->setDataByName("old_level", old_level);
  3968. level_update->setDataByName("new_level", new_level);
  3969. QueuePacket(level_update->serialize());
  3970. safe_delete(level_update);
  3971. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3972. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  3973. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3974. }
  3975. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3976. if (command_packet) {
  3977. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3978. command_packet->setDataByName("anim_type", 1753);
  3979. QueuePacket(command_packet->serialize());
  3980. safe_delete(command_packet);
  3981. }
  3982. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3983. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3984. SendNewSpells(player->GetAdventureClass());
  3985. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3986. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3987. GetPlayer()->ChangePrimaryWeapon();
  3988. GetPlayer()->ChangeSecondaryWeapon();
  3989. GetPlayer()->ChangeRangedWeapon();
  3990. GetPlayer()->GetInfoStruct()->set_level(new_level);
  3991. // GetPlayer()->SetLevel(new_level);
  3992. 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__);
  3993. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3994. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3995. GetPlayer()->CalculateBonuses();
  3996. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3997. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3998. InfoStruct* info = player->GetInfoStruct();
  3999. info->set_agi_base(new_level * 2 + 15);
  4000. info->set_intel_base(new_level * 2 + 15);
  4001. info->set_wis_base(new_level * 2 + 15);
  4002. info->set_str_base(new_level * 2 + 15);
  4003. info->set_sta_base(new_level * 2 + 15);
  4004. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4005. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4006. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4007. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4008. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4009. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4010. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4011. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));
  4012. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4013. GetPlayer()->SetCharSheetChanged(true);
  4014. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4015. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4016. int16 new_skill_cap = 5 * new_level;
  4017. PlayerSkillList* player_skills = player->GetSkills();
  4018. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4019. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4020. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4021. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4022. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4023. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4024. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4025. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4026. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4027. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4028. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4029. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4030. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4031. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4032. if (new_level > player->GetTSLevel())
  4033. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4034. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4035. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4036. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4037. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4038. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4039. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4040. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4041. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4042. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4043. Guild* guild = GetPlayer()->GetGuild();
  4044. if (guild) {
  4045. int8 event_type = 0;
  4046. if (new_level < 10)
  4047. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4048. else if (new_level == 10)
  4049. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4050. else if (new_level >= 11 && new_level < 20)
  4051. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4052. else if (new_level == 20)
  4053. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4054. else if (new_level >= 21 && new_level < 30)
  4055. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4056. else if (new_level == 30)
  4057. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4058. else if (new_level >= 31 && new_level < 40)
  4059. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4060. else if (new_level == 40)
  4061. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4062. else if (new_level >= 41 && new_level < 50)
  4063. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4064. else if (new_level == 50)
  4065. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4066. else if (new_level >= 51 && new_level < 60)
  4067. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4068. else if (new_level == 60)
  4069. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4070. else if (new_level >= 61 && new_level < 70)
  4071. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4072. else if (new_level == 70)
  4073. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4074. else if (new_level >= 71 && new_level < 80)
  4075. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4076. else if (new_level == 80)
  4077. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4078. 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());
  4079. 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());
  4080. guild->UpdateGuildMemberInfo(GetPlayer());
  4081. guild->SendGuildMember(GetPlayer());
  4082. guild->SendGuildMemberList();
  4083. }
  4084. // Need to send the trait list every time the players level changes
  4085. // Also need to force the char sheet update or else there can be a large delay from when you level
  4086. // to when you are actually able to select traits.
  4087. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4088. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4089. if (version > 546)
  4090. master_aa_list.DisplayAA(this, 0, 0);
  4091. if (GetPlayer()->SpawnedBots.size() > 0) {
  4092. map<int32, int32>::iterator itr;
  4093. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4094. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4095. if (bot && bot->IsBot())
  4096. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4097. }
  4098. }
  4099. }
  4100. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4101. if (new_level < 1) {
  4102. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4103. return;
  4104. }
  4105. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4106. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4107. return;
  4108. }
  4109. if (new_level > old_level)
  4110. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4111. if (player->GetTSLevel() != new_level) {
  4112. player->SetTSLevel(new_level);
  4113. if (player->GetGroupMemberInfo()) {
  4114. player->UpdateGroupMemberInfo();
  4115. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4116. }
  4117. }
  4118. // Only tradeskill skills should increace, and then only those related to your class
  4119. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4120. if (level_update) {
  4121. level_update->setDataByName("old_level", old_level);
  4122. level_update->setDataByName("new_level", new_level);
  4123. level_update->setDataByName("type", 1);
  4124. QueuePacket(level_update->serialize());
  4125. safe_delete(level_update);
  4126. }
  4127. // Need to make tradeskill versions of the following
  4128. //SendNewSpells(player->GetAdventureClass());
  4129. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4130. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4131. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4132. if (command_packet) {
  4133. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4134. command_packet->setDataByName("anim_type", 1753);
  4135. QueuePacket(command_packet->serialize());
  4136. safe_delete(command_packet);
  4137. }
  4138. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4139. GetPlayer()->SetTSLevel(new_level);
  4140. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4141. GetPlayer()->SetCharSheetChanged(true);
  4142. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4143. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4144. PlayerSkillList* player_skills = player->GetSkills();
  4145. int16 specialize_skill_cap = new_level * 5;
  4146. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4147. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4148. int8 ts_class = player->GetTradeskillClass();
  4149. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4150. int32 skill_id_1, skill_id_2, skill_id_3;
  4151. switch (base_ts_class) {
  4152. case ARTISAN:
  4153. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4154. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4155. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4156. break;
  4157. case OUTFITTER:
  4158. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4159. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4160. skill_id_1 = SKILL_ID_TAILORING;
  4161. skill_id_2 = SKILL_ID_METALSHAPING;
  4162. skill_id_3 = SKILL_ID_METALWORKING;
  4163. if (ts_class == TAILOR) {
  4164. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4165. skill_id_1 = 0;
  4166. }
  4167. else if (ts_class == ARMORER) {
  4168. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4169. skill_id_2 = 0;
  4170. }
  4171. else if (ts_class == WEAPONSMITH) {
  4172. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4173. skill_id_3 = 0;
  4174. }
  4175. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4176. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4177. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4178. break;
  4179. case SCHOLAR:
  4180. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4181. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4182. skill_id_1 = SKILL_ID_SCRIBING;
  4183. skill_id_2 = SKILL_ID_CHEMISTRY;
  4184. skill_id_3 = SKILL_ID_ARTIFICING;
  4185. if (ts_class == SAGE) {
  4186. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4187. skill_id_1 = 0;
  4188. }
  4189. else if (ts_class == ALCHEMIST) {
  4190. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4191. skill_id_2 = 0;
  4192. }
  4193. else if (ts_class == JEWELER) {
  4194. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4195. skill_id_3 = 0;
  4196. }
  4197. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4198. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4199. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4200. break;
  4201. case CRAFTSMAN:
  4202. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4203. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4204. skill_id_1 = SKILL_ID_ARTISTRY;
  4205. skill_id_2 = SKILL_ID_FLETCHING;
  4206. skill_id_3 = SKILL_ID_SCULPTING;
  4207. if (ts_class == PROVISIONER) {
  4208. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4209. skill_id_1 = 0;
  4210. }
  4211. else if (ts_class == WOODWORKER) {
  4212. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4213. skill_id_2 = 0;
  4214. }
  4215. else if (ts_class == CARPENTER) {
  4216. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4217. skill_id_3 = 0;
  4218. }
  4219. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4220. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4221. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4222. break;
  4223. default:
  4224. break;
  4225. }
  4226. if (new_level > player->GetAdventureClass())
  4227. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4228. Guild* guild = GetPlayer()->GetGuild();
  4229. if (guild) {
  4230. int8 event_type = 0;
  4231. if (new_level < 10)
  4232. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4233. else if (new_level == 10)
  4234. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4235. else if (new_level >= 11 && new_level < 20)
  4236. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4237. else if (new_level == 20)
  4238. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4239. else if (new_level >= 21 && new_level < 30)
  4240. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4241. else if (new_level == 30)
  4242. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4243. else if (new_level >= 31 && new_level < 40)
  4244. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4245. else if (new_level == 40)
  4246. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4247. else if (new_level >= 41 && new_level < 50)
  4248. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4249. else if (new_level == 50)
  4250. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4251. else if (new_level >= 51 && new_level < 60)
  4252. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4253. else if (new_level == 60)
  4254. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4255. else if (new_level >= 61 && new_level < 70)
  4256. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4257. else if (new_level == 70)
  4258. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4259. else if (new_level >= 71 && new_level < 80)
  4260. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4261. else if (new_level == 80)
  4262. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4263. 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());
  4264. 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());
  4265. guild->UpdateGuildMemberInfo(GetPlayer());
  4266. guild->SendGuildMember(GetPlayer());
  4267. guild->SendGuildMemberList();
  4268. }
  4269. // Need to send the trait list every time the players level changes
  4270. // Also need to force the char sheet update or else there can be a large delay from when you level
  4271. // to when you are actually able to select traits.
  4272. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4273. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4274. }
  4275. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4276. if (entity)
  4277. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4278. }
  4279. void Client::CloseLoot(int32 spawn_id) {
  4280. if (GetVersion() > 546) {
  4281. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4282. if (packet) {
  4283. packet->setDataByName("window_id", 4);
  4284. EQ2Packet* outapp = packet->serialize();
  4285. if (outapp) {
  4286. //DumpPacket(outapp);
  4287. QueuePacket(outapp);
  4288. }
  4289. safe_delete(packet);
  4290. }
  4291. }
  4292. else if(spawn_id > 0){
  4293. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4294. if (packet) {
  4295. packet->setDataByName("spawn_id", spawn_id);
  4296. EQ2Packet* outapp = packet->serialize();
  4297. if (outapp)
  4298. QueuePacket(outapp);
  4299. safe_delete(packet);
  4300. }
  4301. }
  4302. }
  4303. string Client::GetCoinMessage(int32 total_coins) {
  4304. if (total_coins == 0) {
  4305. return " 0 Copper";
  4306. }
  4307. char tmp[64] = { 0 };
  4308. string message = "";
  4309. int32 val = 0;
  4310. if (total_coins >= 1000000) {
  4311. val = total_coins / 1000000;
  4312. total_coins -= 1000000 * val;
  4313. sprintf(tmp, " %u Platinum", val);
  4314. message.append(tmp);
  4315. memset(tmp, 0, 64);
  4316. }
  4317. if (total_coins >= 10000) {
  4318. val = total_coins / 10000;
  4319. total_coins -= 10000 * val;
  4320. sprintf(tmp, " %u Gold", val);
  4321. message.append(tmp);
  4322. memset(tmp, 0, 64);
  4323. }
  4324. if (total_coins >= 100) {
  4325. val = total_coins / 100;
  4326. total_coins -= 100 * val;
  4327. sprintf(tmp, " %u Silver", val);
  4328. message.append(tmp);
  4329. memset(tmp, 0, 64);
  4330. }
  4331. if (total_coins > 0) {
  4332. sprintf(tmp, " %u Copper", (int32)total_coins);
  4333. message.append(tmp);
  4334. }
  4335. return message;
  4336. }
  4337. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4338. if (!entity) {
  4339. CloseLoot(0);
  4340. return;
  4341. }
  4342. if (total_coins > 0) {
  4343. player->AddCoins(total_coins);
  4344. //PlaySound("coin_cha_ching");
  4345. string message = "";
  4346. if (entity->GetHP() == 0) {
  4347. message = "You loot ";
  4348. entity->SetLootCoins(0);
  4349. }
  4350. else
  4351. message = "You receive ";
  4352. message.append(GetCoinMessage(total_coins));
  4353. if (entity->GetHP() == 0)
  4354. message.append(" from the corpse of ").append(entity->GetName());
  4355. int8 type = CHANNEL_LOOT;
  4356. SimpleMessage(type, message.c_str());
  4357. }
  4358. if (!items || items->size() == 0)
  4359. CloseLoot(entity->GetID());
  4360. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4361. if (packet) {
  4362. vector<Item*>::iterator itr;
  4363. int32 packet_size = 0;
  4364. EQ2Packet* outapp = 0;
  4365. uchar* data = 0;
  4366. if (GetVersion() >= 284) {
  4367. if (GetVersion() > 546) {
  4368. if (items && items->size() > 0) {
  4369. packet->setDataByName("loot_count", items->size());
  4370. packet->setDataByName("display", 1);
  4371. }
  4372. packet->setDataByName("loot_type", 1);
  4373. if (version >= 1096)
  4374. packet->setDataByName("lotto_timeout", 0x78);
  4375. else
  4376. packet->setDataByName("lotto_timeout", 0x3C);
  4377. packet->setDataByName("loot_id", entity->GetID());
  4378. EQ2Packet* tmpPacket = packet->serialize();
  4379. packet_size += tmpPacket->size;
  4380. if (items && items->size() > 0) {
  4381. data = new uchar[items->size() * 1000 + packet_size];
  4382. memset(data, 0, items->size() * 1000 + packet_size);
  4383. }
  4384. else {
  4385. data = new uchar[packet_size];
  4386. memset(data, 0, packet_size);
  4387. }
  4388. uchar* ptr = data;
  4389. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4390. ptr += tmpPacket->size;
  4391. safe_delete(tmpPacket);
  4392. Item* item = 0;
  4393. if (items && items->size() > 0) {
  4394. for (itr = items->begin(); itr != items->end(); itr++) {
  4395. item = *itr;
  4396. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4397. ptr += sizeof(int32);
  4398. packet_size += sizeof(int32);
  4399. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4400. int8 offset = 0;
  4401. if (GetVersion() >= 1188) {
  4402. offset = 13;
  4403. }
  4404. else if (GetVersion() >= 860) {
  4405. offset = 11;
  4406. }
  4407. else if (GetVersion() <= 546) {
  4408. offset = 19;
  4409. }
  4410. else {
  4411. offset = 10;
  4412. }
  4413. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4414. ptr += tmpPacket->size - offset;
  4415. packet_size += tmpPacket->size - offset;
  4416. safe_delete(tmpPacket);
  4417. }
  4418. }
  4419. packet_size -= sizeof(int32);
  4420. memcpy(data, &packet_size, sizeof(int32));
  4421. packet_size += sizeof(int32);
  4422. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4423. }
  4424. else {
  4425. if (items && items->size() > 0) {
  4426. packet->setArrayLengthByName("loot_count", items->size());
  4427. Item* item = 0;
  4428. if (items && items->size() > 0) {
  4429. int i = 0;
  4430. for (itr = items->begin(); itr != items->end(); itr++) {
  4431. item = *itr;
  4432. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4433. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4434. i++;
  4435. }
  4436. }
  4437. packet->setDataByName("display", 1);
  4438. }
  4439. packet->setDataByName("loot_type", 1); // normal
  4440. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4441. packet->setDataByName("spawn_id", entity->GetID());
  4442. outapp = packet->serialize();
  4443. }
  4444. }
  4445. else {
  4446. if (items && items->size() > 0) {
  4447. packet->setArrayLengthByName("loot_count", items->size());
  4448. for (int i = 0; i < items->size(); i++) {
  4449. Item* item = (*items)[i];
  4450. packet->setArrayDataByName("name", item->name.c_str(), i);
  4451. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4452. packet->setArrayDataByName("count", item->details.count, i);
  4453. packet->setArrayDataByName("icon", item->details.icon, i);
  4454. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4455. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4456. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4457. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4458. else
  4459. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4460. }
  4461. }
  4462. packet->setDataByName("object_id", entity->GetID());
  4463. packet->setDataByName("unknown3", 1);
  4464. packet->setDataByName("unknown4", 1);
  4465. packet->setDataByName("unknown5", 60);
  4466. outapp = packet->serialize();
  4467. }
  4468. if (outapp) {
  4469. DumpPacket(outapp);
  4470. QueuePacket(outapp);
  4471. }
  4472. safe_delete_array(data);
  4473. safe_delete(packet);
  4474. }
  4475. }
  4476. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4477. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4478. int32 total_coins = entity->GetLootCoins();
  4479. entity->LockLoot();
  4480. Loot(total_coins, entity->GetLootItems(), entity);
  4481. entity->UnlockLoot();
  4482. OpenChest(entity, attemptDisarm);
  4483. }
  4484. else
  4485. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4486. }
  4487. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4488. {
  4489. if (!entity)
  4490. return;
  4491. int8 chest_difficulty = 0;
  4492. int32 state = 0;
  4493. // Check for the chest and set the action state
  4494. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4495. string modelName;
  4496. if (entity->GetModelType() == 4034) {
  4497. // small chest, open with copper coins
  4498. // does not include traps, however can be disarmed
  4499. chest_difficulty = 1;
  4500. state = 11899;
  4501. modelName.append("Small Chest");
  4502. }
  4503. else if (entity->GetModelType() == 5864) {
  4504. // treasure chest, open with silver coins
  4505. chest_difficulty = 2;
  4506. state = 11901;
  4507. modelName.append("Treasure Chest");
  4508. }
  4509. else if (entity->GetModelType() == 5865) {
  4510. // ornate chest, open with gold coins
  4511. chest_difficulty = 3;
  4512. state = 11900;
  4513. modelName.append("Ornate Chest");
  4514. }
  4515. else if (entity->GetModelType() == 4015) {
  4516. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4517. chest_difficulty = 5;
  4518. state = 11898;
  4519. modelName.append("Exquisite Chest");
  4520. }
  4521. bool firstChestOpen = false;
  4522. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4523. {
  4524. ChestTrap::ChestTrapInfo nextTrap;
  4525. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4526. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4527. firstChestOpen = true;
  4528. entity->SetTrapTriggered(true, state);
  4529. if (ret)
  4530. {
  4531. if (disarmSkill && attemptDisarm)
  4532. {
  4533. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4534. {
  4535. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4536. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4537. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4538. }
  4539. else
  4540. {
  4541. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4542. }
  4543. // despite fail/succeed we should always try to increase skill if disarm is available
  4544. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4545. }
  4546. else // no disarm skill, always fail
  4547. {
  4548. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4549. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4550. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4551. }
  4552. }
  4553. }
  4554. else if (!entity->HasTrapTriggered())
  4555. {
  4556. firstChestOpen = true;
  4557. entity->SetTrapTriggered(true, state);
  4558. }
  4559. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4560. // for those in range the SendStateCommand will cause it to animate open.
  4561. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4562. if (firstChestOpen)
  4563. GetCurrentZone()->SendStateCommand(entity, state);
  4564. }
  4565. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4566. {
  4567. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4568. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4569. if (source == NULL)
  4570. source = (Entity*)GetPlayer();
  4571. if (spell)
  4572. {
  4573. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4574. if (gmi && gmi->group_id)
  4575. {
  4576. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4577. if (group)
  4578. {
  4579. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4580. deque<GroupMemberInfo*>* members = group->GetMembers();
  4581. for (int8 i = 0; i < members->size(); i++) {
  4582. Entity* member = members->at(i)->member;
  4583. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4584. continue;
  4585. // if we have a radius provided then check if the group member is outside the radius or not
  4586. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4587. continue;
  4588. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4589. }
  4590. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4591. }
  4592. }
  4593. else
  4594. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4595. }
  4596. }
  4597. Spawn* Client::GetBanker() {
  4598. return banker;
  4599. }
  4600. void Client::SetBanker(Spawn* in_banker) {
  4601. banker = in_banker;
  4602. }
  4603. void Client::Bank(Spawn* banker, bool cancel) {
  4604. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4605. if (!cancel)
  4606. SetBanker(banker);
  4607. else
  4608. SetBanker(0);
  4609. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4610. if (packet) {
  4611. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4612. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4613. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4614. int32 coins1, coins2;
  4615. coins1 = ((int32*)&coins)[0];
  4616. coins2 = ((int32*)&coins)[1];
  4617. packet->setDataByName("bank_coins", coins1);
  4618. packet->setDataByName("bank_coins2", coins2);
  4619. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4620. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4621. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4622. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4623. if (!cancel)
  4624. packet->setDataByName("display", 1);
  4625. QueuePacket(packet->serialize());
  4626. safe_delete(packet);
  4627. }
  4628. }
  4629. }
  4630. void Client::BankWithdrawal(int64 amount) {
  4631. bool cheater = false;
  4632. if (GetBanker() && amount > 0) {
  4633. string withdrawal = "";
  4634. char withdrawal_data[512] = { 0 };
  4635. int32 tmp = 0;
  4636. if (amount >= 1000000) {
  4637. tmp = amount / 1000000;
  4638. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4639. if (tmp > bank_coins_plat)
  4640. cheater = true;
  4641. else {
  4642. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4643. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4644. amount -= (int64)tmp * 1000000;
  4645. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4646. withdrawal.append(withdrawal_data);
  4647. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4648. }
  4649. }
  4650. if (!cheater && amount >= 10000) {
  4651. tmp = amount / 10000;
  4652. if (tmp > GetPlayer()->GetBankCoinsGold())
  4653. cheater = true;
  4654. else {
  4655. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4656. bank_coins_gold -= tmp;
  4657. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4658. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4659. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4660. }
  4661. else
  4662. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4663. amount -= tmp * 10000;
  4664. sprintf(withdrawal_data, "%u Gold ", tmp);
  4665. withdrawal.append(withdrawal_data);
  4666. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4667. }
  4668. }
  4669. if (!cheater && amount >= 100) {
  4670. tmp = amount / 100;
  4671. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4672. if (tmp > bank_coins_silver)
  4673. cheater = true;
  4674. else {
  4675. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4676. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4677. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4678. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4679. }
  4680. else
  4681. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4682. amount -= tmp * 100;
  4683. sprintf(withdrawal_data, "%u Silver ", tmp);
  4684. withdrawal.append(withdrawal_data);
  4685. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4686. }
  4687. }
  4688. if (!cheater) {
  4689. if (amount > 0) {
  4690. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4691. withdrawal.append(withdrawal_data);
  4692. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4693. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4694. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4695. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4696. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4697. }
  4698. else
  4699. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4700. }
  4701. if (withdrawal.length() > 0) {
  4702. withdrawal.append("withdrawn ");
  4703. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4704. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4705. withdrawal.append(withdrawal_data);
  4706. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4707. }
  4708. }
  4709. else
  4710. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4711. player->SetCharSheetChanged(true);
  4712. Bank(banker);
  4713. }
  4714. }
  4715. void Client::BankDeposit(int64 amount) {
  4716. bool cheater = false;
  4717. if (GetBanker() && amount > 0) {
  4718. int32 tmp = 0;
  4719. char deposit_data[512] = { 0 };
  4720. string deposit = "";
  4721. if (amount >= 1000000) {
  4722. tmp = amount / 1000000;
  4723. if (tmp > GetPlayer()->GetCoinsPlat())
  4724. cheater = true;
  4725. else {
  4726. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4727. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4728. amount -= (int64)tmp * 1000000;
  4729. sprintf(deposit_data, "%u Platinum ", tmp);
  4730. deposit.append(deposit_data);
  4731. memset(deposit_data, 0, sizeof(deposit_data));
  4732. }
  4733. }
  4734. if (!cheater && amount >= 10000) {
  4735. tmp = amount / 10000;
  4736. if (tmp > GetPlayer()->GetCoinsGold())
  4737. cheater = true;
  4738. else {
  4739. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4740. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4741. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4742. }
  4743. else
  4744. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4745. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4746. amount -= tmp * 10000;
  4747. sprintf(deposit_data, "%u Gold ", tmp);
  4748. deposit.append(deposit_data);
  4749. memset(deposit_data, 0, sizeof(deposit_data));
  4750. }
  4751. }
  4752. if (!cheater && amount >= 100) {
  4753. tmp = amount / 100;
  4754. if (tmp > GetPlayer()->GetCoinsSilver())
  4755. cheater = true;
  4756. else {
  4757. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4758. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4759. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4760. }
  4761. else
  4762. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4763. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4764. amount -= tmp * 100;
  4765. sprintf(deposit_data, "%u Silver ", tmp);
  4766. deposit.append(deposit_data);
  4767. memset(deposit_data, 0, sizeof(deposit_data));
  4768. }
  4769. }
  4770. if (!cheater) {
  4771. if (amount > 0) {
  4772. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4773. deposit.append(deposit_data);
  4774. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4775. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4776. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4777. }
  4778. else
  4779. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4780. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4781. }
  4782. if (deposit.length() > 0) {
  4783. deposit.append("deposited ");
  4784. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4785. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4786. deposit.append(deposit_data);
  4787. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4788. }
  4789. }
  4790. else
  4791. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4792. player->SetCharSheetChanged(true);
  4793. Bank(banker);
  4794. }
  4795. }
  4796. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4797. {
  4798. MPendingQuestAccept.lock();
  4799. pending_quest_accept.push_back(quest);
  4800. MPendingQuestAccept.unlock();
  4801. }
  4802. void Client::AddPendingQuestReward(Quest* quest, bool update) {
  4803. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4804. quest_pending_reward.push_back(quest);
  4805. quest_updates = update;
  4806. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4807. }
  4808. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4809. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4810. quest_pending_updates[quest_id][step_id] = progress;
  4811. quest_updates = true;
  4812. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4813. }
  4814. void Client::ProcessQuestUpdates() {
  4815. if (quest_pending_updates.size() > 0) {
  4816. map<int32, map<int32, int32> > tmp_quest_updates;
  4817. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4818. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4819. quest_pending_updates.clear();
  4820. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4821. map<int32, map<int32, int32> >::iterator quest_itr;
  4822. map<int32, int32>::iterator step_itr;
  4823. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4824. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4825. if (step_itr->second == 0xFFFFFFFF) {
  4826. SetStepComplete(quest_itr->first, step_itr->first);
  4827. player->SendQuestRequiredSpawns(quest_itr->first);
  4828. }
  4829. else
  4830. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4831. }
  4832. }
  4833. }
  4834. if (quest_pending_reward.size() > 0) {
  4835. vector<Quest*>::iterator itr;
  4836. vector<Quest*> tmp_quest_rewards;
  4837. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4838. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4839. quest_pending_reward.clear();
  4840. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4841. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4842. GiveQuestReward(*itr);
  4843. }
  4844. }
  4845. quest_updates = false;
  4846. }
  4847. void Client::CheckQuestQueue() {
  4848. MQuestQueue.writelock();
  4849. last_update_time = 0;
  4850. vector<QueuedQuest*>::iterator itr;
  4851. QueuedQuest* queued_quest = 0;
  4852. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4853. queued_quest = *itr;
  4854. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4855. if(queued_quest->quest && queued_quest->quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  4856. SendQuestJournal();
  4857. safe_delete(queued_quest);
  4858. }
  4859. quest_queue.clear();
  4860. MQuestQueue.releasewritelock();
  4861. }
  4862. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4863. Quest* quest = player->SetStepComplete(quest_id, step);
  4864. if (quest) {
  4865. SendQuestUpdate(quest);
  4866. GetCurrentZone()->SendQuestUpdates(this);
  4867. }
  4868. }
  4869. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4870. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4871. if (quest) {
  4872. SendQuestUpdate(quest);
  4873. GetCurrentZone()->SendQuestUpdates(this);
  4874. }
  4875. }
  4876. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4877. bool hadUpdates = false;
  4878. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4879. if (quest_updates) {
  4880. for (int32 i = 0; i < quest_updates->size(); i++)
  4881. {
  4882. SendQuestUpdate(quest_updates->at(i));
  4883. hadUpdates = true;
  4884. }
  4885. }
  4886. safe_delete(quest_updates);
  4887. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4888. if (quest_failures) {
  4889. for (int32 i = 0; i < quest_failures->size(); i++)
  4890. {
  4891. SendQuestFailure(quest_failures->at(i));
  4892. hadUpdates = true;
  4893. }
  4894. }
  4895. safe_delete(quest_failures);
  4896. if (hadUpdates)
  4897. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4898. }
  4899. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4900. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4901. if (quest_updates) {
  4902. for (int32 i = 0; i < quest_updates->size(); i++)
  4903. SendQuestUpdate(quest_updates->at(i));
  4904. GetCurrentZone()->SendQuestUpdates(this);
  4905. }
  4906. safe_delete(quest_updates);
  4907. }
  4908. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4909. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4910. if (quest_updates) {
  4911. for (int32 i = 0; i < quest_updates->size(); i++)
  4912. SendQuestUpdate(quest_updates->at(i));
  4913. }
  4914. safe_delete(quest_updates);
  4915. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4916. if (quest_failures) {
  4917. for (int32 i = 0; i < quest_failures->size(); i++)
  4918. SendQuestFailure(quest_failures->at(i));
  4919. }
  4920. safe_delete(quest_failures);
  4921. }
  4922. void Client::CheckPlayerQuestsLocationUpdate() {
  4923. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4924. if (quest_updates) {
  4925. for (int32 i = 0; i < quest_updates->size(); i++)
  4926. SendQuestUpdate(quest_updates->at(i));
  4927. }
  4928. safe_delete(quest_updates);
  4929. }
  4930. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4931. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4932. if (quest_updates) {
  4933. for (int32 i = 0; i < quest_updates->size(); i++)
  4934. SendQuestUpdate(quest_updates->at(i));
  4935. }
  4936. safe_delete(quest_updates);
  4937. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4938. if (quest_failures) {
  4939. for (int32 i = 0; i < quest_failures->size(); i++)
  4940. SendQuestFailure(quest_failures->at(i));
  4941. }
  4942. safe_delete(quest_failures);
  4943. }
  4944. void Client::AddPendingQuest(Quest* quest, bool forced) {
  4945. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  4946. player->pending_quests[quest->GetQuestID()] = quest;
  4947. AcceptQuest(quest->GetQuestID());
  4948. }
  4949. else {
  4950. player->pending_quests[quest->GetQuestID()] = quest;
  4951. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4952. //DumpPacket(outapp);
  4953. QueuePacket(outapp);
  4954. }
  4955. }
  4956. Quest* Client::GetActiveQuest(int32 quest_id) {
  4957. Quest* quest = 0;
  4958. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  4959. if (player->player_quests.count(quest_id) > 0) {
  4960. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4961. quest = player->player_quests[quest_id];
  4962. }
  4963. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  4964. return quest;
  4965. }
  4966. void Client::AcceptQuest(int32 id) {
  4967. Quest* quest = GetPendingQuest(id);
  4968. if (quest) {
  4969. RemovePendingQuest(quest);
  4970. AddPlayerQuest(quest);
  4971. GetCurrentZone()->SendQuestUpdates(this);
  4972. // If character has already completed this quest once update the given date in the database
  4973. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  4974. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  4975. if (quest2)
  4976. quest->SetCompleteCount(quest2->GetCompleteCount());
  4977. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  4978. }
  4979. }
  4980. }
  4981. Quest* Client::GetPendingQuest(int32 id) {
  4982. if (player->pending_quests.count(id) > 0) {
  4983. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4984. return player->pending_quests[id];
  4985. }
  4986. return 0;
  4987. }
  4988. void Client::RemovePendingQuest(Quest* quest) {
  4989. player->pending_quests.erase(quest->GetQuestID());
  4990. }
  4991. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4992. if (!quest || !progress) {
  4993. return;
  4994. }
  4995. map<int32, int32>::iterator itr;
  4996. QuestStep* step = 0;
  4997. player->SetZone(GetCurrentZone(), GetVersion());
  4998. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4999. step = quest->GetQuestStep(itr->first);
  5000. if (step && itr->second > 0) {
  5001. step->SetStepProgress(itr->second);
  5002. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5003. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5004. }
  5005. }
  5006. if (lua_interface && step)
  5007. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5008. else if(!step) {
  5009. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5010. }
  5011. }
  5012. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5013. bool lockCleared = false;
  5014. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5015. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5016. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5017. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5018. int32 questID = quest->GetQuestID();
  5019. lockCleared = true;
  5020. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5021. RemovePlayerQuest(questID, false, false);
  5022. }
  5023. player->player_quests[quest->GetQuestID()] = quest;
  5024. if(!lockCleared)
  5025. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5026. quest->SetPlayer(player);
  5027. current_quest_id = quest->GetQuestID();
  5028. if (send_packets && quest->GetQuestGiver() > 0)
  5029. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5030. if (lua_interface && call_accepted)
  5031. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5032. if (send_packets) {
  5033. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5034. //SendQuestJournal();
  5035. SendQuestJournalUpdate(quest);
  5036. // sent twice to match live
  5037. quest->SetTracked(false);
  5038. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5039. quest->SetTracked(true);
  5040. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5041. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5042. }
  5043. //This isn't during a load screen, so update spawns with required quests
  5044. if (call_accepted)
  5045. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5046. }
  5047. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5048. if (current_quest_id == id)
  5049. current_quest_id = 0;
  5050. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5051. if (player->player_quests.count(id) > 0) {
  5052. if (delete_quest) {
  5053. player->player_quests[id]->SetDeleted(true);
  5054. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5055. }
  5056. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5057. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5058. if (send_update && quest_giver > 0)
  5059. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5060. if (send_update) {
  5061. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5062. SendQuestJournal(false, 0, true);
  5063. }
  5064. player->RemoveQuest(id, delete_quest);
  5065. if (send_update) {
  5066. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5067. SendQuestJournal(false, 0, true);
  5068. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5069. }
  5070. }
  5071. else {
  5072. // if we don't have any quests to count then release the write lock
  5073. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5074. }
  5075. }
  5076. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5077. if (quest) {
  5078. QuestStep* quest_step = quest->GetQuestStep(step);
  5079. if (quest_step) {
  5080. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5081. quest_step->WasUpdated(false);
  5082. }
  5083. }
  5084. }
  5085. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5086. QueuedQuest* item = new QueuedQuest;
  5087. item->quest = quest;
  5088. item->step = step;
  5089. item->display_quest_helper = display_quest_helper;
  5090. MQuestQueue.writelock();
  5091. quest_queue.push_back(item);
  5092. last_update_time = Timer::GetCurrentTime2();
  5093. MQuestQueue.releasewritelock();
  5094. }
  5095. void Client::SendQuestFailure(Quest* quest) {
  5096. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5097. if (failures) {
  5098. QuestStep* step = 0;
  5099. for (int32 i = 0; i < failures->size(); i++) {
  5100. step = failures->at(i);
  5101. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5102. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5103. SendQuestJournal(false, 0, true);
  5104. }
  5105. failures->clear();
  5106. }
  5107. }
  5108. void Client::SendQuestUpdate(Quest* quest) {
  5109. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5110. if (updates) {
  5111. QuestStep* step = 0;
  5112. bool updated = false;
  5113. for (int32 i = 0; i < updates->size(); i++) {
  5114. step = updates->at(i);
  5115. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5116. {
  5117. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5118. SendQuestUpdateStep(quest, step->GetStepID());
  5119. updated = true;
  5120. }
  5121. if (step->WasUpdated()) {
  5122. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5123. SendQuestJournal(false, 0, true);
  5124. if(!updated)
  5125. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5126. updated = true;
  5127. }
  5128. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5129. }
  5130. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5131. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5132. SendQuestJournalUpdate(quest, true);
  5133. }
  5134. if (quest->GetCompleted()) {
  5135. if (quest->GetQuestReturnNPC() > 0)
  5136. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5137. if (quest->GetCompletedFlag())
  5138. quest->SetCompletedFlag(false);
  5139. }
  5140. updates->clear();
  5141. }
  5142. }
  5143. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5144. if (!client)
  5145. client = this;
  5146. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5147. if (packet) {
  5148. EQ2Packet* outapp = packet->serialize();
  5149. //DumpPacket(outapp);
  5150. client->QueuePacket(outapp);
  5151. safe_delete(packet);
  5152. }
  5153. }
  5154. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5155. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5156. if (packet) {
  5157. QueuePacket(packet->serialize());
  5158. safe_delete(packet);
  5159. }
  5160. }
  5161. void Client::ReloadQuests() {
  5162. vector<int32> ids = player->GetQuestIDs();
  5163. Quest* quest = 0;
  5164. for (int32 i = 0; i < ids.size(); i++) {
  5165. quest = master_quest_list.GetQuest(ids[i]);
  5166. if (quest)
  5167. AddPlayerQuest(quest, false);
  5168. else
  5169. RemovePlayerQuest(ids[i]);
  5170. }
  5171. }
  5172. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5173. bool found_quest = false;
  5174. vector<Quest*>::iterator itr;
  5175. vector<Item*>* items = 0;
  5176. Quest* quest = 0;
  5177. MPendingQuestAccept.lock();
  5178. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  5179. quest = *itr;
  5180. if(quest->GetQuestTemporaryState())
  5181. items = quest->GetTmpRewardItems();
  5182. else
  5183. items = quest->GetRewardItems();
  5184. if (item_id == 0 && items && items->size() > 0) {
  5185. found_quest = true;
  5186. }
  5187. else {
  5188. items = quest->GetSelectableRewardItems();
  5189. if (items && items->size() > 0) {
  5190. for (int32 i = 0; i < items->size(); i++) {
  5191. if (items->at(i)->details.item_id == item_id) {
  5192. found_quest = true;
  5193. break;
  5194. }
  5195. }
  5196. }
  5197. }
  5198. if (found_quest) {
  5199. pending_quest_accept.erase(itr);
  5200. break;
  5201. }
  5202. }
  5203. MPendingQuestAccept.unlock();
  5204. if (found_quest)
  5205. return quest;
  5206. return 0;
  5207. }
  5208. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5209. int8 num_slots_needed = 0;
  5210. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5211. Item* master_item = 0;
  5212. if (item_id > 0) {
  5213. num_slots_needed++;
  5214. master_item = master_item_list.GetItem(item_id);
  5215. }
  5216. int32 totalItems = 0;
  5217. vector<Item*>* items = 0;
  5218. vector<Item*>* tmpItems = 0;
  5219. bool isTempState = quest->GetQuestTemporaryState();
  5220. if(isTempState)
  5221. {
  5222. tmpItems = quest->GetTmpRewardItems();
  5223. if (tmpItems && tmpItems->size() > 0)
  5224. {
  5225. num_slots_needed += tmpItems->size();
  5226. totalItems += tmpItems->size();
  5227. }
  5228. }
  5229. else
  5230. {
  5231. items = quest->GetRewardItems();
  5232. if (items && items->size() > 0)
  5233. {
  5234. num_slots_needed += items->size();
  5235. totalItems += items->size();
  5236. }
  5237. }
  5238. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5239. if (master_item)
  5240. AddItem(item_id);
  5241. if (tmpItems && tmpItems->size() > 0) {
  5242. for (int32 i = 0; i < tmpItems->size(); i++)
  5243. AddItem(new Item(tmpItems->at(i)));
  5244. }
  5245. if (items && items->size() > 0) {
  5246. for (int32 i = 0; i < items->size(); i++)
  5247. AddItem(new Item(items->at(i)));
  5248. }
  5249. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5250. if (outapp)
  5251. QueuePacket(outapp);
  5252. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5253. map<int32, sint32>::iterator itr;
  5254. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5255. int32 faction_id = itr->first;
  5256. sint32 amount = itr->second;
  5257. if (amount > 0)
  5258. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5259. else
  5260. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5261. }
  5262. if(quest->GetQuestTemporaryState())
  5263. {
  5264. int64 total_coins = quest->GetCoinTmpReward();
  5265. if (total_coins > 0)
  5266. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5267. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5268. quest->SetQuestTemporaryState(false);
  5269. }
  5270. else
  5271. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5272. player->SetCharSheetChanged(true);
  5273. }
  5274. else {
  5275. MPendingQuestAccept.lock();
  5276. pending_quest_accept.push_back(quest);
  5277. MPendingQuestAccept.unlock();
  5278. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5279. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5280. }
  5281. }
  5282. 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) {
  5283. 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))) {
  5284. /*if (quest)
  5285. text = quest->GetName();
  5286. else*/
  5287. return;//nothing to give
  5288. }
  5289. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5290. if (packet2) {
  5291. int32 source_id = 0;
  5292. if (quest)
  5293. source_id = quest->GetQuestID();
  5294. int64 rewarded_coin = 0;
  5295. if (quest) {
  5296. if (quest->GetCoinsReward() > 0) {
  5297. if (quest->GetCoinsRewardMax() > 0)
  5298. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5299. else
  5300. rewarded_coin = quest->GetCoinsReward();
  5301. }
  5302. quest->SetGeneratedCoin(rewarded_coin);
  5303. }
  5304. if (rewarded_coin > coin)
  5305. coin = rewarded_coin;
  5306. 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
  5307. if (coin > 0) {
  5308. player->AddCoins(coin);
  5309. PlaySound("coin_cha_ching");
  5310. }
  5311. }
  5312. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5313. packet2->setSubstructDataByName("reward_data", "reward", header);
  5314. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5315. if (player->GetGuild()) {
  5316. 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
  5317. player->GetInfoStruct()->add_status_points(status_points);
  5318. player->SetCharSheetChanged(true);
  5319. }
  5320. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5321. }
  5322. if(text)
  5323. packet2->setSubstructDataByName("reward_data", "text", text);
  5324. if(rewards){
  5325. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5326. for (int i = 0; i < rewards->size(); i++) {
  5327. Item* item = rewards->at(i);
  5328. if (item) {
  5329. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5330. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5331. }
  5332. 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
  5333. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5334. }
  5335. }
  5336. if (selectable_rewards) {
  5337. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5338. for (int i = 0; i < selectable_rewards->size(); i++) {
  5339. Item* item = selectable_rewards->at(i);
  5340. if (item) {
  5341. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5342. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5343. 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
  5344. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5345. }
  5346. }
  5347. }
  5348. if (factions) {
  5349. map<int32, sint32>::iterator itr;
  5350. map<Faction*, signed int> factions_map;
  5351. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5352. Faction* faction = master_faction_list.GetFaction(itr->first);
  5353. if (faction)
  5354. factions_map[faction] = itr->second;
  5355. }
  5356. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5357. map<Faction*, signed int>::iterator faction_itr;
  5358. int8 i = 0;
  5359. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5360. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5361. sint32 amount = faction_itr->second;
  5362. packet2->setArrayDataByName("amount", amount, i);
  5363. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5364. if (amount > 0)
  5365. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5366. else
  5367. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5368. }
  5369. i++;
  5370. }
  5371. }
  5372. QueuePacket(packet2->serialize());
  5373. safe_delete(packet2);
  5374. }
  5375. }
  5376. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription) {
  5377. if (!quest)
  5378. return;
  5379. quest->SetQuestTemporaryState(tempReward, customDescription);
  5380. AddPendingQuestAcceptReward(quest);
  5381. if (GetVersion() <= 546) {
  5382. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints());
  5383. return;
  5384. }
  5385. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5386. if (packet) {
  5387. packet->setDataByName("title", "Quest Reward!");
  5388. packet->setDataByName("name", quest->GetName());
  5389. if(customDescription.size() > 0)
  5390. {
  5391. packet->setDataByName("description", customDescription.c_str());
  5392. }
  5393. else
  5394. packet->setDataByName("description", quest->GetDescription());
  5395. packet->setDataByName("level", quest->GetLevel());
  5396. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5397. int8 difficulty = 0;
  5398. if ((string)quest->GetType() == "Tradeskill")
  5399. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5400. else
  5401. difficulty = player->GetArrowColor(quest->GetLevel());
  5402. packet->setDataByName("difficulty", difficulty);
  5403. if(tempReward)
  5404. {
  5405. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5406. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5407. packet->setDataByName("status_points", quest->GetStatusPoints());
  5408. }
  5409. else
  5410. {
  5411. int64 rewarded_coin = 0;
  5412. if (quest->GetCoinsReward() > 0) {
  5413. if (quest->GetCoinsRewardMax() > 0)
  5414. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5415. else
  5416. rewarded_coin = quest->GetCoinsReward();
  5417. }
  5418. quest->SetGeneratedCoin(rewarded_coin);
  5419. packet->setDataByName("max_coin", rewarded_coin);
  5420. packet->setDataByName("min_coin", rewarded_coin);
  5421. packet->setDataByName("status_points", quest->GetStatusPoints());
  5422. }
  5423. vector<Item*>* items = quest->GetTmpRewardItems();
  5424. if(tempReward)
  5425. {
  5426. if (items) {
  5427. packet->setArrayLengthByName("num_rewards", items->size());
  5428. for (int32 i = 0; i < items->size(); i++) {
  5429. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5430. if (version < 860)
  5431. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5432. else if (version < 1193)
  5433. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5434. else
  5435. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5436. }
  5437. }
  5438. }
  5439. else
  5440. {
  5441. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5442. vector<Item*>* items = quest->GetRewardItems();
  5443. if (items) {
  5444. packet->setArrayLengthByName("num_rewards", items->size());
  5445. for (int32 i = 0; i < items->size(); i++) {
  5446. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5447. if (version < 860)
  5448. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5449. else if (version < 1193)
  5450. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5451. else
  5452. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5453. }
  5454. }
  5455. if (items2 && items2->size() > 0) {
  5456. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5457. for (int32 i = 0; i < items2->size(); i++) {
  5458. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5459. if (version < 860)
  5460. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5461. else if (version < 1193)
  5462. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5463. else
  5464. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5465. }
  5466. }
  5467. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5468. if (reward_factions && reward_factions->size() > 0) {
  5469. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5470. map<int32, sint32>::iterator itr;
  5471. int16 index = 0;
  5472. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5473. int32 faction_id = itr->first;
  5474. sint32 amount = itr->second;
  5475. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5476. if (faction_name) {
  5477. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5478. packet->setArrayDataByName("amount", amount, index);
  5479. }
  5480. index++;
  5481. }
  5482. }
  5483. }
  5484. EQ2Packet* outapp = packet->serialize();
  5485. // DumpPacket(outapp);
  5486. QueuePacket(outapp);
  5487. safe_delete(packet);
  5488. }
  5489. }
  5490. void Client::DisplayRandomizeFeatures(int32 flags) {
  5491. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5492. if (flags > 0) {
  5493. if (flags & RANDOMIZE_GENDER)
  5494. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5495. if (flags & RANDOMIZE_RACE)
  5496. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5497. if (flags & RANDOMIZE_MODEL_TYPE)
  5498. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5499. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5500. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5501. if (flags & RANDOMIZE_HAIR_TYPE)
  5502. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5503. if (flags & RANDOMIZE_WING_TYPE)
  5504. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5505. if (flags & RANDOMIZE_CHEEK_TYPE)
  5506. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5507. if (flags & RANDOMIZE_CHIN_TYPE)
  5508. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5509. if (flags & RANDOMIZE_EAR_TYPE)
  5510. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5511. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5512. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5513. if (flags & RANDOMIZE_EYE_TYPE)
  5514. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5515. if (flags & RANDOMIZE_LIP_TYPE)
  5516. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5517. if (flags & RANDOMIZE_NOSE_TYPE)
  5518. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5519. if (flags & RANDOMIZE_EYE_COLOR)
  5520. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5521. if (flags & RANDOMIZE_HAIR_COLOR1)
  5522. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5523. if (flags & RANDOMIZE_HAIR_COLOR2)
  5524. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5525. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5526. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5527. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5528. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5529. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5530. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5531. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5532. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5533. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5534. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5535. if (flags & RANDOMIZE_SKIN_COLOR)
  5536. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5537. if (flags & RANDOMIZE_WING_COLOR1)
  5538. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5539. if (flags & RANDOMIZE_WING_COLOR2)
  5540. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5541. }
  5542. else
  5543. {
  5544. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5545. }
  5546. }
  5547. void Client::GiveQuestReward(Quest* quest) {
  5548. current_quest_id = 0;
  5549. if(!quest->GetQuestTemporaryState())
  5550. {
  5551. quest->IncrementCompleteCount();
  5552. player->AddCompletedQuest(quest);
  5553. }
  5554. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5555. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5556. SendQuestJournal();
  5557. if(quest->GetQuestTemporaryState())
  5558. return;
  5559. player->RemoveQuest(quest->GetQuestID(), false);
  5560. if (quest->GetExpReward() > 0) {
  5561. int16 level = player->GetLevel();
  5562. int32 xp = quest->GetExpReward();
  5563. if (player->AddXP(xp)) {
  5564. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5565. if (player->GetLevel() != level)
  5566. ChangeLevel(level, player->GetLevel());
  5567. player->SetCharSheetChanged(true);
  5568. }
  5569. }
  5570. if (quest->GetTSExpReward() > 0) {
  5571. int8 ts_level = player->GetTSLevel();
  5572. int32 xp = quest->GetTSExpReward();
  5573. if (player->AddTSXP(xp)) {
  5574. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5575. if (player->GetTSLevel() != ts_level)
  5576. ChangeTSLevel(ts_level, player->GetTSLevel());
  5577. player->SetCharSheetChanged(true);
  5578. }
  5579. }
  5580. int64 total_coins = quest->GetGeneratedCoin();
  5581. if (total_coins > 0)
  5582. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5583. if (quest->GetQuestGiver() > 0)
  5584. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5585. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5586. }
  5587. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5588. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5589. if (packet) {
  5590. packet->setDataByName("conversation_id", conversation_id);
  5591. packet->setDataByName("text", text);
  5592. packet->setDataByName("unknown2", 1);
  5593. conversation_map[conversation_id].clear();
  5594. if (conversations) {
  5595. packet->setArrayLengthByName("num_responses", conversations->size());
  5596. for (int32 i = 0; i < conversations->size(); i++) {
  5597. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5598. if (conversations->at(i).function.length() > 0)
  5599. conversation_map[conversation_id][i] = conversations->at(i).function;
  5600. }
  5601. }
  5602. packet->setDataByName("spawn_id", spawn_id);
  5603. if (mp3) {
  5604. packet->setDataByName("voice", mp3);
  5605. packet->setDataByName("key1", key1);
  5606. packet->setDataByName("key2", key2);
  5607. }
  5608. QueuePacket(packet->serialize());
  5609. safe_delete(packet);
  5610. }
  5611. }
  5612. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  5613. if (!item || !text || !conversations || conversations->size() == 0) {
  5614. return;
  5615. }
  5616. int32 conversation_id = GetConversationID(0, item);
  5617. if (conversation_id == 0) {
  5618. next_conversation_id++;
  5619. conversation_id = next_conversation_id;
  5620. }
  5621. MConversation.writelock();
  5622. conversation_items[conversation_id] = item;
  5623. MConversation.releasewritelock();
  5624. if (type == 4)
  5625. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5626. else
  5627. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5628. }
  5629. void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5630. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5631. return;
  5632. }
  5633. int32 conversation_id = GetConversationID(src, 0);
  5634. if (conversation_id == 0) {
  5635. next_conversation_id++;
  5636. conversation_id = next_conversation_id;
  5637. }
  5638. MConversation.writelock();
  5639. conversation_spawns[conversation_id] = src;
  5640. MConversation.releasewritelock();
  5641. /* Spawns can start two different types of conversations.
  5642. * Type 1: The chat type with bubbles.
  5643. * Type 2: The dialog type with the blue box. */
  5644. if (type == 1)
  5645. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2);
  5646. else if (type == 2)
  5647. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5648. else //if (type == 3)
  5649. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5650. }
  5651. void Client::CloseDialog(int32 conversation_id) {
  5652. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5653. if (packet) {
  5654. packet->setDataByName("conversation_id", conversation_id);
  5655. QueuePacket(packet->serialize());
  5656. safe_delete(packet);
  5657. }
  5658. MConversation.writelock();
  5659. std::map<int32, Item*>::iterator itr;
  5660. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5661. {
  5662. conversation_items.erase(itr);
  5663. }
  5664. std::map<int32, Spawn*>::iterator itr2 = conversation_spawns.find(conversation_id);
  5665. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5666. {
  5667. conversation_spawns.erase(itr2);
  5668. }
  5669. MConversation.releasewritelock();
  5670. }
  5671. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5672. int32 conversation_id = 0;
  5673. MConversation.readlock();
  5674. if (spawn) {
  5675. map<int32, Spawn*>::iterator itr;
  5676. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5677. if (itr->second == spawn) {
  5678. conversation_id = itr->first;
  5679. break;
  5680. }
  5681. }
  5682. }
  5683. else if (item) {
  5684. map<int32, Item*>::iterator itr;
  5685. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5686. if (itr->second == item) {
  5687. conversation_id = itr->first;
  5688. break;
  5689. }
  5690. }
  5691. }
  5692. MConversation.releasereadlock();
  5693. return conversation_id;
  5694. }
  5695. Spawn* Client::GetCombineSpawn() {
  5696. return combine_spawn;
  5697. }
  5698. bool Client::ShouldTarget() {
  5699. return should_target;
  5700. }
  5701. void Client::TargetSpawn(Spawn* spawn) {
  5702. should_target = false;
  5703. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5704. if (packet) {
  5705. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5706. QueuePacket(packet->serialize());
  5707. safe_delete(packet);
  5708. }
  5709. }
  5710. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5711. combine_spawn = spawn;
  5712. spawn->RemoveSpawnFromGroup(true);
  5713. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5714. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5715. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5716. should_target = true;
  5717. }
  5718. void Client::AddCombineSpawn(Spawn* spawn) {
  5719. if (combine_spawn && combine_spawn != spawn && spawn) {
  5720. combine_spawn->AddSpawnToGroup(spawn);
  5721. spawn->AddSpawnToGroup(combine_spawn);
  5722. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5723. }
  5724. else if (spawn)
  5725. combine_spawn = spawn;
  5726. should_target = true;
  5727. }
  5728. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5729. if (combine_spawn && spawn)
  5730. spawn->RemoveSpawnFromGroup();
  5731. if (combine_spawn == spawn)
  5732. combine_spawn->RemoveSpawnFromGroup(true);
  5733. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5734. if (combine_spawn == spawn)
  5735. combine_spawn = 0;
  5736. }
  5737. void Client::SaveCombineSpawns(const char* name) {
  5738. if (!combine_spawn) {
  5739. return;
  5740. }
  5741. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5742. if (!spawns) {
  5743. return;
  5744. }
  5745. int32 count = spawns->size();
  5746. int32 spawnLocationID = 0;
  5747. if (count == 1)
  5748. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5749. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5750. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5751. // we remove the spawn inside SaveCombinedSpawnLocation
  5752. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5753. }
  5754. else
  5755. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5756. safe_delete(spawns);
  5757. combine_spawn = 0;
  5758. }
  5759. bool Client::AddItem(int32 item_id, int16 quantity) {
  5760. Item* master_item = master_item_list.GetItem(item_id);
  5761. Item* item = 0;
  5762. if (master_item)
  5763. item = new Item(master_item);
  5764. if (item) {
  5765. if (quantity > 0)
  5766. item->details.count = quantity;
  5767. return AddItem(item);
  5768. }
  5769. else
  5770. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5771. return false;
  5772. }
  5773. bool Client::AddItem(Item* item, bool* item_deleted) {
  5774. if (!item) {
  5775. return false;
  5776. }
  5777. if (item->IsBag()) {
  5778. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5779. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5780. }
  5781. if (player->AddItem(item)) {
  5782. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5783. if (outapp) {
  5784. //DumpPacket(outapp);
  5785. QueuePacket(outapp);
  5786. //resend bag desc with new item name added
  5787. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5788. if (outapp) {
  5789. //DumpPacket(outapp);
  5790. QueuePacket(outapp);
  5791. }
  5792. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5793. DumpPacket(app);
  5794. client->QueuePacket(app);
  5795. */
  5796. }
  5797. CheckPlayerQuestsItemUpdate(item);
  5798. if (item->GetItemScript() && lua_interface)
  5799. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5800. }
  5801. else {
  5802. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5803. safe_delete(item);
  5804. if(item_deleted)
  5805. *item_deleted = true;
  5806. return false;
  5807. }
  5808. return true;
  5809. }
  5810. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5811. Item* master_item = master_item_list.GetItem(item_id);
  5812. Item* item = 0;
  5813. if (master_item)
  5814. item = new Item(master_item);
  5815. if (item) {
  5816. if (quantity > 0)
  5817. item->details.count = quantity;
  5818. return AddItemToBank(item);
  5819. }
  5820. else
  5821. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5822. return false;
  5823. }
  5824. bool Client::AddItemToBank(Item* item) {
  5825. if (!item) {
  5826. return false;
  5827. }
  5828. if (player->AddItemToBank(item)) {
  5829. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5830. if (outapp) {
  5831. QueuePacket(outapp);
  5832. //resend bag desc with new item name added
  5833. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5834. if (outapp)
  5835. QueuePacket(outapp);
  5836. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5837. DumpPacket(app);
  5838. client->QueuePacket(app);
  5839. */
  5840. }
  5841. CheckPlayerQuestsItemUpdate(item);
  5842. if (item->GetItemScript() && lua_interface)
  5843. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5844. }
  5845. else {
  5846. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5847. safe_delete(item);
  5848. return false;
  5849. }
  5850. return true;
  5851. }
  5852. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  5853. EQ2Packet* outapp;
  5854. bool delete_item = false;
  5855. assert(item);
  5856. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5857. item->details.count -= quantity;
  5858. item->save_needed = true;
  5859. }
  5860. else {
  5861. database.DeleteItem(character_id, item, 0);
  5862. player->GetPlayerItemList()->RemoveItem(item, false);
  5863. delete_item = true;
  5864. }
  5865. if(force_override_no_delete)
  5866. delete_item = false;
  5867. if ((outapp = player->SendInventoryUpdate(version))) {
  5868. QueuePacket(outapp);
  5869. if (item->GetItemScript() && lua_interface)
  5870. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5871. if (delete_item)
  5872. {
  5873. PurgeItem(item);
  5874. safe_delete(item);
  5875. }
  5876. return true;
  5877. }
  5878. return false;
  5879. }
  5880. void Client::SetLuaDebugClient(bool val) {
  5881. if (val)
  5882. lua_debug_timer.Start();
  5883. lua_debug = val;
  5884. if (lua_interface && !val) {
  5885. lua_interface->RemoveDebugClients(this);
  5886. lua_debug_timer.Disable();
  5887. }
  5888. }
  5889. void Client::SetMerchantTransaction(Spawn* spawn) {
  5890. merchant_transaction = spawn;
  5891. }
  5892. Spawn* Client::GetMerchantTransaction() {
  5893. return merchant_transaction;
  5894. }
  5895. void Client::SetMailTransaction(Spawn* spawn) {
  5896. ResetSendMail(spawn ? false : true);
  5897. MMailWindowMutex.lock();
  5898. mail_transaction = spawn;
  5899. MMailWindowMutex.unlock();
  5900. }
  5901. Spawn* Client::GetMailTransaction() {
  5902. return mail_transaction;
  5903. }
  5904. void Client::PlaySound(const char* name) {
  5905. if (name) {
  5906. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5907. if (packet) {
  5908. packet->setMediumStringByName("name", name);
  5909. QueuePacket(packet->serialize());
  5910. safe_delete(packet);
  5911. }
  5912. }
  5913. }
  5914. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5915. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5916. if(multiplier){
  5917. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5918. float diff_low = faction_val - multiplier->faction_min;
  5919. if(diff_low < 0)
  5920. diff_low*=-1;
  5921. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5922. if(total_diff < 0)
  5923. total_diff*=-1;
  5924. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5925. float total1 = (diff_low/total_diff);
  5926. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5927. return final_buy_multiplier;
  5928. }*/
  5929. return 1;
  5930. }
  5931. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5932. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5933. if(multiplier){
  5934. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5935. float diff_low = faction_val - multiplier->faction_min;
  5936. if(diff_low < 0)
  5937. diff_low*=-1;
  5938. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5939. if(total_diff < 0)
  5940. total_diff*=-1;
  5941. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5942. float total1 = (diff_low/total_diff);
  5943. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5944. return final_sell_multiplier;
  5945. }*/
  5946. return 1;
  5947. }
  5948. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5949. Spawn* spawn = GetMerchantTransaction();
  5950. Guild* guild = GetPlayer()->GetGuild();
  5951. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  5952. spawn->IsClientInMerchantLevelRange(this)) {
  5953. int32 total_sell_price = 0;
  5954. int32 total_status_sell_price = 0; //for status
  5955. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5956. int32 sell_price = 0;
  5957. int32 status_sell_price = 0; //for status
  5958. Item* master_item = master_item_list.GetItem(item_id);
  5959. Item* item = 0;
  5960. if (unique_id == 0)
  5961. item = player->item_list.GetItemFromID(item_id, quantity);
  5962. else
  5963. item = player->item_list.GetItemFromUniqueID(unique_id);
  5964. if (!item)
  5965. item = player->item_list.GetItemFromID(item_id);
  5966. if (item && master_item) {
  5967. if(item->details.item_locked)
  5968. {
  5969. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  5970. return;
  5971. }
  5972. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5973. if (sell_price > item->sell_price)
  5974. sell_price = item->sell_price;
  5975. if (quantity > item->details.count)
  5976. quantity = item->details.count;
  5977. total_sell_price = sell_price * quantity;
  5978. //------------------------------For Selling Status Items
  5979. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5980. if (status_sell_price > item->sell_status)
  5981. status_sell_price = item->sell_status;
  5982. if (quantity > item->details.count)
  5983. quantity = item->details.count;
  5984. total_status_sell_price = status_sell_price * quantity;
  5985. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  5986. total_status_sell_price = 0;
  5987. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  5988. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  5989. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  5990. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5991. guild->SendGuildMemberList();
  5992. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5993. }
  5994. if (quantity > 1)
  5995. {
  5996. if(total_status_sell_price)
  5997. 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);
  5998. else
  5999. 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());
  6000. }
  6001. else
  6002. {
  6003. if(total_status_sell_price)
  6004. 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);
  6005. else
  6006. 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());
  6007. }
  6008. player->AddCoins(total_sell_price);
  6009. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6010. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6011. if (quantity >= item->details.count) {
  6012. database.DeleteItem(GetCharacterID(), item, 0);
  6013. player->item_list.DestroyItem(item->details.index);
  6014. }
  6015. else {
  6016. item->details.count -= quantity;
  6017. item->save_needed = true;
  6018. }
  6019. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6020. if (outapp)
  6021. QueuePacket(outapp);
  6022. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6023. SendBuyBackList();
  6024. }
  6025. }
  6026. }
  6027. void Client::BuyBack(int32 item_id, int16 quantity) {
  6028. Spawn* spawn = GetMerchantTransaction();
  6029. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6030. spawn->IsClientInMerchantLevelRange(this)) {
  6031. deque<BuyBackItem*>::iterator itr;
  6032. BuyBackItem* buyback = 0;
  6033. BuyBackItem* closest = 0;
  6034. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6035. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6036. buyback = *itr;
  6037. if (buyback->unique_id == item_id) {
  6038. closest = buyback;
  6039. quantity = buyback->quantity;
  6040. break;
  6041. }
  6042. }
  6043. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6044. if (closest) {
  6045. Item* item = 0;
  6046. Item* master_item = master_item_list.GetItem(closest->item_id);
  6047. if (master_item) {
  6048. item = new Item(master_item);
  6049. if (closest->quantity >= quantity)
  6050. item->details.count = quantity;
  6051. else
  6052. item->details.count = closest->quantity;
  6053. }
  6054. bool itemDeleted = false;
  6055. bool itemAdded = false;
  6056. sint64 dispFlags = 0;
  6057. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6058. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6059. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6060. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6061. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6062. bool removed = false;
  6063. if (closest->quantity == quantity) {
  6064. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6065. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6066. if (*itr == closest) {
  6067. buy_back_items.erase(itr);
  6068. removed = true;
  6069. break;
  6070. }
  6071. }
  6072. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6073. }
  6074. else {
  6075. closest->quantity -= quantity;
  6076. closest->save_needed = true;
  6077. }
  6078. itemAdded = AddItem(item, &itemDeleted);
  6079. if (removed) {
  6080. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6081. safe_delete(closest);
  6082. }
  6083. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6084. SendBuyBackList();
  6085. }
  6086. else
  6087. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6088. if(!itemAdded && !itemDeleted)
  6089. safe_delete(item);
  6090. }
  6091. }
  6092. }
  6093. void Client::BuyItem(int32 item_id, int16 quantity) {
  6094. // Get the merchant we are buying from
  6095. Spawn* spawn = GetMerchantTransaction();
  6096. // Make sure the spawn has a merchant list
  6097. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6098. int32 total_buy_price = 0;
  6099. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6100. int32 sell_price = 0;
  6101. Item* master_item = master_item_list.GetItem(item_id);
  6102. Item* item = 0;
  6103. int16 total_available = 0;
  6104. vector<MerchantItemInfo>* temp;
  6105. vector<MerchantItemInfo>::iterator itr;
  6106. MerchantItemInfo* ItemInfo = 0;
  6107. temp = world.GetMerchantList(spawn->GetMerchantID());
  6108. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6109. if ((*itr).item_id == item_id) {
  6110. ItemInfo = &(*itr);
  6111. break;
  6112. }
  6113. }
  6114. if (master_item && ItemInfo) {
  6115. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6116. quantity = 1;
  6117. total_available = 0xFFFF;
  6118. sell_price = master_item->sell_price;
  6119. }
  6120. else {
  6121. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6122. sell_price = (int32)(master_item->sell_price * multiplier);
  6123. if (quantity > total_available)
  6124. quantity = total_available;
  6125. }
  6126. sint64 dispFlags = 0;
  6127. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6128. {
  6129. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6130. return;
  6131. }
  6132. if(quantity < 1)
  6133. {
  6134. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6135. return;
  6136. }
  6137. total_buy_price = sell_price * quantity;
  6138. item = new Item(master_item);
  6139. item->details.count = quantity;
  6140. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6141. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6142. safe_delete(item);
  6143. }
  6144. else {
  6145. // Price not set in the merchant_inventory table, use the old method
  6146. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6147. if (player->RemoveCoins(total_buy_price)) {
  6148. item->SetMaxSellValue(sell_price);
  6149. if (quantity > 1)
  6150. 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());
  6151. else
  6152. 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());
  6153. bool itemDeleted = false;
  6154. AddItem(item, &itemDeleted);
  6155. if(!itemDeleted) {
  6156. CheckPlayerQuestsItemUpdate(item);
  6157. if (item && total_available < 0xFF) {
  6158. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6159. SendBuyMerchantList();
  6160. }
  6161. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6162. PlayLotto(total_buy_price, item->details.item_id);
  6163. }
  6164. }
  6165. else {
  6166. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6167. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6168. PlaySound("buy_failed");
  6169. }
  6170. }
  6171. else {
  6172. // Price set in merchant_inventory table
  6173. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6174. // TODO: need to add support for station cash
  6175. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6176. // Check items
  6177. int16 item_quantity = 0;
  6178. // Default these to true in case price_item_id or price_item2_id was never set
  6179. bool hasItem1 = true;
  6180. bool hasItem2 = true;
  6181. Item* tempItem1 = 0;
  6182. Item* tempItem2 = 0;
  6183. if (ItemInfo->price_item_id != 0) {
  6184. // Same item for whatever reason lets add the quantities together
  6185. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6186. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6187. else
  6188. item_quantity = ItemInfo->price_item_qty;
  6189. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6190. if (tempItem1) {
  6191. if (tempItem1->details.count < item_quantity)
  6192. hasItem1 = false;
  6193. }
  6194. else {
  6195. hasItem1 = false;
  6196. }
  6197. }
  6198. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6199. // as item1 and we already checked for it so we can skip this check
  6200. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6201. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6202. if (tempItem2) {
  6203. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6204. hasItem2 = false;
  6205. }
  6206. else {
  6207. hasItem2 = false;
  6208. }
  6209. }
  6210. // if we have every thing then remove the price and give the item
  6211. if (hasItem1 && hasItem2) {
  6212. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6213. // TODO: station cash
  6214. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6215. // so there is no need to send it more then that one time
  6216. if (tempItem1) {
  6217. if (tempItem1->details.count > item_quantity) {
  6218. tempItem1->details.count -= item_quantity;
  6219. tempItem1->save_needed = true;
  6220. }
  6221. else {
  6222. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6223. player->item_list.DestroyItem(tempItem1->details.index);
  6224. }
  6225. }
  6226. if (tempItem2) {
  6227. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6228. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6229. tempItem2->save_needed = true;
  6230. }
  6231. else {
  6232. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6233. player->item_list.DestroyItem(tempItem2->details.index);
  6234. }
  6235. }
  6236. // 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
  6237. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6238. item->SetMaxSellValue(sell_price);
  6239. if (quantity > 1)
  6240. 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());
  6241. else
  6242. 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());
  6243. bool itemDeleted = false;
  6244. AddItem(item, &itemDeleted);
  6245. if(!itemDeleted) {
  6246. CheckPlayerQuestsItemUpdate(item);
  6247. if (item && total_available < 0xFF) {
  6248. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6249. SendBuyMerchantList();
  6250. }
  6251. SendSellMerchantList();
  6252. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6253. PlayLotto(total_buy_price, item->details.item_id);
  6254. }
  6255. }
  6256. else {
  6257. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6258. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6259. PlaySound("buy_failed");
  6260. }
  6261. }
  6262. else {
  6263. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6264. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6265. PlaySound("buy_failed");
  6266. }
  6267. }
  6268. }
  6269. }
  6270. }
  6271. }
  6272. void Client::RepairItem(int32 item_id) {
  6273. Spawn* spawn = GetMerchantTransaction();
  6274. if (spawn) {
  6275. Item* item = player->item_list.GetItemFromID(item_id);
  6276. if (!item)
  6277. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6278. if (item) {
  6279. int32 repair_cost = item->CalculateRepairCost();
  6280. if (player->RemoveCoins((int32)repair_cost)) {
  6281. item->generic_info.condition = 100;
  6282. item->save_needed = true;
  6283. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6284. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6285. QueuePacket(item->serialize(version, false, player));
  6286. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6287. PlaySound("coin_cha_ching");
  6288. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6289. SendRepairList();
  6290. }
  6291. else {
  6292. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6293. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6294. PlaySound("buy_failed");
  6295. }
  6296. }
  6297. }
  6298. }
  6299. void Client::RepairAllItems() {
  6300. Spawn* spawn = GetMerchantTransaction();
  6301. if (spawn) {
  6302. vector<Item*>* repairable_items = GetRepairableItems();
  6303. if (repairable_items && repairable_items->size() > 0) {
  6304. vector<Item*>::iterator itr;
  6305. int64 total_cost = 0;
  6306. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6307. total_cost += (*itr)->CalculateRepairCost();
  6308. if (player->RemoveCoins((int32)total_cost)) {
  6309. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6310. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6311. Item* item = *itr;
  6312. if (item) {
  6313. item->generic_info.condition = 100;
  6314. item->save_needed = true;
  6315. QueuePacket(item->serialize(version, false, player));
  6316. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6317. }
  6318. }
  6319. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6320. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6321. PlaySound("coin_cha_ching");
  6322. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6323. SendRepairList();
  6324. }
  6325. else {
  6326. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6327. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6328. PlaySound("buy_failed");
  6329. }
  6330. }
  6331. safe_delete(repairable_items);
  6332. }
  6333. }
  6334. void Client::SendAchievementsList()
  6335. {
  6336. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6337. map<int32, Achievement *>::iterator itr;
  6338. Achievement *achievement;
  6339. vector<AchievementRequirements *> *requirements = 0;
  6340. vector<AchievementRequirements *>::iterator itr2;
  6341. AchievementRequirements *requirement;
  6342. vector<AchievementRewards *> *rewards = 0;
  6343. vector<AchievementRewards *>::iterator itr3;
  6344. AchievementRewards *reward;
  6345. PacketStruct *packet;
  6346. int16 i = 0;
  6347. int16 j = 0;
  6348. int16 k = 0;
  6349. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6350. return;
  6351. }
  6352. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6353. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6354. achievement = itr->second;
  6355. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6356. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6357. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6358. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6359. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6360. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6361. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6362. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6363. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6364. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6365. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6366. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6367. requirements = achievement->GetRequirements();
  6368. rewards = achievement->GetRewards();
  6369. j = 0;
  6370. k = 0;
  6371. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6372. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6373. requirement = *itr2;
  6374. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6375. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6376. j++;
  6377. }
  6378. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6379. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6380. reward = *itr3;
  6381. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6382. k++;
  6383. }
  6384. i++;
  6385. }
  6386. //packet->PrintPacket();
  6387. EQ2Packet* data = packet->serialize();
  6388. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6389. safe_delete(packet);
  6390. safe_delete(data);
  6391. //DumpPacket(app);
  6392. QueuePacket(app);*/
  6393. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6394. SendAchievementUpdate(true);
  6395. }
  6396. void Client::SendAchievementUpdate(bool first_login) {
  6397. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6398. map<int32, AchievementUpdate*>::iterator itr;
  6399. AchievementUpdate* update;
  6400. vector<AchievementUpdateItems*>* update_items = 0;
  6401. vector<AchievementUpdateItems*>::iterator itr2;
  6402. AchievementUpdateItems* update_item;
  6403. int16 i = 0;
  6404. int16 j = 0;
  6405. PacketStruct* packet;
  6406. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6407. return;
  6408. }
  6409. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6410. packet->setArrayLengthByName("num_achievements", updates->size());
  6411. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6412. update = itr->second;
  6413. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6414. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6415. update_items = update->GetUpdateItems();
  6416. j = 0;
  6417. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6418. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6419. update_item = *itr2;
  6420. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6421. j++;
  6422. }
  6423. i++;
  6424. }
  6425. //packet->PrintPacket();
  6426. EQ2Packet* data = packet->serialize();
  6427. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6428. safe_delete(packet);
  6429. safe_delete(data);
  6430. //DumpPacket(app);
  6431. QueuePacket(app);
  6432. }
  6433. void Client::SendBuyMerchantList(bool sell) {
  6434. Spawn* spawn = GetMerchantTransaction();
  6435. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6436. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6437. if (items) {
  6438. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6439. if (packet) {
  6440. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6441. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6442. packet->setArrayLengthByName("num_items", items->size());
  6443. vector<MerchantItemInfo>::iterator itr;
  6444. sint8 item_difficulty = 0;
  6445. int32 sell_price = 0;
  6446. int i = 0;
  6447. int tmp_level = 0;
  6448. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6449. MerchantItemInfo ItemInfo = *itr;
  6450. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6451. if (!item)
  6452. continue;
  6453. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6454. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6455. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6456. packet->setArrayDataByName("icon", item->details.icon, i);
  6457. if (item->generic_info.adventure_default_level > 0)
  6458. tmp_level = item->generic_info.adventure_default_level;
  6459. else
  6460. tmp_level = item->generic_info.tradeskill_default_level;
  6461. packet->setArrayDataByName("level", tmp_level, i);
  6462. packet->setArrayDataByName("tier", item->details.tier, i);
  6463. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6464. item_difficulty = player->GetArrowColor(tmp_level);
  6465. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6466. item_difficulty = ARROW_COLOR_WHITE;
  6467. sint64 overrideValue = 0;
  6468. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, &overrideValue))
  6469. item_difficulty = (sint8)overrideValue;
  6470. item_difficulty -= 6;
  6471. if (item_difficulty < 0)
  6472. item_difficulty *= -1;
  6473. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6474. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6475. packet->setArrayDataByName("unknown5", 255, i);
  6476. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6477. sint64 dispFlags = 0;
  6478. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, &dispFlags))
  6479. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6480. std::string overrideValueStr;
  6481. // 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)
  6482. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6483. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6484. // If no price set in the merchant_inventory table then use the old method
  6485. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6486. sell_price = (int32)(item->sell_price * multiplier);
  6487. packet->setArrayDataByName("price", sell_price, i);
  6488. }
  6489. else {
  6490. int8 count = 0;
  6491. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6492. count++;
  6493. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6494. count++;
  6495. if (count != 0) {
  6496. packet->setSubArrayLengthByName("num_tokens", count, i);
  6497. int8 index = 0;
  6498. Item* token = 0;
  6499. if (ItemInfo.price_item_id != 0) {
  6500. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6501. if (item) {
  6502. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6503. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6504. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6505. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6506. }
  6507. token = 0;
  6508. index++;
  6509. }
  6510. if (ItemInfo.price_item2_id != 0) {
  6511. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6512. if (item) {
  6513. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6514. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6515. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6516. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6517. }
  6518. }
  6519. }
  6520. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6521. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6522. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6523. }
  6524. }
  6525. if (GetVersion() <= 546) {
  6526. //buy is 0 so dont need to set it
  6527. if (sell)
  6528. packet->setDataByName("type", 1);
  6529. }
  6530. else {
  6531. if (sell)
  6532. packet->setDataByName("type", 130);
  6533. else
  6534. packet->setDataByName("type", 2);
  6535. }
  6536. EQ2Packet* outapp = packet->serialize();
  6537. // DumpPacket(outapp);
  6538. QueuePacket(outapp);
  6539. safe_delete(packet);
  6540. }
  6541. safe_delete(items);
  6542. }
  6543. else {
  6544. // Need to send an empty packet in the event there is no item list, otherwise the
  6545. // last item list sent to the player will show for this merchant
  6546. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6547. if (packet) {
  6548. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6549. if (GetVersion() <= 546) {
  6550. //buy is 0 so dont need to set it
  6551. if (sell)
  6552. packet->setDataByName("type", 1);
  6553. }
  6554. else {
  6555. if (sell)
  6556. packet->setDataByName("type", 130);
  6557. else
  6558. packet->setDataByName("type", 2);
  6559. }
  6560. EQ2Packet* outapp = packet->serialize();
  6561. QueuePacket(outapp);
  6562. safe_delete(packet);
  6563. }
  6564. }
  6565. }
  6566. }
  6567. void Client::SendSellMerchantList(bool sell) {
  6568. Spawn* spawn = GetMerchantTransaction();
  6569. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6570. return;
  6571. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6572. map<int32, Item*>* items = player->GetItemList();
  6573. if (items) {
  6574. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6575. if (packet) {
  6576. vector<Item*> sellable_items;
  6577. map<int32, Item*>::iterator test_itr;
  6578. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6579. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6580. sellable_items.push_back(test_itr->second);
  6581. }
  6582. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6583. packet->setArrayLengthByName("num_items", sellable_items.size());
  6584. vector<Item*>::iterator itr;
  6585. Item* item = 0;
  6586. sint8 item_difficulty = 0;
  6587. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6588. int32 sell_price = 0;
  6589. Item* master_item = 0;
  6590. int i = 0;
  6591. int tmp_level = 0;
  6592. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6593. item = *itr;
  6594. master_item = master_item_list.GetItem(item->details.item_id);
  6595. if (master_item)
  6596. sell_price = (int32)(master_item->sell_price * multiplier);
  6597. else
  6598. sell_price = 0;
  6599. if (sell_price > item->sell_price)
  6600. sell_price = item->sell_price;
  6601. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6602. string thename = item->name;
  6603. packet->setArrayDataByName("price", sell_price, i);
  6604. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6605. int8 dispFlags = 0;
  6606. // only city merchants allow selling for status
  6607. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6608. {
  6609. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6610. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6611. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6612. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6613. }
  6614. }
  6615. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6616. {
  6617. if(GetVersion() < 1188)
  6618. 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
  6619. else
  6620. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6621. }
  6622. if(item->no_sale)
  6623. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6624. packet->setArrayDataByName("display_flags", dispFlags, i);
  6625. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6626. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6627. packet->setArrayDataByName("stack_size", item->details.count, i);
  6628. packet->setArrayDataByName("icon", item->details.icon, i);
  6629. if (item->generic_info.adventure_default_level > 0)
  6630. tmp_level = item->generic_info.adventure_default_level;
  6631. else
  6632. tmp_level = item->generic_info.tradeskill_default_level;
  6633. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6634. packet->setArrayDataByName("tier", item->details.tier, i);
  6635. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6636. item_difficulty = player->GetArrowColor(tmp_level);
  6637. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6638. item_difficulty = ARROW_COLOR_WHITE;
  6639. sint64 overrideValue = 0;
  6640. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, &overrideValue))
  6641. item_difficulty = (sint8)overrideValue;
  6642. item_difficulty -= 6;
  6643. if (item_difficulty < 0)
  6644. item_difficulty *= -1;
  6645. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6646. if (item->details.count == 1)
  6647. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6648. else
  6649. packet->setArrayDataByName("quantity", item->details.count, i);
  6650. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6651. if (GetVersion() <= 1096)
  6652. packet->setArrayDataByName("description", item->description.c_str(), i);
  6653. }
  6654. if (GetVersion() <= 546) {
  6655. packet->setDataByName("type", 1);
  6656. }
  6657. else {
  6658. if (sell)
  6659. packet->setDataByName("type", 129);
  6660. else
  6661. packet->setDataByName("type", 1);
  6662. }
  6663. packet->setDataByName("unknown8a", 16256, 6);
  6664. packet->setDataByName("unknown8a", 16256, 10);
  6665. //packet->PrintPacket();
  6666. EQ2Packet* outapp = packet->serialize();
  6667. //DumpPacket(outapp);
  6668. QueuePacket(outapp);
  6669. safe_delete(packet);
  6670. }
  6671. safe_delete(items);
  6672. }
  6673. }
  6674. }
  6675. void Client::SendBuyBackList(bool sell) {
  6676. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6677. return;
  6678. Spawn* spawn = GetMerchantTransaction();
  6679. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6680. deque<BuyBackItem*>::iterator itr;
  6681. int i = 0;
  6682. Item* master_item = 0;
  6683. BuyBackItem* buyback = 0;
  6684. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6685. if (packet) {
  6686. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6687. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6688. sint8 item_difficulty = 0;
  6689. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6690. int tmp_level = 0;
  6691. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6692. buyback = *itr;
  6693. master_item = master_item_list.GetItem(buyback->item_id);
  6694. if (master_item) {
  6695. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6696. packet->setArrayDataByName("price", buyback->price, i);
  6697. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6698. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6699. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6700. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6701. if (master_item->generic_info.adventure_default_level > 0)
  6702. tmp_level = master_item->generic_info.adventure_default_level;
  6703. else
  6704. tmp_level = master_item->generic_info.tradeskill_default_level;
  6705. packet->setArrayDataByName("level", tmp_level, i);
  6706. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6707. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6708. item_difficulty = player->GetArrowColor(tmp_level);
  6709. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6710. item_difficulty = ARROW_COLOR_WHITE;
  6711. sint64 overrideValue = 0;
  6712. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, &overrideValue))
  6713. item_difficulty = (sint8)overrideValue;
  6714. item_difficulty -= 6;
  6715. if (item_difficulty < 0)
  6716. item_difficulty *= -1;
  6717. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6718. sint64 dispFlags = 0;
  6719. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, &dispFlags))
  6720. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6721. if (buyback->quantity == 1)
  6722. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6723. else
  6724. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6725. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6726. if (GetVersion() <= 1096)
  6727. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6728. }
  6729. }
  6730. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6731. if (sell)
  6732. packet->setDataByName("type", 640);
  6733. else
  6734. packet->setDataByName("type", 512);
  6735. EQ2Packet* outapp = packet->serialize();
  6736. // DumpPacket(outapp);
  6737. QueuePacket(outapp);
  6738. safe_delete(packet);
  6739. }
  6740. }
  6741. }
  6742. void Client::SendRepairList() {
  6743. Spawn* spawn = GetMerchantTransaction();
  6744. if (spawn) {
  6745. vector<Item*>* repairable_items = GetRepairableItems();
  6746. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6747. if (packet) {
  6748. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6749. packet->setArrayLengthByName("num_items", repairable_items->size());
  6750. Item* item = 0;
  6751. sint8 item_difficulty = 0;
  6752. int32 i = 0;
  6753. vector<Item*>::iterator itr;
  6754. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  6755. item = *itr;
  6756. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6757. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  6758. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6759. packet->setArrayDataByName("stack_size", item->details.count, i);
  6760. packet->setArrayDataByName("icon", item->details.icon, i);
  6761. /*if (item->generic_info.adventure_default_level > 0)
  6762. tmp_level = item->generic_info.adventure_default_level;
  6763. else
  6764. tmp_level = item->generic_info.tradeskill_default_level;
  6765. packet->setArrayDataByName("level", tmp_level, i);*/
  6766. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  6767. packet->setArrayDataByName("tier", item->details.tier, i);
  6768. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6769. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6770. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6771. item_difficulty = ARROW_COLOR_WHITE;
  6772. item_difficulty -= 6;
  6773. if (item_difficulty < 0)
  6774. item_difficulty *= -1;
  6775. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6776. if (item->details.count == 1)
  6777. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6778. else
  6779. packet->setArrayDataByName("quantity", item->details.count, i);
  6780. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6781. if (GetVersion() <= 1096)
  6782. packet->setArrayDataByName("description", item->description.c_str(), i);
  6783. }
  6784. if (GetVersion() <= 546) {
  6785. packet->setDataByName("type", 16);
  6786. }
  6787. else {
  6788. packet->setDataByName("type", 96);
  6789. }
  6790. EQ2Packet* outapp = packet->serialize();
  6791. QueuePacket(outapp);
  6792. safe_delete(packet);
  6793. }
  6794. safe_delete(repairable_items);
  6795. }
  6796. }
  6797. void Client::ShowLottoWindow() {
  6798. Spawn* spawn = GetMerchantTransaction();
  6799. if (spawn) {
  6800. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  6801. if (!item_id)
  6802. {
  6803. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  6804. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  6805. return;
  6806. }
  6807. else if (item_id == 0)
  6808. {
  6809. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  6810. return;
  6811. }
  6812. Item* item = master_item_list.GetItem(item_id);
  6813. if (!item) {
  6814. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  6815. return;
  6816. }
  6817. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  6818. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6819. if (packet) {
  6820. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6821. packet->setArrayLengthByName("num_items", 1);
  6822. packet->setArrayDataByName("item_name", item->name.c_str());
  6823. packet->setArrayDataByName("price", item->sell_price);
  6824. packet->setArrayDataByName("item_id", item->details.item_id);
  6825. packet->setArrayDataByName("stack_size", item->details.count);
  6826. packet->setArrayDataByName("icon", item->details.icon);
  6827. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  6828. packet->setArrayDataByName("tier", item->details.tier);
  6829. packet->setArrayDataByName("item_id2", item->details.item_id);
  6830. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6831. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6832. item_difficulty = ARROW_COLOR_WHITE;
  6833. item_difficulty -= 6;
  6834. if (item_difficulty < 0)
  6835. item_difficulty *= -1;
  6836. packet->setArrayDataByName("item_difficulty", item_difficulty);
  6837. //if(item->details.count == 1)
  6838. packet->setArrayDataByName("quantity", 0xFFFF);
  6839. //else
  6840. // packet->setArrayDataByName("quantity", item->details.count);
  6841. packet->setArrayDataByName("stack_size2", item->details.count);
  6842. packet->setArrayDataByName("description", item->description.c_str());
  6843. if (GetVersion() <= 546) {
  6844. packet->setDataByName("type", 128);
  6845. }
  6846. else {
  6847. packet->setDataByName("type", 0x00000102);
  6848. }
  6849. QueuePacket(packet->serialize());
  6850. safe_delete(packet);
  6851. }
  6852. }
  6853. }
  6854. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  6855. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  6856. if (packet) {
  6857. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  6858. int32 rolls[6] = { 0 };
  6859. int32 lottery_digits[6] = { 0 };
  6860. int8 num_matches = 0;
  6861. int64 jackpot = 0;
  6862. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  6863. if (!item) {
  6864. return;
  6865. }
  6866. database.DeleteItem(GetCharacterID(), item, 0);
  6867. GetPlayer()->item_list.RemoveItem(item, true);
  6868. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6869. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6870. if (!winning_numbers) {
  6871. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6872. variables.AddVariable(winning_numbers);
  6873. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6874. }
  6875. if (strlen(winning_numbers->GetValue()) != 12) {
  6876. winning_numbers->SetValue("231205182236");
  6877. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6878. }
  6879. try {
  6880. for (int32 i = 0; i < 12; i += 2) {
  6881. char num[4];
  6882. strncpy(num, winning_numbers->GetValue() + i, 2);
  6883. lottery_digits[i / 2] = atoi(num);
  6884. }
  6885. }
  6886. catch (...) {
  6887. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6888. return;
  6889. }
  6890. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6891. if (!jackpot_var) {
  6892. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6893. variables.AddVariable(jackpot_var);
  6894. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6895. }
  6896. try {
  6897. jackpot = atoul(jackpot_var->GetValue());
  6898. if (jackpot < 10000)
  6899. jackpot = 10000;
  6900. }
  6901. catch (...) {
  6902. jackpot = 10000;
  6903. }
  6904. char new_jackpot[128] = { 0 };
  6905. sprintf(new_jackpot, "%llu", jackpot + price);
  6906. jackpot_var->SetValue(new_jackpot);
  6907. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6908. world.PickRandomLottoDigits(rolls);
  6909. packet->setDataByName("roll_digit1", rolls[0]);
  6910. packet->setDataByName("roll_digit2", rolls[1]);
  6911. packet->setDataByName("roll_digit3", rolls[2]);
  6912. packet->setDataByName("roll_digit4", rolls[3]);
  6913. packet->setDataByName("roll_digit5", rolls[4]);
  6914. packet->setDataByName("roll_digit6", rolls[5]);
  6915. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6916. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6917. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6918. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6919. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6920. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6921. QueuePacket(packet->serialize());
  6922. safe_delete(packet);
  6923. for (int32 i = 0; i < 6; i++) {
  6924. for (int32 j = 0; j < 6; j++) {
  6925. if (rolls[i] == lottery_digits[j]) {
  6926. num_matches++;
  6927. break;
  6928. }
  6929. }
  6930. }
  6931. char new_jackpot_str[16];
  6932. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6933. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6934. if (num_matches == 6) {
  6935. world.PickRandomLottoDigits(lottery_digits);
  6936. for (int32 i = 0; i < 12; i += 2)
  6937. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6938. winning_numbers->SetValue(new_jackpot_str);
  6939. jackpot_var->SetValue("10000");
  6940. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6941. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6942. }
  6943. }
  6944. }
  6945. void Client::SendGuildCreateWindow() {
  6946. if (GetVersion() <= 546) {
  6947. SimpleMessage(0, "Not implemented on this client...yet?");
  6948. }
  6949. else {
  6950. Spawn* spawn = GetPlayer()->GetTarget();
  6951. if (spawn) {
  6952. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6953. if (packet) {
  6954. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6955. packet->setArrayLengthByName("num_items", 0);
  6956. packet->setDataByName("type", 0x00008000);
  6957. QueuePacket(packet->serialize());
  6958. safe_delete(packet);
  6959. }
  6960. }
  6961. }
  6962. }
  6963. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  6964. BuyBackItem* item = new BuyBackItem;
  6965. item->item_id = item_id;
  6966. item->unique_id = unique_id;
  6967. item->price = price;
  6968. item->quantity = quantity;
  6969. item->save_needed = save_needed;
  6970. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6971. buy_back_items.push_back(item);
  6972. if (buy_back_items.size() > 10) {
  6973. safe_delete(buy_back_items.front());
  6974. buy_back_items.pop_front();
  6975. }
  6976. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6977. }
  6978. deque<BuyBackItem*>* Client::GetBuyBacks() {
  6979. return &buy_back_items;
  6980. }
  6981. vector<Item*>* Client::GetRepairableItems() {
  6982. vector<Item*>* repairable_items = new vector<Item*>;
  6983. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  6984. map<int32, Item*>* items = player->GetItemList();
  6985. if (equipped_items && equipped_items->size() > 0) {
  6986. for (int32 i = 0; i < equipped_items->size(); i++) {
  6987. Item* item = equipped_items->at(i);
  6988. if (item && item->generic_info.condition < 100)
  6989. repairable_items->push_back(item);
  6990. }
  6991. }
  6992. if (items && items->size() > 0) {
  6993. map<int32, Item*>::iterator itr;
  6994. for (itr = items->begin(); itr != items->end(); itr++) {
  6995. Item* item = itr->second;
  6996. if (item && item->generic_info.condition < 100)
  6997. repairable_items->push_back(item);
  6998. }
  6999. }
  7000. safe_delete(equipped_items);
  7001. safe_delete(items);
  7002. return repairable_items;
  7003. }
  7004. void Client::SendMailList() {
  7005. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7006. if (kiosk_id > 0) {
  7007. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7008. if (p) {
  7009. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7010. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7011. int32 i = 0;
  7012. p->setDataByName("kiosk_id", kiosk_id);
  7013. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7014. while (itr.Next()) {
  7015. Mail* mail = itr->second;
  7016. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7017. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7018. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7019. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7020. p->setArrayDataByName("unknown1", 0x0000, i);
  7021. p->setArrayDataByName("already_read", mail->already_read, i);
  7022. if(mail->expire_time)
  7023. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7024. else
  7025. p->setArrayDataByName("mail_deletion", 0, i);
  7026. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7027. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7028. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7029. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7030. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7031. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7032. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7033. //p->setArrayDataByName("unknown2", 0, i);
  7034. bool successItemAdd = false;
  7035. if(mail->stack || mail->char_item_id)
  7036. {
  7037. Item* item = master_item_list.GetItem(mail->char_item_id);
  7038. if(item)
  7039. {
  7040. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7041. if (version < 860)
  7042. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7043. else if (version < 1193)
  7044. p->setItemArrayDataByName("item", item, player, i);
  7045. else
  7046. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7047. successItemAdd = true;
  7048. }
  7049. }
  7050. if(!successItemAdd)
  7051. {
  7052. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7053. p->setArrayDataByName("end_tag3", 0xFF, i);
  7054. }
  7055. i++;
  7056. }
  7057. // GMs send mail for free!
  7058. if (GetAdminStatus() > 0)
  7059. {
  7060. p->setDataByName("postage_cost", 0);
  7061. p->setDataByName("attachment_cost", 0);
  7062. }
  7063. else
  7064. {
  7065. p->setDataByName("postage_cost", 10);
  7066. p->setDataByName("attachment_cost", 50);
  7067. }
  7068. p->setDataByName("unknown3", 0x01F4);
  7069. p->setDataByName("unknown4", 0x01000000);
  7070. EQ2Packet* pack = p->serialize();
  7071. DumpPacket(pack->pBuffer, pack->size);
  7072. QueuePacket(pack);
  7073. safe_delete(p);
  7074. }
  7075. }
  7076. else
  7077. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7078. }
  7079. void Client::DisplayMailMessage(int32 mail_id) {
  7080. Mail* mail = player->GetMail(mail_id);
  7081. if (mail) {
  7082. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7083. if (kiosk_id > 0) {
  7084. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7085. if (update) {
  7086. update->setDataByName("action", 0x03);
  7087. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7088. update->setDataByName("packetsubtype", 0xFF);
  7089. QueuePacket(update->serialize());
  7090. safe_delete(update);
  7091. }
  7092. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7093. if (packet) {
  7094. packet->setDataByName("kiosk_id", kiosk_id);
  7095. packet->setDataByName("mail_id", mail->mail_id);
  7096. packet->setDataByName("player_to_id", mail->player_to_id);
  7097. packet->setDataByName("player_from", mail->player_from.c_str());
  7098. packet->setDataByName("subject", mail->subject.c_str());
  7099. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7100. packet->setDataByName("unknown1", 1);
  7101. packet->setDataByName("unknown2", 0);
  7102. packet->setDataByName("lock_report_button", 1);
  7103. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7104. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7105. packet->setDataByName("coin_copper", mail->coin_copper);
  7106. packet->setDataByName("coin_silver", mail->coin_silver);
  7107. packet->setDataByName("coin_gold", mail->coin_gold);
  7108. packet->setDataByName("coin_plat", mail->coin_plat);
  7109. if(mail->stack || mail->char_item_id)
  7110. {
  7111. Item* item = master_item_list.GetItem(mail->char_item_id);
  7112. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7113. if (version < 860)
  7114. packet->setItemByName("item", item, player, 0, -1);
  7115. else if (version < 1193)
  7116. packet->setItemByName("item", item, player, 0, 0);
  7117. else
  7118. packet->setItemByName("item", item, player, 0, 2);
  7119. }
  7120. else
  7121. {
  7122. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7123. packet->setDataByName("end_tag3", 0xFF);
  7124. }
  7125. mail->already_read = true;
  7126. mail->save_needed = true;
  7127. EQ2Packet* pack = packet->serialize();
  7128. DumpPacket(pack);
  7129. QueuePacket(pack);
  7130. safe_delete(packet);
  7131. // trying to update this causes the window not to open
  7132. //SendMailList();
  7133. }
  7134. }
  7135. else
  7136. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7137. }
  7138. }
  7139. /* 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
  7140. packet back to the client before the mail actually sent. */
  7141. void Client::HandleSentMail(EQApplicationPacket* app) {
  7142. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7143. if (packet) {
  7144. packet->LoadPacketData(app->pBuffer, app->size);
  7145. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7146. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7147. vector<int32>* ids = 0;
  7148. MMailWindowMutex.lock();
  7149. if (reply_packet) {
  7150. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7151. if (player_to.length() == 0)
  7152. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7153. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7154. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7155. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7156. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7157. else {
  7158. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7159. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7160. ids = database.GetAllPlayerIDs();
  7161. else
  7162. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7163. }
  7164. else {
  7165. ids = new vector<int32>;
  7166. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7167. }
  7168. if (ids) {
  7169. for (int32 i = 0; i < ids->size(); i++) {
  7170. int32 player_to_id = ids->at(i);
  7171. if (player_to_id > 0) {
  7172. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7173. Mail* mail = new Mail;
  7174. mail->mail_id = 0;
  7175. mail->player_to_id = player_to_id;
  7176. mail->player_from = string(GetPlayer()->GetName());
  7177. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7178. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7179. mail->already_read = 0;
  7180. mail->mail_type = MAIL_TYPE_REGULAR;
  7181. mail->coin_copper = mail_window.coin_copper;
  7182. mail->coin_silver = mail_window.coin_silver;
  7183. mail->coin_gold = mail_window.coin_gold;
  7184. mail->coin_plat = mail_window.coin_plat;
  7185. mail->char_item_id = mail_window.char_item_id;
  7186. mail->stack = mail_window.stack;
  7187. // GM's send mail for free!
  7188. if (GetAdminStatus() > 0)
  7189. {
  7190. mail->postage_cost = 0;
  7191. mail->attachment_cost = 0;
  7192. }
  7193. else
  7194. {
  7195. mail->postage_cost = 10;
  7196. mail->attachment_cost = 50;
  7197. }
  7198. mail->time_sent = Timer::GetUnixTimeStamp();
  7199. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7200. //int16 packettype = packet->getType_int16_ByName("packettype");
  7201. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  7202. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  7203. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  7204. if (postage_cost > 0 || attachment_cost > 0)
  7205. PlaySoundA("coin_cha_ching");*/
  7206. mail->save_needed = false;
  7207. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7208. if (to_client) {
  7209. to_client->GetPlayer()->AddMail(mail);
  7210. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You've got mail! :)");
  7211. }
  7212. database.SavePlayerMail(mail);
  7213. ResetSendMail(false, false);
  7214. }
  7215. else
  7216. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  7217. }
  7218. }
  7219. }
  7220. string players_to = "";
  7221. if (ids) {
  7222. for (int32 i = 0; i < ids->size(); i++) {
  7223. if (ids->at(i) != 0)
  7224. players_to.append(database.GetCharacterName(ids->at(i)));
  7225. if (i < (ids->size() - 1))
  7226. players_to.append(", ");
  7227. }
  7228. }
  7229. reply_packet->setDataByName("player_to", players_to.c_str());
  7230. reply_packet->setDataByName("reply_type", reply_type);
  7231. QueuePacket(reply_packet->serialize());
  7232. safe_delete(reply_packet);
  7233. safe_delete(ids);
  7234. }
  7235. safe_delete(packet);
  7236. MMailWindowMutex.unlock();
  7237. }
  7238. }
  7239. void Client::DeleteMail(int32 mail_id, bool from_database) {
  7240. player->DeleteMail(mail_id, from_database);
  7241. }
  7242. bool Client::AddMailItem(Item* item)
  7243. {
  7244. bool ret = false;
  7245. if (GetMailTransaction()) {
  7246. MMailWindowMutex.lock();
  7247. if(mail_window.char_item_id == 0)
  7248. {
  7249. mail_window.item = item;
  7250. mail_window.char_item_id = item->details.item_id;
  7251. mail_window.stack = item->details.count;
  7252. ret = true;
  7253. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7254. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7255. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7256. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7257. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7258. if(item)
  7259. {
  7260. packet->setDataByName("stack", mail_window.stack);
  7261. item->stack_count = mail_window.stack;
  7262. if (version < 860)
  7263. packet->setItemByName("item", item, player, 0, -1);
  7264. else if (version < 1193)
  7265. packet->setItemByName("item", item, player, 0, 0);
  7266. else
  7267. packet->setItemByName("item", item, player, 0, 2);
  7268. }
  7269. else
  7270. {
  7271. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7272. packet->setDataByName("end_tag3", 0xFF);
  7273. }
  7274. //packet->setDataByName("packettype", GetItemPacketType(version));
  7275. //packet->setDataByName("packetsubtype", 0xFF);
  7276. //packet->setDataByName("unknown2", 0);
  7277. //packet->PrintPacket();
  7278. QueuePacket(packet->serialize());
  7279. }
  7280. MMailWindowMutex.unlock();
  7281. }
  7282. return ret;
  7283. }
  7284. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7285. bool ret = false;
  7286. if (GetMailTransaction()) {
  7287. MMailWindowMutex.lock();
  7288. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7289. if (packet) {
  7290. if (copper > 0) {
  7291. if (player->RemoveCoins(copper)) {
  7292. mail_window.coin_copper += copper;
  7293. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7294. ret = true;
  7295. }
  7296. }
  7297. else if (silver > 0) {
  7298. if (player->RemoveCoins(silver * 100)) {
  7299. mail_window.coin_silver += silver;
  7300. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7301. ret = true;
  7302. }
  7303. }
  7304. else if (gold > 0) {
  7305. if (player->RemoveCoins(gold * 10000)) {
  7306. mail_window.coin_gold += gold;
  7307. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7308. ret = true;
  7309. }
  7310. }
  7311. else if (plat > 0) {
  7312. if (player->RemoveCoins(plat * 1000000)) {
  7313. mail_window.coin_plat += plat;
  7314. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7315. ret = true;
  7316. }
  7317. }
  7318. if (ret) {
  7319. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7320. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7321. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7322. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7323. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7324. if(item)
  7325. {
  7326. packet->setDataByName("stack", mail_window.stack);
  7327. item->stack_count = mail_window.stack;
  7328. if (version < 860)
  7329. packet->setItemByName("item", item, player, 0, -1);
  7330. else if (version < 1193)
  7331. packet->setItemByName("item", item, player, 0, 0);
  7332. else
  7333. packet->setItemByName("item", item, player, 0, 2);
  7334. }
  7335. else
  7336. {
  7337. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7338. packet->setDataByName("end_tag3", 0xFF);
  7339. }
  7340. //packet->PrintPacket();
  7341. QueuePacket(packet->serialize());
  7342. }
  7343. else
  7344. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7345. safe_delete(packet);
  7346. }
  7347. MMailWindowMutex.unlock();
  7348. }
  7349. else
  7350. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7351. return ret;
  7352. }
  7353. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7354. bool ret = false;
  7355. if (GetMailTransaction()) {
  7356. MMailWindowMutex.lock();
  7357. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7358. if (packet) {
  7359. if (copper > 0) {
  7360. player->AddCoins(copper);
  7361. mail_window.coin_copper -= copper;
  7362. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7363. ret = true;
  7364. }
  7365. else if (silver > 0) {
  7366. player->AddCoins(silver * 100);
  7367. mail_window.coin_silver -= silver;
  7368. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7369. ret = true;
  7370. }
  7371. else if (gold > 0) {
  7372. player->AddCoins(gold * 10000);
  7373. mail_window.coin_gold -= gold;
  7374. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7375. ret = true;
  7376. }
  7377. else if (plat > 0) {
  7378. player->AddCoins(plat * 1000000);
  7379. mail_window.coin_plat -= plat;
  7380. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7381. ret = true;
  7382. }
  7383. if (ret) {
  7384. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7385. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7386. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7387. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7388. packet->setDataByName("stack", 0);
  7389. packet->setDataByName("packettype", 0x2BFE);
  7390. packet->setDataByName("packetsubtype", 0xFF);
  7391. packet->setDataByName("unknown2", 0);
  7392. QueuePacket(packet->serialize());
  7393. }
  7394. safe_delete(packet);
  7395. }
  7396. MMailWindowMutex.unlock();
  7397. }
  7398. else
  7399. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7400. return ret;
  7401. }
  7402. void Client::TakeMailAttachments(int32 mail_id) {
  7403. if (GetMailTransaction()) {
  7404. Mail* mail = player->GetMail(mail_id);
  7405. if (mail) {
  7406. int64 amount = 0;
  7407. if (mail->coin_copper > 0) {
  7408. amount += mail->coin_copper;
  7409. mail->coin_copper = 0;
  7410. }
  7411. if (mail->coin_silver > 0) {
  7412. amount += mail->coin_silver * 100;
  7413. mail->coin_silver = 0;
  7414. }
  7415. if (mail->coin_gold > 0) {
  7416. amount += mail->coin_gold * 10000;
  7417. mail->coin_gold = 0;
  7418. }
  7419. if (mail->coin_plat > 0) {
  7420. amount += mail->coin_plat * 1000000;
  7421. mail->coin_plat = 0;
  7422. }
  7423. if (mail->char_item_id > 0) {
  7424. AddItem(mail->char_item_id, mail->stack);
  7425. mail->char_item_id = 0;
  7426. mail->stack = 0;
  7427. }
  7428. /* 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
  7429. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7430. find it in any packet logs.*/
  7431. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7432. if (packet) {
  7433. packet->setDataByName("unknown", 0x03);
  7434. packet->setDataByName("coin_copper", mail->coin_copper);
  7435. packet->setDataByName("coin_silver", mail->coin_silver);
  7436. packet->setDataByName("coin_gold", mail->coin_gold);
  7437. packet->setDataByName("coin_plat", mail->coin_plat);
  7438. packet->setDataByName("stack", 0);
  7439. packet->setDataByName("packettype", 0x2BFE);
  7440. packet->setDataByName("packetsubtype", 0xFF);
  7441. packet->setDataByName("unknown2", 0);
  7442. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7443. DumpPacket(packet->serialize());
  7444. QueuePacket(packet->serialize());
  7445. safe_delete(packet);
  7446. }*/
  7447. database.SavePlayerMail(mail);
  7448. if (amount > 0)
  7449. player->AddCoins(amount);
  7450. SendMailList();
  7451. }
  7452. }
  7453. else
  7454. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7455. }
  7456. void Client::ResetSendMail(bool cancel, bool needslock) {
  7457. if(cancel && mail_transaction)
  7458. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7459. if(needslock)
  7460. MMailWindowMutex.lock();
  7461. if(cancel)
  7462. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7463. if(!cancel)
  7464. mail_transaction = 0;
  7465. mail_window.coin_copper = 0;
  7466. mail_window.coin_silver = 0;
  7467. mail_window.coin_gold = 0;
  7468. mail_window.coin_plat = 0;
  7469. mail_window.char_item_id = 0;
  7470. mail_window.stack = 0;
  7471. if(mail_window.item){
  7472. if(cancel)
  7473. AddItem(mail_window.item);
  7474. else
  7475. safe_delete(mail_window.item);
  7476. }
  7477. mail_window.item = nullptr;
  7478. if(needslock)
  7479. MMailWindowMutex.unlock();
  7480. }
  7481. bool Client::GateAllowed() {
  7482. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7483. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to gate from this spot, allow for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7484. if (zone)
  7485. return true;
  7486. return false;
  7487. }
  7488. bool Client::BindAllowed() {
  7489. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to bind in this spot, allow anywhere for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7490. return true;
  7491. }
  7492. bool Client::Bind() {
  7493. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7494. player->GetPlayerInfo()->SetBindX(player->GetX());
  7495. player->GetPlayerInfo()->SetBindY(player->GetY());
  7496. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7497. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7498. return true;
  7499. }
  7500. bool Client::Gate(bool is_spell) {
  7501. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  7502. return false;
  7503. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7504. if (zone) {
  7505. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7506. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7507. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7508. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7509. Zone(zone, false, is_spell);
  7510. return true;
  7511. }
  7512. return false;
  7513. }
  7514. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7515. if (!destinations || !spawn) {
  7516. return;
  7517. }
  7518. bool has_map = false;
  7519. if (transport_id > 0)
  7520. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7521. transport_spawn = spawn;
  7522. vector<TransportDestination*> transport_list;
  7523. vector<TransportDestination*>::iterator itr;
  7524. TransportDestination* destination = 0;
  7525. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7526. destination = *itr;
  7527. 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)))
  7528. transport_list.push_back(destination);
  7529. }
  7530. if (transport_list.size() == 0 && destination) {
  7531. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7532. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7533. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7534. else
  7535. {
  7536. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7537. if (app)
  7538. QueuePacket(app);
  7539. }
  7540. }
  7541. else {
  7542. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7543. // determine if this is an instanced zone that already exists
  7544. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7545. if (instance_zone || new_zone) {
  7546. GetPlayer()->SetX(destination->destination_x);
  7547. GetPlayer()->SetY(destination->destination_y);
  7548. GetPlayer()->SetZ(destination->destination_z);
  7549. GetPlayer()->SetHeading(destination->destination_heading);
  7550. if (instance_zone)
  7551. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7552. else
  7553. Zone(new_zone, false, is_spell);
  7554. }
  7555. }
  7556. if (destination->message.length() > 0)
  7557. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7558. }
  7559. else if (transport_list.size() > 0) {
  7560. if (!spawn->IsSoundsDisabled())
  7561. PlaySound("mariner_bell");
  7562. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7563. if (packet) {
  7564. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7565. // Put all the destinations the player can go in a new vector
  7566. vector<TransportDestination*> destinations;
  7567. for (int32 i = 0; i < transport_list.size(); i++) {
  7568. destination = transport_list.at(i);
  7569. // Check min level
  7570. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7571. continue;
  7572. // Check max level
  7573. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7574. continue;
  7575. // Check quest complete
  7576. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7577. continue;
  7578. // Check req quest and step
  7579. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7580. continue;
  7581. // 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
  7582. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7583. packet->setDataByName("current_zone", destination->display_name.c_str());
  7584. packet->setDataByName("current_map_x", destination->map_x);
  7585. packet->setDataByName("current_map_y", destination->map_y);
  7586. }
  7587. else {
  7588. destinations.push_back(destination);
  7589. }
  7590. }
  7591. // Use the new vector to create the packet
  7592. destination = 0;
  7593. packet->setArrayLengthByName("num_destinations", destinations.size());
  7594. for (int32 i = 0; i < destinations.size(); i++) {
  7595. destination = destinations.at(i);
  7596. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7597. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7598. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7599. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7600. packet->setArrayDataByName("cost", destination->cost, i);
  7601. if (has_map) {
  7602. packet->setArrayDataByName("map_x", destination->map_x, i);
  7603. packet->setArrayDataByName("map_y", destination->map_y, i);
  7604. }
  7605. }
  7606. if (has_map)
  7607. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7608. EQ2Packet* app = packet->serialize();
  7609. //DumpPacket(app);
  7610. if (destinations.size() > 0)
  7611. QueuePacket(app);
  7612. safe_delete(packet);
  7613. }
  7614. }
  7615. }
  7616. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7617. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7618. if (packet) {
  7619. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7620. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7621. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7622. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7623. int32 cost = packet->getType_int32_ByName("cost");
  7624. vector<TransportDestination*> destinations;
  7625. TransportDestination* destination = 0;
  7626. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7627. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7628. vector<TransportDestination*>::iterator itr;
  7629. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7630. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7631. destination = *itr;
  7632. break;
  7633. }
  7634. }
  7635. SetTemporaryTransportID(0);
  7636. if (!destination)
  7637. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7638. else {
  7639. if (cost == 0 || player->RemoveCoins(cost)) {
  7640. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7641. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7642. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7643. else
  7644. {
  7645. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7646. if (outapp)
  7647. QueuePacket(outapp);
  7648. }
  7649. }
  7650. else {
  7651. GetPlayer()->SetX(destination->destination_x);
  7652. GetPlayer()->SetY(destination->destination_y);
  7653. GetPlayer()->SetZ(destination->destination_z);
  7654. GetPlayer()->SetHeading(destination->destination_heading);
  7655. // Test if where we're going is an Instanced zone
  7656. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7657. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7658. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7659. Zone(new_zone, false);
  7660. }
  7661. }
  7662. if (destination->message.length() > 0)
  7663. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7664. }
  7665. else
  7666. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7667. }
  7668. }
  7669. safe_delete(packet);
  7670. }
  7671. }
  7672. void Client::SendNewSpells(int8 class_id) {
  7673. if (class_id > 0) {
  7674. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7675. vector<Spell*>::iterator itr;
  7676. Spell* spell = 0;
  7677. bool send_updates = false;
  7678. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7679. spell = *itr;
  7680. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7681. send_updates = true;
  7682. SendSpellUpdate(spell);
  7683. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7684. player->UnlockSpell(spell);
  7685. }
  7686. }
  7687. if (send_updates) {
  7688. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7689. if (outapp)
  7690. QueuePacket(outapp);
  7691. }
  7692. safe_delete(spells);
  7693. }
  7694. }
  7695. void Client::SetItemSearch(vector<Item*>* items) {
  7696. if (items) {
  7697. safe_delete(search_items);
  7698. search_items = items;
  7699. }
  7700. }
  7701. vector<Item*>* Client::GetSearchItems() {
  7702. return search_items;
  7703. }
  7704. void Client::SearchStore(int32 page) {
  7705. if (search_items) {
  7706. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7707. if (packet) {
  7708. int32 x = page * 8;
  7709. if (search_items->size() > 8) {
  7710. if ((search_items->size() - x) > 8)
  7711. packet->setArrayLengthByName("num_items", 8);
  7712. else
  7713. packet->setArrayLengthByName("num_items", search_items->size() - x);
  7714. }
  7715. else
  7716. packet->setArrayLengthByName("num_items", search_items->size());
  7717. if (search_items->size() > 0) {
  7718. packet->setArrayLengthByName("num_sellers", 1);
  7719. packet->setArrayDataByName("seller_seller_id", 1);
  7720. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  7721. packet->setDataByName("per_page", 8);
  7722. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  7723. packet->setDataByName("page", page);
  7724. Item* item = 0;
  7725. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  7726. for (int32 i = 0; i < limit; i++, x++) {
  7727. if (x >= search_items->size())
  7728. break;
  7729. item = search_items->at(x);
  7730. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7731. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7732. packet->setArrayDataByName("icon", item->details.icon, i);
  7733. //packet->setArrayDataByName("unknown2b", i, i);
  7734. packet->setArrayDataByName("item_seller_id", 1, i);
  7735. if (item->stack_count == 0)
  7736. packet->setArrayDataByName("quantity", 1, i);
  7737. else
  7738. packet->setArrayDataByName("quantity", item->stack_count, i);
  7739. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7740. std::string tmpStr("");
  7741. tmpStr.append(item->name.c_str());
  7742. tmpStr.append(" (");
  7743. tmpStr.append(std::to_string(item->details.item_id));
  7744. tmpStr.append(")");
  7745. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  7746. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  7747. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  7748. }
  7749. }
  7750. /*EQ2Packet* outapp = packet->serialize();
  7751. DumpPacket(outapp);
  7752. QueuePacket(outapp);*/
  7753. QueuePacket(packet->serialize());
  7754. safe_delete(packet);
  7755. }
  7756. }
  7757. }
  7758. void Client::SetReadyForUpdates() {
  7759. GetPlayer()->SetFullyLoggedIn(true);
  7760. if (!ready_for_updates)
  7761. database.loadCharacterProperties(this);
  7762. ready_for_updates = true;
  7763. }
  7764. void Client::SetReadyForSpawns(bool val) {
  7765. ready_for_spawns = val;
  7766. if (GetPlayer()->GetActivityStatus() > 0) {
  7767. GetPlayer()->SetActivityStatus(0);
  7768. if (GetPlayer()->GetGroupMemberInfo()) {
  7769. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  7770. }
  7771. }
  7772. zone_list.CheckFriendZoned(this);
  7773. }
  7774. void Client::SendChatRelationship(int8 type, const char* name) {
  7775. if (!name) {
  7776. return;
  7777. }
  7778. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7779. if (packet) {
  7780. packet->setDataByName("account_id", GetAccountID());
  7781. packet->setDataByName("type", type);
  7782. packet->setArrayLengthByName("num_names", 1);
  7783. packet->setArrayDataByName("name", name);
  7784. if (type == 0) {
  7785. Client* client = zone_list.GetClientByCharName(name);
  7786. if (client) {
  7787. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  7788. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  7789. }
  7790. }
  7791. QueuePacket(packet->serialize());
  7792. safe_delete(packet);
  7793. }
  7794. }
  7795. void Client::SendFriendList() {
  7796. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7797. if (packet) {
  7798. packet->setDataByName("account_id", GetAccountID());
  7799. map<string, int8>::iterator itr;
  7800. map<string, int8>* friends = player->GetFriends();
  7801. if (friends && friends->size() > 0) {
  7802. Client* client = 0;
  7803. vector<string> names;
  7804. for (itr = friends->begin(); itr != friends->end(); itr++) {
  7805. if (itr->second == 2)
  7806. continue;
  7807. names.push_back(itr->first);
  7808. }
  7809. packet->setArrayLengthByName("num_names", names.size());
  7810. for (int32 i = 0; i < names.size(); i++) {
  7811. client = zone_list.GetClientByCharName(names[i]);
  7812. packet->setArrayDataByName("name", names[i].c_str(), i);
  7813. if (client) {
  7814. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  7815. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  7816. }
  7817. }
  7818. }
  7819. QueuePacket(packet->serialize());
  7820. safe_delete(packet);
  7821. }
  7822. }
  7823. void Client::SendIgnoreList() {
  7824. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7825. if (packet) {
  7826. packet->setDataByName("account_id", GetAccountID());
  7827. packet->setDataByName("type", 2);
  7828. map<string, int8>::iterator itr;
  7829. map<string, int8>* ignored = player->GetIgnoredPlayers();
  7830. if (ignored && ignored->size() > 0) {
  7831. vector<string> names;
  7832. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  7833. if (itr->second == 2)
  7834. continue;
  7835. names.push_back(itr->first);
  7836. }
  7837. packet->setArrayLengthByName("num_names", names.size());
  7838. for (int32 i = 0; i < names.size(); i++)
  7839. packet->setArrayDataByName("name", names[i].c_str(), i);
  7840. }
  7841. QueuePacket(packet->serialize());
  7842. safe_delete(packet);
  7843. }
  7844. }
  7845. void Client::AddWaypoint(string name, int8 type) {
  7846. waypoint_id++;
  7847. WaypointInfo info;
  7848. info.id = waypoint_id;
  7849. info.type = type;
  7850. waypoints[name] = info;
  7851. }
  7852. void Client::SendWaypoints() {
  7853. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7854. if (packet) {
  7855. packet->setArrayLengthByName("num_updates", waypoints.size());
  7856. map<string, WaypointInfo>::iterator itr;
  7857. int16 i = 0;
  7858. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7859. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  7860. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  7861. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  7862. i++;
  7863. }
  7864. packet->setDataByName("unknown", 0xFFFFFFFF);
  7865. QueuePacket(packet->serialize());
  7866. safe_delete(packet);
  7867. }
  7868. }
  7869. void Client::SelectWaypoint(int32 id) {
  7870. string found_name = "";
  7871. map<string, WaypointInfo>::iterator itr;
  7872. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7873. if (itr->second.id == id) {
  7874. found_name = itr->first;
  7875. break;
  7876. }
  7877. }
  7878. if (found_name.length() > 0) {
  7879. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  7880. ShowPathToTarget(spawn);
  7881. }
  7882. }
  7883. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  7884. if (waypoint_name) {
  7885. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7886. if (packet) {
  7887. packet->setArrayLengthByName("num_updates", 1);
  7888. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  7889. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  7890. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  7891. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  7892. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  7893. packet->setDataByName("unknown", 0xFFFFFFFF);
  7894. QueuePacket(packet->serialize());
  7895. safe_delete(packet);
  7896. }
  7897. }
  7898. }
  7899. void Client::ClearWaypoint() {
  7900. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7901. if (packet) {
  7902. QueuePacket(packet->serialize());
  7903. safe_delete(packet);
  7904. }
  7905. }
  7906. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  7907. if (current_zone->pathing) {
  7908. if (GetPlayer()->GetMap()) {
  7909. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  7910. return false;
  7911. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  7912. return false;
  7913. auto loc = glm::vec3(x, z, y);
  7914. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  7915. if (new_z != BEST_Z_INVALID) //this is actually y
  7916. y = new_z;
  7917. }
  7918. bool partial = false;
  7919. bool stuck = false;
  7920. PathfinderOptions opts;
  7921. opts.smooth_path = true;
  7922. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  7923. opts.offset = y_offset + 1.0f;
  7924. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  7925. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7926. if (packet) {
  7927. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  7928. packet->setArrayLengthByName("num_points", path.size());
  7929. int i = 0;
  7930. for (auto& node : path)
  7931. {
  7932. packet->setArrayDataByName("x", node.pos.x, i);
  7933. packet->setArrayDataByName("y", node.pos.z, i);
  7934. packet->setArrayDataByName("z", node.pos.y, i);
  7935. packet->setDataByName("waypoint_x", x);
  7936. packet->setDataByName("waypoint_y", y);
  7937. packet->setDataByName("waypoint_z", z);
  7938. i++;
  7939. }
  7940. if (i > 0)
  7941. QueuePacket(packet->serialize());
  7942. safe_delete(packet);
  7943. return (i > 0);
  7944. }
  7945. }
  7946. return false;
  7947. }
  7948. bool Client::ShowPathToTarget(Spawn* spawn) {
  7949. if (spawn) {
  7950. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  7951. }
  7952. return false;
  7953. }
  7954. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  7955. if (waypoint_name) {
  7956. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7957. if (packet) {
  7958. packet->setArrayLengthByName("num_points", 1);
  7959. packet->setArrayDataByName("x", x, 0);
  7960. packet->setArrayDataByName("y", y, 0);
  7961. packet->setArrayDataByName("z", z, 0);
  7962. packet->setDataByName("waypoint_x", x);
  7963. packet->setDataByName("waypoint_y", y);
  7964. packet->setDataByName("waypoint_z", z);
  7965. packet->setDataByName("waypoint_name", waypoint_name);
  7966. packet->setDataByName("unknown", 0);
  7967. QueuePacket(packet->serialize());
  7968. safe_delete(packet);
  7969. }
  7970. }
  7971. }
  7972. void Client::InspectPlayer(Player* player_to_inspect) {
  7973. if (player_to_inspect) {
  7974. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  7975. if (packet) {
  7976. packet->setDataByName("unknown", 0);
  7977. packet->setSmallStringByName("name", player_to_inspect->GetName());
  7978. packet->setDataByName("race", player_to_inspect->GetRace());
  7979. packet->setDataByName("gender", player_to_inspect->GetGender());
  7980. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  7981. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7982. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  7983. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  7984. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  7985. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  7986. packet->setDataByName("health", player_to_inspect->GetHP());
  7987. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  7988. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  7989. packet->setDataByName("power", player_to_inspect->GetPower());
  7990. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  7991. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  7992. packet->setDataByName("mitigation", 0);
  7993. packet->setDataByName("unknown1", 0);
  7994. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_cur_avoidance());
  7995. packet->setDataByName("unknown2", 0);
  7996. packet->setDataByName("mitigation_percentage", 0);
  7997. packet->setDataByName("strength", player_to_inspect->GetStr());
  7998. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  7999. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8000. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8001. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8002. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8003. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8004. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8005. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8006. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8007. packet->setDataByName("unknown4", 0);
  8008. packet->setDataByName("unknown5", 0);
  8009. packet->setDataByName("unknown6", 0);
  8010. packet->setDataByName("unknown7", 0);
  8011. packet->setDataByName("unknown8", 0);
  8012. packet->setDataByName("unknown9", 0);
  8013. packet->setDataByName("unknown10", 0);
  8014. packet->setDataByName("unknown11", 0);
  8015. packet->setDataByName("unknown12", 0);
  8016. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8017. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8018. packet->setDataByName("heat_resist_percentage", 0);
  8019. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8020. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8021. packet->setDataByName("cold_resist_percentage", 0);
  8022. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8023. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8024. packet->setDataByName("magic_resist_percentage", 0);
  8025. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8026. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8027. packet->setDataByName("mental_resist_percentage", 0);
  8028. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8029. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8030. packet->setDataByName("divine_resist_percentage", 0);
  8031. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8032. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8033. packet->setDataByName("disease_resist_percentage", 0);
  8034. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8035. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8036. packet->setDataByName("poison_resist_percentage", 0);
  8037. packet->setArrayLengthByName("num_chars", 0x01FF);
  8038. string biography = player_to_inspect->GetBiography();
  8039. for (size_t i = 0; i < biography.length(); i++)
  8040. packet->setArrayDataByName("biography_char", biography[i], i);
  8041. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  8042. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  8043. if (pw)
  8044. packet->setItemByName("primary", pw, player_to_inspect, 0);
  8045. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  8046. if (sw)
  8047. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  8048. //DumpPacket(packet->serialize());
  8049. QueuePacket(packet->serialize());
  8050. safe_delete(packet);
  8051. }
  8052. }
  8053. }
  8054. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8055. pending_guild_invite.guild = guild;
  8056. pending_guild_invite.invited_by = invited_by;
  8057. }
  8058. void Client::ShowClaimWindow() {
  8059. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8060. if (packet) {
  8061. map<int32, Item*>* items = &master_item_list.items;
  8062. map<int32, Item*>::iterator itr;
  8063. int32 i = 0;
  8064. if (items->size() > 10)
  8065. packet->setArrayLengthByName("num_claim_items", 10);
  8066. else
  8067. packet->setArrayLengthByName("num_claim_items", items->size());
  8068. for (itr = items->begin(); itr != items->end(); itr++) {
  8069. if (i == 10)
  8070. break;
  8071. Item* item = itr->second;
  8072. packet->setArrayDataByName("id", i, i);
  8073. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8074. packet->setArrayDataByName("num_remaining", 5, i);
  8075. packet->setArrayDataByName("one_per_character", 1, i);
  8076. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8077. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8078. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8079. packet->setArrayDataByName("category", "Scott's Shit", i);
  8080. packet->setArrayDataByName("icon", item->details.icon, i);
  8081. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8082. i++;
  8083. }
  8084. packet->setDataByName("unknown3", 1);
  8085. QueuePacket(packet->serialize());
  8086. safe_delete(packet);
  8087. }
  8088. }
  8089. void Client::ShowGuildSearchWindow() {
  8090. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8091. if (packet) {
  8092. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8093. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8094. packet->setArrayLengthByName("num_guilds", guilds->size());
  8095. int32 i = 0;
  8096. while (itr.Next()) {
  8097. Guild* guild = itr.second;
  8098. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8099. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8100. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8101. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8102. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8103. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8104. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8105. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8106. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8107. packet->setArrayDataByName("unknown7", 0x02, i);
  8108. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8109. i++;
  8110. }
  8111. QueuePacket(packet->serialize());
  8112. safe_delete(packet);
  8113. }
  8114. }
  8115. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8116. PacketStruct* packet;
  8117. vector<int8>* slot_data;
  8118. vector<int8>::iterator itr;
  8119. int32 slots = 0;
  8120. assert(item);
  8121. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8122. return;
  8123. }
  8124. slot_data = &item->slot_data;
  8125. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8126. if (version >= 1188)
  8127. slots = *itr;
  8128. else
  8129. slots += (int8)pow(2.0, *itr);
  8130. }
  8131. packet->setDataByName("slot", slots);
  8132. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8133. if (slots == 2) {
  8134. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8135. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8136. }
  8137. else {
  8138. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8139. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8140. }
  8141. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8142. if (slots == 4) {
  8143. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8144. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8145. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8146. }
  8147. else if (slots == 7) {
  8148. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8149. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8150. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8151. }
  8152. else {
  8153. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8154. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8155. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8156. }
  8157. packet->setDataByName("icon", item->details.icon);
  8158. packet->setDataByName("item_id", item->details.item_id);
  8159. packet->setDataByName("item_crc", crc);
  8160. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8161. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8162. packet->setDataByName("unknown5", 0xFF, 9);
  8163. packet->setDataByName("unknown5", 0xFF, 10);
  8164. QueuePacket(packet->serialize());
  8165. safe_delete(packet);
  8166. }
  8167. void Client::SendCollectionList() {
  8168. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8169. map<int32, Collection*>::iterator itr;
  8170. vector<struct CollectionItem*>* collection_items;
  8171. Collection* collection;
  8172. struct CollectionItem* collection_item;
  8173. PacketStruct* packet = 0;
  8174. int16 i = 0, j;
  8175. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8176. return;
  8177. packet->setArrayLengthByName("num_collections", collections->size());
  8178. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8179. collection = itr->second;
  8180. collection_items = collection->GetCollectionItems();
  8181. packet->setArrayDataByName("unknown", 1, i);
  8182. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8183. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8184. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8185. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8186. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8187. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8188. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8189. for (j = 0; j < collection_items->size(); j++) {
  8190. collection_item = collection_items->at(j);
  8191. Item* item = master_item_list.GetItem(collection_item->item);
  8192. if (item) {
  8193. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8194. if (version < 955)
  8195. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8196. else
  8197. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8198. }
  8199. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8200. }
  8201. i++;
  8202. }
  8203. packet->setDataByName("new_collection_flag", 1);
  8204. QueuePacket(packet->serialize());
  8205. safe_delete(packet);
  8206. }
  8207. bool Client::SendCollectionsForItem(Item* item) {
  8208. map<int32, Collection*> collections_to_send;
  8209. map<int32, Collection*>* collections;
  8210. map<int32, Collection*>::iterator itr;
  8211. vector<struct CollectionItem*>* collection_items;
  8212. Collection* collection;
  8213. struct CollectionItem* collection_item;
  8214. PacketStruct* packet;
  8215. int16 i;
  8216. assert(item);
  8217. /* get any collections required by this item that the player already has */
  8218. collections = player->GetCollectionList()->GetCollections();
  8219. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8220. collection = itr->second;
  8221. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8222. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8223. collections_to_send[collection->GetID()] = collection;
  8224. }
  8225. }
  8226. /* get any collections required by this item that the player does not have and send it to the client */
  8227. collections = master_collection_list.GetCollections();
  8228. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8229. collection = itr->second;
  8230. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8231. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8232. return false;
  8233. }
  8234. packet->setArrayLengthByName("num_collections", 1);
  8235. packet->setArrayDataByName("unknown", 1, 0);
  8236. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8237. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8238. packet->setArrayDataByName("completed", 0, 0);
  8239. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8240. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8241. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8242. packet->setArrayDataByName("unknown3", 0x28, 0);
  8243. collection_items = collection->GetCollectionItems();
  8244. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8245. for (i = 0; i < collection_items->size(); i++) {
  8246. collection_item = collection_items->at(i);
  8247. Item* item2 = master_item_list.GetItem(collection_item->item);
  8248. if (item2) {
  8249. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8250. if (version < 955)
  8251. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8252. else
  8253. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8254. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8255. }
  8256. }
  8257. packet->setDataByName("new_collection_flag", 0);
  8258. QueuePacket(packet->serialize());
  8259. safe_delete(packet);
  8260. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8261. collections_to_send[collection->GetID()] = collection;
  8262. }
  8263. }
  8264. /* send the client a list of collections that should be filtered for this item */
  8265. if (collections_to_send.size() > 0) {
  8266. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8267. return false;
  8268. }
  8269. i = 0;
  8270. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8271. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8272. collection = itr->second;
  8273. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8274. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8275. i++;
  8276. }
  8277. packet->setDataByName("item_icon", item->details.icon);
  8278. packet->setDataByName("item_name", item->name.c_str());
  8279. packet->setDataByName("item_id", item->details.item_id);
  8280. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8281. QueuePacket(packet->serialize());
  8282. safe_delete(packet);
  8283. }
  8284. return collections_to_send.size() > 0;
  8285. }
  8286. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8287. Collection* collection;
  8288. struct CollectionItem* collection_item;
  8289. PacketStruct* packet;
  8290. char tmp[200] = { 0 };
  8291. assert(item);
  8292. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8293. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8294. /* get the item struct that represents the item for this collection */
  8295. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8296. SendCollectionList();
  8297. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8298. return;
  8299. }
  8300. /* sanity check */
  8301. if (collection_item->found) {
  8302. SendCollectionList();
  8303. 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());
  8304. return;
  8305. }
  8306. }
  8307. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8308. collection = new Collection(collection);
  8309. /* get the item struct that represents the item for this collection */
  8310. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8311. SendCollectionList();
  8312. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8313. safe_delete(collection);
  8314. return;
  8315. }
  8316. /* add the new collection to the player's collection list */
  8317. if (!player->GetCollectionList()->AddCollection(collection)) {
  8318. SendCollectionList();
  8319. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8320. safe_delete(collection);
  8321. return;
  8322. }
  8323. }
  8324. else {
  8325. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8326. return;
  8327. }
  8328. collection_item->found = 1;
  8329. collection->SetSaveNeeded(true);
  8330. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8331. SendCollectionList();
  8332. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8333. return;
  8334. }
  8335. packet->setDataByName("collection_id", collection_id);
  8336. packet->setDataByName("collection_item_num", collection_item->index);
  8337. packet->setDataByName("add", 1);
  8338. QueuePacket(packet->serialize());
  8339. Item* item2 = master_item_list.GetItem(collection_item->item);
  8340. if (item2) {
  8341. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8342. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8343. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8344. }
  8345. safe_delete(packet);
  8346. RemoveItem(item, 1);
  8347. SendCollectionList();
  8348. }
  8349. void Client::DisplayCollectionComplete(Collection* collection) {
  8350. vector<struct CollectionRewardItem*>* reward_items;
  8351. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8352. struct CollectionRewardItem* reward_item;
  8353. PacketStruct* packet;
  8354. int32 i;
  8355. assert(collection);
  8356. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8357. return;
  8358. }
  8359. reward_items = collection->GetRewardItems();
  8360. selectable_reward_items = collection->GetSelectableRewardItems();
  8361. packet->setDataByName("title", "Quest Reward!");
  8362. packet->setDataByName("name", collection->GetName());
  8363. packet->setDataByName("description", collection->GetCategory());
  8364. packet->setDataByName("level", collection->GetLevel());
  8365. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8366. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8367. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8368. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8369. for (i = 0; i < reward_items->size(); i++) {
  8370. reward_item = reward_items->at(i);
  8371. if(!reward_item->item)
  8372. {
  8373. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8374. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8375. continue;
  8376. }
  8377. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8378. if (version < 860)
  8379. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8380. else if (version < 1193)
  8381. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8382. else
  8383. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8384. }
  8385. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8386. for (i = 0; i < selectable_reward_items->size(); i++) {
  8387. reward_item = selectable_reward_items->at(i);
  8388. if(!reward_item->item)
  8389. {
  8390. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8391. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8392. continue;
  8393. }
  8394. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8395. if (version < 860)
  8396. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8397. else if (version < 1193)
  8398. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8399. else
  8400. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8401. }
  8402. QueuePacket(packet->serialize());
  8403. safe_delete(packet);
  8404. }
  8405. void Client::HandInCollections() {
  8406. map<int32, Collection*>* collections;
  8407. map<int32, Collection*>::iterator itr;
  8408. Collection* collection;
  8409. /* only show 1 collection reward dialog at a time */
  8410. if (player->GetPendingCollectionReward()) {
  8411. return;
  8412. }
  8413. collections = player->GetCollectionList()->GetCollections();
  8414. /* 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
  8415. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8416. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8417. collection = itr->second;
  8418. if (collection->GetIsReadyToTurnIn()) {
  8419. player->SetPendingCollectionReward(collection);
  8420. DisplayCollectionComplete(collection);
  8421. return;
  8422. }
  8423. }
  8424. }
  8425. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8426. vector<struct CollectionRewardItem*>* reward_items;
  8427. vector<struct CollectionRewardItem*>::iterator itr;
  8428. struct CollectionRewardItem* reward_item;
  8429. int16 num_slots_needed;
  8430. int16 num_slots;
  8431. assert(collection);
  8432. reward_items = collection->GetRewardItems();
  8433. num_slots_needed = (int16)reward_items->size();
  8434. if (selectable_item_id > 0)
  8435. num_slots_needed++;
  8436. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8437. if (num_slots < num_slots_needed) {
  8438. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8439. HandInCollections();
  8440. return;
  8441. }
  8442. /* add manditory items */
  8443. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8444. reward_item = *itr;
  8445. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8446. }
  8447. /* find and add the selectable item if there's one */
  8448. if (selectable_item_id > 0) {
  8449. reward_items = collection->GetSelectableRewardItems();
  8450. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8451. reward_item = *itr;
  8452. if (reward_item->item->details.item_id == selectable_item_id) {
  8453. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8454. break;
  8455. }
  8456. }
  8457. }
  8458. if (collection->GetRewardXP() > 0) {
  8459. player->AddXP((int32)collection->GetRewardXP());
  8460. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  8461. }
  8462. if (collection->GetRewardCoin() > 0) {
  8463. player->AddCoins(collection->GetRewardCoin());
  8464. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8465. }
  8466. collection->SetCompleted(true);
  8467. //update achievements for completeing collection here
  8468. collection->SetSaveNeeded(true);
  8469. SendCollectionList();
  8470. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8471. player->SetPendingCollectionReward(0);
  8472. HandInCollections();
  8473. }
  8474. void Client::SendRecipeList() {
  8475. PacketStruct* packet = 0;
  8476. if (GetRecipeListSent()) {
  8477. return;
  8478. }
  8479. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8480. return;
  8481. }
  8482. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8483. map<int32, Recipe*>::iterator itr;
  8484. Recipe* recipe;
  8485. int16 i = 0;
  8486. packet->setArrayLengthByName("num_recipes", recipes->size());
  8487. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8488. recipe = itr->second;
  8489. packet->setArrayDataByName("id", recipe->GetID(), i);
  8490. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8491. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8492. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8493. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8494. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8495. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8496. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8497. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8498. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8499. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8500. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8501. i++;
  8502. }
  8503. //packet->PrintPacket();
  8504. //DumpPacket(packet->serialize());
  8505. QueuePacket(packet->serialize());
  8506. safe_delete(packet);
  8507. SetRecipeListSent(true);
  8508. }
  8509. void Client::ShowRecipeBook() {
  8510. PacketStruct* packet = 0;
  8511. Spawn* target = 0;
  8512. if (!(target = player->GetTarget())) {
  8513. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8514. return;
  8515. }
  8516. if (!target->IsObject()) {
  8517. return;
  8518. }
  8519. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8520. return;
  8521. }
  8522. packet->setDataByName("device", target->GetName());
  8523. packet->setDataByName("unknown1", 1);
  8524. if (((Object*)target)->GetDeviceID() > 0) {
  8525. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8526. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8527. packet->setDataByName("unknown2", 8);
  8528. packet->setDataByName("unknown3", deviceID);
  8529. }
  8530. //packet->PrintPacket();
  8531. QueuePacket(packet->serialize());
  8532. safe_delete(packet);
  8533. }
  8534. void Client::SendTitleUpdate() {
  8535. // must call release read lock before leaving function on GetPlayerTitles
  8536. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8537. vector<Title*>::iterator itr;
  8538. Title* title;
  8539. sint32 i = 0;
  8540. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8541. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8542. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8543. if (packet) {
  8544. packet->setArrayLengthByName("num_titles", titles->size());
  8545. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8546. title = *itr;
  8547. packet->setArrayDataByName("title", title->GetName(), i);
  8548. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8549. i++;
  8550. }
  8551. packet->setDataByName("current_prefix", prefix_index);
  8552. packet->setDataByName("current_suffix", suffix_index);
  8553. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8554. #if EQDEBUG >= 9
  8555. packet->PrintPacket();
  8556. #endif
  8557. QueuePacket(packet->serialize());
  8558. safe_delete(packet);
  8559. SendUpdateTitles(prefix_index, suffix_index);
  8560. }
  8561. player->GetPlayerTitles()->ReleaseReadLock();
  8562. }
  8563. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8564. Title* suffix_title = 0;
  8565. Title* prefix_title = 0;
  8566. if (suffix != -1) {
  8567. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8568. if(suffix_title)
  8569. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8570. }
  8571. else
  8572. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8573. if (prefix != -1) {
  8574. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8575. if(prefix_title)
  8576. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8577. }
  8578. else
  8579. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8580. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8581. }
  8582. void Client::SendLanguagesUpdate(int32 id) {
  8583. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8584. list<Language*>::iterator itr;
  8585. Language* language;
  8586. int32 i = 0;
  8587. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8588. if (packet) {
  8589. packet->setArrayLengthByName("num_languages", languages->size());
  8590. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8591. language = *itr;
  8592. packet->setArrayDataByName("language_id", language->GetID(), i);
  8593. i++;
  8594. }
  8595. packet->setDataByName("current_language", id);
  8596. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8597. #if EQDEBUG >= 9
  8598. packet->PrintPacket();
  8599. #endif
  8600. QueuePacket(packet->serialize());
  8601. safe_delete(packet);
  8602. }
  8603. }
  8604. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8605. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8606. if (packet) {
  8607. if (pet_name)
  8608. packet->setDataByName("pet_name", pet_name);
  8609. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  8610. packet->setDataByName("protect_master", 1);
  8611. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  8612. packet->setDataByName("protect_self", 1);
  8613. if (player->GetInfoStruct()->get_pet_movement() == 2)
  8614. packet->setDataByName("stay_follow_toggle", 1);
  8615. packet->setDataByName("pet_type", type);
  8616. QueuePacket(packet->serialize());
  8617. }
  8618. safe_delete(packet);
  8619. }
  8620. bool Client::IsCrafting() {
  8621. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8622. }
  8623. void Client::SendBiography() {
  8624. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8625. if (packet) {
  8626. char biography[512];
  8627. if(player->GetInfoStruct()->get_biography().size() < 1)
  8628. {
  8629. safe_delete(packet);
  8630. return;
  8631. }
  8632. else
  8633. {
  8634. int16 size = player->GetInfoStruct()->get_biography().size();
  8635. if(size>511)
  8636. size = 511;
  8637. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  8638. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  8639. }
  8640. packet->setDataByName("biography", biography);
  8641. QueuePacket(packet->serialize());
  8642. }
  8643. safe_delete(packet);
  8644. }
  8645. PendingResurrection* Client::GetCurrentRez() {
  8646. return &current_rez;
  8647. }
  8648. Mutex* Client::GetResurrectMutex() {
  8649. return &m_resurrect;
  8650. }
  8651. void Client::SendResurrectionWindow() {
  8652. Spawn* caster = current_rez.caster;
  8653. if (!caster || !player)
  8654. return;
  8655. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8656. if (!packet)
  8657. return;
  8658. char* tmp = new char[512];
  8659. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8660. packet->setMediumStringByName("text", tmp);
  8661. packet->setMediumStringByName("accept_text", "Yes");
  8662. packet->setMediumStringByName("cancel_text", "No");
  8663. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8664. packet->setMediumStringByName("accept_command", tmp);
  8665. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8666. packet->setMediumStringByName("cancel_command", tmp);
  8667. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8668. QueuePacket(packet->serialize());
  8669. safe_delete(packet);
  8670. safe_delete_array(tmp);
  8671. }
  8672. void Client::AcceptResurrection() {
  8673. Spawn* caster = current_rez.caster;
  8674. if (!player || !caster)
  8675. return;
  8676. if (player->Alive())
  8677. return;
  8678. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  8679. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  8680. SendResurrectionWindow();
  8681. return;
  8682. }
  8683. player->GetZone()->ResurrectSpawn(player, this);
  8684. current_rez.should_delete = true;
  8685. }
  8686. void Client::SetPendingLastName(string last_name) {
  8687. pending_last_name = new string;
  8688. pending_last_name->assign(last_name);
  8689. }
  8690. string* Client::GetPendingLastName() {
  8691. return pending_last_name;
  8692. }
  8693. void Client::RemovePendingLastName() {
  8694. safe_delete(pending_last_name);
  8695. }
  8696. void Client::SendLastNameConfirmation() {
  8697. if (!pending_last_name)
  8698. return;
  8699. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8700. if (packet) {
  8701. char* text = new char[128];
  8702. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  8703. packet->setDataByName("text", text);
  8704. packet->setDataByName("accept_text", "Yes");
  8705. packet->setDataByName("accept_command", "confirmedlastname");
  8706. packet->setDataByName("cancel_text", "No");
  8707. packet->setDataByName("max_length", 50);
  8708. packet->setDataByName("unknown4", 1);
  8709. packet->setDataByName("unknown5", 1);
  8710. QueuePacket(packet->serialize());
  8711. safe_delete(packet);
  8712. safe_delete_array(text);
  8713. }
  8714. }
  8715. void Client::AddQuestTimer(int32 quest_id) {
  8716. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8717. quest_timers.push_back(quest_id);
  8718. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8719. }
  8720. void Client::RemoveQuestTimer(int32 quest_id) {
  8721. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8722. vector<int32>::iterator itr;
  8723. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  8724. if ((*itr) == quest_id) {
  8725. quest_timers.erase(itr);
  8726. break;
  8727. }
  8728. }
  8729. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8730. }
  8731. void Client::SavePlayerImages() {
  8732. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  8733. // Save the paperdoll image if the server allows it
  8734. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  8735. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8736. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  8737. // Save the head shot if the server allows it
  8738. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  8739. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8740. // Send the head shot to the login server
  8741. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  8742. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  8743. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  8744. memset(packet->pBuffer, 0, size);
  8745. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  8746. pic->account_id = GetAccountID();
  8747. pic->char_id = GetCharacterID();
  8748. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  8749. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8750. loginserver.SendPacket(packet);
  8751. safe_delete(packet);
  8752. }
  8753. }
  8754. safe_delete_array(incoming_paperdoll.image_bytes);
  8755. incoming_paperdoll.current_size_bytes = 0;
  8756. }
  8757. void Client::EndAutoMount() {
  8758. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8759. if (packet) {
  8760. packet->setDataByName("parameter1", 128);
  8761. packet->setDataByName("parameter2", 64);
  8762. packet->setDataByName("value", 1);
  8763. QueuePacket(packet->serialize());
  8764. safe_delete(packet);
  8765. }
  8766. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8767. if (packet) {
  8768. packet->setDataByName("parameter3", 4);
  8769. packet->setDataByName("parameter5", 2);
  8770. packet->setDataByName("value", 0);
  8771. QueuePacket(packet->serialize());
  8772. safe_delete(packet);
  8773. }
  8774. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  8775. if (packet) {
  8776. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  8777. QueuePacket(packet->serialize());
  8778. safe_delete(packet);
  8779. }
  8780. on_auto_mount = false;
  8781. player->SetMount(((Player*)player)->GetTempMount());
  8782. EQ2_Color mount_color = player->GetTempMountColor();
  8783. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  8784. player->SetMountColor(&mount_color);
  8785. player->SetMountSaddleColor(&saddle_color);
  8786. player->SetTempMount(0);
  8787. }
  8788. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  8789. const char* spawn_script = spawn->GetSpawnScript();
  8790. bool should_use_spawn = true;
  8791. if (spawn_script) {
  8792. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  8793. if (state) {
  8794. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  8795. if (state_mutex)
  8796. state_mutex->writelock(__FUNCTION__, __LINE__);
  8797. lua_getglobal(state, "can_use_command");
  8798. if (lua_isfunction(state, -1)) {
  8799. lua_interface->SetSpawnValue(state, spawn);
  8800. lua_interface->SetSpawnValue(state, GetPlayer());
  8801. lua_interface->SetStringValue(state, command ? command : "");
  8802. if (lua_pcall(state, 3, 1, 0) == 0) {
  8803. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  8804. }
  8805. }
  8806. lua_interface->ResetFunctionStack(state);
  8807. if (state_mutex)
  8808. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  8809. }
  8810. }
  8811. return should_use_spawn;
  8812. }
  8813. bool Client::IsCurrentTransmuteID(int32 req_id) {
  8814. return req_id == transmuteID;
  8815. }
  8816. void Client::SetTransmuteID(int32 trans_id) {
  8817. transmuteID = trans_id;
  8818. }
  8819. int32 Client::GetTransmuteID() {
  8820. return transmuteID;
  8821. }
  8822. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  8823. {
  8824. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  8825. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  8826. if (zar)
  8827. {
  8828. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  8829. if (database.IsActiveQuery(charID))
  8830. {
  8831. delayedLogin = true;
  8832. delayedAccountID = account_id;
  8833. delayedAccessKey = access_code;
  8834. delayTimer.Start(500);
  8835. 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);
  8836. return true;
  8837. }
  8838. delayedLogin = false;
  8839. delayTimer.Disable();
  8840. firstlogin = zar->isFirstLogin();
  8841. 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);
  8842. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  8843. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  8844. GetPlayer()->vis_changed = false;
  8845. GetPlayer()->info_changed = false;
  8846. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8847. if (pvp_allowed)
  8848. this->GetPlayer()->SetAttackable(1);
  8849. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  8850. Client* client = zone_list.GetClientByCharName(player->GetName());
  8851. if (client) {
  8852. if (client->getConnection())
  8853. client->getConnection()->SendDisconnect(true);
  8854. if (client->GetCurrentZone() && !client->IsZoning()) {
  8855. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  8856. if (client->GetVersion() == version) {
  8857. client->DisableSave();
  8858. client->ReplaceGroupClient(this);
  8859. Player* current_player = GetPlayer();
  8860. SetPlayer(client->GetPlayer());
  8861. GetPlayer()->SetClient(this);
  8862. GetPlayer()->SetReturningFromLD(true);
  8863. SetCurrentZone(GetPlayer()->GetZone());
  8864. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  8865. client->SetPlayer(current_player);
  8866. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  8867. GetPlayer()->ResetSavedSpawns();
  8868. }
  8869. ZoneServer* tmpZone = client->GetCurrentZone();
  8870. tmpZone->RemoveClientImmediately(client);
  8871. }
  8872. }
  8873. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  8874. if (!GetCurrentZone()) {
  8875. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  8876. ClientPacketFunctions::SendLoginDenied(this);
  8877. }
  8878. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  8879. getConnection()->SetClientVersion(version);
  8880. GetCurrentZone()->SetSpawnStructs(this);
  8881. connected_to_zone = true;
  8882. client_list.Remove(this); //remove from master client list
  8883. GetCurrentZone()->AddClient(this); //add to zones client list
  8884. zone_list.AddClientToMap(player->GetName(), this);
  8885. // 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.
  8886. new_client_login = true;
  8887. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  8888. if (zone_script && lua_interface)
  8889. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  8890. }
  8891. else {
  8892. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  8893. ClientPacketFunctions::SendLoginDenied(this);
  8894. return false;
  8895. }
  8896. }
  8897. else {
  8898. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  8899. ClientPacketFunctions::SendLoginDenied(this);
  8900. }
  8901. zone_auth.RemoveAuth(zar);
  8902. }
  8903. else
  8904. {
  8905. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  8906. Disconnect();
  8907. }
  8908. return true;
  8909. }
  8910. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  8911. if (!IsReadyForUpdates())
  8912. return;
  8913. map<int32, SpawnData> info_changes;
  8914. map<int32, SpawnData> pos_changes;
  8915. map<int32, SpawnData> vis_changes;
  8916. map<int32, SpawnData> empty_changes;
  8917. int32 info_size = 0;
  8918. int32 pos_size = 0;
  8919. int32 vis_size = 0;
  8920. int count = 0;
  8921. for (const auto& spawn : spawns) {
  8922. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  8923. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  8924. continue;
  8925. if (spawn->vis_changed)
  8926. {
  8927. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8928. if (vis_change) {
  8929. SpawnData data;
  8930. data.spawn = spawn;
  8931. data.data = vis_change;
  8932. data.size = spawn->vis_packet_size;
  8933. map<int32, SpawnData> tmp_vis_changes;
  8934. tmp_vis_changes[index] = data;
  8935. map<int32, SpawnData> tmp_info_changes;
  8936. map<int32, SpawnData> tmp_pos_changes;
  8937. int32 tmp_info_size = 0;
  8938. int32 tmp_pos_size = 0;
  8939. if (spawn->info_changed) {
  8940. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8941. if (info_change) {
  8942. SpawnData data;
  8943. data.spawn = spawn;
  8944. data.data = info_change;
  8945. data.size = spawn->info_packet_size;
  8946. tmp_info_size = data.size;
  8947. tmp_info_changes[index] = data;
  8948. }
  8949. }
  8950. if (spawn->position_changed) {
  8951. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8952. if (pos_change) {
  8953. SpawnData data;
  8954. data.spawn = spawn;
  8955. data.data = pos_change;
  8956. data.size = spawn->pos_packet_size;
  8957. tmp_pos_size = data.size;
  8958. tmp_pos_changes[index] = data;
  8959. }
  8960. }
  8961. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  8962. for (auto& kv : tmp_info_changes) {
  8963. safe_delete_array(kv.second.data);
  8964. }
  8965. for (auto& kv : tmp_pos_changes) {
  8966. safe_delete_array(kv.second.data);
  8967. }
  8968. for (auto& kv : tmp_vis_changes) {
  8969. safe_delete_array(kv.second.data);
  8970. }
  8971. continue;
  8972. }
  8973. }
  8974. if (spawn->info_changed) {
  8975. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8976. if (info_change) {
  8977. SpawnData data;
  8978. data.spawn = spawn;
  8979. data.data = info_change;
  8980. data.size = spawn->info_packet_size;
  8981. info_size += spawn->info_packet_size;
  8982. info_changes[index] = data;
  8983. }
  8984. count++;
  8985. }
  8986. if (spawn->position_changed) {
  8987. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8988. if (pos_change) {
  8989. SpawnData data;
  8990. data.spawn = spawn;
  8991. data.data = pos_change;
  8992. data.size = spawn->pos_packet_size;
  8993. pos_size += spawn->pos_packet_size;
  8994. pos_changes[index] = data;
  8995. }
  8996. count++;
  8997. }
  8998. if (spawn->vis_changed) {
  8999. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9000. if (vis_change) {
  9001. SpawnData data;
  9002. data.spawn = spawn;
  9003. data.data = vis_change;
  9004. data.size = spawn->vis_packet_size;
  9005. vis_size += spawn->vis_packet_size;
  9006. vis_changes[index] = data;
  9007. }
  9008. count++;
  9009. }
  9010. }
  9011. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9012. return;
  9013. }
  9014. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9015. for (auto& kv : info_changes) {
  9016. safe_delete_array(kv.second.data);
  9017. }
  9018. for (auto& kv : pos_changes) {
  9019. safe_delete_array(kv.second.data);
  9020. }
  9021. for (auto& kv : vis_changes) {
  9022. safe_delete_array(kv.second.data);
  9023. }
  9024. }
  9025. 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)
  9026. {
  9027. static const int8 oversized = 255;
  9028. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9029. int32 size = info_size + pos_size + vis_size + 8;
  9030. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9031. size += 3;
  9032. size += CheckOverLoadSize(info_size);
  9033. size += CheckOverLoadSize(pos_size);
  9034. size += CheckOverLoadSize(vis_size);
  9035. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9036. size += 2;
  9037. }
  9038. uchar* tmp = new uchar[size];
  9039. uchar* ptr = tmp;
  9040. memset(tmp, 0, size);
  9041. if (version <= 283) {
  9042. if (size >= 255) {
  9043. size -= 3;
  9044. memcpy(ptr, &oversized, sizeof(int8));
  9045. ptr += sizeof(int8);
  9046. memcpy(ptr, &size, sizeof(int16));
  9047. ptr += sizeof(int16);
  9048. size += 3;
  9049. }
  9050. else {
  9051. size -= 1;
  9052. memcpy(ptr, &size, sizeof(int8));
  9053. ptr += sizeof(int8);
  9054. size += 1;
  9055. }
  9056. }
  9057. else {
  9058. size -= 4;
  9059. memcpy(ptr, &size, sizeof(int32));
  9060. ptr += sizeof(int32);
  9061. size += 4;
  9062. }
  9063. memcpy(ptr, &oversized, sizeof(int8));
  9064. ptr += sizeof(int8);
  9065. memcpy(ptr, &opcode_val, sizeof(int16));
  9066. ptr += sizeof(int16);
  9067. int32 current_time = Timer::GetCurrentTime2();
  9068. memcpy(ptr, &current_time, sizeof(int32));
  9069. ptr += sizeof(int32);
  9070. ptr += DoOverLoad(info_size, ptr);
  9071. for (const auto& kv : info_changes) {
  9072. auto info = kv.second;
  9073. memcpy(ptr, info.data, info.size);
  9074. ptr += info.size;
  9075. }
  9076. ptr += DoOverLoad(pos_size, ptr);
  9077. for (const auto& kv : pos_changes) {
  9078. auto pos = kv.second;
  9079. memcpy(ptr, pos.data, pos.size);
  9080. ptr += pos.size;
  9081. }
  9082. ptr += DoOverLoad(vis_size, ptr);
  9083. for (const auto& kv : vis_changes) {
  9084. auto vis = kv.second;
  9085. memcpy(ptr, vis.data, vis.size);
  9086. ptr += vis.size;
  9087. }
  9088. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9089. if (packet) {
  9090. /*char blah[64];
  9091. snprintf(blah, 64, "Sending %i", current_time);
  9092. SimpleMessage(4, blah);*/
  9093. QueuePacket(packet);
  9094. }
  9095. delete[] tmp;
  9096. }
  9097. void Client::SendHailCommand(Spawn* spawn)
  9098. {
  9099. // hardcoded 'hail' entity commands
  9100. switch (spawn->secondary_command_list_id)
  9101. {
  9102. case 9:
  9103. case 1262:
  9104. case 1265:
  9105. case 1267:
  9106. {
  9107. EQ2_16BitString* command = new EQ2_16BitString();
  9108. command->data = "";
  9109. command->size = 0;
  9110. commands.Process(COMMAND_HAIL, command, this, spawn);
  9111. safe_delete(command);
  9112. break;
  9113. }
  9114. }
  9115. }
  9116. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9117. {
  9118. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9119. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9120. if (packet) {
  9121. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9122. packet->setMediumStringByName("command_name", command);
  9123. packet->setDataByName("distance", distance);
  9124. QueuePacket(packet->serialize());
  9125. safe_delete(packet);
  9126. }
  9127. }
  9128. }
  9129. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9130. {
  9131. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9132. return false;
  9133. if (command == "house_spawn_examine")
  9134. {
  9135. uint32 itemID = spawn->GetPickupItemID();
  9136. if (itemID)
  9137. {
  9138. Item* item = master_item_list.GetItem(itemID);
  9139. if (item)
  9140. {
  9141. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9142. //DumpPacket(app);
  9143. QueuePacket(app);
  9144. }
  9145. }
  9146. return true;
  9147. }
  9148. return false;
  9149. }
  9150. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9151. {
  9152. if (GetTempPlacementSpawn())
  9153. {
  9154. Spawn* tmp = GetTempPlacementSpawn();
  9155. int32 spawn_group_id = database.GetNextSpawnLocation();
  9156. tmp->SetSpawnLocationID(spawn_group_id);
  9157. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9158. int32 spawnDBID = 0;
  9159. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9160. {
  9161. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9162. tmp->SetDatabaseID(spawnDBID);
  9163. }
  9164. else
  9165. {
  9166. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9167. if (spawnDBID)
  9168. {
  9169. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9170. tmp->SetDatabaseID(spawnDBID);
  9171. }
  9172. }
  9173. tmp->SetX(place_object->getType_float_ByName("x"));
  9174. tmp->SetY(place_object->getType_float_ByName("y"));
  9175. tmp->SetZ(place_object->getType_float_ByName("z"));
  9176. tmp->SetHeading(newHeading);
  9177. tmp->SetSpawnOrigX(tmp->GetX());
  9178. tmp->SetSpawnOrigY(tmp->GetY());
  9179. tmp->SetSpawnOrigZ(tmp->GetZ());
  9180. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9181. database.SaveSpawnInfo(tmp);
  9182. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9183. if (!spawnDBID)
  9184. {
  9185. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9186. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  9187. }
  9188. return true;
  9189. }
  9190. return false;
  9191. }
  9192. bool Client::PopulateHouseSpawnFinalize()
  9193. {
  9194. if (GetTempPlacementSpawn())
  9195. {
  9196. Spawn* tmp = GetTempPlacementSpawn();
  9197. GetCurrentZone()->AddSpawn(tmp);
  9198. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9199. SetTempPlacementSpawn(nullptr);
  9200. int32 uniqueID = GetPlacementUniqueItemID();
  9201. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9202. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9203. tmp->SetPickupUniqueItemID(uniqueID);
  9204. if (uniqueItem)
  9205. {
  9206. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9207. {
  9208. Query query;
  9209. 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);
  9210. }
  9211. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9212. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9213. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9214. SetPlacementUniqueItemID(0);
  9215. }
  9216. return true;
  9217. }
  9218. return false;
  9219. }
  9220. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9221. {
  9222. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9223. packet->setDataByName("placement_mode", placementMode);
  9224. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9225. packet->setDataByName("model_type", spawn->GetModelType());
  9226. packet->setDataByName("unknown", 1); //size
  9227. packet->setDataByName("unknown2", 1); //size 2
  9228. packet->setDataByName("unknown2", .5, 1); //size 3
  9229. packet->setDataByName("unknown2", 3, 2);
  9230. packet->setDataByName("unknown2", unknown2_3, 3);
  9231. packet->setDataByName("max_distance", 500);
  9232. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9233. QueuePacket(packet->serialize());
  9234. safe_delete(packet);
  9235. }
  9236. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9237. {
  9238. SetPendingFlightPath(path_id);
  9239. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9240. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9241. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9242. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9243. if (packet) {
  9244. QueuePacket(packet->serialize());
  9245. safe_delete(packet);
  9246. }
  9247. if (mount_id)
  9248. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9249. }
  9250. void Client::SendShowBook(Spawn* sender, string title, int8 num_pages, ...)
  9251. {
  9252. if (!sender)
  9253. {
  9254. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9255. return;
  9256. }
  9257. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9258. if (!packet) {
  9259. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9260. return;
  9261. }
  9262. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9263. packet->setDataByName("book_title", title.c_str());
  9264. packet->setDataByName("book_type", "simple");
  9265. packet->setDataByName("unknown2", 1);
  9266. if (GetVersion() > 546)
  9267. packet->setDataByName("unknown5", 1, 4);
  9268. packet->setArrayLengthByName("num_pages", num_pages);
  9269. va_list args;
  9270. va_start(args, num_pages);
  9271. std::string endString("");
  9272. for (int8 p = 0; p < num_pages; p++)
  9273. {
  9274. std::string page = va_arg(args, string);
  9275. switch (GetVersion())
  9276. {
  9277. // release client
  9278. case 283:
  9279. {
  9280. endString.append(page);
  9281. break;
  9282. }
  9283. // DoF trial
  9284. case 546:
  9285. {
  9286. if (p == 0)
  9287. packet->setDataByName("cover_page", page.c_str());
  9288. else
  9289. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9290. break;
  9291. }
  9292. // all other clients
  9293. default:
  9294. {
  9295. packet->setArrayDataByName("page_text", page.c_str(), p);
  9296. break;
  9297. }
  9298. }
  9299. }
  9300. if (GetVersion() == 283)
  9301. {
  9302. packet->setDataByName("page_text", endString.c_str());
  9303. }
  9304. va_end(args);
  9305. QueuePacket(packet->serialize());
  9306. safe_delete(packet);
  9307. }
  9308. void Client::SendShowBook(Spawn* sender, string title, vector<Item::BookPage*> pages)
  9309. {
  9310. if (!sender)
  9311. {
  9312. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9313. return;
  9314. }
  9315. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9316. if (!packet) {
  9317. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9318. return;
  9319. }
  9320. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9321. packet->setDataByName("book_title", title.c_str());
  9322. packet->setDataByName("book_type", "simple");
  9323. packet->setDataByName("unknown2", 1);
  9324. if (GetVersion() > 546)
  9325. packet->setDataByName("unknown5", 1, 4);
  9326. packet->setArrayLengthByName("num_pages", pages.size());
  9327. std::string endString("");
  9328. for (int8 p = 0; p < pages.size(); p++)
  9329. {
  9330. Item::BookPage* page = pages[p];
  9331. std::string pageText = string(page->page_text.data);
  9332. switch (GetVersion())
  9333. {
  9334. // release client
  9335. case 283:
  9336. {
  9337. endString.append(pageText);
  9338. break;
  9339. }
  9340. // DoF trial
  9341. case 546:
  9342. {
  9343. if (p == 0)
  9344. packet->setDataByName("cover_page", pageText.c_str());
  9345. else
  9346. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9347. break;
  9348. }
  9349. // all other clients
  9350. default:
  9351. {
  9352. int8 valign = int8(page->valign);
  9353. int8 halign = int8(page->halign);
  9354. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9355. packet->setArrayDataByName("page_text_valign", valign, p);
  9356. packet->setArrayDataByName("page_text_halign", halign, p);
  9357. break;
  9358. }
  9359. }
  9360. }
  9361. if (GetVersion() == 283)
  9362. {
  9363. packet->setDataByName("page_text", endString.c_str());
  9364. }
  9365. QueuePacket(packet->serialize());
  9366. safe_delete(packet);
  9367. }
  9368. void Client::ReplaceGroupClient(Client* new_client)
  9369. {
  9370. if (this->GetPlayer()->GetGroupMemberInfo())
  9371. {
  9372. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9373. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9374. if(group)
  9375. {
  9376. group->MGroupMembers.writelock();
  9377. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9378. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9379. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9380. group->MGroupMembers.releasewritelock();
  9381. }
  9382. else
  9383. {
  9384. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9385. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9386. this->GetPlayer()->SetGroupMemberInfo(0);
  9387. }
  9388. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9389. }
  9390. }
  9391. void Client::TempRemoveGroup()
  9392. {
  9393. if (this->GetPlayer()->GetGroupMemberInfo())
  9394. {
  9395. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9396. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9397. if(group)
  9398. {
  9399. group->MGroupMembers.writelock();
  9400. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9401. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9402. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9403. this->GetPlayer()->SetGroupMemberInfo(0);
  9404. group->MGroupMembers.releasewritelock();
  9405. group->RemoveClientReference(this);
  9406. }
  9407. else
  9408. {
  9409. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9410. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9411. this->GetPlayer()->SetGroupMemberInfo(0);
  9412. }
  9413. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9414. }
  9415. }
  9416. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9417. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9418. {
  9419. Mail mail;
  9420. memset(&mail,0,sizeof(Mail));
  9421. mail.player_to_id = charID;
  9422. mail.player_from = fromName;
  9423. mail.subject = subjectName;
  9424. mail.mail_body = mailBody;
  9425. mail.mail_type = mailType;
  9426. mail.coin_copper = copper;
  9427. mail.coin_silver = silver;
  9428. mail.coin_gold = gold;
  9429. mail.coin_plat = platinum;
  9430. mail.char_item_id = item_id;
  9431. mail.stack = stack_size;
  9432. mail.time_sent = time_sent;
  9433. mail.expire_time = expire_time;
  9434. database.SavePlayerMail(&mail);
  9435. }
  9436. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9437. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9438. {
  9439. Mail* mail = new Mail();
  9440. mail->player_to_id = GetCharacterID();
  9441. mail->player_from = fromName;
  9442. mail->subject = subjectName;
  9443. mail->mail_body = mailBody;
  9444. mail->mail_type = mailType;
  9445. mail->coin_copper = copper;
  9446. mail->coin_silver = silver;
  9447. mail->coin_gold = gold;
  9448. mail->coin_plat = platinum;
  9449. mail->char_item_id = item_id;
  9450. mail->stack = stack_size;
  9451. mail->time_sent = time_sent;
  9452. mail->expire_time = expire_time;
  9453. mail->postage_cost = 0;
  9454. mail->save_needed = 1;
  9455. mail->already_read = 0;
  9456. database.SavePlayerMail(mail);
  9457. GetPlayer()->AddMail(mail);
  9458. }
  9459. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9460. {
  9461. if(slot < NUM_SLOTS)
  9462. {
  9463. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9464. if (app)
  9465. QueuePacket(app);
  9466. }
  9467. else
  9468. {
  9469. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9470. if (outapp)
  9471. QueuePacket(outapp);
  9472. }
  9473. }
  9474. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9475. {
  9476. if(spawn_player_id < 1)
  9477. return;
  9478. MQueueStateCmds.writelock();
  9479. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9480. MQueueStateCmds.releasewritelock();
  9481. }
  9482. void Client::ProcessStateCommands()
  9483. {
  9484. if(!IsReadyForUpdates())
  9485. return;
  9486. MQueueStateCmds.writelock();
  9487. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9488. for(; itr != queued_state_commands.end(); itr++)
  9489. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9490. queued_state_commands.clear();
  9491. MQueueStateCmds.releasewritelock();
  9492. }
  9493. void Client::PurgeItem(Item* item)
  9494. {
  9495. MConversation.writelock();
  9496. map<int32, Item*>::iterator itr;
  9497. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9498. {
  9499. if ( itr->second == item )
  9500. {
  9501. conversation_items.erase(itr);
  9502. break;
  9503. }
  9504. }
  9505. MConversation.releasewritelock();
  9506. }
  9507. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9508. {
  9509. if(GetPlayer()->StopSaveSpellEffects())
  9510. return;
  9511. if(item) {
  9512. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9513. if(item->GetItemScript() && lua_interface){
  9514. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9515. if (slot == 22)
  9516. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9517. else
  9518. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9519. }
  9520. if (item->details.count > 1) {
  9521. item->details.count -= 1;
  9522. item->save_needed = true;
  9523. }
  9524. else {
  9525. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9526. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9527. }
  9528. GetPlayer()->SetCharSheetChanged(true);
  9529. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9530. }
  9531. }
  9532. void Client::AwardCoins(int64 total_coins, std::string reason)
  9533. {
  9534. if (total_coins > 0) {
  9535. player->AddCoins(total_coins);
  9536. PlaySound("coin_cha_ching");
  9537. char tmp[64] = { 0 };
  9538. string message = "You receive ";
  9539. int32 val = 0;
  9540. if (total_coins >= 1000000) {
  9541. val = total_coins / 1000000;
  9542. total_coins -= 1000000 * val;
  9543. sprintf(tmp, "%u Platinum ", val);
  9544. message.append(tmp);
  9545. memset(tmp, 0, 64);
  9546. }
  9547. if (total_coins >= 10000) {
  9548. val = total_coins / 10000;
  9549. total_coins -= 10000 * val;
  9550. sprintf(tmp, "%u Gold ", val);
  9551. message.append(tmp);
  9552. memset(tmp, 0, 64);
  9553. }
  9554. if (total_coins >= 100) {
  9555. val = total_coins / 100;
  9556. total_coins -= 100 * val;
  9557. sprintf(tmp, "%u Silver ", val);
  9558. message.append(tmp);
  9559. memset(tmp, 0, 64);
  9560. }
  9561. if (total_coins > 0) {
  9562. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9563. message.append(tmp);
  9564. }
  9565. message.append(reason);
  9566. int8 type = CHANNEL_LOOT;
  9567. SimpleMessage(type, message.c_str());
  9568. }
  9569. }
  9570. void Client::TriggerSpellSave()
  9571. {
  9572. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  9573. // default to not have some bogus value in the rule
  9574. if(interval < 1)
  9575. interval = 100;
  9576. MSaveSpellStateMutex.lock();
  9577. if(!save_spell_state_timer.Enabled())
  9578. {
  9579. save_spell_state_time_bucket = 0;
  9580. save_spell_state_timer.Start(interval, true);
  9581. }
  9582. else
  9583. {
  9584. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  9585. save_spell_state_time_bucket += elapsed_time;
  9586. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  9587. // default to not have some bogus value in the rule
  9588. if(save_wait_cap < interval)
  9589. save_wait_cap = interval+1;
  9590. if(save_spell_state_time_bucket >= save_wait_cap)
  9591. {
  9592. // save immediately and disable timer
  9593. GetPlayer()->SaveSpellEffects();
  9594. save_spell_state_timer.Disable();
  9595. }
  9596. }
  9597. MSaveSpellStateMutex.unlock();
  9598. }
  9599. void Client::UpdateSentSpellList() {
  9600. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  9601. std::map<int32, int32>::iterator itr;
  9602. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  9603. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  9604. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  9605. QueuePacket(app);
  9606. }
  9607. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  9608. }
  9609. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  9610. tempPlacementSpawn = tmp;
  9611. hasSentTempPlacementSpawn = false;
  9612. if(tempPlacementSpawn)
  9613. temp_placement_timer.Start();
  9614. else
  9615. temp_placement_timer.Disable();
  9616. }