9
3

client.cpp 374 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "IRC/IRC.h"
  36. #include "Chat/Chat.h"
  37. #include "SpellProcess.h"
  38. #include "Zone/ChestTrap.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. extern WorldDatabase database;
  81. extern const char* ZONE_NAME;
  82. extern LoginServer loginserver;
  83. extern sint32 numclients;
  84. extern NetConnection net;
  85. extern Commands commands;
  86. extern ClientList client_list;
  87. extern ZoneList zone_list;
  88. extern ZoneAuth zone_auth;
  89. extern MasterItemList master_item_list;
  90. extern MasterSkillList master_skill_list;
  91. extern MasterSpellList master_spell_list;
  92. extern MasterTraitList master_trait_list;
  93. extern MasterQuestList master_quest_list;
  94. extern MasterFactionList master_faction_list;
  95. extern MasterRecipeList master_recipe_list;
  96. extern volatile bool RunLoops;
  97. extern ConfigReader configReader;
  98. extern LuaInterface* lua_interface;
  99. extern World world;
  100. extern Variables variables;
  101. extern Classes classes;
  102. extern Races races;
  103. extern GuildList guild_list;
  104. extern MasterCollectionList master_collection_list;
  105. extern MasterAchievementList master_achievement_list;
  106. extern RuleManager rule_manager;
  107. extern IRC irc;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. using namespace std;
  113. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0), temp_placement_timer(10), spawn_removal_timer(250) {
  114. eqs = ieqs;
  115. ip = eqs->GetrIP();
  116. port = ntohs(eqs->GetrPort());
  117. merchant_transaction = nullptr;
  118. mail_window.item = nullptr; // don't want this to be set(loose ptr) when using ResetSendMail to provide rest of the defaults
  119. ResetSendMail(false);
  120. timestamp_flag = 0;
  121. current_quest_id = 0;
  122. last_update_time = 0;
  123. quest_updates = false;
  124. //autobootup_timeout = new Timer(10000);
  125. //autobootup_timeout->Disable();
  126. CLE_keepalive_timer = new Timer(15000);
  127. connect = new Timer(1000);
  128. connect->Disable();
  129. zoneID = 0;
  130. account_name[0] = 0;
  131. character_id = 0;
  132. account_id = 0;
  133. pwaitingforbootup = 0;
  134. current_zone = 0;
  135. connected_to_zone = false;
  136. connected = false;
  137. camp_timer = 0;
  138. client_zoning = false;
  139. zoning_id = 0;
  140. zoning_x = 0;
  141. zoning_y = 0;
  142. zoning_z = 0;
  143. zoning_instance_id = 0;
  144. player_pos_changed = false;
  145. ++numclients;
  146. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  147. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  148. remove_from_list = false;
  149. new_client_login = false;
  150. UpdateWindowTitle(0);
  151. num_active_failures = 0;
  152. player = new Player();
  153. player->SetClient(this);
  154. combine_spawn = 0;
  155. lua_debug = false;
  156. ready_for_spawns = false;
  157. ready_for_updates = false;
  158. lua_debug_timer.Disable();
  159. transport_spawn = 0;
  160. MBuyBack.SetName("Client::MBuyBack");
  161. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  162. MDeletePlayer.SetName("Client::MDeletePlayer");
  163. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  164. search_items = 0;
  165. version = 0;
  166. next_conversation_id = 0;
  167. pending_guild_invite.guild = 0;
  168. pending_guild_invite.invited_by = 0;
  169. m_recipeListSent = false;
  170. m_resurrect.SetName("Client::m_resurrect");
  171. current_rez.expire_timer = 0;
  172. current_rez.should_delete = true;
  173. pending_last_name = 0;
  174. should_target = false;
  175. initial_spawns_sent = false;
  176. MQuestTimers.SetName("Client::quest_timers");
  177. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  178. on_auto_mount = false;
  179. should_load_spells = true;
  180. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  181. delayedLogin = false;
  182. delayedAccountID = 0;
  183. delayedAccessKey = 0;
  184. delayTimer.Disable();
  185. tempPlacementSpawn = nullptr;
  186. placement_unique_item_id = 0;
  187. SetHasOwnerOrEditAccess(false);
  188. temporary_transport_id = 0;
  189. rejoin_group_id = 0;
  190. lastRegionRemapTime = 0;
  191. regionDebugMessaging = false;
  192. client_reloading_zone = false;
  193. last_saved_timestamp = 0;
  194. MQueueStateCmds.SetName("Client::MQueueStateCmds");
  195. MConversation.SetName("Client::MConversation");
  196. save_spell_state_timer.Disable();
  197. save_spell_state_time_bucket = 0;
  198. player_loading_complete = false;
  199. MItemDetails.SetName("Client::MItemDetails");
  200. MSpellDetails.SetName("Client::MSpellDetails");
  201. hasSentTempPlacementSpawn = false;
  202. spawn_removal_timer.Start();
  203. disable_save = false;
  204. SetZoningDestination(nullptr);
  205. }
  206. Client::~Client() {
  207. RemoveClientFromZone();
  208. //let the stream factory know were done with this stream
  209. if (eqs) {
  210. eqs->Close();
  211. try {
  212. eqs->ReleaseFromUse();
  213. }
  214. catch (...) {}
  215. }
  216. eqs = NULL;
  217. //safe_delete(autobootup_timeout);
  218. safe_delete(CLE_keepalive_timer);
  219. safe_delete(connect);
  220. --numclients;
  221. UpdateWindowTitle(0);
  222. }
  223. void Client::RemoveClientFromZone() {
  224. if (GetTempPlacementSpawn() && GetCurrentZone()) {
  225. Spawn* tmp = GetTempPlacementSpawn();
  226. SetTempPlacementSpawn(nullptr);
  227. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  228. }
  229. if(player && player->GetZone())
  230. player->GetZone()->GetSpellProcess()->RemoveSpellTimersFromSpawn(player, true, false, true, true);
  231. if (current_zone && player) {
  232. if (player->GetGroupMemberInfo())
  233. {
  234. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  235. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  236. else
  237. TempRemoveGroup();
  238. }
  239. world.GetGroupManager()->ClearPendingInvite(player);
  240. }
  241. if (lua_interface)
  242. lua_interface->RemoveDebugClients(this);
  243. if (player)
  244. zone_list.RemoveClientFromMap(player->GetName(), this);
  245. safe_delete(camp_timer);
  246. safe_delete(search_items);
  247. safe_delete(current_rez.expire_timer);
  248. safe_delete(pending_last_name);
  249. safe_delete_array(incoming_paperdoll.image_bytes);
  250. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  251. if (player && !player->GetPendingDeletion())
  252. safe_delete(player);
  253. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  254. }
  255. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  256. if (eqs) {
  257. if (!eqs->CheckActive()) {
  258. client_list.Remove(this);
  259. eqs = 0;
  260. }
  261. }
  262. if (app && eqs && version > 0)
  263. eqs->EQ2QueuePacket(app, attemptedCombine);
  264. else {
  265. safe_delete(app);
  266. }
  267. }
  268. void Client::PopulateSkillMap() {
  269. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  270. if (app)
  271. QueuePacket(app);
  272. else {
  273. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  274. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  275. }
  276. }
  277. void Client::SendLoginInfo() {
  278. if(GetPlayer()->IsReturningFromLD())
  279. firstlogin = true;
  280. if (firstlogin) {
  281. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  282. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  283. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  284. PopulateSkillMap();
  285. // 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!
  286. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  287. }
  288. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  289. database.ToggleCharacterOnline(this, 1);
  290. int32 count = 0;
  291. if(!GetPlayer()->IsReturningFromLD())
  292. {
  293. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  294. count = database.LoadCharacterSkills(GetCharacterID(), player);
  295. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  296. count = database.LoadCharacterSpells(GetCharacterID(), player);
  297. }
  298. else
  299. {
  300. LogWrite(CCLIENT__INFO, 0, "Client", "Player is returning from linkdead status (Player does not need reload) thus skipping database loading for '%s'...", player->GetName());
  301. }
  302. // get the latest character starting skills / spells, may have been updated after character creation
  303. world.SyncCharacterAbilities(this);
  304. if(!GetPlayer()->IsReturningFromLD())
  305. {
  306. count = database.LoadCharacterTitles(GetCharacterID(), player);
  307. if (count == 0) {
  308. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  309. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  310. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  311. }
  312. }
  313. if(!GetPlayer()->IsReturningFromLD())
  314. {
  315. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  316. if (count == 0)
  317. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  318. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  319. if (count == 0)
  320. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  321. }
  322. ClientPacketFunctions::SendLoginAccepted(this);
  323. ClientPacketFunctions::SendAbilities ( this );
  324. ClientPacketFunctions::SendCommandNamePacket(this);
  325. ClientPacketFunctions::SendQuickBarInit(this);
  326. // we only need to send the MOTD if it is the first time the person is logging in.
  327. if (firstlogin) {
  328. ClientPacketFunctions::SendMOTD(this);
  329. ClientPacketFunctions::SendCharacterMacros(this);
  330. zone_list.CheckFriendList(this);
  331. }
  332. if(!GetPlayer()->IsReturningFromLD())
  333. {
  334. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  335. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  336. {
  337. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  338. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  339. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  340. }
  341. database.LoadPlayerFactions(this);
  342. database.LoadCharacterQuests(this);
  343. database.LoadPlayerMail(this);
  344. }
  345. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  346. SendQuestJournal(true, 0, false);
  347. if (version > 546) // right version? possibly not!
  348. master_aa_list.DisplayAA(this, 0, 3);
  349. if (version > 283)
  350. SendCollectionList();
  351. SendBiography();
  352. map<int32, Quest*>::iterator itr;
  353. Quest* quest = 0;
  354. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  355. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  356. quest = itr->second;
  357. if (quest->IsTracked()) {
  358. quest->SetTracked(false);
  359. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  360. quest->SetTracked(true);
  361. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  362. }
  363. }
  364. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  365. // SendAchievementsList();
  366. /*Guild* guild = player->GetGuild();
  367. if (guild) {
  368. guild->UpdateGuildMemberInfo(GetPlayer());
  369. if (firstlogin)
  370. guild->SendGuildMOTD(this);
  371. guild->SendGuildUpdate(this);
  372. guild->SendGuildMember(GetPlayer(), firstlogin);
  373. guild->SendGuildEventList(this);
  374. guild->SendGuildBankEventList(this);
  375. guild->SendAllGuildEvents(this);
  376. guild->SendGuildMemberList(this);
  377. }*/
  378. if (version > 283) {
  379. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  380. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  381. if (outapp) {
  382. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  383. //DumpPacket(outapp);
  384. QueuePacket(outapp);
  385. }
  386. }
  387. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  388. ClientPacketFunctions::SendCommandList(this);
  389. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  390. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  391. ClientPacketFunctions::SendInstanceList(this);
  392. SendZoneInfo();
  393. /*Spell* spell = 0;
  394. vector<QuickBarItem*>::iterator itr;
  395. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  396. if((*itr)->type == 1){
  397. spell = master_spell_list.GetSpell((*itr)->id);
  398. if(spell)
  399. QueuePacket(spell->serialize(this, false, 0x20));
  400. }
  401. }*/
  402. }
  403. void Client::SendPlayerDeathWindow()
  404. {
  405. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  406. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  407. vector<RevivePoint*>::iterator itr;
  408. if (results && results->size() > 0)
  409. {
  410. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  411. if (packet)
  412. {
  413. packet->setArrayLengthByName("location_count", results->size());
  414. RevivePoint* point = 0;
  415. int32 i = 0;
  416. for (itr = results->begin(); itr != results->end(); itr++, i++)
  417. {
  418. point = *itr;
  419. if (point)
  420. {
  421. packet->setArrayDataByName("location_id", point->id, i);
  422. //zone_name = database.GetZoneName(point->zone_id);
  423. string zone_name = database.GetZoneDescription(point->zone_id);
  424. if (zone_name.length() > 0)
  425. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  426. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  427. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  428. }
  429. if (point->id == 0xFFFFFFFF)//tmp location
  430. safe_delete(point);
  431. }
  432. // done with the revive points so lets free up the pointer
  433. safe_delete(results);
  434. #if EQDEBUG >= 3
  435. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  436. packet->PrintPacket();
  437. #endif
  438. EQ2Packet* outapp = packet->serialize();
  439. QueuePacket(outapp);
  440. safe_delete(packet);
  441. }
  442. }
  443. }
  444. void Client::DisplayDeadWindow()
  445. {
  446. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  447. player->SetHP(0);
  448. player->SetPower(0);
  449. GetCurrentZone()->TriggerCharSheetTimer();
  450. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  451. if (packet)
  452. {
  453. packet->setDataByName("parameter1", 8);
  454. packet->setDataByName("value", 1);
  455. QueuePacket(packet->serialize());
  456. packet->setDataByName("parameter1", 16);
  457. QueuePacket(packet->serialize());
  458. safe_delete(packet);
  459. }
  460. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  461. if (packet)
  462. {
  463. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  464. QueuePacket(packet->serialize());
  465. safe_delete(packet);
  466. }
  467. SendPlayerDeathWindow();
  468. }
  469. void Client::HandlePlayerRevive(int32 point_id)
  470. {
  471. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  472. if (packet)
  473. {
  474. packet->setDataByName("parameter1", 8);
  475. QueuePacket(packet->serialize());
  476. packet->setDataByName("parameter1", 16);
  477. QueuePacket(packet->serialize());
  478. safe_delete(packet);
  479. }
  480. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  481. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  482. if (packet)
  483. {
  484. QueuePacket(packet->serialize());
  485. safe_delete(packet);
  486. }
  487. float origX, origY, origZ, origHeading = 0.0f;
  488. origX = player->GetX();
  489. origY = player->GetY();
  490. origZ = player->GetZ();
  491. origHeading = player->GetHeading();
  492. ZoneServer* originalZone = GetCurrentZone();
  493. int32 origGridID = GetPlayer()->appearance.pos.grid_id;
  494. float x, y, z, heading;
  495. RevivePoint* revive_point = 0;
  496. if (point_id != 0xFFFFFFFF)
  497. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  498. string zone_desc;
  499. const char* location_name = "Unknown";
  500. //revive at zone safe coords
  501. if (!revive_point)
  502. {
  503. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  504. x = GetCurrentZone()->GetSafeX();
  505. y = GetCurrentZone()->GetSafeY();
  506. z = GetCurrentZone()->GetSafeZ();
  507. heading = GetCurrentZone()->GetSafeHeading();
  508. zone_desc = GetCurrentZone()->GetZoneDescription();
  509. location_name = "Zone Safe Point";
  510. Zone(GetCurrentZone()->GetZoneName(), false);
  511. }
  512. else
  513. {
  514. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  515. x = revive_point->x;
  516. y = revive_point->y;
  517. z = revive_point->z;
  518. heading = revive_point->heading;
  519. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  520. location_name = revive_point->location_name.c_str();
  521. Zone(GetCurrentZone()->GetZoneName(), false);
  522. }
  523. player->SetResurrecting(true);
  524. player->SetX(x);
  525. player->SetY(y);
  526. player->SetZ(z);
  527. player->SetHeading(heading);
  528. player->SetHP(player->GetTotalHP());
  529. player->SetPower(player->GetTotalPower());
  530. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  531. zone_desc.c_str(),
  532. player->GetX(),
  533. player->GetY(),
  534. player->GetZ(),
  535. player->GetHeading(),
  536. player->GetHP(),
  537. player->GetPower(),
  538. location_name);
  539. //player->ClearEverything();
  540. Save();
  541. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  542. {
  543. string zone_name = database.GetZoneName(revive_point->zone_id);
  544. if (zone_name.length() == 0)
  545. {
  546. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  547. x = GetCurrentZone()->GetSafeX();
  548. y = GetCurrentZone()->GetSafeY();
  549. z = GetCurrentZone()->GetSafeZ();
  550. heading = GetCurrentZone()->GetSafeHeading();
  551. location_name = "Zone Safe Point";
  552. }
  553. else
  554. {
  555. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  556. location_name = revive_point->location_name.c_str();
  557. player->ClearEverything();
  558. Zone(zone_name.c_str(), false);
  559. }
  560. }
  561. zone_desc = GetCurrentZone()->GetZoneDescription();
  562. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  563. player->SetSpawnType(4);
  564. if (version > 283) {
  565. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  566. if (packet)
  567. {
  568. QueuePacket(packet->serialize());
  569. safe_delete(packet);
  570. }
  571. }
  572. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  573. if (packet)
  574. {
  575. packet->setDataByName("x", x);
  576. packet->setDataByName("y", y);
  577. packet->setDataByName("z", z);
  578. QueuePacket(packet->serialize());
  579. safe_delete(packet);
  580. }
  581. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  582. if (packet)
  583. {
  584. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  585. packet->setDataByName("speed", 32);
  586. packet->setDataByName("unknown2", 0);
  587. //DoF Merge: old value and speed wasn't included
  588. //packet->setDataByName("unknown2", 255);
  589. QueuePacket(packet->serialize());
  590. safe_delete(packet);
  591. }
  592. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  593. if (packet)
  594. {
  595. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  596. QueuePacket(packet->serialize());
  597. safe_delete(packet);
  598. }
  599. if(rule_manager.GetGlobalRule(R_Combat, EnableSpiritShards)->GetBool())
  600. {
  601. NPC* shard = player->InstantiateSpiritShard(origX, origY, origZ, origHeading, origGridID, originalZone);
  602. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  603. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_PRESPAWN);
  604. originalZone->RemoveSpawn(player, false, true, true, true, true);
  605. originalZone->AddSpawn(shard);
  606. if(shard->GetSpawnScript() && strlen(shard->GetSpawnScript()) > 0)
  607. originalZone->CallSpawnScript(shard, SPAWN_SCRIPT_SPAWN);
  608. }
  609. m_resurrect.writelock(__FUNCTION__, __LINE__);
  610. if (current_rez.active)
  611. current_rez.should_delete = true;
  612. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  613. }
  614. void Client::SendCharInfo() {
  615. EQ2Packet* app;
  616. player->SetEquippedItemAppearances();
  617. ClientPacketFunctions::SendCharacterData(this);
  618. SendCharPOVGhost();
  619. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  620. if (packet) {
  621. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  622. packet->setDataByName("size", .56);
  623. packet->setDataByName("unknown2", 255);
  624. packet->setDataByName("speed", player->GetSpeed());
  625. packet->setDataByName("air_speed", player->GetAirSpeed());
  626. EQ2Packet* app = packet->serialize();
  627. QueuePacket(app);
  628. safe_delete(packet);
  629. }
  630. if (version <= 283) {
  631. //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
  632. Sleep(2000);
  633. }
  634. //sending bad spawn packet?
  635. //SendAchievementsList();
  636. ClientPacketFunctions::SendCharacterSheet(this);
  637. ClientPacketFunctions::SendTraitList(this);// moved from below
  638. ClientPacketFunctions::SendAbilities(this);
  639. ClientPacketFunctions::SendSkillBook(this);
  640. if (!IsReloadingZone() && !player->IsResurrecting()) {
  641. if(GetVersion() > 546) //we will send this later on for 546 and below
  642. ClientPacketFunctions::SendUpdateSpellBook(this);
  643. }
  644. else {
  645. player->SetResurrecting(false);
  646. }
  647. ClientPacketFunctions::SendLoginCommandMessages(this);
  648. GetCurrentZone()->AddSpawn(player);
  649. if(IsReloadingZone() && (zoning_x || zoning_y || zoning_z)) {
  650. GetPlayer()->SetX(zoning_x);
  651. GetPlayer()->SetY(zoning_y);
  652. GetPlayer()->SetZ(zoning_z);
  653. GetPlayer()->SetHeading(zoning_h);
  654. EQ2Packet* packet = GetPlayer()->Move(zoning_x, zoning_y, zoning_z, GetVersion(), zoning_h);
  655. QueuePacket(packet);
  656. }
  657. //SendCollectionList();
  658. Guild* guild = player->GetGuild();
  659. if (guild)
  660. guild->GuildMemberLogin(this, firstlogin);
  661. app = player->GetPlayerItemList()->serialize(GetPlayer(), GetVersion());
  662. if (app) {
  663. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  664. //DumpPacket(app);
  665. QueuePacket(app);
  666. }
  667. app = player->GetEquipmentList()->serialize(GetVersion(), player);
  668. if (app) {
  669. QueuePacket(app);
  670. }
  671. app = player->GetAppearanceEquipmentList()->serialize(GetVersion(), player);
  672. if (app) {
  673. QueuePacket(app);
  674. }
  675. vector<Item*>* items = player->GetPlayerItemList()->GetItemsFromBagID(-3); // bank items
  676. if (items && items->size() > 0) {
  677. for (int32 i = 0; i < items->size(); i++) {
  678. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  679. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  680. //DumpPacket(outapp);
  681. QueuePacket(outapp);
  682. }
  683. }
  684. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  685. QueuePacket(app);
  686. safe_delete(items);
  687. items = player->GetPlayerItemList()->GetItemsFromBagID(-4); //shared bank items
  688. if (items && items->size() > 0) {
  689. for (int32 i = 0; i < items->size(); i++)
  690. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  691. }
  692. safe_delete(items);
  693. if (version > 283) {
  694. SendTitleUpdate();
  695. }
  696. GetPlayer()->ChangePrimaryWeapon();
  697. GetPlayer()->ChangeSecondaryWeapon();
  698. GetPlayer()->ChangeRangedWeapon();
  699. if(!GetPlayer()->IsReturningFromLD()) {
  700. database.LoadBuyBacks(this);
  701. }
  702. if (version > 546)
  703. master_aa_list.DisplayAA(this, 0, 0);
  704. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  705. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  706. string zone_motd_send = "Zone MOTD: " + zone_motd;
  707. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  708. }
  709. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  710. if (zone_script && lua_interface)
  711. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  712. this->client_zoning = false;
  713. this->zoning_id = 0;
  714. this->zoning_instance_id = 0;
  715. SetZoningDestination(nullptr);
  716. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  717. GetCurrentZone()->AddDamagedSpawn(player);
  718. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  719. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  720. if (firstlogin)
  721. firstlogin = false;
  722. player->ClearProcs();
  723. items = player->GetEquippedItemList();
  724. if (items && items->size() > 0) {
  725. for (int32 i = 0; i < items->size(); i++) {
  726. Item* item = items->at(i);
  727. if (item && item->GetItemScript() && lua_interface)
  728. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  729. }
  730. }
  731. //Allow this player to change their last name if they meet the level requirement
  732. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  733. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  734. safe_delete(items);
  735. if (!player->Alive())
  736. DisplayDeadWindow();
  737. ClientPacketFunctions::SendLocalizedTextMessage(this);
  738. if (GetCurrentZone()->GetInstanceID())
  739. {
  740. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  741. if (ph) {
  742. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  743. string name = string(GetPlayer()->GetName());
  744. if (name.compare(ph->player_name) == 0)
  745. SetHasOwnerOrEditAccess(true);
  746. }
  747. }
  748. if (version > 546)
  749. ClientPacketFunctions::SendHousingList(this);
  750. bool groupMentor = false;
  751. GetPlayer()->group_id = rejoin_group_id;
  752. if(!world.RejoinGroup(this, rejoin_group_id))
  753. GetPlayer()->group_id = 0;
  754. else
  755. {
  756. Entity* ent = world.GetGroupManager()->IsPlayerInGroup(rejoin_group_id, GetPlayer()->GetGroupMemberInfo()->mentor_target_char_id);
  757. if(ent && ent->IsPlayer())
  758. {
  759. GetPlayer()->SetMentorStats(ent->GetLevel(), ent->GetID());
  760. groupMentor = true;
  761. }
  762. }
  763. if(!groupMentor)
  764. GetPlayer()->SetMentorStats(GetPlayer()->GetLevel(), 0);
  765. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_MAINTAINEDEFFECTS);
  766. database.LoadCharacterSpellEffects(GetCharacterID(), this, DB_TYPE_SPELLEFFECTS);
  767. GetPlayer()->SetSaveSpellEffects(false);
  768. GetPlayer()->SetCharSheetChanged(true);
  769. GetPlayer()->SetReturningFromLD(false);
  770. }
  771. void Client::SendZoneSpawns() {
  772. //Allows us to place spawns almost anywhere
  773. if (version > 283) {
  774. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  775. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  776. QueuePacket(app);
  777. }
  778. ClientPacketFunctions::SendSkillSlotMappings(this);
  779. ClientPacketFunctions::SendGameWorldTime(this);
  780. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  781. }
  782. void Client::SendCharPOVGhost() {
  783. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  784. if (set_pov) {
  785. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  786. EQ2Packet* app_pov = set_pov->serialize();
  787. QueuePacket(app_pov);
  788. safe_delete(set_pov);
  789. }
  790. }
  791. void Client::SendZoneInfo() {
  792. ZoneServer* zone = GetCurrentZone();
  793. if (zone) {
  794. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  795. QueuePacket(packet);
  796. if (version > 283) {
  797. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  798. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  799. #if EQDEBUG >= 9
  800. fog_packet->PrintPacket();
  801. #endif
  802. if (fog_packet) {
  803. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  804. QueuePacket(fog_packet->serialize());
  805. safe_delete(fog_packet);
  806. }
  807. zone->SendFlightPathsPackets(this);
  808. }
  809. }
  810. /*
  811. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,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,0xFF,0xFF,0xFF,0xFF
  814. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  815. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  816. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,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,0x00,0x00
  833. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  834. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  835. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,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,0x00,0x00,0x00
  839. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  840. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  841. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  842. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  843. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  844. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  845. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  846. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  847. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  848. QueuePacket(appA);
  849. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  850. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  851. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  852. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  853. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  854. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  855. QueuePacket(appB);
  856. */
  857. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  858. SendFriendList();
  859. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  860. SendIgnoreList();
  861. }
  862. void Client::SendDefaultGroupOptions() {
  863. /*
  864. 0 - loot method
  865. 1 - loot items rarity
  866. 2 - Auto split coin
  867. 4 - default yell method
  868. 6 - group autolock
  869. 7 - solo autolock
  870. */
  871. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  872. if (default_options) {
  873. default_options->setDataByName("loot_method", 1);
  874. default_options->setDataByName("loot_items_rarity", 1);
  875. default_options->setDataByName("auto_split_coin", 1);
  876. default_options->setDataByName("default_yell_method", 1);
  877. EQ2Packet* app7 = default_options->serialize();
  878. QueuePacket(app7);
  879. safe_delete(default_options);
  880. }
  881. }
  882. bool Client::HandlePacket(EQApplicationPacket* app) {
  883. bool ret = true;
  884. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  885. //DumpPacket(app);
  886. #if EQDEBUG >= 9
  887. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  888. DumpPacket(app, true);
  889. #endif
  890. EmuOpcode opcode = app->GetOpcode();
  891. #if EQDEBUG >= 9
  892. const char* name = app->GetOpcodeName();
  893. if (name)
  894. cout << name;
  895. else
  896. cout << "Unknown";
  897. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  898. DumpPacket(app);
  899. #endif
  900. //if (opcode != OP_UpdatePositionMsg) {
  901. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  902. //}
  903. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  904. {
  905. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  906. }
  907. switch (opcode) {
  908. case _maxEmuOpcode:
  909. break;
  910. case OP_LoginByNumRequestMsg: {
  911. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  912. PacketStruct* request;
  913. request = configReader.getStruct("LoginByNumRequest", 1);
  914. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  915. // test the original location of Version for clients older than 1212
  916. version = request->getType_int16_ByName("version");
  917. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  918. // must be new client data version method, re-fetch the packet
  919. safe_delete(request);
  920. request = configReader.getStruct("LoginByNumRequest", 1208);
  921. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  922. // Xinux suggests using an INT16 here. Our first new version = 57000
  923. version = request->getType_int16_ByName("version");
  924. }
  925. else {
  926. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  927. break;
  928. }
  929. }
  930. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  931. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  932. ClientPacketFunctions::SendLoginDenied(this);
  933. return false;
  934. }
  935. int32 account_id = request->getType_int32_ByName("account_id");
  936. int32 access_code = request->getType_int32_ByName("access_code");
  937. if (!HandleNewLogin(account_id, access_code))
  938. return false;
  939. }
  940. safe_delete(request);
  941. break;
  942. }
  943. case OP_MapRequest: {
  944. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  945. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  946. if (packet && app->size > 2 && GetCurrentZone()) {
  947. packet->LoadPacketData(app->pBuffer, app->size);
  948. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  949. if (fog_packet) {
  950. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  951. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  952. fog_packet->setDataByName("unknown1", 1);
  953. fog_packet->setDataByName("unknown3", 1);
  954. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  955. //fog_packet->PrintPacket();
  956. QueuePacket(fog_packet->serialize());
  957. safe_delete(fog_packet);
  958. }
  959. safe_delete(packet);
  960. }
  961. break;
  962. }
  963. case OP_RequestCampMsg: {
  964. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  965. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  966. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  967. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  968. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  969. request->getType_int8_ByName("quit"),
  970. request->getType_int8_ByName("camp_desktop"),
  971. request->getType_int16_ByName("camp_char_select"),
  972. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  973. //DumpPacket(app->pBuffer, app->size);
  974. //request->PrintPacket();
  975. if (!camp_timer) {
  976. int16 camp_time = 20; // default if rule cannot be found
  977. if (GetAdminStatus() >= 100)
  978. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  979. else
  980. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  981. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  982. if (response) {
  983. bool disconnect = false;
  984. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  985. // Command: /camp desktop
  986. // Command: /quit
  987. response->setDataByName("camp_desktop", 1);
  988. disconnect = true;
  989. }
  990. else {
  991. // Command: /camp
  992. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  993. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  994. response->setDataByName("seconds", camp_time);
  995. }
  996. camp_timer = new Timer(camp_time * 1000);
  997. camp_timer->Enable();
  998. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  999. // /camp {char_name}
  1000. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  1001. }
  1002. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  1003. // /camp (go back to char selection screen)
  1004. response->setDataByName("char_name", " ");
  1005. response->setDataByName("camp_char_select", 1);
  1006. }
  1007. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  1008. response->getType_int8_ByName("seconds"),
  1009. response->getType_int8_ByName("camp_desktop"),
  1010. response->getType_int8_ByName("camp_char_select"),
  1011. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  1012. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  1013. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  1014. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  1015. //response->PrintPacket();
  1016. QueuePacket(response->serialize());
  1017. safe_delete(response);
  1018. if (disconnect)
  1019. Disconnect();
  1020. }
  1021. }
  1022. }
  1023. safe_delete(request);
  1024. break;
  1025. }
  1026. case OP_StoodMsg: {
  1027. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  1028. if (camp_timer)
  1029. {
  1030. // JA: clear camping flag
  1031. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1032. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1033. safe_delete(camp_timer);
  1034. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1035. QueuePacket(outapp);
  1036. }
  1037. player->SetTempVisualState(0);
  1038. break;
  1039. }
  1040. case OP_StandMsg: {
  1041. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  1042. if (camp_timer)
  1043. {
  1044. // JA: clear camping flag
  1045. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1046. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1047. safe_delete(camp_timer);
  1048. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1049. QueuePacket(outapp);
  1050. }
  1051. player->SetTempVisualState(539);
  1052. break;
  1053. }
  1054. case OP_SitMsg: {
  1055. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  1056. player->SetTempVisualState(538);
  1057. break;
  1058. }
  1059. case OP_SatMsg: {
  1060. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  1061. player->SetTempVisualState(540);
  1062. break;
  1063. }
  1064. case OP_QuestJournalOpenMsg:
  1065. case OP_QuestJournalInspectMsg: {
  1066. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  1067. if (app->size < sizeof(int32))
  1068. break;
  1069. int32 quest_id = 0;
  1070. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  1071. Quest* quest = GetActiveQuest(quest_id);
  1072. if (quest)
  1073. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  1074. else {
  1075. quest = player->GetCompletedQuest(quest_id);
  1076. if (quest)
  1077. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  1078. }
  1079. break;
  1080. }
  1081. case OP_QuestJournalSetVisibleMsg: {
  1082. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  1083. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  1084. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1085. int32 quest_id = packet->getType_int32_ByName("quest_id");
  1086. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  1087. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  1088. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  1089. if (player_quests) {
  1090. if (player_quests->count(quest_id) > 0)
  1091. player_quests->at(quest_id)->SetHidden(hidden);
  1092. else
  1093. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1094. }
  1095. else
  1096. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1097. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  1098. safe_delete(packet);
  1099. }
  1100. break;
  1101. }
  1102. case OP_MacroUpdateMsg: {
  1103. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1104. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1105. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1106. vector<string>* update = new vector<string>;
  1107. int8 number = macro_update->getType_int8_ByName("number");
  1108. int16 icon = macro_update->getType_int16_ByName("icon");
  1109. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1110. int8 count = macro_update->getType_int8_ByName("macro_count");
  1111. if (GetVersion() <= 283) {
  1112. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1113. }
  1114. else {
  1115. for (int8 i = 0; i < count; i++) {
  1116. char tmp_command[15] = { 0 };
  1117. sprintf(tmp_command, "command_%i", i);
  1118. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1119. }
  1120. }
  1121. if (name.length() == 0)
  1122. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1123. else
  1124. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1125. safe_delete(update);
  1126. safe_delete(macro_update);
  1127. }
  1128. break;
  1129. }
  1130. case OP_DialogSelectMsg: {
  1131. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1132. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1133. if (packet) {
  1134. packet->LoadPacketData(app->pBuffer, app->size);
  1135. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1136. int32 response_index = packet->getType_int32_ByName("response");
  1137. if (GetCurrentZone()) {
  1138. MConversation.readlock();
  1139. Spawn* spawn = conversation_spawns[conversation_id];
  1140. Item* item = conversation_items[conversation_id];
  1141. MConversation.releasereadlock();
  1142. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1143. if (spawn)
  1144. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1145. else if (item && lua_interface && item->GetItemScript())
  1146. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1147. else
  1148. CloseDialog(conversation_id);
  1149. }
  1150. else
  1151. CloseDialog(conversation_id);
  1152. }
  1153. safe_delete(packet);
  1154. }
  1155. break;
  1156. }
  1157. case OP_CancelMoveObjectModeMsg: {
  1158. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1159. if (GetTempPlacementSpawn())
  1160. {
  1161. Spawn* tmp = GetTempPlacementSpawn();
  1162. SetTempPlacementSpawn(nullptr);
  1163. SetPlacementUniqueItemID(0);
  1164. GetCurrentZone()->RemoveSpawn(tmp, true, false, true, true, true);
  1165. break; // break out early if we are tied to a temp spawn
  1166. }
  1167. // if we are moving some other object? other use-cases not covered
  1168. break;
  1169. }
  1170. case OP_PositionMoveableObject: {
  1171. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1172. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1173. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1174. Spawn* spawn = 0;
  1175. if (GetTempPlacementSpawn())
  1176. spawn = GetTempPlacementSpawn();
  1177. else
  1178. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1179. if (!spawn) {
  1180. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1181. break;
  1182. }
  1183. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1184. {
  1185. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1186. break;
  1187. }
  1188. // handles instantiation logic + adding to zone of a new house object
  1189. PopulateHouseSpawn(place_object);
  1190. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1191. char query[256];
  1192. switch (GetSpawnPlacementMode())
  1193. {
  1194. case ServerSpawnPlacementMode::OPEN_HEADING:
  1195. {
  1196. if (spawn && spawn->IsWidget())
  1197. {
  1198. Widget* widget = (Widget*)spawn;
  1199. widget->SetOpenHeading(newHeading);
  1200. widget->SetIncludeHeading(true);
  1201. spawn->position_changed = true;
  1202. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1203. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1204. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1205. }
  1206. else
  1207. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1208. break;
  1209. }
  1210. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1211. {
  1212. if (spawn && spawn->IsWidget())
  1213. {
  1214. Widget* widget = (Widget*)spawn;
  1215. widget->SetClosedHeading(newHeading);
  1216. widget->SetIncludeHeading(true);
  1217. spawn->position_changed = true;
  1218. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1219. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1220. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1221. if (spawn->GetSpawnLocationID())
  1222. {
  1223. Query query;
  1224. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1225. }
  1226. }
  1227. else
  1228. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1229. break;
  1230. }
  1231. default:
  1232. {
  1233. spawn->SetX(place_object->getType_float_ByName("x"));
  1234. spawn->SetY(place_object->getType_float_ByName("y"));
  1235. spawn->SetZ(place_object->getType_float_ByName("z"));
  1236. spawn->SetHeading(newHeading);
  1237. spawn->SetSpawnOrigX(spawn->GetX());
  1238. spawn->SetSpawnOrigY(spawn->GetY());
  1239. spawn->SetSpawnOrigZ(spawn->GetZ());
  1240. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1241. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1242. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1243. else if (spawn->GetSpawnLocationID() > 0)
  1244. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1245. }
  1246. }
  1247. PopulateHouseSpawnFinalize();
  1248. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1249. safe_delete(place_object);
  1250. }
  1251. break;
  1252. }
  1253. case OP_CampAbortedMsg: {
  1254. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1255. if (camp_timer)
  1256. {
  1257. // JA: clear camping flag
  1258. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1259. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1260. safe_delete(camp_timer);
  1261. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1262. QueuePacket(outapp);
  1263. }
  1264. break;
  1265. }
  1266. case OP_DoneLoadingUIResourcesMsg: {
  1267. ClientPacketFunctions::SendUpdateSpellBook(this);
  1268. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1269. QueuePacket(app);
  1270. if(!player_loading_complete)
  1271. {
  1272. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  1273. if (zone_script && lua_interface)
  1274. lua_interface->RunZoneScript(zone_script, "player_loadcomplete", GetCurrentZone(), GetPlayer());
  1275. player_loading_complete = true;
  1276. }
  1277. break;
  1278. }
  1279. case OP_DoneLoadingZoneResourcesMsg: {
  1280. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1281. SendZoneSpawns();
  1282. break;
  1283. }
  1284. case OP_DefaultGroupOptionsRequestMsg: {
  1285. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1286. SendDefaultGroupOptions();
  1287. break;
  1288. }
  1289. case OP_DoneLoadingEntityResourcesMsg: {
  1290. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1291. if (!IsReadyForSpawns())
  1292. SetReadyForSpawns(true);
  1293. SendCharInfo();
  1294. pos_update.Start();
  1295. quest_pos_timer.Start();
  1296. break;
  1297. }
  1298. case OP_LootItemsRequestMsg: {
  1299. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1300. HandleLoot(app);
  1301. break;
  1302. }
  1303. case OP_WaypointSelectMsg: {
  1304. PacketStruct* packet = configReader.getStruct("WS_WaypointSelect", GetVersion());
  1305. if (packet) {
  1306. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1307. int32 selection = packet->getType_int32_ByName("selection");
  1308. if (selection > 0) {
  1309. SelectWaypoint(selection);
  1310. }
  1311. }
  1312. }
  1313. break;
  1314. }
  1315. case OP_KnowledgeWindowSlotMappingMsg: {
  1316. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1317. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1318. if (packet) {
  1319. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1320. int num_updates = packet->getType_int16_ByName("spell_count");
  1321. int32 spell_id = 0;
  1322. int16 slot_id = 0;
  1323. char tmp_spell_id[15];
  1324. char tmp_slot[15];
  1325. for (int i = 0; i < num_updates; i++) {
  1326. memset(tmp_spell_id, 0, 15);
  1327. memset(tmp_slot, 0, 15);
  1328. sprintf(tmp_spell_id, "spell_id_%i", i);
  1329. sprintf(tmp_slot, "slot_id_%i", i);
  1330. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1331. if (spell_id > 0) {
  1332. slot_id = packet->getType_int16_ByName(tmp_slot);
  1333. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1334. if (spell && spell->slot != slot_id) {
  1335. spell->slot = slot_id;
  1336. spell->save_needed = true;
  1337. }
  1338. }
  1339. }
  1340. }
  1341. safe_delete(packet);
  1342. }
  1343. //SendKnowledgeWindowSlot();
  1344. break;
  1345. }
  1346. case OP_ReadyToZoneMsg: {
  1347. if (!IsReadyForSpawns())
  1348. {
  1349. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1350. }
  1351. else
  1352. {
  1353. if(zoning_destination)
  1354. SetCurrentZone(zoning_destination);
  1355. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1356. bool succeed_override_zone = true;
  1357. if(!GetCurrentZone()) {
  1358. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone and zone is not there! Emergency boot!", player->GetName());
  1359. if(zoning_instance_id) {
  1360. ZoneServer* zone = zone_list.GetByInstanceID(zoning_instance_id, zoning_id, true);
  1361. if(!zone) {
  1362. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver instance id %u zone id %u.", player->GetName(), zoning_instance_id, zoning_id);
  1363. succeed_override_zone = false;
  1364. }
  1365. else {
  1366. SetCurrentZone(zone);
  1367. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique instance has been created for %s through emergency boot!", player->GetName());
  1368. }
  1369. }
  1370. else if(zoning_id) {
  1371. ZoneServer* zone = zone_list.Get(zoning_id, true, true);
  1372. if(!zone) {
  1373. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Emergency boot failed for %s, unable to get zoneserver zone id %u.", player->GetName(), zoning_id);
  1374. succeed_override_zone = false;
  1375. }
  1376. else {
  1377. SetCurrentZone(zone);
  1378. LogWrite(WORLD__WARNING, 0, "World", "OP_ReadyToZone: Unique zone has been created for %s through emergency boot!", player->GetName());
  1379. }
  1380. }
  1381. }
  1382. if (client_zoning)
  1383. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1384. else
  1385. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1386. Disconnect();
  1387. }
  1388. break;
  1389. }
  1390. case OP_ClientFellMsg: {
  1391. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1392. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1393. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1394. float height = request->getType_float_ByName("height");
  1395. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1396. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1397. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1398. break;
  1399. }*/
  1400. float safe_height = 13.0f;
  1401. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1402. GetPlayer()->MStats.lock();
  1403. float deflectionStat = GetPlayer()->stats[ITEM_STAT_SAFE_FALL];
  1404. GetPlayer()->MStats.unlock();
  1405. if (skill)
  1406. safe_height += (skill->current_val + 1 + deflectionStat) / 5;
  1407. if (height > safe_height) {
  1408. int16 damage = (int16)ceil((height - safe_height) * 125);
  1409. if (height >= 80)
  1410. damage = 30000;
  1411. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1412. if (damage > 0) {
  1413. GetPlayer()->TakeDamage(damage);
  1414. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1415. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1416. if (!GetPlayer()->GetInvulnerable())
  1417. GetPlayer()->SetCharSheetChanged(true);
  1418. 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);
  1419. if (GetPlayer()->GetHP() == 0) {
  1420. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1421. }
  1422. }
  1423. }
  1424. safe_delete(request);
  1425. }
  1426. break;
  1427. }
  1428. case OP_MapFogDataUpdateMsg: {
  1429. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1430. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1431. break;
  1432. }
  1433. case OP_SelectZoneTeleporterDestinatio: {
  1434. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1435. ProcessTeleportLocation(app);
  1436. break;
  1437. }
  1438. case OP_SendLatestRequestMsg: {
  1439. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1440. uchar blah25[] = { 0x01 };
  1441. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1442. QueuePacket(app25);
  1443. break;
  1444. }
  1445. case OP_ShowCreateFromRecipeUIMsg: {
  1446. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1447. break;
  1448. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1449. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1450. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1451. QueuePacket(app);
  1452. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1453. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1454. QueuePacket(app);
  1455. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1456. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1457. ,0xff,0xff,0xff};
  1458. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1459. QueuePacket(app);
  1460. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1461. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1462. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1463. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1464. QueuePacket(app);
  1465. uchar blah5[] ={0x00,0x00};
  1466. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1467. QueuePacket(app);
  1468. break;*/
  1469. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1470. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1471. //QueuePacket(app);
  1472. }
  1473. case OP_BeginItemCreationMsg: {
  1474. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1475. //DumpPacket(app->pBuffer, app->size);
  1476. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1477. if (packet) {
  1478. packet->LoadPacketData(app->pBuffer, app->size);
  1479. int32 item = 0;
  1480. vector<int32> items;
  1481. char tmp_item_id[20];
  1482. item = packet->getType_int32_ByName("primary_component_id");
  1483. if (item > 0)
  1484. items.push_back(item);
  1485. item = 0;
  1486. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1487. for (int8 i = 0; i < build_components; i++) {
  1488. memset(tmp_item_id, 0, 20);
  1489. sprintf(tmp_item_id, "component_id_%i", i);
  1490. item = packet->getType_int32_ByName(tmp_item_id);
  1491. if (item > 0)
  1492. items.push_back(item);
  1493. item = 0;
  1494. }
  1495. item = packet->getType_int32_ByName("fuel_id");
  1496. if (item > 0)
  1497. items.push_back(item);
  1498. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1499. safe_delete(packet);
  1500. }
  1501. break;
  1502. }
  1503. case OP_StopItemCreationMsg: {
  1504. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1505. //DumpPacket(app->pBuffer, app->size);
  1506. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1507. break;
  1508. }
  1509. case OP_SysClient:
  1510. case OP_SignalMsg: {
  1511. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient/OP_SignalMsg", opcode, opcode);
  1512. PacketStruct* packet = configReader.getStruct("WS_Signal", 1);
  1513. if (packet) {
  1514. packet->LoadPacketData(app->pBuffer, app->size);
  1515. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1516. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1517. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  1518. SetReloadingZone(false);
  1519. if(GetPlayer()->IsDeletedSpawn()) {
  1520. GetPlayer()->SetDeletedSpawn(false);
  1521. }
  1522. ResetZoningCoords();
  1523. SetReadyForUpdates();
  1524. GetPlayer()->SendSpawnChanges(true);
  1525. ProcessStateCommands();
  1526. GetPlayer()->changed = true;
  1527. GetPlayer()->info_changed = true;
  1528. GetPlayer()->vis_changed = true;
  1529. player_pos_changed = true;
  1530. GetPlayer()->AddChangedZoneSpawn();
  1531. }
  1532. else {
  1533. LogWrite(CCLIENT__WARNING, 0, "Client", "Player %s reported SysClient/SignalMsg state %s.", GetPlayer()->GetName(), str.data.c_str());
  1534. }
  1535. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1536. if (zone_script && lua_interface)
  1537. {
  1538. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1539. }
  1540. }
  1541. break;
  1542. }
  1543. case OP_EntityVerbsRequestMsg: {
  1544. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1545. HandleVerbRequest(app);
  1546. break;
  1547. }
  1548. case OP_EntityVerbsVerbMsg: {
  1549. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1550. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1551. if (packet) {
  1552. packet->LoadPacketData(app->pBuffer, app->size);
  1553. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1554. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1555. Spawn* spawn = player->GetTarget();
  1556. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1557. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1558. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1559. {
  1560. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1561. if (spawn->IsGroundSpawn())
  1562. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1563. else if (spawn->IsObject())
  1564. ((Object*)spawn)->HandleUse(this, command);
  1565. else if (spawn->IsWidget())
  1566. ((Widget*)spawn)->HandleUse(this, command);
  1567. else if (spawn->IsSign())
  1568. ((Sign*)spawn)->HandleUse(this, command);
  1569. }
  1570. }
  1571. }
  1572. else {
  1573. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1574. if (command.size > 0) {
  1575. string command_name = command.data;
  1576. if (command_name.find(" ") < 0xFFFFFFFF) {
  1577. if (GetVersion() <= 546) { //this version uses commands in the form "Buy From Merchant" instead of buy_from_merchant
  1578. string::size_type pos = command_name.find(" ");
  1579. while(pos != string::npos){
  1580. command_name.replace(pos, 1, "_");
  1581. pos = command_name.find(" ");
  1582. }
  1583. }
  1584. else
  1585. command_name = command_name.substr(0, command_name.find(" "));
  1586. }
  1587. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1588. if (handler != 0xFFFFFFFF) {
  1589. if (command.data == command_name) {
  1590. command.data = "";
  1591. command.size = 0;
  1592. }
  1593. else {
  1594. command.data = command.data.substr(command.data.find(" ") + 1);
  1595. command.size = command.data.length();
  1596. }
  1597. commands.Process(handler, &command, this);
  1598. }
  1599. else {
  1600. if (spawn && spawn->IsNPC()) {
  1601. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1602. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1603. command_name = command.data;
  1604. string::size_type pos = command_name.find(" ");
  1605. while (pos != string::npos) {
  1606. command_name.replace(pos, 1, "_");
  1607. pos = command_name.find(" ");
  1608. }
  1609. if (!((NPC*)spawn)->HandleUse(this, command_name)) { //convert the spaces to underscores and see if that makes a difference
  1610. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1611. }
  1612. }
  1613. }
  1614. }
  1615. else
  1616. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1617. }
  1618. }
  1619. }
  1620. safe_delete(packet);
  1621. }
  1622. break;
  1623. }
  1624. case OP_SkillInfoRequest: {
  1625. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1626. HandleSkillInfoRequest(app);
  1627. break;
  1628. }
  1629. case OP_UpdateTargetMsg: {
  1630. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1631. int16 index = 0;
  1632. memcpy(&index, app->pBuffer, sizeof(int16));
  1633. if (index == 0xFFFF)
  1634. GetPlayer()->SetTarget(0);
  1635. else {
  1636. Spawn* spawn = GetPlayer()->GetSpawnByIndex(index);
  1637. if(spawn)
  1638. GetPlayer()->SetTarget(spawn);
  1639. else {
  1640. LogWrite(PLAYER__ERROR, 1, "Player", "Player %s tried to target %u index, but that index was not valid.", GetPlayer()->GetName(), index);
  1641. }
  1642. }
  1643. if (GetPlayer()->GetTarget())
  1644. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1645. //player->SetTarget((int16*)app->pBuffer);
  1646. break;
  1647. }
  1648. case OP_ExamineInfoRequestMsg: {
  1649. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1650. HandleExamineInfoRequest(app);
  1651. break;
  1652. }
  1653. case OP_QuickbarUpdateMsg:
  1654. //case OP_QuickbarAddMsg:
  1655. {
  1656. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1657. HandleQuickbarUpdateRequest(app);
  1658. break;
  1659. }
  1660. case OP_PredictionUpdateMsg: {
  1661. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1662. if (version <= 546) {
  1663. int8 offset = 9;
  1664. if (app->pBuffer[0] == 0xFF)
  1665. offset += 2;
  1666. if (app->size > offset) {
  1667. if (player->IsCasting()) {
  1668. float distance = 0;
  1669. float x = player->GetX();
  1670. float y = player->GetY();
  1671. float z = player->GetZ();
  1672. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1673. distance = player->GetDistance(x, y, z, false);
  1674. if (distance > .5)
  1675. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1676. }
  1677. else
  1678. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1679. player_pos_changed = true;
  1680. //DumpPacket(app);
  1681. }
  1682. }
  1683. else {
  1684. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1685. QueuePacket(app);
  1686. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1687. }
  1688. break;
  1689. }
  1690. case OP_RemoteCmdMsg: {
  1691. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1692. if (app->size > 0) {
  1693. EQ2_CommandString remote(app->pBuffer, app->size);
  1694. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1695. #if EQDEBUG >= 9
  1696. DumpPacket(app);
  1697. #endif
  1698. commands.Process(remote.handler, &remote.command, this);
  1699. }
  1700. else //bad client, disconnect
  1701. Disconnect();
  1702. break;
  1703. }
  1704. case OP_CancelSpellCast: {
  1705. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1706. current_zone->Interrupted(player, 0, 0, true);
  1707. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1708. break;
  1709. }
  1710. case OP_UpdatePositionMsg: {
  1711. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1712. int8 offset = 13;
  1713. if (app->pBuffer[0] == 0xFF)
  1714. offset += 2;
  1715. if (app->size > offset) {
  1716. if (player->IsCasting()) {
  1717. float distance = 0;
  1718. float x = player->GetX();
  1719. float y = player->GetY();
  1720. float z = player->GetZ();
  1721. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1722. distance = player->GetDistance(x, y, z, false);
  1723. if (distance > .5)
  1724. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1725. }
  1726. else
  1727. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1728. player_pos_changed = true;
  1729. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1730. //DumpPacket(app);
  1731. }
  1732. break;
  1733. }
  1734. case OP_MailSendMessageMsg: {
  1735. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1736. HandleSentMail(app);
  1737. break;
  1738. }
  1739. case OP_StopTrackingMsg: {
  1740. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1741. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1742. break;
  1743. }
  1744. case OP_BeginTrackingMsg: {
  1745. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1746. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1747. if (packet) {
  1748. packet->LoadPacketData(app->pBuffer, app->size);
  1749. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1750. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1751. if (spawn) {
  1752. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1753. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1754. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1755. }
  1756. safe_delete(packet);
  1757. }
  1758. break;
  1759. }
  1760. case OP_BioUpdateMsg: {
  1761. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1762. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1763. if (packet) {
  1764. packet->LoadPacketData(app->pBuffer, app->size);
  1765. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1766. safe_delete(packet);
  1767. }
  1768. break;
  1769. }
  1770. case OP_RewardPackMsg: {
  1771. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1772. /* 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
  1773. when we come across it (scatman) */
  1774. const char* name = app->GetOpcodeName();
  1775. if (name)
  1776. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1777. else
  1778. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1779. //DumpPacket(app);
  1780. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1781. if (packet) {
  1782. packet->LoadPacketData(app->pBuffer, app->size);
  1783. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1784. /* Player has contacted a guild recruiter */
  1785. if (recruiter_name.length() > 0) {
  1786. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1787. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1788. if (recruiter && guild) {
  1789. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1790. 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()));
  1791. recruiter->PlaySound("ui_guild_page");
  1792. }
  1793. }
  1794. /* New picture taken for guild recruiting */
  1795. else {
  1796. //DumpPacket(app->pBuffer, app->size);
  1797. int32 guild_id = 0;
  1798. int16 picture_data_size = 0;
  1799. unsigned char* recruiter_picture_data = 0;
  1800. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1801. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1802. Guild* guild = guild_list.GetGuild(guild_id);
  1803. if (guild) {
  1804. GuildMember* gm = guild->GetGuildMember(player);
  1805. if (gm) {
  1806. safe_delete_array(gm->recruiter_picture_data);
  1807. recruiter_picture_data = new unsigned char[picture_data_size];
  1808. for (int16 i = 0; i < picture_data_size; i++)
  1809. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1810. gm->recruiter_picture_data = recruiter_picture_data;
  1811. gm->recruiter_picture_data_size = picture_data_size;
  1812. guild->SetMemberSaveNeeded(true);
  1813. }
  1814. }
  1815. }
  1816. safe_delete(packet);
  1817. }
  1818. break;
  1819. }
  1820. case OP_PetOptions: {
  1821. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1822. Spawn* target = player->GetTarget();
  1823. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1824. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1825. bool change = false;
  1826. packet->LoadPacketData(app->pBuffer, app->size);
  1827. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1828. if (strlen(name.c_str()) != 0) {
  1829. target->SetName(name.c_str());
  1830. player->GetInfoStruct()->set_pet_name(name);
  1831. GetCurrentZone()->SendUpdateTitles(target);
  1832. change = true;
  1833. }
  1834. int8 pet_behavior = player->GetInfoStruct()->get_pet_behavior();
  1835. // Check protect self setting and update if needed
  1836. if (packet->getType_int8_ByName("protect_self") == 1) {
  1837. if ((pet_behavior & 2) == 0) {
  1838. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 2);
  1839. change = true;
  1840. }
  1841. }
  1842. else {
  1843. if ((pet_behavior & 2) != 0) {
  1844. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 2);
  1845. change = true;
  1846. }
  1847. }
  1848. // Check protect master setting and update if needed
  1849. if (packet->getType_int8_ByName("protect_master") == 1) {
  1850. if ((pet_behavior & 1) == 0) {
  1851. player->GetInfoStruct()->set_pet_behavior(pet_behavior + 1);
  1852. change = true;
  1853. }
  1854. }
  1855. else {
  1856. if ((pet_behavior & 1) != 0) {
  1857. player->GetInfoStruct()->set_pet_behavior(pet_behavior - 1);
  1858. change = true;
  1859. }
  1860. }
  1861. int8 pet_movement = player->GetInfoStruct()->get_pet_movement();
  1862. // Check stay/follow setting and update if needed
  1863. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1864. if (pet_movement != 2) {
  1865. player->GetInfoStruct()->set_pet_movement(2);
  1866. change = true;
  1867. }
  1868. }
  1869. else {
  1870. if (pet_movement != 1) {
  1871. player->GetInfoStruct()->set_pet_movement(1);
  1872. change = true;
  1873. }
  1874. }
  1875. // Ranged/Melee settings are not implemented yet
  1876. if (change)
  1877. player->SetCharSheetChanged(true);
  1878. safe_delete(packet);
  1879. }
  1880. break;
  1881. }
  1882. case OP_RecipeBook: {
  1883. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1884. SendRecipeList();
  1885. break;
  1886. }
  1887. case OP_BuyPlayerHouseMsg: {
  1888. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1889. DumpPacket(app);
  1890. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1891. if (packet) {
  1892. packet->LoadPacketData(app->pBuffer, app->size);
  1893. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1894. if (hz) {
  1895. int8 disable_alignment_req = rule_manager.GetGlobalRule(R_Player, DisableHouseAlignmentRequirement)->GetInt8();
  1896. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1897. if (houses.size() > 24)
  1898. {
  1899. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1900. safe_delete(packet);
  1901. break;
  1902. }
  1903. if(disable_alignment_req && hz->alignment > 0 && hz->alignment != GetPlayer()->GetAlignment())
  1904. {
  1905. std::string req = "You must be of ";
  1906. if (hz->alignment == 1)
  1907. req.append("Good");
  1908. else
  1909. req.append("Evil");
  1910. req.append(" alignment to purchase this house");
  1911. SimpleMessage(CHANNEL_COLOR_YELLOW, req.c_str());
  1912. safe_delete(packet);
  1913. break;
  1914. }
  1915. int32 status_req = hz->upkeep_status + hz->cost_status;
  1916. int32 available_status = player->GetInfoStruct()->get_status_points();
  1917. if (status_req <= available_status &&
  1918. ((!hz->upkeep_coin && !hz->cost_coin) ||
  1919. ( (hz->upkeep_coin || hz->cost_coin) && player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)))
  1920. ) // TODO: Need option to take from bank if player does not have enough coin on them
  1921. {
  1922. player->GetInfoStruct()->subtract_status_points(status_req);
  1923. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1924. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1925. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1926. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1927. //ClientPacketFunctions::SendHousingList(this);
  1928. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1929. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1930. PlaySound("coin_cha_ching");
  1931. }
  1932. else
  1933. {
  1934. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1935. PlaySound("buy_failed");
  1936. }
  1937. }
  1938. }
  1939. safe_delete(packet);
  1940. break;
  1941. }
  1942. case OP_EnterHouseMsg: {
  1943. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1944. DumpPacket(app);
  1945. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1946. if (packet) {
  1947. packet->LoadPacketData(app->pBuffer, app->size);
  1948. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1949. if (ph) {
  1950. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1951. if (hz) {
  1952. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1953. if (house) {
  1954. Zone(house, true);
  1955. }
  1956. }
  1957. }
  1958. }
  1959. safe_delete(packet);
  1960. break;
  1961. }
  1962. case OP_PayHouseUpkeepMsg: {
  1963. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1964. DumpPacket(app);
  1965. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1966. if (packet) {
  1967. packet->LoadPacketData(app->pBuffer, app->size);
  1968. int64 houseID = packet->getType_int64_ByName("house_id");
  1969. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1970. if (ph)
  1971. {
  1972. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1973. if (!hz)
  1974. {
  1975. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1976. safe_delete(packet);
  1977. break;
  1978. }
  1979. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1980. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1981. {
  1982. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1983. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1984. {
  1985. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1986. PlaySound("buy_failed");
  1987. safe_delete(packet);
  1988. break;
  1989. }
  1990. }
  1991. bool escrowChange = false;
  1992. int64 statusReq = hz->upkeep_status;
  1993. int64 tmpRecoverStatus = 0;
  1994. if(ph->escrow_status && statusReq >= ph->escrow_status )
  1995. {
  1996. escrowChange = true;
  1997. tmpRecoverStatus = ph->escrow_status;
  1998. statusReq -= ph->escrow_status;
  1999. ph->escrow_status = 0;
  2000. }
  2001. else if (ph->escrow_status && statusReq && statusReq <= ph->escrow_status)
  2002. {
  2003. escrowChange = true;
  2004. ph->escrow_status -= statusReq;
  2005. tmpRecoverStatus = statusReq;
  2006. statusReq = 0;
  2007. }
  2008. int64 coinReq = hz->upkeep_coin;
  2009. int64 tmpRecoverCoins = 0;
  2010. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  2011. {
  2012. escrowChange = true;
  2013. tmpRecoverCoins = ph->escrow_coins;
  2014. coinReq -= ph->escrow_coins;
  2015. ph->escrow_coins = 0;
  2016. }
  2017. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  2018. {
  2019. escrowChange = true;
  2020. // more than enough in escrow, subtract and make our cost 0!
  2021. ph->escrow_coins -= coinReq;
  2022. tmpRecoverCoins = coinReq;
  2023. coinReq = 0;
  2024. }
  2025. int32 available_status_points = player->GetInfoStruct()->get_status_points();
  2026. if(!statusReq || (statusReq && statusReq <= available_status_points))
  2027. {
  2028. if(coinReq && player->RemoveCoins(coinReq))
  2029. coinReq = 0;
  2030. if(!coinReq && statusReq && player->GetInfoStruct()->subtract_status_points(statusReq))
  2031. statusReq = 0;
  2032. }
  2033. if (!coinReq && !statusReq) // TODO: Need option to take from bank if player does not have enough coin on them
  2034. {
  2035. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  2036. if (escrowChange)
  2037. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins, ph->escrow_status);
  2038. ph->upkeep_due = upkeep_due;
  2039. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  2040. //ClientPacketFunctions::SendHousingList(this);
  2041. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  2042. PlaySound("coin_cha_ching");
  2043. }
  2044. else
  2045. {
  2046. // recover the escrow we were going to use but could not spend due to lack of funds
  2047. if (tmpRecoverCoins)
  2048. ph->escrow_coins += tmpRecoverCoins;
  2049. if(tmpRecoverStatus)
  2050. ph->escrow_status += tmpRecoverStatus;
  2051. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money or status to pay for upkeep.");
  2052. PlaySound("buy_failed");
  2053. }
  2054. }
  2055. else
  2056. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  2057. }
  2058. safe_delete(packet);
  2059. break;
  2060. }
  2061. case OP_ExitHouseMsg: {
  2062. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  2063. int32 instance_id = GetCurrentZone()->GetInstanceID();
  2064. if (instance_id > 0) {
  2065. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  2066. if (ph) {
  2067. HouseZone* hz = world.GetHouseZone(ph->house_id);
  2068. if (hz) {
  2069. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  2070. // determine if this is an instanced zone that already exists
  2071. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  2072. if (instance_zone || new_zone) {
  2073. GetPlayer()->SetX(hz->exit_x);
  2074. GetPlayer()->SetY(hz->exit_y);
  2075. GetPlayer()->SetZ(hz->exit_z);
  2076. GetPlayer()->SetHeading(hz->exit_heading);
  2077. if (instance_zone)
  2078. Zone(instance_zone->GetInstanceID(), false, true);
  2079. else
  2080. Zone(new_zone, false);
  2081. }
  2082. }
  2083. }
  2084. }
  2085. DumpPacket(app);
  2086. break;
  2087. }
  2088. case OP_QuestJournalWaypointMsg: {
  2089. //DumpPacket(app);
  2090. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  2091. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  2092. if (packet) {
  2093. packet->LoadPacketData(app->pBuffer, app->size);
  2094. int32 quests = packet->getType_int32_ByName("num_quests");
  2095. if (quests > 100) // just picking a number higher than max allowed
  2096. {
  2097. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  2098. break;
  2099. }
  2100. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  2101. for (int32 i = 0; i < quests; i++) {
  2102. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  2103. if (id == 0)
  2104. continue;
  2105. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  2106. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  2107. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  2108. if (player->player_quests.count(id) > 0) {
  2109. player->player_quests[id]->SetTracked(tracked);
  2110. player->player_quests[id]->SetSaveNeeded(true);
  2111. }
  2112. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  2113. }
  2114. safe_delete(packet);
  2115. }
  2116. break;
  2117. }
  2118. case OP_PaperdollImage: {
  2119. /* PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  2120. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2121. //First check if this is a new image... delete an existing partial image if one exists
  2122. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  2123. if (packet_index == 0) {
  2124. safe_delete_array(incoming_paperdoll.image_bytes);
  2125. incoming_paperdoll.last_received_packet_index = 0;
  2126. incoming_paperdoll.current_size_bytes = 0;
  2127. }
  2128. //return if this packet is not the one we are expecting...
  2129. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  2130. safe_delete(packet);
  2131. break;
  2132. }
  2133. //Check how many packets we're supposed to be receiving for this/these images
  2134. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  2135. //Check the image type, if this is a new type in the same series of packets we have a new image
  2136. int8 img_type = packet->getType_int8_ByName("image_type");
  2137. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  2138. //We have a new image. Save the old data and clear before continuing
  2139. SavePlayerImages();
  2140. }
  2141. incoming_paperdoll.image_type = img_type;
  2142. //Get the size of the image data in this packet
  2143. sint64 image_size = packet->getType_int32_ByName("imageSize");
  2144. if (image_size <= 0 || image_size > 1048576) {
  2145. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  2146. safe_delete(packet);
  2147. break;
  2148. }
  2149. //Create a new array
  2150. int32 new_image_size = image_size;
  2151. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  2152. if (incoming_paperdoll.image_bytes) {
  2153. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  2154. safe_delete_array(incoming_paperdoll.image_bytes);
  2155. }
  2156. //variable i should be the index in the packet of the first PNG file byte
  2157. vector<DataStruct*>* d_structs = packet->getStructs();
  2158. vector<DataStruct*>::iterator itr;
  2159. int32 i = 0;
  2160. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  2161. DataStruct* ds = (*itr);
  2162. if (strcmp(ds->GetName(), "pngData_0") != 0)
  2163. i += ds->GetDataSizeInBytes();
  2164. else
  2165. break;
  2166. }
  2167. //Return if this packet is bad and we would read out of bounds
  2168. if (app->size - i < new_image_size) {
  2169. safe_delete(packet);
  2170. safe_delete_array(new_image);
  2171. break;
  2172. }
  2173. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  2174. memcpy(tmp, app->pBuffer + i, new_image_size);
  2175. incoming_paperdoll.current_size_bytes += new_image_size;
  2176. incoming_paperdoll.image_bytes = new_image;
  2177. //Check if this is the last packet we're expecting for this image. Create a final image if so
  2178. if (incoming_paperdoll.image_num_packets == 1 ||
  2179. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  2180. SavePlayerImages();
  2181. }
  2182. incoming_paperdoll.last_received_packet_index = packet_index;
  2183. }
  2184. safe_delete(packet);
  2185. */
  2186. break;
  2187. }
  2188. case OP_ReadyForTakeOffMsg:
  2189. {
  2190. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  2191. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  2192. if (GetPendingFlightPath() > 0) {
  2193. if (index != -1) {
  2194. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  2195. if (packet) {
  2196. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  2197. packet->setDataByName("path_id", index);
  2198. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  2199. QueuePacket(packet->serialize());
  2200. safe_delete(packet);
  2201. on_auto_mount = true;
  2202. }
  2203. }
  2204. else {
  2205. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2206. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  2207. EndAutoMount();
  2208. }
  2209. SetPendingFlightPath(0);
  2210. }
  2211. else
  2212. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  2213. break;
  2214. }
  2215. case OP_EarlyLandingRequestMsg:
  2216. {
  2217. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  2218. EndAutoMount();
  2219. break;
  2220. }
  2221. case OP_SubmitCharCust:
  2222. {
  2223. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  2224. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  2225. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  2226. int8 type = packet->getType_int8_ByName("type");
  2227. if (type == 0) {
  2228. if (player->custNPC) {
  2229. player->custNPCTarget->CustomizeAppearance(packet);
  2230. current_zone->SendSpawnChanges(player->custNPCTarget);
  2231. }
  2232. else {
  2233. player->CustomizeAppearance(packet);
  2234. current_zone->SendSpawnChanges(player);
  2235. }
  2236. }
  2237. }
  2238. if (player->custNPC) {
  2239. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2240. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2241. if (player->custNPCTarget->IsBot())
  2242. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2243. player->custNPC = false;
  2244. player->custNPCTarget = 0;
  2245. player->changed = true;
  2246. player->info_changed = true;
  2247. current_zone->SendSpawnChanges(player, this);
  2248. }
  2249. break;
  2250. }
  2251. default: {
  2252. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2253. const char* name = app->GetOpcodeName();
  2254. if (name)
  2255. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2256. else
  2257. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2258. //DumpPacket(app);
  2259. }
  2260. }
  2261. if (!eqs || !eqs->CheckActive()) {
  2262. return false;
  2263. }
  2264. return ret;
  2265. }
  2266. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2267. if (!item) {
  2268. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2269. return false;
  2270. }
  2271. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2272. if (player->item_list.AssignItemToFreeSlot(item)) {
  2273. int8 type = CHANNEL_LOOT;
  2274. if (entity) {
  2275. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2276. }
  2277. else {
  2278. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2279. }
  2280. Guild* guild = player->GetGuild();
  2281. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2282. char adjective[32];
  2283. int8 type;
  2284. memset(adjective, 0, sizeof(adjective));
  2285. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2286. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2287. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2288. }
  2289. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2290. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2291. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2292. }
  2293. else {
  2294. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2295. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2296. }
  2297. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2298. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2299. }
  2300. if (item->GetItemScript() && lua_interface)
  2301. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  2302. CheckPlayerQuestsItemUpdate(item);
  2303. return true;
  2304. }
  2305. else
  2306. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2307. }
  2308. else
  2309. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2310. return false;
  2311. }
  2312. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2313. if (!entity) {
  2314. return false;
  2315. }
  2316. Item* item = entity->LootItem(item_id);
  2317. bool success = false;
  2318. success = HandleLootItem(entity, item);
  2319. if(!success)
  2320. entity->AddLootItem(item);
  2321. return success;
  2322. }
  2323. void Client::HandleLoot(EQApplicationPacket* app) {
  2324. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2325. if (packet) {
  2326. packet->LoadPacketData(app->pBuffer, app->size);
  2327. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2328. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2329. safe_delete(packet);
  2330. int32 item_id = 0;
  2331. Item* item = 0;
  2332. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2333. if (player->HasPendingLootItems(loot_id)) {
  2334. Item* master_item = 0;
  2335. if (loot_all) {
  2336. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2337. if (items) {
  2338. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2339. master_item = items->at(i);
  2340. if (master_item) {
  2341. item = new Item(master_item);
  2342. if (item) {
  2343. loot_all = HandleLootItem(0, item);
  2344. if (loot_all)
  2345. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2346. }
  2347. }
  2348. }
  2349. safe_delete(items);
  2350. }
  2351. }
  2352. else {
  2353. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2354. if (packet) {
  2355. packet->LoadPacketData(app->pBuffer, app->size);
  2356. item_id = packet->getType_int32_ByName("item_id");
  2357. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2358. if (items) {
  2359. for (int32 i = 0; i < items->size(); i++) {
  2360. master_item = items->at(i);
  2361. if (master_item && master_item->details.item_id == item_id) {
  2362. item = new Item(master_item);
  2363. if (item && HandleLootItem(0, item))
  2364. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2365. break;
  2366. }
  2367. }
  2368. safe_delete(items);
  2369. }
  2370. safe_delete(packet);
  2371. }
  2372. }
  2373. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2374. if (outapp)
  2375. QueuePacket(outapp);
  2376. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2377. }
  2378. else {
  2379. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2380. if (loot_all) {
  2381. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2382. loot_all = HandleLootItem(spawn, item_id);
  2383. }
  2384. }
  2385. else {
  2386. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2387. if (packet) {
  2388. packet->LoadPacketData(app->pBuffer, app->size);
  2389. item_id = packet->getType_int32_ByName("item_id");
  2390. HandleLootItem(spawn, item_id);
  2391. safe_delete(packet);
  2392. }
  2393. }
  2394. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2395. if (outapp)
  2396. QueuePacket(outapp);
  2397. Loot(spawn);
  2398. if (!spawn->HasLoot()) {
  2399. CloseLoot(loot_id);
  2400. if (spawn->IsNPC())
  2401. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2402. }
  2403. }
  2404. else {
  2405. if (!spawn) {
  2406. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2407. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2408. }
  2409. else
  2410. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2411. }
  2412. }
  2413. }
  2414. }
  2415. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2416. PacketStruct* request = 0;
  2417. // cout << "Request: \n";
  2418. // DumpPacket(app);
  2419. switch (app->pBuffer[0]) {
  2420. case 0: { //items
  2421. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2422. if (request) {
  2423. request->LoadPacketData(app->pBuffer, app->size);
  2424. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2425. if (!item)
  2426. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2427. if (item) {
  2428. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2429. if (response) {
  2430. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2431. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2432. response->setSmallStringByName("name", item->name.c_str());
  2433. EQ2Packet* app2 = response->serialize();
  2434. //DumpPacket(app2);
  2435. QueuePacket(app2);
  2436. safe_delete(response);
  2437. }
  2438. }
  2439. }
  2440. break;
  2441. }
  2442. case 2: {//spells
  2443. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2444. if (request) {
  2445. request->LoadPacketData(app->pBuffer, app->size);
  2446. int32 id = request->getType_int32_ByName("id");
  2447. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2448. Spell* spell = master_spell_list.GetSpell(id, tier);
  2449. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2450. if (response) {
  2451. response->setDataByName("request_type", 2);
  2452. response->setDataByName("unique_id", tier);
  2453. response->setDataByName("id", id);
  2454. if (spell)
  2455. response->setSmallStringByName("name", spell->GetName());
  2456. else
  2457. response->setSmallStringByName("name", "Unknown Spell");
  2458. EQ2Packet* app2 = response->serialize();
  2459. // DumpPacket(app2);
  2460. QueuePacket(app2);
  2461. safe_delete(response);
  2462. }
  2463. }
  2464. break;
  2465. }
  2466. default: {
  2467. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2468. }
  2469. }
  2470. safe_delete(request);
  2471. }
  2472. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2473. PacketStruct* request = 0;
  2474. if (!app || app->size == 0)
  2475. return;
  2476. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2477. //DumpPacket(app);
  2478. int8 type = app->pBuffer[0];
  2479. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2480. if (version <= 283) {
  2481. if (type == 1)
  2482. type = 4;
  2483. else if (type == 2)
  2484. type = 5;
  2485. }
  2486. if (type == 3) {
  2487. Spell* spell = 0;
  2488. bool trait_display;
  2489. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2490. if (!request) {
  2491. return;
  2492. }
  2493. request->LoadPacketData(app->pBuffer, app->size);
  2494. int32 id = request->getType_int32_ByName("id");
  2495. int32 tier = request->getType_int32_ByName("tier");
  2496. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2497. bool display = true;
  2498. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2499. display = false;
  2500. else if (version <= 546)
  2501. display = request->getType_int8_ByName("display");
  2502. else if (version > 546)
  2503. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2504. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2505. if (trait_tier != 0xFFFFFFFF) {
  2506. spell = master_spell_list.GetSpell(id, trait_tier);
  2507. if (!spell) {
  2508. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2509. }
  2510. trait_display = true;
  2511. }
  2512. else {
  2513. spell = master_spell_list.GetSpell(id, tier);
  2514. trait_display = false;
  2515. }
  2516. // if we can't find it on the master spell list, see if it is a custom spell
  2517. if (!spell)
  2518. {
  2519. lua_interface->FindCustomSpellLock();
  2520. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2521. if (tmpSpell)
  2522. spell = tmpSpell->spell;
  2523. lua_interface->FindCustomSpellUnlock();
  2524. }
  2525. if (spell && !CountSentSpell(id, tier)) {
  2526. if (!spell->IsCopiedSpell())
  2527. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2528. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2529. //DumpPacket(app);
  2530. QueuePacket(app);
  2531. }
  2532. }
  2533. else if (type == 0) {
  2534. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2535. if (!request) {
  2536. return;
  2537. }
  2538. request->LoadPacketData(app->pBuffer, app->size);
  2539. int32 id = request->getType_int32_ByName("id");
  2540. Item* item = 0;
  2541. // translate from unique id to spawn id for houses
  2542. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2543. bool wasSpawn = false;
  2544. if (spawn)
  2545. {
  2546. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2547. if (item)
  2548. {
  2549. wasSpawn = true;
  2550. item = new Item(item);
  2551. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2552. }
  2553. }
  2554. if (!item)
  2555. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2556. if (!item)
  2557. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2558. if (!item)
  2559. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(id);
  2560. if (!item)
  2561. item = master_item_list.GetItem(id);
  2562. if (item) {// && sent_item_details.count(id) == 0){
  2563. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2564. sent_item_details[id] = true;
  2565. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2566. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2567. //DumpPacket(app);
  2568. QueuePacket(app);
  2569. if (wasSpawn)
  2570. delete item;
  2571. }
  2572. else {
  2573. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2574. DumpPacket(app);
  2575. }
  2576. }
  2577. else if (type == 1) {
  2578. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2579. if (!request) {
  2580. return;
  2581. }
  2582. request->LoadPacketData(app->pBuffer, app->size);
  2583. int32 id = request->getType_int32_ByName("id");
  2584. int32 unique_id = request->getType_int32_ByName("unique_id");
  2585. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2586. if (!item)
  2587. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2588. if (!item)
  2589. item = GetPlayer()->GetAppearanceEquipmentList()->GetItemFromUniqueID(unique_id);
  2590. if (!item)
  2591. item = master_item_list.GetItem(id);
  2592. if (item) {
  2593. MItemDetails.writelock(__FUNCTION__, __LINE__);
  2594. sent_item_details[id] = true;
  2595. MItemDetails.releasewritelock(__FUNCTION__, __LINE__);
  2596. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2597. //DumpPacket(app);
  2598. QueuePacket(app);
  2599. }
  2600. else {
  2601. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2602. DumpPacket(app);
  2603. }
  2604. }
  2605. else if (type == 2) {
  2606. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2607. if (!request) {
  2608. return;
  2609. }
  2610. request->LoadPacketData(app->pBuffer, app->size);
  2611. int32 id = request->getType_int32_ByName("item_id");
  2612. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2613. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2614. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2615. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2616. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2617. //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);
  2618. Item* item = master_item_list.GetItem(id);
  2619. if (item) {
  2620. //only display popup for non merchant links
  2621. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2622. //DumpPacket(app);
  2623. QueuePacket(app);
  2624. }
  2625. else {
  2626. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2627. DumpPacket(app);
  2628. }
  2629. }
  2630. else if (type == 4) { //spell effect
  2631. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2632. if (!request) {
  2633. return;
  2634. }
  2635. request->LoadPacketData(app->pBuffer, app->size);
  2636. int32 id = request->getType_int32_ByName("id");
  2637. int16 display = request->getType_int8_ByName("partial_info");
  2638. SpellEffects* effect = player->GetSpellEffect(id);
  2639. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2640. if (effect) {
  2641. int8 tier = effect->tier;
  2642. Spell* spell = master_spell_list.GetSpell(id, tier);
  2643. // if we can't find it on the master spell list, see if it is a custom spell
  2644. if (!spell)
  2645. {
  2646. lua_interface->FindCustomSpellLock();
  2647. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2648. EQ2Packet* pack = 0;
  2649. if (tmpSpell)
  2650. spell = tmpSpell->spell;
  2651. lua_interface->FindCustomSpellUnlock();
  2652. }
  2653. if (spell && !CountSentSpell(id, tier)) {
  2654. if (!spell->IsCopiedSpell())
  2655. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2656. int8 type = 0;
  2657. if (version <= 283)
  2658. type = 1;
  2659. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2660. //DumpPacket(app);
  2661. QueuePacket(app);
  2662. }
  2663. }
  2664. }
  2665. else if (type == 5) { // recipe info
  2666. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2667. if (!request)
  2668. return;
  2669. request->LoadPacketData(app->pBuffer, app->size);
  2670. int32 id = request->getType_int32_ByName("unknown_id");
  2671. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2672. if (recipe) {
  2673. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2674. //DumpPacket(app);
  2675. QueuePacket(app);
  2676. }
  2677. }
  2678. else if (type == 6) { // AA spell info
  2679. Spell* spell = 0;
  2680. //Spell* spell2 = 0;
  2681. //AltAdvanceData* data = 0;
  2682. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2683. if (!request)
  2684. return;
  2685. request->LoadPacketData(app->pBuffer, app->size);
  2686. int32 id = request->getType_int32_ByName("id");
  2687. int32 tier = GetPlayer()->GetSpellTier(id);
  2688. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2689. //data = master_aa_list.GetAltAdvancement(id);
  2690. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2691. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2692. spell = master_spell_list.GetSpell(id, tier);
  2693. if (!spell)
  2694. spell = master_spell_list.GetSpell(id, 1);
  2695. if (!spell)
  2696. {
  2697. lua_interface->FindCustomSpellLock();
  2698. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2699. if (tmpSpell)
  2700. spell = tmpSpell->spell;
  2701. lua_interface->FindCustomSpellUnlock();
  2702. }
  2703. if (!spell)
  2704. {
  2705. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2706. return;
  2707. }
  2708. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2709. if (!spell->IsCopiedSpell())
  2710. SetSentSpell(spell->GetSpellID(), spell->GetSpellTier());
  2711. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2712. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2713. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2714. //DumpPacket(app);
  2715. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2716. QueuePacket(app);
  2717. //}
  2718. }
  2719. else {
  2720. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2721. DumpPacket(app);
  2722. }
  2723. safe_delete(request);
  2724. }
  2725. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2726. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2727. if (request) {
  2728. request->LoadPacketData(app->pBuffer, app->size);
  2729. int32 id = request->getType_int32_ByName("id");
  2730. int32 bar = request->getType_int32_ByName("hotbar_number");
  2731. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2732. int32 type = request->getType_int32_ByName("type");
  2733. int8 tier = request->getType_int32_ByName("unique_id");
  2734. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2735. Spell* spell = 0;
  2736. if (type == 0xFFFFFFFF)
  2737. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2738. else {
  2739. if (type == QUICKBAR_NORMAL)
  2740. spell = master_spell_list.GetSpell(id, tier);
  2741. if (spell)
  2742. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2743. else
  2744. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2745. }
  2746. safe_delete(request);
  2747. }
  2748. }
  2749. bool Client::Process(bool zone_process) {
  2750. if (!eqs) {
  2751. return false;
  2752. }
  2753. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2754. return true;
  2755. }
  2756. if (new_client_login) {
  2757. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2758. SendLoginInfo();
  2759. new_client_login = false;
  2760. }
  2761. bool ret = true;
  2762. sockaddr_in to;
  2763. memset((char*)&to, 0, sizeof(to));
  2764. to.sin_family = AF_INET;
  2765. to.sin_port = port;
  2766. to.sin_addr.s_addr = ip;
  2767. /************ Get all packets from packet manager out queue and process them ************/
  2768. EQApplicationPacket* app = 0;
  2769. if (eqs && !eqs->CheckActive()) {
  2770. num_active_failures++;
  2771. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2772. if (num_active_failures > 100) {
  2773. return false;
  2774. }
  2775. return true;
  2776. }
  2777. while (ret && eqs && (app = eqs->PopPacket())) {
  2778. ret = HandlePacket(app);
  2779. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2780. delete app;
  2781. }
  2782. if (GetCurrentZone() && !GetCurrentZone()->IsLoading() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2783. player->ApplyPassiveSpells();
  2784. //database.LoadCharacterActiveSpells(player);
  2785. player->UnlockAllSpells(true);
  2786. should_load_spells = false;
  2787. }
  2788. if(spawn_removal_timer.Check() && GetPlayer()) {
  2789. GetPlayer()->CheckSpawnStateQueue();
  2790. }
  2791. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2792. {
  2793. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2794. return false;
  2795. }
  2796. if (quest_updates) {
  2797. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2798. ProcessQuestUpdates();
  2799. }
  2800. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2801. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2802. CheckQuestQueue();
  2803. }
  2804. MSaveSpellStateMutex.lock();
  2805. if(save_spell_state_timer.Check())
  2806. {
  2807. save_spell_state_timer.Disable();
  2808. GetPlayer()->SaveSpellEffects();
  2809. }
  2810. MSaveSpellStateMutex.unlock();
  2811. if (temp_placement_timer.Check()) {
  2812. if(GetTempPlacementSpawn() && GetPlayer()->WasSentSpawn(GetTempPlacementSpawn()->GetID()) && !hasSentTempPlacementSpawn) {
  2813. SendMoveObjectMode(GetTempPlacementSpawn(), 0);
  2814. hasSentTempPlacementSpawn = true;
  2815. temp_placement_timer.Disable();
  2816. }
  2817. }
  2818. if (pos_update.Check())
  2819. {
  2820. ProcessStateCommands();
  2821. GetPlayer()->ResetMentorship(); // check if we need to asynchronously reset mentorship
  2822. if(GetPlayer()->GetRegionMap())
  2823. GetPlayer()->GetRegionMap()->TicRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2824. if(player_pos_changed && IsReadyForUpdates()) {
  2825. //GetPlayer()->CalculateLocation();
  2826. client_list.CheckPlayersInvisStatus(this);
  2827. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2828. player_pos_changed = false;
  2829. GetCurrentZone()->CheckTransporters(this);
  2830. if(GetPlayer()->GetRegionMap())
  2831. {
  2832. if((lastRegionRemapTime+1000) < Timer::GetCurrentTime2())
  2833. {
  2834. lastRegionRemapTime = Timer::GetCurrentTime2() + 1000;
  2835. GetPlayer()->GetRegionMap()->MapRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2836. }
  2837. else
  2838. GetPlayer()->GetRegionMap()->UpdateRegionsNearSpawn(this->GetPlayer(), regionDebugMessaging ? this : nullptr);
  2839. }
  2840. }
  2841. }
  2842. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2843. lua_interface->UpdateDebugClients(this);
  2844. if (quest_pos_timer.Check())
  2845. CheckPlayerQuestsLocationUpdate();
  2846. if (player->GetSkills()->HasSkillUpdates()) {
  2847. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2848. if (skills) {
  2849. Skill* skill = 0;
  2850. vector<Skill*>::iterator itr;
  2851. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2852. skill = *itr;
  2853. SkillChanged(skill, skill->previous_val, skill->current_val);
  2854. }
  2855. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2856. if (app) QueuePacket(app);
  2857. safe_delete(skills);
  2858. }
  2859. }
  2860. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2861. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2862. safe_delete(current_rez.expire_timer);
  2863. current_rez.expire_timer = 0;
  2864. current_rez.active = false;
  2865. current_rez.caster = 0;
  2866. current_rez.crit = false;
  2867. current_rez.crit_mod = 0;
  2868. current_rez.expire_timer = 0;
  2869. current_rez.heal_name = "";
  2870. current_rez.hp_perc = 0;
  2871. current_rez.mp_perc = 0;
  2872. current_rez.no_calcs = false;
  2873. current_rez.range = 0;
  2874. current_rez.should_delete = false;
  2875. current_rez.spell_name = "";
  2876. current_rez.spell_visual = 0;
  2877. current_rez.subspell = 0;
  2878. }
  2879. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2880. // Quest timers
  2881. Quest* failed_step = 0;
  2882. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2883. if (quest_timers.size() > 0) {
  2884. vector<int32>::iterator itr;
  2885. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  2886. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2887. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2888. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2889. Quest* quest = player_quests->at(*itr);
  2890. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2891. failed_step = quest;
  2892. break;
  2893. }
  2894. }
  2895. else {
  2896. itr = quest_timers.erase(itr);
  2897. break;
  2898. }
  2899. }
  2900. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  2901. }
  2902. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2903. if (failed_step)
  2904. failed_step->StepFailed(failed_step->GetTimerStep());
  2905. if (player->ControlFlagsChanged())
  2906. player->SendControlFlagUpdates(this);
  2907. if (camp_timer && camp_timer->Check()) {
  2908. ResetSendMail();
  2909. if(getConnection())
  2910. getConnection()->SendDisconnect(false);
  2911. safe_delete(camp_timer);
  2912. ret = false;
  2913. }
  2914. if (!eqs || (eqs && !eqs->CheckActive()))
  2915. ret = false;
  2916. // redundant to client disconnect
  2917. // if(!ret)
  2918. // Save();
  2919. return ret;
  2920. }
  2921. ClientList::ClientList() {
  2922. MClients.SetName("ClientList::MClients");
  2923. }
  2924. ClientList::~ClientList() {
  2925. }
  2926. void ClientList::ReloadQuests() {
  2927. list<Client*>::iterator client_iter;
  2928. Client* client = 0;
  2929. MClients.readlock(__FUNCTION__, __LINE__);
  2930. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2931. client = *client_iter;
  2932. if (client)
  2933. client->ReloadQuests();
  2934. }
  2935. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2936. }
  2937. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2938. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2939. return;
  2940. list<Client*>::iterator client_iter;
  2941. Client* client = 0;
  2942. MClients.readlock(__FUNCTION__, __LINE__);
  2943. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2944. client = *client_iter;
  2945. if (client == owner || client->GetPlayer() == NULL)
  2946. continue;
  2947. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2948. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2949. }
  2950. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2951. }
  2952. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2953. list<Client*>::iterator client_iter;
  2954. Client* client = 0;
  2955. MClients.readlock(__FUNCTION__, __LINE__);
  2956. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2957. client = *client_iter;
  2958. if (!client->GetPlayer())
  2959. continue;
  2960. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2961. }
  2962. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2963. }
  2964. int32 ClientList::Count() {
  2965. return client_list.size();
  2966. }
  2967. void ClientList::Add(Client* client) {
  2968. MClients.writelock(__FUNCTION__, __LINE__);
  2969. client_list.push_back(client);
  2970. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2971. }
  2972. Client* ClientList::FindByAccountID(int32 account_id) {
  2973. list<Client*>::iterator client_iter;
  2974. Client* client = 0;
  2975. Client* ret = 0;
  2976. MClients.readlock(__FUNCTION__, __LINE__);
  2977. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2978. client = *client_iter;
  2979. if (client->GetAccountID() == account_id) {
  2980. ret = client;
  2981. break;
  2982. }
  2983. }
  2984. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2985. return ret;
  2986. }
  2987. Client* ClientList::FindByName(char* charName) {
  2988. list<Client*>::iterator client_iter;
  2989. Client* client = 0;
  2990. Client* ret = 0;
  2991. MClients.readlock(__FUNCTION__, __LINE__);
  2992. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2993. client = *client_iter;
  2994. if (!client || !client->GetPlayer())
  2995. continue;
  2996. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2997. ret = client;
  2998. break;
  2999. }
  3000. }
  3001. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3002. return ret;
  3003. }
  3004. Client* ClientList::Get(int32 ip, int16 port) {
  3005. list<Client*>::iterator client_iter;
  3006. Client* client = 0;
  3007. Client* ret = 0;
  3008. MClients.readlock(__FUNCTION__, __LINE__);
  3009. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  3010. client = *client_iter;
  3011. if (client->GetIP() == ip && client->GetPort() == port) {
  3012. ret = client;
  3013. break;
  3014. }
  3015. }
  3016. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3017. return ret;
  3018. }
  3019. void ClientList::Process() {
  3020. list<Client*>::iterator client_iter;
  3021. list<Client*>::iterator erase_iter;
  3022. Client* client = 0;
  3023. MClients.readlock(__FUNCTION__, __LINE__);
  3024. erase_iter = client_list.end();
  3025. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3026. client = *client_iter;
  3027. // have a sanity check because the client list can sometimes obtain null client pointers
  3028. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  3029. erase_iter = client_iter;
  3030. break;
  3031. }
  3032. }
  3033. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3034. if (erase_iter != client_list.end()) {
  3035. client = *erase_iter;
  3036. MClients.writelock(__FUNCTION__, __LINE__);
  3037. client_list.erase(erase_iter);
  3038. MClients.releasewritelock(__FUNCTION__, __LINE__);
  3039. if (client && !client->remove_from_list) {
  3040. struct in_addr in;
  3041. in.s_addr = client->GetIP();
  3042. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  3043. safe_delete(client);
  3044. }
  3045. }
  3046. }
  3047. void ClientList::RemoveConnection(EQStream* eqs) {
  3048. Client* client;
  3049. if (eqs) {
  3050. list<Client*>::iterator client_iter;
  3051. MClients.readlock(__FUNCTION__, __LINE__);
  3052. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3053. client = *client_iter;
  3054. if (client->getConnection() == eqs)
  3055. client->Disconnect(true);
  3056. }
  3057. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3058. }
  3059. }
  3060. bool ClientList::ContainsStream(EQStream* eqs) {
  3061. if (!eqs) {
  3062. return false;
  3063. }
  3064. list<Client*>::iterator client_iter;
  3065. bool ret = false;
  3066. MClients.readlock(__FUNCTION__, __LINE__);
  3067. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  3068. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  3069. ret = true;
  3070. break;
  3071. }
  3072. }
  3073. MClients.releasereadlock(__FUNCTION__, __LINE__);
  3074. return ret;
  3075. }
  3076. void ClientList::Remove(Client* client, bool remove_data) {
  3077. client->remove_from_list = true;
  3078. if (remove_data) {
  3079. safe_delete(client);
  3080. }
  3081. }
  3082. void Client::SetCurrentZone(int32 id) {
  3083. if (current_zone) {
  3084. //current_zone->GetCombat()->RemoveHate(player);
  3085. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3086. }
  3087. SetCurrentZone(zone_list.Get(id));
  3088. }
  3089. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  3090. if (current_zone) {
  3091. //current_zone->GetCombat()->RemoveHate(player);
  3092. current_zone->RemoveSpawn(player, false, true, true, true, true);
  3093. }
  3094. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  3095. }
  3096. ZoneServer* Client::GetCurrentZone() {
  3097. return current_zone;
  3098. }
  3099. int8 Client::GetMessageChannelColor(int8 channel_type) {
  3100. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  3101. if (channel_type == CHANNEL_LOOT)
  3102. return CHANNEL_COLOR_NEW_LOOT;
  3103. }
  3104. else if (GetVersion() >= 973) {
  3105. if (channel_type == CHANNEL_LOOT)
  3106. return CHANNEL_COLOR_NEWEST_LOOT;
  3107. }
  3108. if (GetVersion() <= 283) {
  3109. if (channel_type <=12)
  3110. return channel_type;
  3111. switch (channel_type) {
  3112. case CHANNEL_GROUP_CHAT:
  3113. case CHANNEL_GROUP_SAY:
  3114. case CHANNEL_RAID_SAY:
  3115. case CHANNEL_GUILD_CHAT:
  3116. case CHANNEL_GUILD_SAY:
  3117. case CHANNEL_OFFICER_SAY:
  3118. case CHANNEL_GUILD_MOTD:
  3119. return channel_type - 1;
  3120. case CHANNEL_PRIVATE_CHAT:
  3121. case CHANNEL_NONPLAYER_TELL:
  3122. return channel_type - 5;
  3123. case CHANNEL_PRIVATE_TELL:
  3124. case CHANNEL_TELL_FROM_CS:
  3125. return channel_type - 6;
  3126. case CHANNEL_CHAT_CHANNEL_TEXT:
  3127. case CHANNEL_OUT_OF_CHARACTER:
  3128. case CHANNEL_AUCTION:
  3129. case CHANNEL_CUSTOM_CHANNEL:
  3130. case CHANNEL_CHARACTER_TEXT:
  3131. case CHANNEL_REWARD:
  3132. case CHANNEL_DEATH:
  3133. case CHANNEL_PET_CHAT:
  3134. case CHANNEL_SKILL:
  3135. return channel_type - 7;
  3136. case CHANNEL_SPELLS:
  3137. case CHANNEL_YOU_CAST:
  3138. case CHANNEL_YOU_FAIL:
  3139. return channel_type - 8;
  3140. case CHANNEL_FRIENDLY_CAST:
  3141. case CHANNEL_FRIENDLY_FAIL:
  3142. case CHANNEL_OTHER_CAST:
  3143. case CHANNEL_OTHER_FAIL:
  3144. case CHANNEL_HOSTILE_CAST:
  3145. case CHANNEL_HOSTILE_FAIL:
  3146. case CHANNEL_WORN_OFF:
  3147. case CHANNEL_SPELLS_OTHER:
  3148. return channel_type - 9;
  3149. case CHANNEL_COMBAT:
  3150. return channel_type - 15;
  3151. case CHANNEL_HEROIC_OPPORTUNITY:
  3152. case CHANNEL_NON_MELEE_DAMAGE:
  3153. case CHANNEL_DAMAGE_SHIELD:
  3154. return channel_type - 16;
  3155. case CHANNEL_MELEE_COMBAT:
  3156. case CHANNEL_WARNINGS:
  3157. case CHANNEL_YOU_HIT:
  3158. case CHANNEL_YOU_MISS:
  3159. case CHANNEL_ATTACKER_HITS:
  3160. case CHANNEL_ATTACKER_MISSES:
  3161. return channel_type - 18;
  3162. case CHANNEL_OTHER_HIT:
  3163. case CHANNEL_OTHER_MISSES:
  3164. case CHANNEL_CRITICAL_HIT:
  3165. return channel_type - 22;
  3166. case CHANNEL_OTHER:
  3167. case CHANNEL_MONEY_SPLIT:
  3168. case CHANNEL_LOOT:
  3169. return channel_type - 30;
  3170. case CHANNEL_COMMAND_TEXT:
  3171. case CHANNEL_BROADCAST:
  3172. case CHANNEL_WHO:
  3173. case CHANNEL_COMMANDS:
  3174. case CHANNEL_MERCHANT:
  3175. case CHANNEL_MERCHANT_BUY_SELL:
  3176. case CHANNEL_CONSIDER_MESSAGE:
  3177. case CHANNEL_CON_MINUS_2:
  3178. case CHANNEL_CON_MINUS_1:
  3179. case CHANNEL_CON_0:
  3180. case CHANNEL_CON_1:
  3181. case CHANNEL_CON_2:
  3182. return channel_type - 31;
  3183. default: {
  3184. return CHANNEL_DEFAULT;
  3185. }
  3186. }
  3187. }
  3188. else if (GetVersion() <= 546) {
  3189. if (channel_type < 20)
  3190. return channel_type;
  3191. switch (channel_type) {
  3192. case CHANNEL_GUILD_MOTD:
  3193. case CHANNEL_GUILD_MEMBER_ONLINE:
  3194. case CHANNEL_GUILD_EVENT:
  3195. return channel_type + 1;
  3196. case CHANNEL_PRIVATE_CHAT:
  3197. case CHANNEL_NONPLAYER_TELL:
  3198. return channel_type - 1;
  3199. case CHANNEL_PRIVATE_TELL:
  3200. case CHANNEL_TELL_FROM_CS:
  3201. case CHANNEL_ARENA:
  3202. case CHANNEL_CHAT_CHANNEL_TEXT:
  3203. case CHANNEL_OUT_OF_CHARACTER:
  3204. case CHANNEL_AUCTION:
  3205. case CHANNEL_CUSTOM_CHANNEL:
  3206. case CHANNEL_CHARACTER_TEXT:
  3207. case CHANNEL_REWARD:
  3208. case CHANNEL_DEATH:
  3209. case CHANNEL_PET_CHAT:
  3210. case CHANNEL_SKILL:
  3211. case CHANNEL_FACTION:
  3212. case CHANNEL_SPELLS:
  3213. case CHANNEL_YOU_CAST:
  3214. case CHANNEL_YOU_FAIL:
  3215. return channel_type - 2;
  3216. case CHANNEL_FRIENDLY_CAST:
  3217. case CHANNEL_FRIENDLY_FAIL:
  3218. case CHANNEL_OTHER_CAST:
  3219. case CHANNEL_OTHER_FAIL:
  3220. case CHANNEL_HOSTILE_CAST:
  3221. case CHANNEL_HOSTILE_FAIL:
  3222. case CHANNEL_WORN_OFF:
  3223. case CHANNEL_SPELLS_OTHER:
  3224. case CHANNEL_HEAL_SPELLS:
  3225. case CHANNEL_HEALS:
  3226. case CHANNEL_FRIENDLY_HEALS:
  3227. case CHANNEL_OTHER_HEALS:
  3228. case CHANNEL_HOSTILE_HEALS:
  3229. return channel_type - 3;
  3230. case CHANNEL_COMBAT:
  3231. case CHANNEL_GENERAL_COMBAT:
  3232. case CHANNEL_HEROIC_OPPORTUNITY:
  3233. case CHANNEL_NON_MELEE_DAMAGE:
  3234. case CHANNEL_DAMAGE_SHIELD:
  3235. case CHANNEL_WARD:
  3236. return channel_type - 4;
  3237. case CHANNEL_MELEE_COMBAT:
  3238. case CHANNEL_WARNINGS:
  3239. case CHANNEL_YOU_HIT:
  3240. case CHANNEL_YOU_MISS:
  3241. case CHANNEL_ATTACKER_HITS:
  3242. case CHANNEL_ATTACKER_MISSES:
  3243. case CHANNEL_YOUR_PET_HITS:
  3244. case CHANNEL_YOUR_PET_MISSES:
  3245. case CHANNEL_ATTACKER_HITS_PET:
  3246. case CHANNEL_ATTACKER_MISSES_PET:
  3247. case CHANNEL_OTHER_HIT:
  3248. case CHANNEL_OTHER_MISSES:
  3249. return channel_type - 5;
  3250. case CHANNEL_OTHER:
  3251. case CHANNEL_MONEY_SPLIT:
  3252. case CHANNEL_LOOT:
  3253. return channel_type - 14;
  3254. case CHANNEL_COMMAND_TEXT:
  3255. case CHANNEL_BROADCAST:
  3256. case CHANNEL_WHO:
  3257. case CHANNEL_COMMANDS:
  3258. case CHANNEL_MERCHANT:
  3259. case CHANNEL_MERCHANT_BUY_SELL:
  3260. case CHANNEL_CONSIDER_MESSAGE:
  3261. case CHANNEL_CON_MINUS_2:
  3262. case CHANNEL_CON_MINUS_1:
  3263. case CHANNEL_CON_0:
  3264. case CHANNEL_CON_1:
  3265. case CHANNEL_CON_2:
  3266. case CHANNEL_TRADESKILLS:
  3267. case CHANNEL_HARVESTING:
  3268. case CHANNEL_HARVESTING_WARNINGS:
  3269. return channel_type - 15;
  3270. default: {
  3271. return CHANNEL_DEFAULT;
  3272. }
  3273. }
  3274. }
  3275. else {
  3276. switch (channel_type) {
  3277. default: {
  3278. return channel_type;
  3279. }
  3280. }
  3281. }
  3282. return channel_type;
  3283. }
  3284. void Client::HandleTellMessage(Client* from, const char* message, const char* to=NULL) {
  3285. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3286. return;
  3287. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3288. if (packet) {
  3289. packet->setDataByName("from", from->GetPlayer()->GetName());
  3290. packet->setDataByName("to", to);
  3291. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3292. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3293. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3294. packet->setDataByName("unknown2", 1, 1);
  3295. packet->setDataByName("show_bubble", 1);
  3296. packet->setDataByName("understood", 1);
  3297. packet->setDataByName("time", 2);
  3298. packet->setMediumStringByName("message", message);
  3299. EQ2Packet* outpacket = packet->serialize();
  3300. QueuePacket(outpacket);
  3301. safe_delete(packet);
  3302. }
  3303. }
  3304. void Client::SimpleMessage(int8 color, const char* message) {
  3305. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3306. if (command_packet) {
  3307. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3308. command_packet->setMediumStringByName("text", message);
  3309. command_packet->setDataByName("unknown02", 0x00ff);
  3310. EQ2Packet* outapp = command_packet->serialize();
  3311. QueuePacket(outapp);
  3312. safe_delete(command_packet);
  3313. }
  3314. }
  3315. void Client::SendSpellUpdate(Spell* spell, bool add_silently, bool add_to_hotbar) {
  3316. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3317. if (packet) {
  3318. int8 xxx = spell->GetSpellData()->is_aa;
  3319. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3320. packet->setDataByName("spell_id", spell->GetSpellID());
  3321. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3322. packet->setDataByName("spell_name", spell->GetName());
  3323. if(add_silently)
  3324. packet->setDataByName("add_silently", 1);
  3325. if(add_to_hotbar)
  3326. packet->setDataByName("add_to_hotbar", 1);
  3327. packet->setDataByName("unknown", xxx);
  3328. packet->setDataByName("display_spell_tier", 1);
  3329. packet->setDataByName("unknown3", 1);
  3330. packet->setDataByName("tier", spell->GetSpellTier());
  3331. packet->setDataByName("icon", spell->GetSpellIcon());
  3332. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3333. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3334. //packet->PrintPacket();
  3335. EQ2Packet* outapp = packet->serialize();
  3336. //DumpPacket(outapp);
  3337. QueuePacket(outapp);
  3338. safe_delete(packet);
  3339. }
  3340. }
  3341. void Client::Message(int8 type, const char* message, ...) {
  3342. va_list argptr;
  3343. char buffer[4096];
  3344. va_start(argptr, message);
  3345. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3346. va_end(argptr);
  3347. SimpleMessage(type, buffer);
  3348. }
  3349. void Client::Disconnect(bool send_disconnect)
  3350. {
  3351. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3352. this->Save();
  3353. this->GetPlayer()->WritePlayerStatistics();
  3354. SetConnected(false);
  3355. if (send_disconnect && getConnection())
  3356. getConnection()->SendDisconnect(true);
  3357. eqs = 0;
  3358. }
  3359. bool Client::Summon(const char* search_name) {
  3360. Spawn* target = 0;
  3361. if (search_name || GetPlayer()->GetTarget()) {
  3362. Client* search_client = 0;
  3363. if (search_name) {
  3364. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3365. if (target && target->IsPlayer())
  3366. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3367. if (!target) {
  3368. search_client = zone_list.GetClientByCharName(string(search_name));
  3369. if (search_client)
  3370. target = search_client->GetPlayer();
  3371. }
  3372. }
  3373. else
  3374. target = GetPlayer()->GetTarget();
  3375. if (target && target != GetPlayer()) {
  3376. target->SetX(GetPlayer()->GetX());
  3377. target->SetY(GetPlayer()->GetY());
  3378. target->SetZ(GetPlayer()->GetZ());
  3379. target->SetHeading(GetPlayer()->GetHeading());
  3380. if (!target->IsPlayer()) {
  3381. target->SetSpawnOrigX(target->GetX());
  3382. target->SetSpawnOrigY(target->GetY());
  3383. target->SetSpawnOrigZ(target->GetZ());
  3384. target->SetSpawnOrigHeading(target->GetHeading());
  3385. }
  3386. target->SetLocation(GetPlayer()->GetLocation());
  3387. }
  3388. else if (target)
  3389. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3390. if (search_client && search_client != this) {
  3391. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3392. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3393. if (search_client->GetCurrentZone() != GetCurrentZone())
  3394. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3395. else {
  3396. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3397. if (app)
  3398. search_client->QueuePacket(app);
  3399. }
  3400. }
  3401. }
  3402. if (!target)
  3403. return false;
  3404. else
  3405. return true;
  3406. }
  3407. std::string Client::IdentifyInstanceLockout(int32 zoneID, bool displayClient) {
  3408. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3409. if(instanceType < 1)
  3410. return std::string("");
  3411. ZoneServer* instance_zone = nullptr;
  3412. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3413. if (data) {
  3414. // If lockout instances check to see if we are locked out
  3415. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3416. int32 time = 0;
  3417. // Check success timer
  3418. if (data->last_success_timestamp > 0) {
  3419. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3420. // Timer has not expired yet can't re enter
  3421. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3422. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3423. }
  3424. }
  3425. // Check failure timer
  3426. if (data->last_failure_timestamp > 0) {
  3427. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3428. // Timer has not expired yet
  3429. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3430. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3431. }
  3432. }
  3433. // Time > 0 then we are locked out, make the message and send it and return true
  3434. if (time > 0) {
  3435. string time_msg = "";
  3436. int16 hour;
  3437. int8 min;
  3438. int8 sec;
  3439. hour = time / 3600;
  3440. time = time % 3600;
  3441. min = time / 60;
  3442. time = time % 60;
  3443. sec = time;
  3444. if (hour > 0) {
  3445. char temp[10];
  3446. snprintf(temp, 9," %i", hour);
  3447. time_msg.append(temp);
  3448. time_msg.append(" hour");
  3449. time_msg.append((hour > 1) ? "s" : "");
  3450. }
  3451. if (min > 0) {
  3452. char temp[5];
  3453. snprintf(temp, 4," %i", min);
  3454. time_msg.append(temp);
  3455. time_msg.append(" minute");
  3456. time_msg.append((min > 1) ? "s" : "");
  3457. }
  3458. // Only add seconds if minutes and hours are 0
  3459. if (hour == 0 && min == 0 && sec > 0) {
  3460. char temp[5];
  3461. snprintf(temp, 4," %i", sec);
  3462. time_msg.append(temp);
  3463. time_msg.append(" second");
  3464. time_msg.append((sec > 1) ? "s" : "");
  3465. }
  3466. if(displayClient)
  3467. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3468. return time_msg;
  3469. }
  3470. }
  3471. }
  3472. return std::string("");
  3473. }
  3474. ZoneServer* Client::IdentifyInstance(int32 zoneID) {
  3475. int8 instanceType = database.GetInstanceTypeByZoneID(zoneID);
  3476. if(instanceType < 1)
  3477. return nullptr;
  3478. ZoneServer* instance_zone = nullptr;
  3479. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3480. if (data) {
  3481. std::string lockoutTime = IdentifyInstanceLockout(zoneID);
  3482. // If lockout instances check to see if we are locked out
  3483. if (lockoutTime.length() > 0) {
  3484. return nullptr;
  3485. }
  3486. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3487. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3488. // 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
  3489. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3490. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3491. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3492. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3493. }
  3494. else
  3495. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3496. data->instance_id = instance_zone->GetInstanceID();
  3497. }
  3498. }
  3499. return instance_zone;
  3500. }
  3501. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3502. ZoneServer* instance_zone = NULL;
  3503. int8 instanceType = 0;
  3504. // determine if this is a group instanced zone that already exists
  3505. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3506. if (instance_zone != NULL)
  3507. Zone(instance_zone->GetInstanceID(), zone_coords_valid);
  3508. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3509. {
  3510. // best to check if we already have our own instance!
  3511. if((instance_zone = IdentifyInstance(zoneID)) == nullptr)
  3512. {
  3513. switch (instanceType)
  3514. {
  3515. case SOLO_LOCKOUT_INSTANCE:
  3516. case GROUP_LOCKOUT_INSTANCE:
  3517. case RAID_LOCKOUT_INSTANCE:
  3518. {
  3519. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3520. if (instance_zone) {
  3521. // 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
  3522. // so delete `instances` entry for the zone when it shuts down.
  3523. 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());
  3524. if (db_id > 0)
  3525. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3526. }
  3527. break;
  3528. }
  3529. case SOLO_PERSIST_INSTANCE:
  3530. case GROUP_PERSIST_INSTANCE:
  3531. case RAID_PERSIST_INSTANCE:
  3532. {
  3533. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3534. if (instance_zone) {
  3535. 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());
  3536. if (db_id > 0)
  3537. 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()));
  3538. }
  3539. break;
  3540. }
  3541. case PUBLIC_INSTANCE:
  3542. case TRADESKILL_INSTANCE:
  3543. {
  3544. // if its public/tradeskill, look for a public already setup
  3545. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3546. if (instance_zone) {
  3547. // Check the current population against the max population, if greater or equal start a new version
  3548. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3549. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3550. }
  3551. else
  3552. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3553. break;
  3554. }
  3555. case PERSONAL_HOUSE_INSTANCE:
  3556. case GUILD_HOUSE_INSTANCE:
  3557. {
  3558. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3559. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3560. // with the OP_EnterHouseMsg opcode
  3561. break;
  3562. }
  3563. case QUEST_INSTANCE:
  3564. {
  3565. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3566. break;
  3567. /*
  3568. 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`;
  3569. */
  3570. }
  3571. default:
  3572. {
  3573. // NONE
  3574. }
  3575. }
  3576. }
  3577. if (instance_zone != NULL)
  3578. Zone(instance_zone, zone_coords_valid);
  3579. }
  3580. if (instance_zone != NULL)
  3581. return true;
  3582. else
  3583. return false;
  3584. }
  3585. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3586. Spawn* target = 0;
  3587. if (search_name || GetPlayer()->GetTarget()) {
  3588. Client* search_client = 0;
  3589. if (search_name) {
  3590. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3591. if (!target) {
  3592. search_client = zone_list.GetClientByCharName(search_name);
  3593. if (search_client)
  3594. target = search_client->GetPlayer();
  3595. }
  3596. if (target)
  3597. GetPlayer()->SetTarget(target);
  3598. }
  3599. else
  3600. target = GetPlayer()->GetTarget();
  3601. if (target && target != GetPlayer()) {
  3602. GetPlayer()->SetX(target->GetX());
  3603. GetPlayer()->SetY(target->GetY());
  3604. GetPlayer()->SetZ(target->GetZ());
  3605. GetPlayer()->SetHeading(target->GetHeading());
  3606. GetPlayer()->SetLocation(target->GetLocation());
  3607. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3608. }
  3609. else if (target)
  3610. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3611. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3612. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3613. else if (target) {
  3614. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3615. if (app)
  3616. QueuePacket(app);
  3617. }
  3618. }
  3619. if (!target)
  3620. return false;
  3621. else
  3622. return true;
  3623. }
  3624. bool Client::CheckZoneAccess(const char* zoneName) {
  3625. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3626. ZoneServer* zone = zone_list.Get(zoneName, false);
  3627. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3628. if (zone && zone->GetZoneLockState())
  3629. {
  3630. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3631. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3632. return false;
  3633. }
  3634. sint16 zoneMinStatus = 0;
  3635. int16 zoneMinLevel = 0;
  3636. int16 zoneMaxLevel = 0;
  3637. int16 zoneMinVersion = 0;
  3638. if (!zone)
  3639. {
  3640. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3641. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3642. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3643. return true;
  3644. }
  3645. }
  3646. else
  3647. {
  3648. zoneMinStatus = zone->GetMinimumStatus();
  3649. zoneMinLevel = zone->GetMinimumLevel();
  3650. zoneMaxLevel = zone->GetMaximumLevel();
  3651. zoneMinVersion = zone->GetMinimumVersion();
  3652. }
  3653. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3654. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3655. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3656. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3657. {
  3658. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3659. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3660. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3661. return false;
  3662. }
  3663. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3664. {
  3665. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3666. {
  3667. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3668. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3669. return false;
  3670. }
  3671. }
  3672. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3673. {
  3674. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3675. {
  3676. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3677. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3678. return false;
  3679. }
  3680. }
  3681. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3682. {
  3683. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3684. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3685. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3686. {
  3687. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3688. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3689. return false;
  3690. }
  3691. }
  3692. return true;
  3693. }
  3694. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID, bool is_spell) {
  3695. Zone(zone_list.GetByInstanceID(instanceid), set_coords, is_spell);
  3696. }
  3697. void Client::Zone(ZoneServer* new_zone, bool set_coords, bool is_spell) {
  3698. if (!new_zone) {
  3699. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3700. return;
  3701. }
  3702. client_zoning = true;
  3703. zoning_id = new_zone->GetZoneID();
  3704. zoning_instance_id = new_zone->GetInstanceID();
  3705. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3706. player->SetResurrecting(true);
  3707. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3708. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3709. MSaveSpellStateMutex.lock();
  3710. player->SaveSpellEffects();
  3711. player->SetSaveSpellEffects(true);
  3712. MSaveSpellStateMutex.unlock();
  3713. ResetSendMail();
  3714. // Remove players pet from zone if there is one
  3715. ((Entity*)player)->DismissAllPets();
  3716. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3717. GetCurrentZone()->RemoveSpawn(player, false, true, true, true, !is_spell);
  3718. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3719. SetZoningDestination(new_zone);
  3720. SetCurrentZone(new_zone);
  3721. if (player->GetGroupMemberInfo())
  3722. {
  3723. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3724. player->UpdateGroupMemberInfo();
  3725. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3726. }
  3727. // block out the member info for the group
  3728. TempRemoveGroup();
  3729. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3730. if (set_coords)
  3731. {
  3732. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3733. __FUNCTION__,
  3734. GetCurrentZone()->GetSafeX(),
  3735. GetCurrentZone()->GetSafeY(),
  3736. GetCurrentZone()->GetSafeZ(),
  3737. GetCurrentZone()->GetSafeHeading(),
  3738. new_zone->GetZoneName()
  3739. );
  3740. player->SetX(GetCurrentZone()->GetSafeX());
  3741. player->SetY(GetCurrentZone()->GetSafeY());
  3742. player->SetZ(GetCurrentZone()->GetSafeZ());
  3743. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3744. SetZoningCoords(GetCurrentZone()->GetSafeX(), GetCurrentZone()->GetSafeY(),
  3745. GetCurrentZone()->GetSafeZ(), GetCurrentZone()->GetSafeHeading());
  3746. }
  3747. else {
  3748. ResetZoningCoords();
  3749. }
  3750. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3751. Save();
  3752. char* new_zone_ip = 0;
  3753. if (IsPrivateAddress(this->GetIP()) && strlen(net.GetInternalWorldAddress()) > 0)
  3754. new_zone_ip = net.GetInternalWorldAddress();
  3755. else
  3756. new_zone_ip = net.GetWorldAddress();
  3757. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3758. int32 key = Timer::GetUnixTimeStamp();
  3759. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3760. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3761. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3762. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3763. if (version > 283) {
  3764. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3765. if (packet)
  3766. {
  3767. QueuePacket(packet->serialize());
  3768. safe_delete(packet);
  3769. }
  3770. }
  3771. }
  3772. void Client::Zone(const char* new_zone, bool set_coords, bool is_spell)
  3773. {
  3774. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3775. Zone(zone_list.Get(new_zone), set_coords, is_spell);
  3776. }
  3777. float Client::DistanceFrom(Client* client) {
  3778. float ret = 0;
  3779. if (client && client != this) {
  3780. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3781. ret = sqrt(ret);
  3782. }
  3783. return ret;
  3784. }
  3785. void Client::DetermineCharacterUpdates() {
  3786. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3787. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3788. cdu->account_id = GetAccountID();
  3789. cdu->char_id = GetCharacterID();
  3790. int32 timestamp = Timer::GetUnixTimeStamp();
  3791. int8 flag = GetTimeStampFlag();
  3792. if (flag & LEVEL_UPDATE_FLAG)
  3793. {
  3794. cdu->update_field = LEVEL_UPDATE_FLAG;
  3795. cdu->update_data = player->GetLevel();
  3796. loginserver.SendPacket(outpack);
  3797. }
  3798. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3799. if (flag & CLASS_UPDATE_FLAG)
  3800. {
  3801. cdu->update_field = CLASS_UPDATE_FLAG;
  3802. cdu->update_data = player->GetAdventureClass();
  3803. loginserver.SendPacket(outpack);
  3804. }
  3805. if (flag & GENDER_UPDATE_FLAG)
  3806. {
  3807. cdu->update_field = GENDER_UPDATE_FLAG;
  3808. cdu->update_data = player->GetGender();
  3809. loginserver.SendPacket(outpack);
  3810. }
  3811. if (flag & DELETE_UPDATE_FLAG) {
  3812. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3813. }
  3814. safe_delete(outpack); // Zone, armor and name use a different structure
  3815. if (flag & RACE_UPDATE_FLAG)
  3816. {
  3817. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3818. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3819. ru->account_id = GetAccountID();
  3820. ru->char_id = GetCharacterID();
  3821. ru->race = player->GetRace();
  3822. ru->model_type = player->GetModelType();
  3823. loginserver.SendPacket(outpack);
  3824. safe_delete(outpack);
  3825. }
  3826. if (flag & ZONE_UPDATE_FLAG) {
  3827. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3828. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3829. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3830. czu->account_id = GetAccountID();
  3831. czu->char_id = GetCharacterID();
  3832. czu->zone_id = GetCurrentZone()->GetZoneID();
  3833. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3834. czu->zone_length = strlen(zone_file);
  3835. if (czu->zone_length > 64)
  3836. czu->zone_length = 64;
  3837. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3838. loginserver.SendPacket(outpack);
  3839. safe_delete(outpack);
  3840. }
  3841. if (flag & ARMOR_UPDATE_FLAG) {
  3842. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3843. }
  3844. if (flag & NAME_UPDATE_FLAG) {
  3845. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3846. }
  3847. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3848. }
  3849. void Client::Save() {
  3850. if (GetCharacterID() == 0)
  3851. return;
  3852. if (current_zone) {
  3853. DetermineCharacterUpdates();
  3854. UpdateCharacterInstances();
  3855. this->SetLastSavedTimeStamp(Timer::GetCurrentTime2());
  3856. database.Save(this);
  3857. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3858. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3859. GetPlayer()->ResetQuickbarNeeded();
  3860. }
  3861. database.SaveItems(this);
  3862. database.SaveBuyBacks(this);
  3863. GetPlayer()->SaveHistory();
  3864. GetPlayer()->SaveLUAHistory();
  3865. MSaveSpellStateMutex.lock();
  3866. GetPlayer()->SaveSpellEffects();
  3867. MSaveSpellStateMutex.unlock();
  3868. }
  3869. }
  3870. void Client::UpdateCharacterInstances() {
  3871. if (GetPlayer() != NULL)
  3872. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3873. /*if ( GetPlayer() != NULL )
  3874. {
  3875. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3876. // to use for applying the update to each instances timer
  3877. int32 lastSaveTS = GetLastSavedTimeStamp();
  3878. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3879. int32 diffTS = newSaveTS - lastSaveTS;
  3880. // update instance timers
  3881. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3882. // update with the new timestamp and save the db
  3883. this->SetLastSavedTimeStamp(newSaveTS);
  3884. }*/
  3885. }
  3886. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3887. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3888. if (packet) {
  3889. packet->LoadPacketData(app->pBuffer, app->size);
  3890. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3891. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3892. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3893. vector<EntityCommand*> commands;
  3894. vector<EntityCommand*> delete_commands;
  3895. if (out && spawn) {
  3896. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3897. {
  3898. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3899. if (!spawn->primary_command_list[i]->default_allow_list)
  3900. {
  3901. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3902. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3903. continue;
  3904. }
  3905. else
  3906. {
  3907. // default is allow list, only deny if added to the list as deny (false itr second)
  3908. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3909. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3910. continue;
  3911. }
  3912. commands.push_back(spawn->primary_command_list[i]);
  3913. }
  3914. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3915. commands.push_back(spawn->secondary_command_list[i]);
  3916. if (spawn->IsPlayer()) {
  3917. if (player->IsFriend(spawn->GetName()))
  3918. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3919. else
  3920. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3921. if (player->IsIgnored(spawn->GetName()))
  3922. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3923. else
  3924. {
  3925. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3926. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3927. }
  3928. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3929. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3930. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3931. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3932. }
  3933. if(spawn->IsPlayer() && !player->GetGroupMemberInfo()->mentor_target_char_id)
  3934. delete_commands.push_back(player->CreateEntityCommand("Mentor", 10000, "mentor", "", 0, 0));
  3935. else if(spawn->IsPlayer() && player->GetGroupMemberInfo()->mentor_target_char_id == ((Player*)spawn)->GetCharacterID())
  3936. delete_commands.push_back(player->CreateEntityCommand("Stop Mentoring", 10000, "unmentor", "", 0, 0));
  3937. }
  3938. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3939. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3940. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3941. }
  3942. out->setDataByName("spawn_id", spawn_id);
  3943. out->setArrayLengthByName("num_verbs", commands.size());
  3944. for (int32 i = 0; i < commands.size(); i++) {
  3945. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3946. out->setArrayDataByName("distance", commands[i]->distance, i);
  3947. if (commands[i]->error_text.length() == 0)
  3948. out->setArrayAddToPacketByName("error", false, i);
  3949. else {
  3950. out->setArrayDataByName("display_error", 1, i);
  3951. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3952. }
  3953. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3954. }
  3955. EQ2Packet* outapp = out->serialize();
  3956. //DumpPacket(outapp);
  3957. QueuePacket(outapp);
  3958. safe_delete(out);
  3959. for (int32 i = 0; i < delete_commands.size(); i++) {
  3960. safe_delete(delete_commands[i]);
  3961. }
  3962. }
  3963. safe_delete(packet);
  3964. }
  3965. }
  3966. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3967. if (previous_value != new_value) {
  3968. 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);
  3969. char tmp[200] = { 0 };
  3970. 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);
  3971. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  3972. }
  3973. }
  3974. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3975. {
  3976. /* JA notes on the unknown:
  3977. 2 = ding glimmer
  3978. 16 = Achievement Unlocked
  3979. 6 no longer does anything
  3980. */
  3981. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3982. if (packet) {
  3983. packet->setDataByName("unknown", unknown);
  3984. packet->setMediumStringByName("text", text);
  3985. if (type && strlen(type) > 0)
  3986. packet->setMediumStringByName("message_type", type);
  3987. packet->setDataByName("size", size);
  3988. packet->setDataByName("red", red);
  3989. packet->setDataByName("green", green);
  3990. packet->setDataByName("blue", blue);
  3991. QueuePacket(packet->serialize());
  3992. safe_delete(packet);
  3993. }
  3994. }
  3995. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3996. if (new_level < 1) {
  3997. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3998. return;
  3999. }
  4000. if (player->GetLevel() != new_level) {
  4001. player->SetLevel(new_level);
  4002. if (player->GetGroupMemberInfo()) {
  4003. player->UpdateGroupMemberInfo();
  4004. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4005. }
  4006. }
  4007. if (new_level > old_level) {
  4008. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  4009. }
  4010. if (player->GetPet()) {
  4011. NPC* pet = (NPC*)player->GetPet();
  4012. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  4013. pet->SetLevel(new_level);
  4014. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4015. if (command_packet) {
  4016. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  4017. command_packet->setDataByName("anim_type", 1753);
  4018. QueuePacket(command_packet->serialize());
  4019. safe_delete(command_packet);
  4020. }
  4021. }
  4022. }
  4023. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4024. if (level_update) {
  4025. level_update->setDataByName("old_level", old_level);
  4026. level_update->setDataByName("new_level", new_level);
  4027. QueuePacket(level_update->serialize());
  4028. safe_delete(level_update);
  4029. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  4030. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  4031. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  4032. }
  4033. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4034. if (command_packet) {
  4035. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  4036. command_packet->setDataByName("anim_type", 1753);
  4037. QueuePacket(command_packet->serialize());
  4038. safe_delete(command_packet);
  4039. }
  4040. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  4041. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  4042. SendNewSpells(player->GetAdventureClass());
  4043. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4044. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4045. GetPlayer()->ChangePrimaryWeapon();
  4046. GetPlayer()->ChangeSecondaryWeapon();
  4047. GetPlayer()->ChangeRangedWeapon();
  4048. GetPlayer()->GetInfoStruct()->set_level(new_level);
  4049. // GetPlayer()->SetLevel(new_level);
  4050. 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__);
  4051. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  4052. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  4053. GetPlayer()->CalculateBonuses();
  4054. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  4055. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  4056. InfoStruct* info = player->GetInfoStruct();
  4057. info->set_agi_base(new_level * 2 + 15);
  4058. info->set_intel_base(new_level * 2 + 15);
  4059. info->set_wis_base(new_level * 2 + 15);
  4060. info->set_str_base(new_level * 2 + 15);
  4061. info->set_sta_base(new_level * 2 + 15);
  4062. info->set_cold_base((int16)(new_level * 1.5 + 10));
  4063. info->set_heat_base((int16)(new_level * 1.5 + 10));
  4064. info->set_disease_base((int16)(new_level * 1.5 + 10));
  4065. info->set_mental_base((int16)(new_level * 1.5 + 10));
  4066. info->set_magic_base((int16)(new_level * 1.5 + 10));
  4067. info->set_divine_base((int16)(new_level * 1.5 + 10));
  4068. info->set_poison_base((int16)(new_level * 1.5 + 10));
  4069. GetPlayer()->GetInfoStruct()->set_poison_base((int16)(new_level * 1.5 + 10));
  4070. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4071. GetPlayer()->SetCharSheetChanged(true);
  4072. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  4073. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4074. int16 new_skill_cap = 5 * new_level;
  4075. PlayerSkillList* player_skills = player->GetSkills();
  4076. player_skills->SetSkillCapsByType(SKILL_TYPE_ARMOR, new_skill_cap);
  4077. player_skills->SetSkillCapsByType(SKILL_TYPE_SHIELD, new_skill_cap);
  4078. //SKILL_TYPE_ARMOR/SKILL_TYPE_SHIELD always has the same current / max values
  4079. player_skills->SetSkillValuesByType(SKILL_TYPE_ARMOR, new_skill_cap, false);
  4080. player_skills->SetSkillValuesByType(SKILL_TYPE_SHIELD, new_skill_cap, false);
  4081. player_skills->SetSkillCapsByType(SKILL_TYPE_CLASS, new_skill_cap);
  4082. player_skills->SetSkillCapsByType(SKILL_TYPE_WEAPON, new_skill_cap);
  4083. //SKILL_TYPE_CLASS/SKILL_TYPE_WEAPON always has the same current/max values
  4084. player_skills->SetSkillValuesByType(SKILL_TYPE_CLASS, new_skill_cap, false);
  4085. player_skills->SetSkillValuesByType(SKILL_TYPE_WEAPON, new_skill_cap, false);
  4086. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  4087. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  4088. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  4089. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  4090. if (new_level > player->GetTSLevel())
  4091. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  4092. //SKILL_ID_DUALWIELD, SKILL_ID_FISTS, SKILL_ID_DESTROYING, and SKILL_ID_MAGIC_AFFINITY always have the current_val equal to max_val
  4093. if (player_skills->HasSkill(SKILL_ID_DUALWIELD))
  4094. player_skills->SetSkill(SKILL_ID_DUALWIELD, new_skill_cap);
  4095. if (player_skills->HasSkill(SKILL_ID_FISTS))
  4096. player_skills->SetSkill(SKILL_ID_FISTS, new_skill_cap);
  4097. if (player_skills->HasSkill(SKILL_ID_DESTROYING))
  4098. player_skills->SetSkill(SKILL_ID_DESTROYING, new_skill_cap);
  4099. if (player_skills->HasSkill(SKILL_ID_MAGIC_AFFINITY))
  4100. player_skills->SetSkill(SKILL_ID_MAGIC_AFFINITY, new_skill_cap);
  4101. Guild* guild = GetPlayer()->GetGuild();
  4102. if (guild) {
  4103. int8 event_type = 0;
  4104. if (new_level < 10)
  4105. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  4106. else if (new_level == 10)
  4107. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  4108. else if (new_level >= 11 && new_level < 20)
  4109. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  4110. else if (new_level == 20)
  4111. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  4112. else if (new_level >= 21 && new_level < 30)
  4113. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  4114. else if (new_level == 30)
  4115. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  4116. else if (new_level >= 31 && new_level < 40)
  4117. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  4118. else if (new_level == 40)
  4119. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  4120. else if (new_level >= 41 && new_level < 50)
  4121. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  4122. else if (new_level == 50)
  4123. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  4124. else if (new_level >= 51 && new_level < 60)
  4125. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  4126. else if (new_level == 60)
  4127. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  4128. else if (new_level >= 61 && new_level < 70)
  4129. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  4130. else if (new_level == 70)
  4131. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  4132. else if (new_level >= 71 && new_level < 80)
  4133. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  4134. else if (new_level == 80)
  4135. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  4136. 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());
  4137. 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());
  4138. guild->UpdateGuildMemberInfo(GetPlayer());
  4139. guild->SendGuildMember(GetPlayer());
  4140. guild->SendGuildMemberList();
  4141. }
  4142. // Need to send the trait list every time the players level changes
  4143. // Also need to force the char sheet update or else there can be a large delay from when you level
  4144. // to when you are actually able to select traits.
  4145. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4146. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4147. if (version > 546)
  4148. master_aa_list.DisplayAA(this, 0, 0);
  4149. if (GetPlayer()->SpawnedBots.size() > 0) {
  4150. map<int32, int32>::iterator itr;
  4151. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  4152. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  4153. if (bot && bot->IsBot())
  4154. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  4155. }
  4156. }
  4157. }
  4158. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  4159. if (new_level < 1) {
  4160. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  4161. return;
  4162. }
  4163. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  4164. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  4165. return;
  4166. }
  4167. if (new_level > old_level)
  4168. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  4169. if (player->GetTSLevel() != new_level) {
  4170. player->SetTSLevel(new_level);
  4171. if (player->GetGroupMemberInfo()) {
  4172. player->UpdateGroupMemberInfo();
  4173. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  4174. }
  4175. }
  4176. // Only tradeskill skills should increace, and then only those related to your class
  4177. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  4178. if (level_update) {
  4179. level_update->setDataByName("old_level", old_level);
  4180. level_update->setDataByName("new_level", new_level);
  4181. level_update->setDataByName("type", 1);
  4182. QueuePacket(level_update->serialize());
  4183. safe_delete(level_update);
  4184. }
  4185. // Need to make tradeskill versions of the following
  4186. //SendNewSpells(player->GetAdventureClass());
  4187. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  4188. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  4189. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  4190. if (command_packet) {
  4191. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  4192. command_packet->setDataByName("anim_type", 1753);
  4193. QueuePacket(command_packet->serialize());
  4194. safe_delete(command_packet);
  4195. }
  4196. GetPlayer()->GetInfoStruct()->set_tradeskill_level(new_level);
  4197. GetPlayer()->SetTSLevel(new_level);
  4198. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  4199. GetPlayer()->SetCharSheetChanged(true);
  4200. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  4201. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  4202. PlayerSkillList* player_skills = player->GetSkills();
  4203. int16 specialize_skill_cap = new_level * 5;
  4204. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  4205. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  4206. int8 ts_class = player->GetTradeskillClass();
  4207. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  4208. int32 skill_id_1, skill_id_2, skill_id_3;
  4209. switch (base_ts_class) {
  4210. case ARTISAN:
  4211. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4212. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4213. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4214. break;
  4215. case OUTFITTER:
  4216. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4217. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4218. skill_id_1 = SKILL_ID_TAILORING;
  4219. skill_id_2 = SKILL_ID_METALSHAPING;
  4220. skill_id_3 = SKILL_ID_METALWORKING;
  4221. if (ts_class == TAILOR) {
  4222. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4223. skill_id_1 = 0;
  4224. }
  4225. else if (ts_class == ARMORER) {
  4226. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4227. skill_id_2 = 0;
  4228. }
  4229. else if (ts_class == WEAPONSMITH) {
  4230. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4231. skill_id_3 = 0;
  4232. }
  4233. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4234. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4235. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4236. break;
  4237. case SCHOLAR:
  4238. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4239. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  4240. skill_id_1 = SKILL_ID_SCRIBING;
  4241. skill_id_2 = SKILL_ID_CHEMISTRY;
  4242. skill_id_3 = SKILL_ID_ARTIFICING;
  4243. if (ts_class == SAGE) {
  4244. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4245. skill_id_1 = 0;
  4246. }
  4247. else if (ts_class == ALCHEMIST) {
  4248. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4249. skill_id_2 = 0;
  4250. }
  4251. else if (ts_class == JEWELER) {
  4252. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4253. skill_id_3 = 0;
  4254. }
  4255. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4256. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4257. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4258. break;
  4259. case CRAFTSMAN:
  4260. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  4261. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  4262. skill_id_1 = SKILL_ID_ARTISTRY;
  4263. skill_id_2 = SKILL_ID_FLETCHING;
  4264. skill_id_3 = SKILL_ID_SCULPTING;
  4265. if (ts_class == PROVISIONER) {
  4266. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  4267. skill_id_1 = 0;
  4268. }
  4269. else if (ts_class == WOODWORKER) {
  4270. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  4271. skill_id_2 = 0;
  4272. }
  4273. else if (ts_class == CARPENTER) {
  4274. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  4275. skill_id_3 = 0;
  4276. }
  4277. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  4278. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  4279. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  4280. break;
  4281. default:
  4282. break;
  4283. }
  4284. if (new_level > player->GetAdventureClass())
  4285. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  4286. Guild* guild = GetPlayer()->GetGuild();
  4287. if (guild) {
  4288. int8 event_type = 0;
  4289. if (new_level < 10)
  4290. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  4291. else if (new_level == 10)
  4292. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  4293. else if (new_level >= 11 && new_level < 20)
  4294. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  4295. else if (new_level == 20)
  4296. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  4297. else if (new_level >= 21 && new_level < 30)
  4298. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  4299. else if (new_level == 30)
  4300. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  4301. else if (new_level >= 31 && new_level < 40)
  4302. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  4303. else if (new_level == 40)
  4304. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  4305. else if (new_level >= 41 && new_level < 50)
  4306. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  4307. else if (new_level == 50)
  4308. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  4309. else if (new_level >= 51 && new_level < 60)
  4310. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  4311. else if (new_level == 60)
  4312. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  4313. else if (new_level >= 61 && new_level < 70)
  4314. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  4315. else if (new_level == 70)
  4316. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  4317. else if (new_level >= 71 && new_level < 80)
  4318. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  4319. else if (new_level == 80)
  4320. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  4321. 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());
  4322. 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());
  4323. guild->UpdateGuildMemberInfo(GetPlayer());
  4324. guild->SendGuildMember(GetPlayer());
  4325. guild->SendGuildMemberList();
  4326. }
  4327. // Need to send the trait list every time the players level changes
  4328. // Also need to force the char sheet update or else there can be a large delay from when you level
  4329. // to when you are actually able to select traits.
  4330. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  4331. QueuePacket(master_trait_list.GetTraitListPacket(this));
  4332. }
  4333. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  4334. if (entity)
  4335. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  4336. }
  4337. void Client::CloseLoot(int32 spawn_id) {
  4338. if (GetVersion() > 546) {
  4339. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  4340. if (packet) {
  4341. packet->setDataByName("window_id", 4);
  4342. EQ2Packet* outapp = packet->serialize();
  4343. if (outapp) {
  4344. //DumpPacket(outapp);
  4345. QueuePacket(outapp);
  4346. }
  4347. safe_delete(packet);
  4348. }
  4349. }
  4350. else if(spawn_id > 0){
  4351. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4352. if (packet) {
  4353. packet->setDataByName("spawn_id", spawn_id);
  4354. EQ2Packet* outapp = packet->serialize();
  4355. if (outapp)
  4356. QueuePacket(outapp);
  4357. safe_delete(packet);
  4358. }
  4359. }
  4360. }
  4361. string Client::GetCoinMessage(int32 total_coins) {
  4362. if (total_coins == 0) {
  4363. return " 0 Copper";
  4364. }
  4365. char tmp[64] = { 0 };
  4366. string message = "";
  4367. int32 val = 0;
  4368. if (total_coins >= 1000000) {
  4369. val = total_coins / 1000000;
  4370. total_coins -= 1000000 * val;
  4371. sprintf(tmp, " %u Platinum", val);
  4372. message.append(tmp);
  4373. memset(tmp, 0, 64);
  4374. }
  4375. if (total_coins >= 10000) {
  4376. val = total_coins / 10000;
  4377. total_coins -= 10000 * val;
  4378. sprintf(tmp, " %u Gold", val);
  4379. message.append(tmp);
  4380. memset(tmp, 0, 64);
  4381. }
  4382. if (total_coins >= 100) {
  4383. val = total_coins / 100;
  4384. total_coins -= 100 * val;
  4385. sprintf(tmp, " %u Silver", val);
  4386. message.append(tmp);
  4387. memset(tmp, 0, 64);
  4388. }
  4389. if (total_coins > 0) {
  4390. sprintf(tmp, " %u Copper", (int32)total_coins);
  4391. message.append(tmp);
  4392. }
  4393. return message;
  4394. }
  4395. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4396. if (!entity) {
  4397. CloseLoot(0);
  4398. return;
  4399. }
  4400. if (total_coins > 0) {
  4401. player->AddCoins(total_coins);
  4402. //PlaySound("coin_cha_ching");
  4403. string message = "";
  4404. if (entity->GetHP() == 0) {
  4405. message = "You loot ";
  4406. entity->SetLootCoins(0);
  4407. }
  4408. else
  4409. message = "You receive ";
  4410. message.append(GetCoinMessage(total_coins));
  4411. if (entity->GetHP() == 0)
  4412. message.append(" from the corpse of ").append(entity->GetName());
  4413. int8 type = CHANNEL_LOOT;
  4414. SimpleMessage(type, message.c_str());
  4415. }
  4416. if (!items || items->size() == 0)
  4417. CloseLoot(entity->GetID());
  4418. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4419. if (packet) {
  4420. vector<Item*>::iterator itr;
  4421. int32 packet_size = 0;
  4422. EQ2Packet* outapp = 0;
  4423. uchar* data = 0;
  4424. if (GetVersion() >= 284) {
  4425. if (GetVersion() > 546) {
  4426. if (items && items->size() > 0) {
  4427. packet->setDataByName("loot_count", items->size());
  4428. packet->setDataByName("display", 1);
  4429. }
  4430. packet->setDataByName("loot_type", 1);
  4431. if (version >= 1096)
  4432. packet->setDataByName("lotto_timeout", 0x78);
  4433. else
  4434. packet->setDataByName("lotto_timeout", 0x3C);
  4435. packet->setDataByName("loot_id", entity->GetID());
  4436. EQ2Packet* tmpPacket = packet->serialize();
  4437. packet_size += tmpPacket->size;
  4438. if (items && items->size() > 0) {
  4439. data = new uchar[items->size() * 1000 + packet_size];
  4440. memset(data, 0, items->size() * 1000 + packet_size);
  4441. }
  4442. else {
  4443. data = new uchar[packet_size];
  4444. memset(data, 0, packet_size);
  4445. }
  4446. uchar* ptr = data;
  4447. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4448. ptr += tmpPacket->size;
  4449. safe_delete(tmpPacket);
  4450. Item* item = 0;
  4451. if (items && items->size() > 0) {
  4452. for (itr = items->begin(); itr != items->end(); itr++) {
  4453. item = *itr;
  4454. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4455. ptr += sizeof(int32);
  4456. packet_size += sizeof(int32);
  4457. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4458. int8 offset = 0;
  4459. if (GetVersion() >= 1188) {
  4460. offset = 13;
  4461. }
  4462. else if (GetVersion() >= 860) {
  4463. offset = 11;
  4464. }
  4465. else if (GetVersion() <= 546) {
  4466. offset = 19;
  4467. }
  4468. else {
  4469. offset = 10;
  4470. }
  4471. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4472. ptr += tmpPacket->size - offset;
  4473. packet_size += tmpPacket->size - offset;
  4474. safe_delete(tmpPacket);
  4475. }
  4476. }
  4477. packet_size -= sizeof(int32);
  4478. memcpy(data, &packet_size, sizeof(int32));
  4479. packet_size += sizeof(int32);
  4480. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4481. }
  4482. else {
  4483. if (items && items->size() > 0) {
  4484. packet->setArrayLengthByName("loot_count", items->size());
  4485. Item* item = 0;
  4486. if (items && items->size() > 0) {
  4487. int i = 0;
  4488. for (itr = items->begin(); itr != items->end(); itr++) {
  4489. item = *itr;
  4490. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4491. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4492. i++;
  4493. }
  4494. }
  4495. packet->setDataByName("display", 1);
  4496. }
  4497. packet->setDataByName("loot_type", 1); // normal
  4498. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4499. packet->setDataByName("spawn_id", entity->GetID());
  4500. outapp = packet->serialize();
  4501. }
  4502. }
  4503. else {
  4504. if (items && items->size() > 0) {
  4505. packet->setArrayLengthByName("loot_count", items->size());
  4506. for (int i = 0; i < items->size(); i++) {
  4507. Item* item = (*items)[i];
  4508. packet->setArrayDataByName("name", item->name.c_str(), i);
  4509. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4510. packet->setArrayDataByName("count", item->details.count, i);
  4511. packet->setArrayDataByName("icon", item->details.icon, i);
  4512. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4513. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4514. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4515. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4516. else
  4517. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4518. }
  4519. }
  4520. packet->setDataByName("object_id", entity->GetID());
  4521. packet->setDataByName("unknown3", 1);
  4522. packet->setDataByName("unknown4", 1);
  4523. packet->setDataByName("unknown5", 60);
  4524. outapp = packet->serialize();
  4525. }
  4526. if (outapp) {
  4527. DumpPacket(outapp);
  4528. QueuePacket(outapp);
  4529. }
  4530. safe_delete_array(data);
  4531. safe_delete(packet);
  4532. }
  4533. }
  4534. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4535. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4536. int32 total_coins = entity->GetLootCoins();
  4537. entity->LockLoot();
  4538. Loot(total_coins, entity->GetLootItems(), entity);
  4539. entity->UnlockLoot();
  4540. OpenChest(entity, attemptDisarm);
  4541. }
  4542. else
  4543. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4544. }
  4545. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4546. {
  4547. if (!entity)
  4548. return;
  4549. int8 chest_difficulty = 0;
  4550. int32 state = 0;
  4551. // Check for the chest and set the action state
  4552. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4553. string modelName;
  4554. if (entity->GetModelType() == 4034) {
  4555. // small chest, open with copper coins
  4556. // does not include traps, however can be disarmed
  4557. chest_difficulty = 1;
  4558. state = 11899;
  4559. modelName.append("Small Chest");
  4560. }
  4561. else if (entity->GetModelType() == 5864) {
  4562. // treasure chest, open with silver coins
  4563. chest_difficulty = 2;
  4564. state = 11901;
  4565. modelName.append("Treasure Chest");
  4566. }
  4567. else if (entity->GetModelType() == 5865) {
  4568. // ornate chest, open with gold coins
  4569. chest_difficulty = 3;
  4570. state = 11900;
  4571. modelName.append("Ornate Chest");
  4572. }
  4573. else if (entity->GetModelType() == 4015) {
  4574. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4575. chest_difficulty = 5;
  4576. state = 11898;
  4577. modelName.append("Exquisite Chest");
  4578. }
  4579. bool firstChestOpen = false;
  4580. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4581. {
  4582. ChestTrap::ChestTrapInfo nextTrap;
  4583. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4584. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4585. firstChestOpen = true;
  4586. entity->SetTrapTriggered(true, state);
  4587. if (ret)
  4588. {
  4589. if (disarmSkill && attemptDisarm)
  4590. {
  4591. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4592. {
  4593. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4594. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4595. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4596. }
  4597. else
  4598. {
  4599. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4600. }
  4601. // despite fail/succeed we should always try to increase skill if disarm is available
  4602. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4603. }
  4604. else // no disarm skill, always fail
  4605. {
  4606. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4607. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4608. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4609. }
  4610. }
  4611. }
  4612. else if (!entity->HasTrapTriggered())
  4613. {
  4614. firstChestOpen = true;
  4615. entity->SetTrapTriggered(true, state);
  4616. }
  4617. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4618. // for those in range the SendStateCommand will cause it to animate open.
  4619. // players not currently in radius will have it queued with client->QueueStateCommand when SendSpawn takes place
  4620. if (firstChestOpen)
  4621. GetCurrentZone()->SendStateCommand(entity, state);
  4622. }
  4623. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4624. {
  4625. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4626. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4627. if (source == NULL)
  4628. source = (Entity*)GetPlayer();
  4629. if (spell)
  4630. {
  4631. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4632. if (gmi && gmi->group_id)
  4633. {
  4634. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4635. if (group)
  4636. {
  4637. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4638. deque<GroupMemberInfo*>* members = group->GetMembers();
  4639. if(!members)
  4640. return;
  4641. for (int8 i = 0; i < members->size(); i++) {
  4642. Entity* member = members->at(i)->member;
  4643. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4644. continue;
  4645. // if we have a radius provided then check if the group member is outside the radius or not
  4646. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4647. continue;
  4648. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4649. }
  4650. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4651. }
  4652. }
  4653. else
  4654. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4655. }
  4656. }
  4657. Spawn* Client::GetBanker() {
  4658. return banker;
  4659. }
  4660. void Client::SetBanker(Spawn* in_banker) {
  4661. banker = in_banker;
  4662. }
  4663. void Client::Bank(Spawn* banker, bool cancel) {
  4664. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4665. if (!cancel)
  4666. SetBanker(banker);
  4667. else
  4668. SetBanker(0);
  4669. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4670. if (packet) {
  4671. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4672. int64 coins = GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + GetPlayer()->GetInfoStruct()->get_bank_coin_silver() * 100 +
  4673. GetPlayer()->GetInfoStruct()->get_bank_coin_gold() * 10000 + (int64)GetPlayer()->GetInfoStruct()->get_bank_coin_plat() * 1000000;
  4674. int32 coins1, coins2;
  4675. coins1 = ((int32*)&coins)[0];
  4676. coins2 = ((int32*)&coins)[1];
  4677. packet->setDataByName("bank_coins", coins1);
  4678. packet->setDataByName("bank_coins2", coins2);
  4679. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->get_coin_copper());
  4680. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->get_coin_silver());
  4681. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->get_coin_gold());
  4682. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->get_coin_plat());
  4683. if (!cancel)
  4684. packet->setDataByName("display", 1);
  4685. QueuePacket(packet->serialize());
  4686. safe_delete(packet);
  4687. }
  4688. }
  4689. }
  4690. void Client::BankWithdrawal(int64 amount) {
  4691. bool cheater = false;
  4692. if (GetBanker() && amount > 0) {
  4693. string withdrawal = "";
  4694. char withdrawal_data[512] = { 0 };
  4695. int32 tmp = 0;
  4696. if (amount >= 1000000) {
  4697. tmp = amount / 1000000;
  4698. int32 bank_coins_plat = GetPlayer()->GetBankCoinsPlat();
  4699. if (tmp > bank_coins_plat)
  4700. cheater = true;
  4701. else {
  4702. GetPlayer()->GetInfoStruct()->set_bank_coin_plat(bank_coins_plat - tmp);
  4703. GetPlayer()->GetInfoStruct()->add_coin_plat(tmp);
  4704. amount -= (int64)tmp * 1000000;
  4705. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4706. withdrawal.append(withdrawal_data);
  4707. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4708. }
  4709. }
  4710. if (!cheater && amount >= 10000) {
  4711. tmp = amount / 10000;
  4712. if (tmp > GetPlayer()->GetBankCoinsGold())
  4713. cheater = true;
  4714. else {
  4715. int32 bank_coins_gold = GetPlayer()->GetInfoStruct()->get_bank_coin_gold();
  4716. bank_coins_gold -= tmp;
  4717. if ((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) > 100) {
  4718. GetPlayer()->GetInfoStruct()->set_coin_gold((GetPlayer()->GetInfoStruct()->get_coin_gold() + tmp) - 100);
  4719. GetPlayer()->GetInfoStruct()->add_coin_plat(1);
  4720. }
  4721. else
  4722. GetPlayer()->GetInfoStruct()->add_coin_gold(tmp);
  4723. amount -= tmp * 10000;
  4724. sprintf(withdrawal_data, "%u Gold ", tmp);
  4725. withdrawal.append(withdrawal_data);
  4726. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4727. }
  4728. }
  4729. if (!cheater && amount >= 100) {
  4730. tmp = amount / 100;
  4731. int32 bank_coins_silver = GetPlayer()->GetBankCoinsSilver();
  4732. if (tmp > bank_coins_silver)
  4733. cheater = true;
  4734. else {
  4735. GetPlayer()->GetInfoStruct()->set_bank_coin_silver(bank_coins_silver - tmp);
  4736. if ((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) > 100) {
  4737. GetPlayer()->GetInfoStruct()->set_coin_silver((GetPlayer()->GetInfoStruct()->get_coin_silver() + tmp) - 100);
  4738. GetPlayer()->GetInfoStruct()->add_coin_gold(1);
  4739. }
  4740. else
  4741. GetPlayer()->GetInfoStruct()->add_coin_silver(tmp);
  4742. amount -= tmp * 100;
  4743. sprintf(withdrawal_data, "%u Silver ", tmp);
  4744. withdrawal.append(withdrawal_data);
  4745. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4746. }
  4747. }
  4748. if (!cheater) {
  4749. if (amount > 0) {
  4750. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4751. withdrawal.append(withdrawal_data);
  4752. int32 bank_coin_copper = GetPlayer()->GetInfoStruct()->get_bank_coin_copper();
  4753. GetPlayer()->GetInfoStruct()->set_bank_coin_copper(bank_coin_copper - amount);
  4754. if ((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) > 100) {
  4755. GetPlayer()->GetInfoStruct()->set_coin_copper((GetPlayer()->GetInfoStruct()->get_coin_copper() + amount) - 100);
  4756. GetPlayer()->GetInfoStruct()->add_coin_silver(1);
  4757. }
  4758. else
  4759. GetPlayer()->GetInfoStruct()->add_coin_copper(amount);
  4760. }
  4761. if (withdrawal.length() > 0) {
  4762. withdrawal.append("withdrawn ");
  4763. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4764. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4765. withdrawal.append(withdrawal_data);
  4766. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4767. }
  4768. }
  4769. else
  4770. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4771. player->SetCharSheetChanged(true);
  4772. Bank(banker);
  4773. }
  4774. }
  4775. void Client::BankDeposit(int64 amount) {
  4776. bool cheater = false;
  4777. if (GetBanker() && amount > 0) {
  4778. int32 tmp = 0;
  4779. char deposit_data[512] = { 0 };
  4780. string deposit = "";
  4781. if (amount >= 1000000) {
  4782. tmp = amount / 1000000;
  4783. if (tmp > GetPlayer()->GetCoinsPlat())
  4784. cheater = true;
  4785. else {
  4786. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(tmp);
  4787. GetPlayer()->GetInfoStruct()->set_coin_plat(GetPlayer()->GetInfoStruct()->get_coin_plat() - tmp);
  4788. amount -= (int64)tmp * 1000000;
  4789. sprintf(deposit_data, "%u Platinum ", tmp);
  4790. deposit.append(deposit_data);
  4791. memset(deposit_data, 0, sizeof(deposit_data));
  4792. }
  4793. }
  4794. if (!cheater && amount >= 10000) {
  4795. tmp = amount / 10000;
  4796. if (tmp > GetPlayer()->GetCoinsGold())
  4797. cheater = true;
  4798. else {
  4799. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) > 100) {
  4800. GetPlayer()->GetInfoStruct()->set_bank_coin_gold((GetPlayer()->GetInfoStruct()->get_bank_coin_gold() + tmp) - 100);
  4801. GetPlayer()->GetInfoStruct()->add_bank_coin_plat(1);
  4802. }
  4803. else
  4804. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(tmp);
  4805. GetPlayer()->GetInfoStruct()->set_coin_gold(GetPlayer()->GetInfoStruct()->get_coin_gold() - tmp);
  4806. amount -= tmp * 10000;
  4807. sprintf(deposit_data, "%u Gold ", tmp);
  4808. deposit.append(deposit_data);
  4809. memset(deposit_data, 0, sizeof(deposit_data));
  4810. }
  4811. }
  4812. if (!cheater && amount >= 100) {
  4813. tmp = amount / 100;
  4814. if (tmp > GetPlayer()->GetCoinsSilver())
  4815. cheater = true;
  4816. else {
  4817. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) > 100) {
  4818. GetPlayer()->GetInfoStruct()->set_bank_coin_silver((GetPlayer()->GetInfoStruct()->get_bank_coin_silver() + tmp) - 100);
  4819. GetPlayer()->GetInfoStruct()->add_bank_coin_gold(1);
  4820. }
  4821. else
  4822. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(tmp);
  4823. GetPlayer()->GetInfoStruct()->set_coin_silver(GetPlayer()->GetInfoStruct()->get_coin_silver() - tmp);
  4824. amount -= tmp * 100;
  4825. sprintf(deposit_data, "%u Silver ", tmp);
  4826. deposit.append(deposit_data);
  4827. memset(deposit_data, 0, sizeof(deposit_data));
  4828. }
  4829. }
  4830. if (!cheater) {
  4831. if (amount > 0) {
  4832. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4833. deposit.append(deposit_data);
  4834. if ((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) > 100) {
  4835. GetPlayer()->GetInfoStruct()->set_bank_coin_copper((GetPlayer()->GetInfoStruct()->get_bank_coin_copper() + amount) - 100);
  4836. GetPlayer()->GetInfoStruct()->add_bank_coin_silver(1);
  4837. }
  4838. else
  4839. GetPlayer()->GetInfoStruct()->add_bank_coin_copper(amount);
  4840. GetPlayer()->GetInfoStruct()->set_coin_copper(GetPlayer()->GetInfoStruct()->get_coin_copper() - amount);
  4841. }
  4842. if (deposit.length() > 0) {
  4843. deposit.append("deposited ");
  4844. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->get_bank_coin_plat(),
  4845. GetPlayer()->GetInfoStruct()->get_bank_coin_gold(), GetPlayer()->GetInfoStruct()->get_bank_coin_silver(), GetPlayer()->GetInfoStruct()->get_bank_coin_copper());
  4846. deposit.append(deposit_data);
  4847. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4848. }
  4849. }
  4850. else
  4851. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4852. player->SetCharSheetChanged(true);
  4853. Bank(banker);
  4854. }
  4855. }
  4856. void Client::AddPendingQuestAcceptReward(Quest* quest)
  4857. {
  4858. MPendingQuestAccept.lock();
  4859. pending_quest_accept.push_back(quest);
  4860. MPendingQuestAccept.unlock();
  4861. }
  4862. void Client::AddPendingQuestReward(Quest* quest, bool update) {
  4863. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4864. quest_pending_reward.push_back(quest);
  4865. quest_updates = update;
  4866. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4867. }
  4868. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4869. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4870. quest_pending_updates[quest_id][step_id] = progress;
  4871. quest_updates = true;
  4872. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4873. }
  4874. void Client::ProcessQuestUpdates() {
  4875. if (quest_pending_updates.size() > 0) {
  4876. map<int32, map<int32, int32> > tmp_quest_updates;
  4877. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4878. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4879. quest_pending_updates.clear();
  4880. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4881. map<int32, map<int32, int32> >::iterator quest_itr;
  4882. map<int32, int32>::iterator step_itr;
  4883. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4884. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4885. if (step_itr->second == 0xFFFFFFFF) {
  4886. SetStepComplete(quest_itr->first, step_itr->first);
  4887. player->SendQuestRequiredSpawns(quest_itr->first);
  4888. }
  4889. else
  4890. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4891. }
  4892. }
  4893. }
  4894. if (quest_pending_reward.size() > 0) {
  4895. vector<Quest*>::iterator itr;
  4896. vector<Quest*> tmp_quest_rewards;
  4897. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4898. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4899. quest_pending_reward.clear();
  4900. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4901. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4902. GiveQuestReward(*itr);
  4903. }
  4904. }
  4905. quest_updates = false;
  4906. }
  4907. void Client::CheckQuestQueue() {
  4908. MQuestQueue.writelock();
  4909. last_update_time = 0;
  4910. vector<QueuedQuest*>::iterator itr;
  4911. QueuedQuest* queued_quest = 0;
  4912. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4913. queued_quest = *itr;
  4914. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4915. 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
  4916. SendQuestJournal();
  4917. safe_delete(queued_quest);
  4918. }
  4919. quest_queue.clear();
  4920. MQuestQueue.releasewritelock();
  4921. }
  4922. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4923. Quest* quest = player->SetStepComplete(quest_id, step);
  4924. if (quest) {
  4925. SendQuestUpdate(quest);
  4926. GetCurrentZone()->SendQuestUpdates(this);
  4927. }
  4928. }
  4929. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4930. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4931. if (quest) {
  4932. SendQuestUpdate(quest);
  4933. GetCurrentZone()->SendQuestUpdates(this);
  4934. }
  4935. }
  4936. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4937. bool hadUpdates = false;
  4938. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4939. if (quest_updates) {
  4940. for (int32 i = 0; i < quest_updates->size(); i++)
  4941. {
  4942. SendQuestUpdate(quest_updates->at(i));
  4943. hadUpdates = true;
  4944. }
  4945. }
  4946. safe_delete(quest_updates);
  4947. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4948. if (quest_failures) {
  4949. for (int32 i = 0; i < quest_failures->size(); i++)
  4950. {
  4951. SendQuestFailure(quest_failures->at(i));
  4952. hadUpdates = true;
  4953. }
  4954. }
  4955. safe_delete(quest_failures);
  4956. if (hadUpdates)
  4957. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4958. }
  4959. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4960. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4961. if (quest_updates) {
  4962. for (int32 i = 0; i < quest_updates->size(); i++)
  4963. SendQuestUpdate(quest_updates->at(i));
  4964. GetCurrentZone()->SendQuestUpdates(this);
  4965. }
  4966. safe_delete(quest_updates);
  4967. }
  4968. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4969. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4970. if (quest_updates) {
  4971. for (int32 i = 0; i < quest_updates->size(); i++)
  4972. SendQuestUpdate(quest_updates->at(i));
  4973. }
  4974. safe_delete(quest_updates);
  4975. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4976. if (quest_failures) {
  4977. for (int32 i = 0; i < quest_failures->size(); i++)
  4978. SendQuestFailure(quest_failures->at(i));
  4979. }
  4980. safe_delete(quest_failures);
  4981. }
  4982. void Client::CheckPlayerQuestsLocationUpdate() {
  4983. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4984. if (quest_updates) {
  4985. for (int32 i = 0; i < quest_updates->size(); i++)
  4986. SendQuestUpdate(quest_updates->at(i));
  4987. }
  4988. safe_delete(quest_updates);
  4989. }
  4990. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4991. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4992. if (quest_updates) {
  4993. for (int32 i = 0; i < quest_updates->size(); i++)
  4994. SendQuestUpdate(quest_updates->at(i));
  4995. }
  4996. safe_delete(quest_updates);
  4997. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4998. if (quest_failures) {
  4999. for (int32 i = 0; i < quest_failures->size(); i++)
  5000. SendQuestFailure(quest_failures->at(i));
  5001. }
  5002. safe_delete(quest_failures);
  5003. }
  5004. void Client::AddPendingQuest(Quest* quest, bool forced) {
  5005. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  5006. player->pending_quests[quest->GetQuestID()] = quest;
  5007. AcceptQuest(quest->GetQuestID());
  5008. }
  5009. else {
  5010. player->pending_quests[quest->GetQuestID()] = quest;
  5011. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  5012. //DumpPacket(outapp);
  5013. QueuePacket(outapp);
  5014. }
  5015. }
  5016. Quest* Client::GetActiveQuest(int32 quest_id) {
  5017. Quest* quest = 0;
  5018. GetPlayer()->MPlayerQuests.readlock(__FUNCTION__, __LINE__);
  5019. if (player->player_quests.count(quest_id) > 0) {
  5020. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  5021. quest = player->player_quests[quest_id];
  5022. }
  5023. GetPlayer()->MPlayerQuests.releasereadlock(__FUNCTION__, __LINE__);
  5024. return quest;
  5025. }
  5026. void Client::AcceptQuest(int32 id) {
  5027. Quest* quest = GetPendingQuest(id);
  5028. if (quest) {
  5029. RemovePendingQuest(quest);
  5030. AddPlayerQuest(quest);
  5031. GetCurrentZone()->SendQuestUpdates(this);
  5032. // If character has already completed this quest once update the given date in the database
  5033. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  5034. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  5035. if (quest2)
  5036. quest->SetCompleteCount(quest2->GetCompleteCount());
  5037. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  5038. }
  5039. }
  5040. }
  5041. Quest* Client::GetPendingQuest(int32 id) {
  5042. if (player->pending_quests.count(id) > 0) {
  5043. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  5044. return player->pending_quests[id];
  5045. }
  5046. return 0;
  5047. }
  5048. void Client::RemovePendingQuest(Quest* quest) {
  5049. player->pending_quests.erase(quest->GetQuestID());
  5050. }
  5051. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  5052. if (!quest || !progress) {
  5053. return;
  5054. }
  5055. map<int32, int32>::iterator itr;
  5056. QuestStep* step = 0;
  5057. player->SetZone(GetCurrentZone(), GetVersion());
  5058. for (itr = progress->begin(); itr != progress->end(); itr++) {
  5059. step = quest->GetQuestStep(itr->first);
  5060. if (step && itr->second > 0) {
  5061. step->SetStepProgress(itr->second);
  5062. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  5063. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  5064. }
  5065. }
  5066. if (lua_interface && step)
  5067. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  5068. else if(!step) {
  5069. LogWrite(QUEST__ERROR, 0, "Client", "Missing step for quest %s (ID %u), cannot CallQuestFunction for CurrentStep", quest->GetName(), quest->GetQuestID());
  5070. }
  5071. }
  5072. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  5073. bool lockCleared = false;
  5074. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5075. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  5076. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  5077. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  5078. int32 questID = quest->GetQuestID();
  5079. lockCleared = true;
  5080. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5081. RemovePlayerQuest(questID, false, false);
  5082. }
  5083. player->player_quests[quest->GetQuestID()] = quest;
  5084. if(!lockCleared)
  5085. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5086. quest->SetPlayer(player);
  5087. current_quest_id = quest->GetQuestID();
  5088. if (send_packets && quest->GetQuestGiver() > 0)
  5089. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5090. if (lua_interface && call_accepted)
  5091. lua_interface->CallQuestFunction(quest, "Accepted", player);
  5092. if (send_packets) {
  5093. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5094. //SendQuestJournal();
  5095. SendQuestJournalUpdate(quest);
  5096. // sent twice to match live
  5097. quest->SetTracked(false);
  5098. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5099. quest->SetTracked(true);
  5100. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  5101. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5102. }
  5103. //This isn't during a load screen, so update spawns with required quests
  5104. if (call_accepted)
  5105. player->SendQuestRequiredSpawns(quest->GetQuestID());
  5106. }
  5107. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  5108. if (current_quest_id == id)
  5109. current_quest_id = 0;
  5110. GetPlayer()->MPlayerQuests.writelock(__FUNCTION__, __LINE__);
  5111. if (player->player_quests.count(id) > 0) {
  5112. if (delete_quest) {
  5113. player->player_quests[id]->SetDeleted(true);
  5114. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  5115. }
  5116. int32 quest_giver = player->player_quests[id]->GetQuestGiver();
  5117. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5118. if (send_update && quest_giver > 0)
  5119. GetCurrentZone()->SendSpawnChangesByDBID(quest_giver, this, false, true);
  5120. if (send_update) {
  5121. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5122. SendQuestJournal(false, 0, true);
  5123. }
  5124. player->RemoveQuest(id, delete_quest);
  5125. if (send_update) {
  5126. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5127. SendQuestJournal(false, 0, true);
  5128. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  5129. }
  5130. }
  5131. else {
  5132. // if we don't have any quests to count then release the write lock
  5133. GetPlayer()->MPlayerQuests.releasewritelock(__FUNCTION__, __LINE__);
  5134. }
  5135. }
  5136. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  5137. if (quest) {
  5138. QuestStep* quest_step = quest->GetQuestStep(step);
  5139. if (quest_step) {
  5140. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  5141. quest_step->WasUpdated(false);
  5142. }
  5143. }
  5144. }
  5145. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  5146. QueuedQuest* item = new QueuedQuest;
  5147. item->quest = quest;
  5148. item->step = step;
  5149. item->display_quest_helper = display_quest_helper;
  5150. MQuestQueue.writelock();
  5151. quest_queue.push_back(item);
  5152. last_update_time = Timer::GetCurrentTime2();
  5153. MQuestQueue.releasewritelock();
  5154. }
  5155. void Client::SendQuestFailure(Quest* quest) {
  5156. vector<QuestStep*>* failures = quest->GetQuestFailures();
  5157. if (failures) {
  5158. QuestStep* step = 0;
  5159. for (int32 i = 0; i < failures->size(); i++) {
  5160. step = failures->at(i);
  5161. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  5162. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5163. SendQuestJournal(false, 0, true);
  5164. }
  5165. failures->clear();
  5166. }
  5167. }
  5168. void Client::SendQuestUpdate(Quest* quest) {
  5169. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  5170. if (updates) {
  5171. QuestStep* step = 0;
  5172. bool updated = false;
  5173. for (int32 i = 0; i < updates->size(); i++) {
  5174. step = updates->at(i);
  5175. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  5176. {
  5177. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  5178. SendQuestUpdateStep(quest, step->GetStepID());
  5179. updated = true;
  5180. }
  5181. if (step->WasUpdated()) {
  5182. // reversing the order of SendQuestJournal and QueuePacket QuestJournalReply causes AoM client to crash!
  5183. SendQuestJournal(false, 0, true);
  5184. if(!updated)
  5185. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  5186. updated = true;
  5187. }
  5188. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5189. }
  5190. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  5191. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  5192. SendQuestJournalUpdate(quest, true);
  5193. }
  5194. if (quest->GetCompleted()) {
  5195. if (quest->GetQuestReturnNPC() > 0)
  5196. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  5197. if (quest->GetCompletedFlag())
  5198. quest->SetCompletedFlag(false);
  5199. }
  5200. updates->clear();
  5201. }
  5202. }
  5203. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  5204. if (!client)
  5205. client = this;
  5206. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  5207. if (packet) {
  5208. EQ2Packet* outapp = packet->serialize();
  5209. //DumpPacket(outapp);
  5210. client->QueuePacket(outapp);
  5211. safe_delete(packet);
  5212. }
  5213. }
  5214. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  5215. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  5216. if (packet) {
  5217. QueuePacket(packet->serialize());
  5218. safe_delete(packet);
  5219. }
  5220. }
  5221. void Client::ReloadQuests() {
  5222. vector<int32> ids = player->GetQuestIDs();
  5223. Quest* quest = 0;
  5224. for (int32 i = 0; i < ids.size(); i++) {
  5225. quest = master_quest_list.GetQuest(ids[i]);
  5226. if (quest)
  5227. AddPlayerQuest(quest, false);
  5228. else
  5229. RemovePlayerQuest(ids[i]);
  5230. }
  5231. }
  5232. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  5233. bool found_quest = false;
  5234. vector<Quest*>::iterator itr;
  5235. vector<Item*>* items = 0;
  5236. Quest* quest = 0;
  5237. MPendingQuestAccept.lock();
  5238. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  5239. quest = *itr;
  5240. if(quest->GetQuestTemporaryState())
  5241. items = quest->GetTmpRewardItems();
  5242. else
  5243. items = quest->GetRewardItems();
  5244. if (item_id == 0 && items && items->size() > 0) {
  5245. found_quest = true;
  5246. }
  5247. else {
  5248. items = quest->GetSelectableRewardItems();
  5249. if (items && items->size() > 0) {
  5250. for (int32 i = 0; i < items->size(); i++) {
  5251. if (items->at(i)->details.item_id == item_id) {
  5252. found_quest = true;
  5253. break;
  5254. }
  5255. }
  5256. }
  5257. }
  5258. if (found_quest) {
  5259. pending_quest_accept.erase(itr);
  5260. break;
  5261. }
  5262. }
  5263. MPendingQuestAccept.unlock();
  5264. if (found_quest)
  5265. return quest;
  5266. return 0;
  5267. }
  5268. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  5269. int8 num_slots_needed = 0;
  5270. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  5271. Item* master_item = 0;
  5272. if (item_id > 0) {
  5273. num_slots_needed++;
  5274. master_item = master_item_list.GetItem(item_id);
  5275. }
  5276. int32 totalItems = 0;
  5277. vector<Item*>* items = 0;
  5278. vector<Item*>* tmpItems = 0;
  5279. bool isTempState = quest->GetQuestTemporaryState();
  5280. if(isTempState)
  5281. {
  5282. tmpItems = quest->GetTmpRewardItems();
  5283. if (tmpItems && tmpItems->size() > 0)
  5284. {
  5285. num_slots_needed += tmpItems->size();
  5286. totalItems += tmpItems->size();
  5287. }
  5288. }
  5289. else
  5290. {
  5291. items = quest->GetRewardItems();
  5292. if (items && items->size() > 0)
  5293. {
  5294. num_slots_needed += items->size();
  5295. totalItems += items->size();
  5296. }
  5297. }
  5298. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= totalItems)) {
  5299. if (master_item)
  5300. AddItem(item_id);
  5301. if (tmpItems && tmpItems->size() > 0) {
  5302. for (int32 i = 0; i < tmpItems->size(); i++)
  5303. AddItem(new Item(tmpItems->at(i)));
  5304. }
  5305. if (items && items->size() > 0) {
  5306. for (int32 i = 0; i < items->size(); i++)
  5307. AddItem(new Item(items->at(i)));
  5308. }
  5309. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5310. if (outapp)
  5311. QueuePacket(outapp);
  5312. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5313. map<int32, sint32>::iterator itr;
  5314. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5315. int32 faction_id = itr->first;
  5316. sint32 amount = itr->second;
  5317. if (amount > 0)
  5318. player->GetFactions()->IncreaseFaction(faction_id, amount);
  5319. else
  5320. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  5321. }
  5322. if(quest->GetQuestTemporaryState())
  5323. {
  5324. int64 total_coins = quest->GetCoinTmpReward();
  5325. if (total_coins > 0)
  5326. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5327. player->GetInfoStruct()->add_status_points(quest->GetStatusTmpReward());
  5328. quest->SetQuestTemporaryState(false);
  5329. }
  5330. else
  5331. player->GetInfoStruct()->add_status_points(quest->GetStatusPoints());
  5332. player->SetCharSheetChanged(true);
  5333. }
  5334. else {
  5335. MPendingQuestAccept.lock();
  5336. pending_quest_accept.push_back(quest);
  5337. MPendingQuestAccept.unlock();
  5338. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  5339. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5340. }
  5341. }
  5342. 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) {
  5343. 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))) {
  5344. /*if (quest)
  5345. text = quest->GetName();
  5346. else*/
  5347. return;//nothing to give
  5348. }
  5349. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  5350. if (packet2) {
  5351. int32 source_id = 0;
  5352. if (quest)
  5353. source_id = quest->GetQuestID();
  5354. int64 rewarded_coin = 0;
  5355. if (quest) {
  5356. if (quest->GetCoinsReward() > 0) {
  5357. if (quest->GetCoinsRewardMax() > 0)
  5358. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5359. else
  5360. rewarded_coin = quest->GetCoinsReward();
  5361. }
  5362. quest->SetGeneratedCoin(rewarded_coin);
  5363. }
  5364. if (rewarded_coin > coin)
  5365. coin = rewarded_coin;
  5366. 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
  5367. if (coin > 0) {
  5368. player->AddCoins(coin);
  5369. PlaySound("coin_cha_ching");
  5370. }
  5371. }
  5372. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  5373. packet2->setSubstructDataByName("reward_data", "reward", header);
  5374. packet2->setSubstructDataByName("reward_data", "max_coin", coin);
  5375. if (player->GetGuild()) {
  5376. 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
  5377. player->GetInfoStruct()->add_status_points(status_points);
  5378. player->SetCharSheetChanged(true);
  5379. }
  5380. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  5381. }
  5382. if(text)
  5383. packet2->setSubstructDataByName("reward_data", "text", text);
  5384. if(rewards){
  5385. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  5386. for (int i = 0; i < rewards->size(); i++) {
  5387. Item* item = rewards->at(i);
  5388. if (item) {
  5389. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  5390. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  5391. }
  5392. 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
  5393. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  5394. }
  5395. }
  5396. if (selectable_rewards) {
  5397. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  5398. for (int i = 0; i < selectable_rewards->size(); i++) {
  5399. Item* item = selectable_rewards->at(i);
  5400. if (item) {
  5401. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  5402. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  5403. 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
  5404. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  5405. }
  5406. }
  5407. }
  5408. if (factions) {
  5409. map<int32, sint32>::iterator itr;
  5410. map<Faction*, signed int> factions_map;
  5411. for (itr = factions->begin(); itr != factions->end(); itr++) {
  5412. Faction* faction = master_faction_list.GetFaction(itr->first);
  5413. if (faction)
  5414. factions_map[faction] = itr->second;
  5415. }
  5416. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  5417. map<Faction*, signed int>::iterator faction_itr;
  5418. int8 i = 0;
  5419. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  5420. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  5421. sint32 amount = faction_itr->second;
  5422. packet2->setArrayDataByName("amount", amount, i);
  5423. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5424. if (amount > 0)
  5425. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5426. else
  5427. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5428. }
  5429. i++;
  5430. }
  5431. }
  5432. QueuePacket(packet2->serialize());
  5433. safe_delete(packet2);
  5434. }
  5435. }
  5436. void Client::DisplayQuestComplete(Quest* quest, bool tempReward, std::string customDescription) {
  5437. if (!quest)
  5438. return;
  5439. quest->SetQuestTemporaryState(tempReward, customDescription);
  5440. AddPendingQuestAcceptReward(quest);
  5441. if (GetVersion() <= 546) {
  5442. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints());
  5443. return;
  5444. }
  5445. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5446. if (packet) {
  5447. packet->setDataByName("title", "Quest Reward!");
  5448. packet->setDataByName("name", quest->GetName());
  5449. if(customDescription.size() > 0)
  5450. {
  5451. packet->setDataByName("description", customDescription.c_str());
  5452. }
  5453. else
  5454. packet->setDataByName("description", quest->GetDescription());
  5455. packet->setDataByName("level", quest->GetLevel());
  5456. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5457. int8 difficulty = 0;
  5458. if ((string)quest->GetType() == "Tradeskill")
  5459. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5460. else
  5461. difficulty = player->GetArrowColor(quest->GetLevel());
  5462. packet->setDataByName("difficulty", difficulty);
  5463. if(tempReward)
  5464. {
  5465. packet->setDataByName("max_coin", quest->GetCoinTmpReward());
  5466. packet->setDataByName("min_coin", quest->GetCoinTmpReward());
  5467. packet->setDataByName("status_points", quest->GetStatusPoints());
  5468. }
  5469. else
  5470. {
  5471. int64 rewarded_coin = 0;
  5472. if (quest->GetCoinsReward() > 0) {
  5473. if (quest->GetCoinsRewardMax() > 0)
  5474. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5475. else
  5476. rewarded_coin = quest->GetCoinsReward();
  5477. }
  5478. quest->SetGeneratedCoin(rewarded_coin);
  5479. packet->setDataByName("max_coin", rewarded_coin);
  5480. packet->setDataByName("min_coin", rewarded_coin);
  5481. packet->setDataByName("status_points", quest->GetStatusPoints());
  5482. }
  5483. vector<Item*>* items = quest->GetTmpRewardItems();
  5484. if(tempReward)
  5485. {
  5486. if (items) {
  5487. packet->setArrayLengthByName("num_rewards", items->size());
  5488. for (int32 i = 0; i < items->size(); i++) {
  5489. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5490. if (version < 860)
  5491. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5492. else if (version < 1193)
  5493. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5494. else
  5495. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5496. }
  5497. }
  5498. }
  5499. else
  5500. {
  5501. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5502. vector<Item*>* items = quest->GetRewardItems();
  5503. if (items) {
  5504. packet->setArrayLengthByName("num_rewards", items->size());
  5505. for (int32 i = 0; i < items->size(); i++) {
  5506. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5507. if (version < 860)
  5508. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5509. else if (version < 1193)
  5510. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5511. else
  5512. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5513. }
  5514. }
  5515. if (items2 && items2->size() > 0) {
  5516. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5517. for (int32 i = 0; i < items2->size(); i++) {
  5518. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5519. if (version < 860)
  5520. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5521. else if (version < 1193)
  5522. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5523. else
  5524. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5525. }
  5526. }
  5527. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5528. if (reward_factions && reward_factions->size() > 0) {
  5529. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5530. map<int32, sint32>::iterator itr;
  5531. int16 index = 0;
  5532. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5533. int32 faction_id = itr->first;
  5534. sint32 amount = itr->second;
  5535. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5536. if (faction_name) {
  5537. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5538. packet->setArrayDataByName("amount", amount, index);
  5539. }
  5540. index++;
  5541. }
  5542. }
  5543. }
  5544. EQ2Packet* outapp = packet->serialize();
  5545. // DumpPacket(outapp);
  5546. QueuePacket(outapp);
  5547. safe_delete(packet);
  5548. }
  5549. }
  5550. void Client::DisplayRandomizeFeatures(int32 flags) {
  5551. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5552. if (flags > 0) {
  5553. if (flags & RANDOMIZE_GENDER)
  5554. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5555. if (flags & RANDOMIZE_RACE)
  5556. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5557. if (flags & RANDOMIZE_MODEL_TYPE)
  5558. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5559. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5560. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5561. if (flags & RANDOMIZE_HAIR_TYPE)
  5562. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5563. if (flags & RANDOMIZE_WING_TYPE)
  5564. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5565. if (flags & RANDOMIZE_CHEEK_TYPE)
  5566. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5567. if (flags & RANDOMIZE_CHIN_TYPE)
  5568. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5569. if (flags & RANDOMIZE_EAR_TYPE)
  5570. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5571. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5572. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5573. if (flags & RANDOMIZE_EYE_TYPE)
  5574. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5575. if (flags & RANDOMIZE_LIP_TYPE)
  5576. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5577. if (flags & RANDOMIZE_NOSE_TYPE)
  5578. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5579. if (flags & RANDOMIZE_EYE_COLOR)
  5580. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5581. if (flags & RANDOMIZE_HAIR_COLOR1)
  5582. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5583. if (flags & RANDOMIZE_HAIR_COLOR2)
  5584. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5585. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5586. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5587. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5588. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5589. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5590. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5591. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5592. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5593. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5594. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5595. if (flags & RANDOMIZE_SKIN_COLOR)
  5596. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5597. if (flags & RANDOMIZE_WING_COLOR1)
  5598. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5599. if (flags & RANDOMIZE_WING_COLOR2)
  5600. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5601. }
  5602. else
  5603. {
  5604. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5605. }
  5606. }
  5607. void Client::GiveQuestReward(Quest* quest) {
  5608. current_quest_id = 0;
  5609. if(!quest->GetQuestTemporaryState())
  5610. {
  5611. quest->IncrementCompleteCount();
  5612. player->AddCompletedQuest(quest);
  5613. }
  5614. DisplayQuestComplete(quest, quest->GetQuestTemporaryState(), quest->GetQuestTemporaryDescription());
  5615. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5616. SendQuestJournal();
  5617. if(quest->GetQuestTemporaryState())
  5618. return;
  5619. player->RemoveQuest(quest->GetQuestID(), false);
  5620. if (quest->GetExpReward() > 0) {
  5621. int16 level = player->GetLevel();
  5622. int32 xp = quest->GetExpReward();
  5623. if (player->AddXP(xp)) {
  5624. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5625. if (player->GetLevel() != level)
  5626. ChangeLevel(level, player->GetLevel());
  5627. player->SetCharSheetChanged(true);
  5628. }
  5629. }
  5630. if (quest->GetTSExpReward() > 0) {
  5631. int8 ts_level = player->GetTSLevel();
  5632. int32 xp = quest->GetTSExpReward();
  5633. if (player->AddTSXP(xp)) {
  5634. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5635. if (player->GetTSLevel() != ts_level)
  5636. ChangeTSLevel(ts_level, player->GetTSLevel());
  5637. player->SetCharSheetChanged(true);
  5638. }
  5639. }
  5640. int64 total_coins = quest->GetGeneratedCoin();
  5641. if (total_coins > 0)
  5642. AwardCoins(total_coins, std::string("for completing ").append(quest->GetName()));
  5643. if (quest->GetQuestGiver() > 0)
  5644. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5645. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5646. }
  5647. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5648. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5649. if (packet) {
  5650. packet->setDataByName("conversation_id", conversation_id);
  5651. packet->setDataByName("text", text);
  5652. packet->setDataByName("unknown2", 1);
  5653. conversation_map[conversation_id].clear();
  5654. if (conversations) {
  5655. packet->setArrayLengthByName("num_responses", conversations->size());
  5656. for (int32 i = 0; i < conversations->size(); i++) {
  5657. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5658. if (conversations->at(i).function.length() > 0)
  5659. conversation_map[conversation_id][i] = conversations->at(i).function;
  5660. }
  5661. }
  5662. packet->setDataByName("spawn_id", spawn_id);
  5663. if (mp3) {
  5664. packet->setDataByName("voice", mp3);
  5665. packet->setDataByName("key1", key1);
  5666. packet->setDataByName("key2", key2);
  5667. }
  5668. QueuePacket(packet->serialize());
  5669. safe_delete(packet);
  5670. }
  5671. }
  5672. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  5673. if (!item || !text || !conversations || conversations->size() == 0) {
  5674. return;
  5675. }
  5676. int32 conversation_id = GetConversationID(0, item);
  5677. if (conversation_id == 0) {
  5678. next_conversation_id++;
  5679. conversation_id = next_conversation_id;
  5680. }
  5681. MConversation.writelock();
  5682. conversation_items[conversation_id] = item;
  5683. MConversation.releasewritelock();
  5684. if (type == 4)
  5685. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5686. else
  5687. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5688. }
  5689. void Client::DisplayConversation(Spawn* src, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5690. if (!src || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5691. return;
  5692. }
  5693. int32 conversation_id = GetConversationID(src, 0);
  5694. if (conversation_id == 0) {
  5695. next_conversation_id++;
  5696. conversation_id = next_conversation_id;
  5697. }
  5698. MConversation.writelock();
  5699. conversation_spawns[conversation_id] = src;
  5700. MConversation.releasewritelock();
  5701. /* Spawns can start two different types of conversations.
  5702. * Type 1: The chat type with bubbles.
  5703. * Type 2: The dialog type with the blue box. */
  5704. if (type == 1)
  5705. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(src), conversations, text, mp3, key1, key2);
  5706. else if (type == 2)
  5707. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5708. else //if (type == 3)
  5709. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5710. }
  5711. void Client::CloseDialog(int32 conversation_id) {
  5712. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5713. if (packet) {
  5714. packet->setDataByName("conversation_id", conversation_id);
  5715. QueuePacket(packet->serialize());
  5716. safe_delete(packet);
  5717. }
  5718. MConversation.writelock();
  5719. std::map<int32, Item*>::iterator itr;
  5720. while((itr = conversation_items.find(conversation_id)) != conversation_items.end())
  5721. {
  5722. conversation_items.erase(itr);
  5723. }
  5724. std::map<int32, Spawn*>::iterator itr2 = conversation_spawns.find(conversation_id);
  5725. while((itr2 = conversation_spawns.find(conversation_id)) != conversation_spawns.end())
  5726. {
  5727. conversation_spawns.erase(itr2);
  5728. }
  5729. MConversation.releasewritelock();
  5730. }
  5731. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5732. int32 conversation_id = 0;
  5733. MConversation.readlock();
  5734. if (spawn) {
  5735. map<int32, Spawn*>::iterator itr;
  5736. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5737. if (itr->second == spawn) {
  5738. conversation_id = itr->first;
  5739. break;
  5740. }
  5741. }
  5742. }
  5743. else if (item) {
  5744. map<int32, Item*>::iterator itr;
  5745. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5746. if (itr->second == item) {
  5747. conversation_id = itr->first;
  5748. break;
  5749. }
  5750. }
  5751. }
  5752. MConversation.releasereadlock();
  5753. return conversation_id;
  5754. }
  5755. Spawn* Client::GetCombineSpawn() {
  5756. return combine_spawn;
  5757. }
  5758. bool Client::ShouldTarget() {
  5759. return should_target;
  5760. }
  5761. void Client::TargetSpawn(Spawn* spawn) {
  5762. should_target = false;
  5763. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5764. if (packet) {
  5765. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5766. QueuePacket(packet->serialize());
  5767. safe_delete(packet);
  5768. }
  5769. }
  5770. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5771. combine_spawn = spawn;
  5772. spawn->RemoveSpawnFromGroup(true);
  5773. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5774. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5775. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5776. should_target = true;
  5777. }
  5778. void Client::AddCombineSpawn(Spawn* spawn) {
  5779. if (combine_spawn && combine_spawn != spawn && spawn) {
  5780. combine_spawn->AddSpawnToGroup(spawn);
  5781. spawn->AddSpawnToGroup(combine_spawn);
  5782. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5783. }
  5784. else if (spawn)
  5785. combine_spawn = spawn;
  5786. should_target = true;
  5787. }
  5788. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5789. if (combine_spawn && spawn)
  5790. spawn->RemoveSpawnFromGroup();
  5791. if (combine_spawn == spawn)
  5792. combine_spawn->RemoveSpawnFromGroup(true);
  5793. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5794. if (combine_spawn == spawn)
  5795. combine_spawn = 0;
  5796. }
  5797. void Client::SaveCombineSpawns(const char* name) {
  5798. if (!combine_spawn) {
  5799. return;
  5800. }
  5801. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5802. if (!spawns) {
  5803. return;
  5804. }
  5805. int32 count = spawns->size();
  5806. int32 spawnLocationID = 0;
  5807. if (count == 1)
  5808. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5809. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5810. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5811. // we remove the spawn inside SaveCombinedSpawnLocation
  5812. //GetCurrentZone()->RemoveSpawn(combine_spawn);
  5813. }
  5814. else
  5815. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5816. safe_delete(spawns);
  5817. combine_spawn = 0;
  5818. }
  5819. bool Client::AddItem(int32 item_id, int16 quantity) {
  5820. Item* master_item = master_item_list.GetItem(item_id);
  5821. Item* item = 0;
  5822. if (master_item)
  5823. item = new Item(master_item);
  5824. if (item) {
  5825. if (quantity > 0)
  5826. item->details.count = quantity;
  5827. return AddItem(item);
  5828. }
  5829. else
  5830. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5831. return false;
  5832. }
  5833. bool Client::AddItem(Item* item, bool* item_deleted) {
  5834. if (!item) {
  5835. return false;
  5836. }
  5837. if (item->IsBag()) {
  5838. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5839. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5840. }
  5841. if (player->AddItem(item)) {
  5842. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5843. if (outapp) {
  5844. //DumpPacket(outapp);
  5845. QueuePacket(outapp);
  5846. //resend bag desc with new item name added
  5847. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5848. if (outapp) {
  5849. //DumpPacket(outapp);
  5850. QueuePacket(outapp);
  5851. }
  5852. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5853. DumpPacket(app);
  5854. client->QueuePacket(app);
  5855. */
  5856. }
  5857. CheckPlayerQuestsItemUpdate(item);
  5858. if (item->GetItemScript() && lua_interface)
  5859. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5860. }
  5861. else {
  5862. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5863. safe_delete(item);
  5864. if(item_deleted)
  5865. *item_deleted = true;
  5866. return false;
  5867. }
  5868. return true;
  5869. }
  5870. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5871. Item* master_item = master_item_list.GetItem(item_id);
  5872. Item* item = 0;
  5873. if (master_item)
  5874. item = new Item(master_item);
  5875. if (item) {
  5876. if (quantity > 0)
  5877. item->details.count = quantity;
  5878. return AddItemToBank(item);
  5879. }
  5880. else
  5881. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5882. return false;
  5883. }
  5884. bool Client::AddItemToBank(Item* item) {
  5885. if (!item) {
  5886. return false;
  5887. }
  5888. if (player->AddItemToBank(item)) {
  5889. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5890. if (outapp) {
  5891. QueuePacket(outapp);
  5892. //resend bag desc with new item name added
  5893. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5894. if (outapp)
  5895. QueuePacket(outapp);
  5896. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5897. DumpPacket(app);
  5898. client->QueuePacket(app);
  5899. */
  5900. }
  5901. CheckPlayerQuestsItemUpdate(item);
  5902. if (item->GetItemScript() && lua_interface)
  5903. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5904. }
  5905. else {
  5906. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5907. safe_delete(item);
  5908. return false;
  5909. }
  5910. return true;
  5911. }
  5912. bool Client::RemoveItem(Item* item, int16 quantity, bool force_override_no_delete) {
  5913. EQ2Packet* outapp;
  5914. bool delete_item = false;
  5915. assert(item);
  5916. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5917. item->details.count -= quantity;
  5918. item->save_needed = true;
  5919. }
  5920. else {
  5921. database.DeleteItem(character_id, item, 0);
  5922. player->GetPlayerItemList()->RemoveItem(item, false);
  5923. delete_item = true;
  5924. }
  5925. if(force_override_no_delete)
  5926. delete_item = false;
  5927. if ((outapp = player->SendInventoryUpdate(version))) {
  5928. QueuePacket(outapp);
  5929. if (item->GetItemScript() && lua_interface)
  5930. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5931. if (delete_item)
  5932. {
  5933. PurgeItem(item);
  5934. safe_delete(item);
  5935. }
  5936. return true;
  5937. }
  5938. return false;
  5939. }
  5940. void Client::SetLuaDebugClient(bool val) {
  5941. if (val)
  5942. lua_debug_timer.Start();
  5943. lua_debug = val;
  5944. if (lua_interface && !val) {
  5945. lua_interface->RemoveDebugClients(this);
  5946. lua_debug_timer.Disable();
  5947. }
  5948. }
  5949. void Client::SetMerchantTransaction(Spawn* spawn) {
  5950. merchant_transaction = spawn;
  5951. }
  5952. Spawn* Client::GetMerchantTransaction() {
  5953. return merchant_transaction;
  5954. }
  5955. void Client::SetMailTransaction(Spawn* spawn) {
  5956. ResetSendMail(spawn ? false : true);
  5957. MMailWindowMutex.lock();
  5958. mail_transaction = spawn;
  5959. MMailWindowMutex.unlock();
  5960. }
  5961. Spawn* Client::GetMailTransaction() {
  5962. return mail_transaction;
  5963. }
  5964. void Client::PlaySound(const char* name) {
  5965. if (name) {
  5966. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5967. if (packet) {
  5968. packet->setMediumStringByName("name", name);
  5969. QueuePacket(packet->serialize());
  5970. safe_delete(packet);
  5971. }
  5972. }
  5973. }
  5974. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5975. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5976. if(multiplier){
  5977. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5978. float diff_low = faction_val - multiplier->faction_min;
  5979. if(diff_low < 0)
  5980. diff_low*=-1;
  5981. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5982. if(total_diff < 0)
  5983. total_diff*=-1;
  5984. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5985. float total1 = (diff_low/total_diff);
  5986. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5987. return final_buy_multiplier;
  5988. }*/
  5989. return 1;
  5990. }
  5991. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5992. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5993. if(multiplier){
  5994. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5995. float diff_low = faction_val - multiplier->faction_min;
  5996. if(diff_low < 0)
  5997. diff_low*=-1;
  5998. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5999. if(total_diff < 0)
  6000. total_diff*=-1;
  6001. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  6002. float total1 = (diff_low/total_diff);
  6003. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  6004. return final_sell_multiplier;
  6005. }*/
  6006. return 1;
  6007. }
  6008. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  6009. Spawn* spawn = GetMerchantTransaction();
  6010. Guild* guild = GetPlayer()->GetGuild();
  6011. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY)) &&
  6012. spawn->IsClientInMerchantLevelRange(this)) {
  6013. int32 total_sell_price = 0;
  6014. int32 total_status_sell_price = 0; //for status
  6015. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6016. int32 sell_price = 0;
  6017. int32 status_sell_price = 0; //for status
  6018. Item* master_item = master_item_list.GetItem(item_id);
  6019. Item* item = 0;
  6020. if (unique_id == 0)
  6021. item = player->item_list.GetItemFromID(item_id, quantity);
  6022. else
  6023. item = player->item_list.GetItemFromUniqueID(unique_id);
  6024. if (!item)
  6025. item = player->item_list.GetItemFromID(item_id);
  6026. if (item && master_item) {
  6027. if(item->details.item_locked)
  6028. {
  6029. SimpleMessage(CHANNEL_COLOR_RED, "You cannot sell the item in use.");
  6030. return;
  6031. }
  6032. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  6033. if (sell_price > item->sell_price)
  6034. sell_price = item->sell_price;
  6035. if (quantity > item->details.count)
  6036. quantity = item->details.count;
  6037. total_sell_price = sell_price * quantity;
  6038. //------------------------------For Selling Status Items
  6039. status_sell_price = (int32)(master_item->sell_status * multiplier);
  6040. if (status_sell_price > item->sell_status)
  6041. status_sell_price = item->sell_status;
  6042. if (quantity > item->details.count)
  6043. quantity = item->details.count;
  6044. total_status_sell_price = status_sell_price * quantity;
  6045. if(total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6046. total_status_sell_price = 0;
  6047. player->GetInfoStruct()->add_status_points(total_status_sell_price);
  6048. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6049. if (player->GetGuild() && guild->GetLevel() < guildMaxLevel) {
  6050. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  6051. guild->SendGuildMemberList();
  6052. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  6053. }
  6054. if (quantity > 1)
  6055. {
  6056. if(total_status_sell_price)
  6057. 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);
  6058. else
  6059. 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());
  6060. }
  6061. else
  6062. {
  6063. if(total_status_sell_price)
  6064. 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);
  6065. else
  6066. 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());
  6067. }
  6068. player->AddCoins(total_sell_price);
  6069. if(!item->no_buy_back && (total_status_sell_price == 0 || (total_status_sell_price > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))))
  6070. AddBuyBack(unique_id, item_id, quantity, sell_price);
  6071. if (quantity >= item->details.count) {
  6072. database.DeleteItem(GetCharacterID(), item, 0);
  6073. player->item_list.DestroyItem(item->details.index);
  6074. }
  6075. else {
  6076. item->details.count -= quantity;
  6077. item->save_needed = true;
  6078. }
  6079. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  6080. if (outapp)
  6081. QueuePacket(outapp);
  6082. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6083. SendBuyBackList();
  6084. }
  6085. }
  6086. }
  6087. void Client::BuyBack(int32 item_id, int16 quantity) {
  6088. Spawn* spawn = GetMerchantTransaction();
  6089. if (spawn && spawn->GetMerchantID() > 0 && (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK)) &&
  6090. spawn->IsClientInMerchantLevelRange(this)) {
  6091. deque<BuyBackItem*>::iterator itr;
  6092. BuyBackItem* buyback = 0;
  6093. BuyBackItem* closest = 0;
  6094. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6095. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6096. buyback = *itr;
  6097. if (buyback->unique_id == item_id) {
  6098. closest = buyback;
  6099. quantity = buyback->quantity;
  6100. break;
  6101. }
  6102. }
  6103. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6104. if (closest) {
  6105. Item* item = 0;
  6106. Item* master_item = master_item_list.GetItem(closest->item_id);
  6107. if (master_item) {
  6108. item = new Item(master_item);
  6109. if (closest->quantity >= quantity)
  6110. item->details.count = quantity;
  6111. else
  6112. item->details.count = closest->quantity;
  6113. }
  6114. bool itemDeleted = false;
  6115. bool itemAdded = false;
  6116. sint64 dispFlags = 0;
  6117. if (item && item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buyback_display_flags", item, player, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6118. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6119. else if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  6120. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6121. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  6122. bool removed = false;
  6123. if (closest->quantity == quantity) {
  6124. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6125. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  6126. if (*itr == closest) {
  6127. buy_back_items.erase(itr);
  6128. removed = true;
  6129. break;
  6130. }
  6131. }
  6132. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6133. }
  6134. else {
  6135. closest->quantity -= quantity;
  6136. closest->save_needed = true;
  6137. }
  6138. itemAdded = AddItem(item, &itemDeleted);
  6139. if (removed) {
  6140. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  6141. safe_delete(closest);
  6142. }
  6143. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  6144. SendBuyBackList();
  6145. }
  6146. else
  6147. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  6148. if(!itemAdded && !itemDeleted)
  6149. safe_delete(item);
  6150. }
  6151. }
  6152. }
  6153. void Client::BuyItem(int32 item_id, int16 quantity) {
  6154. // Get the merchant we are buying from
  6155. Spawn* spawn = GetMerchantTransaction();
  6156. // Make sure the spawn has a merchant list
  6157. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6158. int32 total_buy_price = 0;
  6159. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6160. int32 sell_price = 0;
  6161. Item* master_item = master_item_list.GetItem(item_id);
  6162. Item* item = 0;
  6163. int16 total_available = 0;
  6164. vector<MerchantItemInfo>* temp;
  6165. vector<MerchantItemInfo>::iterator itr;
  6166. MerchantItemInfo* ItemInfo = 0;
  6167. temp = world.GetMerchantList(spawn->GetMerchantID());
  6168. for (itr = temp->begin(); itr != temp->end(); itr++) {
  6169. if ((*itr).item_id == item_id) {
  6170. ItemInfo = &(*itr);
  6171. break;
  6172. }
  6173. }
  6174. if (master_item && ItemInfo) {
  6175. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  6176. quantity = 1;
  6177. total_available = 0xFFFF;
  6178. sell_price = master_item->sell_price;
  6179. }
  6180. else {
  6181. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  6182. sell_price = (int32)(master_item->sell_price * multiplier);
  6183. if (quantity > total_available)
  6184. quantity = total_available;
  6185. }
  6186. sint64 dispFlags = 0;
  6187. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buy_display_flags", master_item, player, &dispFlags) && (dispFlags & DISPLAY_FLAG_NO_BUY))
  6188. {
  6189. SimpleMessage(CHANNEL_NARRATIVE, "You do not meet all the requirements to buy this item.");
  6190. return;
  6191. }
  6192. if(quantity < 1)
  6193. {
  6194. SimpleMessage(CHANNEL_COLOR_RED, "Merchant does not have item for purchase (quantity < 1).");
  6195. return;
  6196. }
  6197. total_buy_price = sell_price * quantity;
  6198. item = new Item(master_item);
  6199. item->details.count = quantity;
  6200. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  6201. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  6202. safe_delete(item);
  6203. }
  6204. else {
  6205. // Price not set in the merchant_inventory table, use the old method
  6206. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  6207. if (player->RemoveCoins(total_buy_price)) {
  6208. item->SetMaxSellValue(sell_price);
  6209. if (quantity > 1)
  6210. 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());
  6211. else
  6212. 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());
  6213. bool itemDeleted = false;
  6214. AddItem(item, &itemDeleted);
  6215. if(!itemDeleted) {
  6216. CheckPlayerQuestsItemUpdate(item);
  6217. if (item && total_available < 0xFF) {
  6218. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6219. SendBuyMerchantList();
  6220. }
  6221. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6222. PlayLotto(total_buy_price, item->details.item_id);
  6223. }
  6224. }
  6225. else {
  6226. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6227. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6228. PlaySound("buy_failed");
  6229. }
  6230. }
  6231. else {
  6232. // Price set in merchant_inventory table
  6233. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  6234. // TODO: need to add support for station cash
  6235. if (player->GetInfoStruct()->get_status_points() >= (ItemInfo->price_status * quantity) && player->HasCoins(ItemInfo->price_coins * quantity)) {
  6236. // Check items
  6237. int16 item_quantity = 0;
  6238. // Default these to true in case price_item_id or price_item2_id was never set
  6239. bool hasItem1 = true;
  6240. bool hasItem2 = true;
  6241. Item* tempItem1 = 0;
  6242. Item* tempItem2 = 0;
  6243. if (ItemInfo->price_item_id != 0) {
  6244. // Same item for whatever reason lets add the quantities together
  6245. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  6246. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  6247. else
  6248. item_quantity = ItemInfo->price_item_qty;
  6249. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  6250. if (tempItem1) {
  6251. if (tempItem1->details.count < item_quantity)
  6252. hasItem1 = false;
  6253. }
  6254. else {
  6255. hasItem1 = false;
  6256. }
  6257. }
  6258. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  6259. // as item1 and we already checked for it so we can skip this check
  6260. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  6261. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  6262. if (tempItem2) {
  6263. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  6264. hasItem2 = false;
  6265. }
  6266. else {
  6267. hasItem2 = false;
  6268. }
  6269. }
  6270. // if we have every thing then remove the price and give the item
  6271. if (hasItem1 && hasItem2) {
  6272. player->GetInfoStruct()->set_status_points(player->GetInfoStruct()->get_status_points() - (ItemInfo->price_status * quantity));
  6273. // TODO: station cash
  6274. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  6275. // so there is no need to send it more then that one time
  6276. if (tempItem1) {
  6277. if (tempItem1->details.count > item_quantity) {
  6278. tempItem1->details.count -= item_quantity;
  6279. tempItem1->save_needed = true;
  6280. }
  6281. else {
  6282. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  6283. player->item_list.DestroyItem(tempItem1->details.index);
  6284. }
  6285. }
  6286. if (tempItem2) {
  6287. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  6288. tempItem2->details.count -= ItemInfo->price_item2_qty;
  6289. tempItem2->save_needed = true;
  6290. }
  6291. else {
  6292. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  6293. player->item_list.DestroyItem(tempItem2->details.index);
  6294. }
  6295. }
  6296. // 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
  6297. player->RemoveCoins(ItemInfo->price_coins * quantity);
  6298. item->SetMaxSellValue(sell_price);
  6299. if (quantity > 1)
  6300. 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());
  6301. else
  6302. 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());
  6303. bool itemDeleted = false;
  6304. AddItem(item, &itemDeleted);
  6305. if(!itemDeleted) {
  6306. CheckPlayerQuestsItemUpdate(item);
  6307. if (item && total_available < 0xFF) {
  6308. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  6309. SendBuyMerchantList();
  6310. }
  6311. SendSellMerchantList();
  6312. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  6313. PlayLotto(total_buy_price, item->details.item_id);
  6314. }
  6315. }
  6316. else {
  6317. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6318. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6319. PlaySound("buy_failed");
  6320. }
  6321. }
  6322. else {
  6323. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  6324. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  6325. PlaySound("buy_failed");
  6326. }
  6327. }
  6328. }
  6329. }
  6330. }
  6331. }
  6332. void Client::RepairItem(int32 item_id) {
  6333. Spawn* spawn = GetMerchantTransaction();
  6334. if (spawn) {
  6335. Item* item = player->item_list.GetItemFromID(item_id);
  6336. if (!item)
  6337. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  6338. if (item) {
  6339. int32 repair_cost = item->CalculateRepairCost();
  6340. if (player->RemoveCoins((int32)repair_cost)) {
  6341. item->generic_info.condition = 100;
  6342. item->save_needed = true;
  6343. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6344. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6345. QueuePacket(item->serialize(version, false, player));
  6346. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  6347. PlaySound("coin_cha_ching");
  6348. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6349. SendRepairList();
  6350. }
  6351. else {
  6352. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6353. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  6354. PlaySound("buy_failed");
  6355. }
  6356. }
  6357. }
  6358. }
  6359. void Client::RepairAllItems() {
  6360. Spawn* spawn = GetMerchantTransaction();
  6361. if (spawn) {
  6362. vector<Item*>* repairable_items = GetRepairableItems();
  6363. if (repairable_items && repairable_items->size() > 0) {
  6364. vector<Item*>::iterator itr;
  6365. int64 total_cost = 0;
  6366. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  6367. total_cost += (*itr)->CalculateRepairCost();
  6368. if (player->RemoveCoins((int32)total_cost)) {
  6369. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  6370. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  6371. Item* item = *itr;
  6372. if (item) {
  6373. item->generic_info.condition = 100;
  6374. item->save_needed = true;
  6375. QueuePacket(item->serialize(version, false, player));
  6376. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  6377. }
  6378. }
  6379. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  6380. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  6381. PlaySound("coin_cha_ching");
  6382. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  6383. SendRepairList();
  6384. }
  6385. else {
  6386. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6387. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  6388. PlaySound("buy_failed");
  6389. }
  6390. }
  6391. safe_delete(repairable_items);
  6392. }
  6393. }
  6394. void Client::SendAchievementsList()
  6395. {
  6396. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  6397. map<int32, Achievement *>::iterator itr;
  6398. Achievement *achievement;
  6399. vector<AchievementRequirements *> *requirements = 0;
  6400. vector<AchievementRequirements *>::iterator itr2;
  6401. AchievementRequirements *requirement;
  6402. vector<AchievementRewards *> *rewards = 0;
  6403. vector<AchievementRewards *>::iterator itr3;
  6404. AchievementRewards *reward;
  6405. PacketStruct *packet;
  6406. int16 i = 0;
  6407. int16 j = 0;
  6408. int16 k = 0;
  6409. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  6410. return;
  6411. }
  6412. packet->setArrayLengthByName("num_achievements" , achievements->size());
  6413. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  6414. achievement = itr->second;
  6415. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  6416. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  6417. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  6418. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  6419. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  6420. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  6421. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  6422. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  6423. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  6424. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  6425. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  6426. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  6427. requirements = achievement->GetRequirements();
  6428. rewards = achievement->GetRewards();
  6429. j = 0;
  6430. k = 0;
  6431. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  6432. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  6433. requirement = *itr2;
  6434. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  6435. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  6436. j++;
  6437. }
  6438. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  6439. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  6440. reward = *itr3;
  6441. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  6442. k++;
  6443. }
  6444. i++;
  6445. }
  6446. //packet->PrintPacket();
  6447. EQ2Packet* data = packet->serialize();
  6448. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6449. safe_delete(packet);
  6450. safe_delete(data);
  6451. //DumpPacket(app);
  6452. QueuePacket(app);*/
  6453. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  6454. SendAchievementUpdate(true);
  6455. }
  6456. void Client::SendAchievementUpdate(bool first_login) {
  6457. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  6458. map<int32, AchievementUpdate*>::iterator itr;
  6459. AchievementUpdate* update;
  6460. vector<AchievementUpdateItems*>* update_items = 0;
  6461. vector<AchievementUpdateItems*>::iterator itr2;
  6462. AchievementUpdateItems* update_item;
  6463. int16 i = 0;
  6464. int16 j = 0;
  6465. PacketStruct* packet;
  6466. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  6467. return;
  6468. }
  6469. packet->setDataByName("unknown1", first_login ? 1 : 0);
  6470. packet->setArrayLengthByName("num_achievements", updates->size());
  6471. for (itr = updates->begin(); itr != updates->end(); itr++) {
  6472. update = itr->second;
  6473. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  6474. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  6475. update_items = update->GetUpdateItems();
  6476. j = 0;
  6477. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  6478. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6479. update_item = *itr2;
  6480. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6481. j++;
  6482. }
  6483. i++;
  6484. }
  6485. //packet->PrintPacket();
  6486. EQ2Packet* data = packet->serialize();
  6487. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6488. safe_delete(packet);
  6489. safe_delete(data);
  6490. //DumpPacket(app);
  6491. QueuePacket(app);
  6492. }
  6493. void Client::SendBuyMerchantList(bool sell) {
  6494. Spawn* spawn = GetMerchantTransaction();
  6495. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6496. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6497. if (items) {
  6498. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6499. if (packet) {
  6500. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6501. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6502. packet->setArrayLengthByName("num_items", items->size());
  6503. vector<MerchantItemInfo>::iterator itr;
  6504. sint8 item_difficulty = 0;
  6505. int32 sell_price = 0;
  6506. int i = 0;
  6507. int tmp_level = 0;
  6508. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6509. MerchantItemInfo ItemInfo = *itr;
  6510. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6511. if (!item)
  6512. continue;
  6513. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6514. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6515. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6516. packet->setArrayDataByName("icon", item->details.icon, i);
  6517. if (item->generic_info.adventure_default_level > 0)
  6518. tmp_level = item->generic_info.adventure_default_level;
  6519. else
  6520. tmp_level = item->generic_info.tradeskill_default_level;
  6521. packet->setArrayDataByName("level", tmp_level, i);
  6522. packet->setArrayDataByName("tier", item->details.tier, i);
  6523. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6524. item_difficulty = player->GetArrowColor(tmp_level);
  6525. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6526. item_difficulty = ARROW_COLOR_WHITE;
  6527. sint64 overrideValue = 0;
  6528. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, &overrideValue))
  6529. item_difficulty = (sint8)overrideValue;
  6530. item_difficulty -= 6;
  6531. if (item_difficulty < 0)
  6532. item_difficulty *= -1;
  6533. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6534. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6535. packet->setArrayDataByName("unknown5", 255, i);
  6536. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6537. sint64 dispFlags = 0;
  6538. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "buy_display_flags", item, player, &dispFlags))
  6539. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6540. std::string overrideValueStr;
  6541. // 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)
  6542. if (GetVersion() >= 546 && item->GetItemScript() && lua_interface && lua_interface->RunItemScriptWithReturnString(item->GetItemScript(), "item_description", item, player, &overrideValueStr))
  6543. packet->setArrayDataByName("description", overrideValueStr.c_str(), i);
  6544. // If no price set in the merchant_inventory table then use the old method
  6545. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6546. sell_price = (int32)(item->sell_price * multiplier);
  6547. packet->setArrayDataByName("price", sell_price, i);
  6548. }
  6549. else {
  6550. int8 count = 0;
  6551. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6552. count++;
  6553. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6554. count++;
  6555. if (count != 0) {
  6556. packet->setSubArrayLengthByName("num_tokens", count, i);
  6557. int8 index = 0;
  6558. Item* token = 0;
  6559. if (ItemInfo.price_item_id != 0) {
  6560. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6561. if (item) {
  6562. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6563. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6564. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6565. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6566. }
  6567. token = 0;
  6568. index++;
  6569. }
  6570. if (ItemInfo.price_item2_id != 0) {
  6571. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6572. if (item) {
  6573. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6574. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6575. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6576. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6577. }
  6578. }
  6579. }
  6580. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6581. packet->setArrayDataByName("status2", ItemInfo.price_status, i);
  6582. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6583. }
  6584. }
  6585. if (GetVersion() <= 546) {
  6586. //buy is 0 so dont need to set it
  6587. if (sell)
  6588. packet->setDataByName("type", 1);
  6589. }
  6590. else {
  6591. if (sell)
  6592. packet->setDataByName("type", 130);
  6593. else
  6594. packet->setDataByName("type", 2);
  6595. }
  6596. EQ2Packet* outapp = packet->serialize();
  6597. // DumpPacket(outapp);
  6598. QueuePacket(outapp);
  6599. safe_delete(packet);
  6600. }
  6601. safe_delete(items);
  6602. }
  6603. else {
  6604. // Need to send an empty packet in the event there is no item list, otherwise the
  6605. // last item list sent to the player will show for this merchant
  6606. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6607. if (packet) {
  6608. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6609. if (GetVersion() <= 546) {
  6610. //buy is 0 so dont need to set it
  6611. if (sell)
  6612. packet->setDataByName("type", 1);
  6613. }
  6614. else {
  6615. if (sell)
  6616. packet->setDataByName("type", 130);
  6617. else
  6618. packet->setDataByName("type", 2);
  6619. }
  6620. EQ2Packet* outapp = packet->serialize();
  6621. QueuePacket(outapp);
  6622. safe_delete(packet);
  6623. }
  6624. }
  6625. }
  6626. }
  6627. void Client::SendSellMerchantList(bool sell) {
  6628. Spawn* spawn = GetMerchantTransaction();
  6629. if (!spawn || (spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) || (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  6630. return;
  6631. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6632. map<int32, Item*>* items = player->GetItemList();
  6633. if (items) {
  6634. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6635. if (packet) {
  6636. vector<Item*> sellable_items;
  6637. map<int32, Item*>::iterator test_itr;
  6638. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6639. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6640. sellable_items.push_back(test_itr->second);
  6641. }
  6642. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6643. packet->setArrayLengthByName("num_items", sellable_items.size());
  6644. vector<Item*>::iterator itr;
  6645. Item* item = 0;
  6646. sint8 item_difficulty = 0;
  6647. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6648. int32 sell_price = 0;
  6649. Item* master_item = 0;
  6650. int i = 0;
  6651. int tmp_level = 0;
  6652. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6653. item = *itr;
  6654. master_item = master_item_list.GetItem(item->details.item_id);
  6655. if (master_item)
  6656. sell_price = (int32)(master_item->sell_price * multiplier);
  6657. else
  6658. sell_price = 0;
  6659. if (sell_price > item->sell_price)
  6660. sell_price = item->sell_price;
  6661. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6662. string thename = item->name;
  6663. packet->setArrayDataByName("price", sell_price, i);
  6664. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6665. int8 dispFlags = 0;
  6666. // only city merchants allow selling for status
  6667. if(item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT))
  6668. {
  6669. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6670. int32 guildMaxLevel = 5 + item->details.recommended_level; // client hard codes +5 to the level
  6671. if (GetPlayer()->GetGuild() && GetPlayer()->GetGuild()->GetLevel() >= guildMaxLevel) {
  6672. dispFlags += DISPLAY_FLAG_NO_GUILD_STATUS;
  6673. }
  6674. }
  6675. if(item->no_buy_back || (item->sell_status > 0 && (spawn->GetMerchantType() & MERCHANT_TYPE_CITYMERCHANT)))
  6676. {
  6677. if(GetVersion() < 1188)
  6678. 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
  6679. else
  6680. dispFlags += DISPLAY_FLAG_NO_BUYBACK;
  6681. }
  6682. if(item->no_sale)
  6683. dispFlags += DISPLAY_FLAG_NOT_FOR_SALE;
  6684. packet->setArrayDataByName("display_flags", dispFlags, i);
  6685. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6686. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6687. packet->setArrayDataByName("stack_size", item->details.count, i);
  6688. packet->setArrayDataByName("icon", item->details.icon, i);
  6689. if (item->generic_info.adventure_default_level > 0)
  6690. tmp_level = item->generic_info.adventure_default_level;
  6691. else
  6692. tmp_level = item->generic_info.tradeskill_default_level;
  6693. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6694. packet->setArrayDataByName("tier", item->details.tier, i);
  6695. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6696. item_difficulty = player->GetArrowColor(tmp_level);
  6697. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6698. item_difficulty = ARROW_COLOR_WHITE;
  6699. sint64 overrideValue = 0;
  6700. if (item->GetItemScript() && lua_interface && lua_interface->RunItemScript(item->GetItemScript(), "item_difficulty", item, player, &overrideValue))
  6701. item_difficulty = (sint8)overrideValue;
  6702. item_difficulty -= 6;
  6703. if (item_difficulty < 0)
  6704. item_difficulty *= -1;
  6705. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6706. if (item->details.count == 1)
  6707. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6708. else
  6709. packet->setArrayDataByName("quantity", item->details.count, i);
  6710. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6711. if (GetVersion() <= 1096)
  6712. packet->setArrayDataByName("description", item->description.c_str(), i);
  6713. }
  6714. if (GetVersion() <= 546) {
  6715. packet->setDataByName("type", 1);
  6716. }
  6717. else {
  6718. if (sell)
  6719. packet->setDataByName("type", 129);
  6720. else
  6721. packet->setDataByName("type", 1);
  6722. }
  6723. packet->setDataByName("unknown8a", 16256, 6);
  6724. packet->setDataByName("unknown8a", 16256, 10);
  6725. //packet->PrintPacket();
  6726. EQ2Packet* outapp = packet->serialize();
  6727. //DumpPacket(outapp);
  6728. QueuePacket(outapp);
  6729. safe_delete(packet);
  6730. }
  6731. safe_delete(items);
  6732. }
  6733. }
  6734. }
  6735. void Client::SendBuyBackList(bool sell) {
  6736. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6737. return;
  6738. Spawn* spawn = GetMerchantTransaction();
  6739. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6740. deque<BuyBackItem*>::iterator itr;
  6741. int i = 0;
  6742. Item* master_item = 0;
  6743. BuyBackItem* buyback = 0;
  6744. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6745. if (packet) {
  6746. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6747. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6748. sint8 item_difficulty = 0;
  6749. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6750. int tmp_level = 0;
  6751. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6752. buyback = *itr;
  6753. master_item = master_item_list.GetItem(buyback->item_id);
  6754. if (master_item) {
  6755. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6756. packet->setArrayDataByName("price", buyback->price, i);
  6757. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6758. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6759. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6760. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6761. if (master_item->generic_info.adventure_default_level > 0)
  6762. tmp_level = master_item->generic_info.adventure_default_level;
  6763. else
  6764. tmp_level = master_item->generic_info.tradeskill_default_level;
  6765. packet->setArrayDataByName("level", tmp_level, i);
  6766. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6767. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6768. item_difficulty = player->GetArrowColor(tmp_level);
  6769. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6770. item_difficulty = ARROW_COLOR_WHITE;
  6771. sint64 overrideValue = 0;
  6772. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "item_difficulty", master_item, player, &overrideValue))
  6773. item_difficulty = (sint8)overrideValue;
  6774. item_difficulty -= 6;
  6775. if (item_difficulty < 0)
  6776. item_difficulty *= -1;
  6777. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6778. sint64 dispFlags = 0;
  6779. if (master_item->GetItemScript() && lua_interface && lua_interface->RunItemScript(master_item->GetItemScript(), "buyback_display_flags", master_item, player, &dispFlags))
  6780. packet->setArrayDataByName("display_flags", (int8)dispFlags, i);
  6781. if (buyback->quantity == 1)
  6782. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6783. else
  6784. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6785. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6786. if (GetVersion() <= 1096)
  6787. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6788. }
  6789. }
  6790. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6791. if (sell)
  6792. packet->setDataByName("type", 640);
  6793. else
  6794. packet->setDataByName("type", 512);
  6795. EQ2Packet* outapp = packet->serialize();
  6796. // DumpPacket(outapp);
  6797. QueuePacket(outapp);
  6798. safe_delete(packet);
  6799. }
  6800. }
  6801. }
  6802. void Client::SendRepairList() {
  6803. Spawn* spawn = GetMerchantTransaction();
  6804. if (spawn) {
  6805. vector<Item*>* repairable_items = GetRepairableItems();
  6806. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6807. if (packet) {
  6808. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6809. packet->setArrayLengthByName("num_items", repairable_items->size());
  6810. Item* item = 0;
  6811. sint8 item_difficulty = 0;
  6812. int32 i = 0;
  6813. vector<Item*>::iterator itr;
  6814. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  6815. item = *itr;
  6816. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6817. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  6818. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6819. packet->setArrayDataByName("stack_size", item->details.count, i);
  6820. packet->setArrayDataByName("icon", item->details.icon, i);
  6821. /*if (item->generic_info.adventure_default_level > 0)
  6822. tmp_level = item->generic_info.adventure_default_level;
  6823. else
  6824. tmp_level = item->generic_info.tradeskill_default_level;
  6825. packet->setArrayDataByName("level", tmp_level, i);*/
  6826. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  6827. packet->setArrayDataByName("tier", item->details.tier, i);
  6828. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6829. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6830. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6831. item_difficulty = ARROW_COLOR_WHITE;
  6832. item_difficulty -= 6;
  6833. if (item_difficulty < 0)
  6834. item_difficulty *= -1;
  6835. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6836. if (item->details.count == 1)
  6837. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6838. else
  6839. packet->setArrayDataByName("quantity", item->details.count, i);
  6840. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6841. if (GetVersion() <= 1096)
  6842. packet->setArrayDataByName("description", item->description.c_str(), i);
  6843. }
  6844. if (GetVersion() <= 546) {
  6845. packet->setDataByName("type", 16);
  6846. }
  6847. else {
  6848. packet->setDataByName("type", 96);
  6849. }
  6850. EQ2Packet* outapp = packet->serialize();
  6851. QueuePacket(outapp);
  6852. safe_delete(packet);
  6853. }
  6854. safe_delete(repairable_items);
  6855. }
  6856. }
  6857. void Client::ShowLottoWindow() {
  6858. Spawn* spawn = GetMerchantTransaction();
  6859. if (spawn) {
  6860. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  6861. if (!item_id)
  6862. {
  6863. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  6864. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  6865. return;
  6866. }
  6867. else if (item_id == 0)
  6868. {
  6869. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  6870. return;
  6871. }
  6872. Item* item = master_item_list.GetItem(item_id);
  6873. if (!item) {
  6874. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  6875. return;
  6876. }
  6877. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  6878. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6879. if (packet) {
  6880. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6881. packet->setArrayLengthByName("num_items", 1);
  6882. packet->setArrayDataByName("item_name", item->name.c_str());
  6883. packet->setArrayDataByName("price", item->sell_price);
  6884. packet->setArrayDataByName("item_id", item->details.item_id);
  6885. packet->setArrayDataByName("stack_size", item->details.count);
  6886. packet->setArrayDataByName("icon", item->details.icon);
  6887. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  6888. packet->setArrayDataByName("tier", item->details.tier);
  6889. packet->setArrayDataByName("item_id2", item->details.item_id);
  6890. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6891. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6892. item_difficulty = ARROW_COLOR_WHITE;
  6893. item_difficulty -= 6;
  6894. if (item_difficulty < 0)
  6895. item_difficulty *= -1;
  6896. packet->setArrayDataByName("item_difficulty", item_difficulty);
  6897. //if(item->details.count == 1)
  6898. packet->setArrayDataByName("quantity", 0xFFFF);
  6899. //else
  6900. // packet->setArrayDataByName("quantity", item->details.count);
  6901. packet->setArrayDataByName("stack_size2", item->details.count);
  6902. packet->setArrayDataByName("description", item->description.c_str());
  6903. if (GetVersion() <= 546) {
  6904. packet->setDataByName("type", 128);
  6905. }
  6906. else {
  6907. packet->setDataByName("type", 0x00000102);
  6908. }
  6909. QueuePacket(packet->serialize());
  6910. safe_delete(packet);
  6911. }
  6912. }
  6913. }
  6914. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  6915. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  6916. if (packet) {
  6917. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  6918. int32 rolls[6] = { 0 };
  6919. int32 lottery_digits[6] = { 0 };
  6920. int8 num_matches = 0;
  6921. int64 jackpot = 0;
  6922. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  6923. if (!item) {
  6924. return;
  6925. }
  6926. database.DeleteItem(GetCharacterID(), item, 0);
  6927. GetPlayer()->item_list.RemoveItem(item, true);
  6928. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6929. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6930. if (!winning_numbers) {
  6931. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6932. variables.AddVariable(winning_numbers);
  6933. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6934. }
  6935. if (strlen(winning_numbers->GetValue()) != 12) {
  6936. winning_numbers->SetValue("231205182236");
  6937. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6938. }
  6939. try {
  6940. for (int32 i = 0; i < 12; i += 2) {
  6941. char num[4];
  6942. strncpy(num, winning_numbers->GetValue() + i, 2);
  6943. lottery_digits[i / 2] = atoi(num);
  6944. }
  6945. }
  6946. catch (...) {
  6947. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6948. return;
  6949. }
  6950. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6951. if (!jackpot_var) {
  6952. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6953. variables.AddVariable(jackpot_var);
  6954. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6955. }
  6956. try {
  6957. jackpot = atoul(jackpot_var->GetValue());
  6958. if (jackpot < 10000)
  6959. jackpot = 10000;
  6960. }
  6961. catch (...) {
  6962. jackpot = 10000;
  6963. }
  6964. char new_jackpot[128] = { 0 };
  6965. sprintf(new_jackpot, "%llu", jackpot + price);
  6966. jackpot_var->SetValue(new_jackpot);
  6967. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6968. world.PickRandomLottoDigits(rolls);
  6969. packet->setDataByName("roll_digit1", rolls[0]);
  6970. packet->setDataByName("roll_digit2", rolls[1]);
  6971. packet->setDataByName("roll_digit3", rolls[2]);
  6972. packet->setDataByName("roll_digit4", rolls[3]);
  6973. packet->setDataByName("roll_digit5", rolls[4]);
  6974. packet->setDataByName("roll_digit6", rolls[5]);
  6975. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6976. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6977. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6978. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6979. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6980. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6981. QueuePacket(packet->serialize());
  6982. safe_delete(packet);
  6983. for (int32 i = 0; i < 6; i++) {
  6984. for (int32 j = 0; j < 6; j++) {
  6985. if (rolls[i] == lottery_digits[j]) {
  6986. num_matches++;
  6987. break;
  6988. }
  6989. }
  6990. }
  6991. char new_jackpot_str[16];
  6992. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6993. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6994. if (num_matches == 6) {
  6995. world.PickRandomLottoDigits(lottery_digits);
  6996. for (int32 i = 0; i < 12; i += 2)
  6997. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6998. winning_numbers->SetValue(new_jackpot_str);
  6999. jackpot_var->SetValue("10000");
  7000. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  7001. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  7002. }
  7003. }
  7004. }
  7005. void Client::SendGuildCreateWindow() {
  7006. if (GetVersion() <= 546) {
  7007. SimpleMessage(0, "Not implemented on this client...yet?");
  7008. }
  7009. else {
  7010. Spawn* spawn = GetPlayer()->GetTarget();
  7011. if (spawn) {
  7012. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  7013. if (packet) {
  7014. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  7015. packet->setArrayLengthByName("num_items", 0);
  7016. packet->setDataByName("type", 0x00008000);
  7017. QueuePacket(packet->serialize());
  7018. safe_delete(packet);
  7019. }
  7020. }
  7021. }
  7022. }
  7023. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  7024. BuyBackItem* item = new BuyBackItem;
  7025. item->item_id = item_id;
  7026. item->unique_id = unique_id;
  7027. item->price = price;
  7028. item->quantity = quantity;
  7029. item->save_needed = save_needed;
  7030. MBuyBack.writelock(__FUNCTION__, __LINE__);
  7031. buy_back_items.push_back(item);
  7032. if (buy_back_items.size() > 10) {
  7033. safe_delete(buy_back_items.front());
  7034. buy_back_items.pop_front();
  7035. }
  7036. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  7037. }
  7038. deque<BuyBackItem*>* Client::GetBuyBacks() {
  7039. return &buy_back_items;
  7040. }
  7041. vector<Item*>* Client::GetRepairableItems() {
  7042. vector<Item*>* repairable_items = new vector<Item*>;
  7043. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  7044. map<int32, Item*>* items = player->GetItemList();
  7045. if (equipped_items && equipped_items->size() > 0) {
  7046. for (int32 i = 0; i < equipped_items->size(); i++) {
  7047. Item* item = equipped_items->at(i);
  7048. if (item && item->generic_info.condition < 100)
  7049. repairable_items->push_back(item);
  7050. }
  7051. }
  7052. if (items && items->size() > 0) {
  7053. map<int32, Item*>::iterator itr;
  7054. for (itr = items->begin(); itr != items->end(); itr++) {
  7055. Item* item = itr->second;
  7056. if (item && item->generic_info.condition < 100)
  7057. repairable_items->push_back(item);
  7058. }
  7059. }
  7060. safe_delete(equipped_items);
  7061. safe_delete(items);
  7062. return repairable_items;
  7063. }
  7064. void Client::SendMailList() {
  7065. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7066. if (kiosk_id > 0) {
  7067. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  7068. if (p) {
  7069. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  7070. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  7071. int32 i = 0;
  7072. p->setDataByName("kiosk_id", kiosk_id);
  7073. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  7074. while (itr.Next()) {
  7075. Mail* mail = itr->second;
  7076. p->setArrayDataByName("mail_id", mail->mail_id, i);
  7077. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  7078. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  7079. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  7080. p->setArrayDataByName("unknown1", 0x0000, i);
  7081. p->setArrayDataByName("already_read", mail->already_read, i);
  7082. if(mail->expire_time)
  7083. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  7084. else
  7085. p->setArrayDataByName("mail_deletion", 0, i);
  7086. p->setArrayDataByName("mail_type", mail->mail_type, i);
  7087. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  7088. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  7089. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  7090. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  7091. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  7092. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  7093. //p->setArrayDataByName("unknown2", 0, i);
  7094. bool successItemAdd = false;
  7095. if(mail->stack || mail->char_item_id)
  7096. {
  7097. Item* item = master_item_list.GetItem(mail->char_item_id);
  7098. if(item)
  7099. {
  7100. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7101. if (version < 860)
  7102. p->setItemArrayDataByName("item", item, player, i, 0, -1);
  7103. else if (version < 1193)
  7104. p->setItemArrayDataByName("item", item, player, i);
  7105. else
  7106. p->setItemArrayDataByName("item", item, player, i, 0, 2);
  7107. successItemAdd = true;
  7108. }
  7109. }
  7110. if(!successItemAdd)
  7111. {
  7112. p->setArrayDataByName("end_tag2", GetItemPacketType(GetVersion()), i);
  7113. p->setArrayDataByName("end_tag3", 0xFF, i);
  7114. }
  7115. i++;
  7116. }
  7117. // GMs send mail for free!
  7118. if (GetAdminStatus() > 0)
  7119. {
  7120. p->setDataByName("postage_cost", 0);
  7121. p->setDataByName("attachment_cost", 0);
  7122. }
  7123. else
  7124. {
  7125. p->setDataByName("postage_cost", 10);
  7126. p->setDataByName("attachment_cost", 50);
  7127. }
  7128. p->setDataByName("unknown3", 0x01F4);
  7129. p->setDataByName("unknown4", 0x01000000);
  7130. EQ2Packet* pack = p->serialize();
  7131. DumpPacket(pack->pBuffer, pack->size);
  7132. QueuePacket(pack);
  7133. safe_delete(p);
  7134. }
  7135. }
  7136. else
  7137. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7138. }
  7139. void Client::DisplayMailMessage(int32 mail_id) {
  7140. Mail* mail = player->GetMail(mail_id);
  7141. if (mail) {
  7142. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  7143. if (kiosk_id > 0) {
  7144. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7145. if (update) {
  7146. update->setDataByName("action", 0x03);
  7147. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  7148. update->setDataByName("packetsubtype", 0xFF);
  7149. QueuePacket(update->serialize());
  7150. safe_delete(update);
  7151. }
  7152. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  7153. if (packet) {
  7154. packet->setDataByName("kiosk_id", kiosk_id);
  7155. packet->setDataByName("mail_id", mail->mail_id);
  7156. packet->setDataByName("player_to_id", mail->player_to_id);
  7157. packet->setDataByName("player_from", mail->player_from.c_str());
  7158. packet->setDataByName("subject", mail->subject.c_str());
  7159. packet->setDataByName("mail_body", mail->mail_body.c_str());
  7160. packet->setDataByName("unknown1", 1);
  7161. packet->setDataByName("unknown2", 0);
  7162. packet->setDataByName("lock_report_button", 1);
  7163. packet->setDataByName("unknown3", 0xFFFFFFFF);
  7164. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  7165. packet->setDataByName("coin_copper", mail->coin_copper);
  7166. packet->setDataByName("coin_silver", mail->coin_silver);
  7167. packet->setDataByName("coin_gold", mail->coin_gold);
  7168. packet->setDataByName("coin_plat", mail->coin_plat);
  7169. if(mail->stack || mail->char_item_id)
  7170. {
  7171. Item* item = master_item_list.GetItem(mail->char_item_id);
  7172. item->stack_count = mail->stack > 1 ? mail->stack : 0;
  7173. if (version < 860)
  7174. packet->setItemByName("item", item, player, 0, -1);
  7175. else if (version < 1193)
  7176. packet->setItemByName("item", item, player, 0, 0);
  7177. else
  7178. packet->setItemByName("item", item, player, 0, 2);
  7179. }
  7180. else
  7181. {
  7182. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7183. packet->setDataByName("end_tag3", 0xFF);
  7184. }
  7185. mail->already_read = true;
  7186. mail->save_needed = true;
  7187. EQ2Packet* pack = packet->serialize();
  7188. DumpPacket(pack);
  7189. QueuePacket(pack);
  7190. safe_delete(packet);
  7191. // trying to update this causes the window not to open
  7192. //SendMailList();
  7193. }
  7194. }
  7195. else
  7196. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7197. }
  7198. }
  7199. /* 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
  7200. packet back to the client before the mail actually sent. */
  7201. void Client::HandleSentMail(EQApplicationPacket* app) {
  7202. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  7203. if (packet) {
  7204. packet->LoadPacketData(app->pBuffer, app->size);
  7205. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  7206. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  7207. vector<int32>* ids = 0;
  7208. MMailWindowMutex.lock();
  7209. if (reply_packet) {
  7210. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  7211. if (player_to.length() == 0)
  7212. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  7213. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  7214. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  7215. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  7216. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  7217. else {
  7218. if (GetAdminStatus() > 200 && player_to.compare("<all>") == 0) {
  7219. if (mail_window.char_item_id == 0 && (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat) == 0)
  7220. ids = database.GetAllPlayerIDs();
  7221. else
  7222. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  7223. }
  7224. else {
  7225. ids = new vector<int32>;
  7226. ids->push_back(database.GetCharacterID(player_to.c_str()));
  7227. }
  7228. if (ids) {
  7229. for (int32 i = 0; i < ids->size(); i++) {
  7230. int32 player_to_id = ids->at(i);
  7231. if (player_to_id > 0) {
  7232. reply_type = MAIL_SEND_RESULT_SUCCESS;
  7233. Mail* mail = new Mail;
  7234. mail->mail_id = 0;
  7235. mail->player_to_id = player_to_id;
  7236. mail->player_from = string(GetPlayer()->GetName());
  7237. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  7238. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  7239. mail->already_read = 0;
  7240. mail->mail_type = MAIL_TYPE_REGULAR;
  7241. mail->coin_copper = mail_window.coin_copper;
  7242. mail->coin_silver = mail_window.coin_silver;
  7243. mail->coin_gold = mail_window.coin_gold;
  7244. mail->coin_plat = mail_window.coin_plat;
  7245. mail->char_item_id = mail_window.char_item_id;
  7246. mail->stack = mail_window.stack;
  7247. // GM's send mail for free!
  7248. if (GetAdminStatus() > 0)
  7249. {
  7250. mail->postage_cost = 0;
  7251. mail->attachment_cost = 0;
  7252. }
  7253. else
  7254. {
  7255. mail->postage_cost = 10;
  7256. mail->attachment_cost = 50;
  7257. }
  7258. mail->time_sent = Timer::GetUnixTimeStamp();
  7259. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  7260. //int16 packettype = packet->getType_int16_ByName("packettype");
  7261. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  7262. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  7263. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  7264. if (postage_cost > 0 || attachment_cost > 0)
  7265. PlaySoundA("coin_cha_ching");*/
  7266. mail->save_needed = false;
  7267. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  7268. if (to_client) {
  7269. to_client->GetPlayer()->AddMail(mail);
  7270. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You've got mail! :)");
  7271. }
  7272. database.SavePlayerMail(mail);
  7273. ResetSendMail(false, false);
  7274. }
  7275. else
  7276. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  7277. }
  7278. }
  7279. }
  7280. string players_to = "";
  7281. if (ids) {
  7282. for (int32 i = 0; i < ids->size(); i++) {
  7283. if (ids->at(i) != 0)
  7284. players_to.append(database.GetCharacterName(ids->at(i)));
  7285. if (i < (ids->size() - 1))
  7286. players_to.append(", ");
  7287. }
  7288. }
  7289. reply_packet->setDataByName("player_to", players_to.c_str());
  7290. reply_packet->setDataByName("reply_type", reply_type);
  7291. QueuePacket(reply_packet->serialize());
  7292. safe_delete(reply_packet);
  7293. safe_delete(ids);
  7294. }
  7295. safe_delete(packet);
  7296. MMailWindowMutex.unlock();
  7297. }
  7298. }
  7299. void Client::DeleteMail(int32 mail_id, bool from_database) {
  7300. player->DeleteMail(mail_id, from_database);
  7301. }
  7302. bool Client::AddMailItem(Item* item)
  7303. {
  7304. bool ret = false;
  7305. if (GetMailTransaction()) {
  7306. MMailWindowMutex.lock();
  7307. if(mail_window.char_item_id == 0)
  7308. {
  7309. mail_window.item = item;
  7310. mail_window.char_item_id = item->details.item_id;
  7311. mail_window.stack = item->details.count;
  7312. ret = true;
  7313. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7314. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7315. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7316. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7317. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7318. if(item)
  7319. {
  7320. packet->setDataByName("stack", mail_window.stack);
  7321. item->stack_count = mail_window.stack;
  7322. if (version < 860)
  7323. packet->setItemByName("item", item, player, 0, -1);
  7324. else if (version < 1193)
  7325. packet->setItemByName("item", item, player, 0, 0);
  7326. else
  7327. packet->setItemByName("item", item, player, 0, 2);
  7328. }
  7329. else
  7330. {
  7331. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7332. packet->setDataByName("end_tag3", 0xFF);
  7333. }
  7334. //packet->setDataByName("packettype", GetItemPacketType(version));
  7335. //packet->setDataByName("packetsubtype", 0xFF);
  7336. //packet->setDataByName("unknown2", 0);
  7337. //packet->PrintPacket();
  7338. QueuePacket(packet->serialize());
  7339. }
  7340. MMailWindowMutex.unlock();
  7341. }
  7342. return ret;
  7343. }
  7344. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7345. bool ret = false;
  7346. if (GetMailTransaction()) {
  7347. MMailWindowMutex.lock();
  7348. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7349. if (packet) {
  7350. if (copper > 0) {
  7351. if (player->RemoveCoins(copper)) {
  7352. mail_window.coin_copper += copper;
  7353. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  7354. ret = true;
  7355. }
  7356. }
  7357. else if (silver > 0) {
  7358. if (player->RemoveCoins(silver * 100)) {
  7359. mail_window.coin_silver += silver;
  7360. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  7361. ret = true;
  7362. }
  7363. }
  7364. else if (gold > 0) {
  7365. if (player->RemoveCoins(gold * 10000)) {
  7366. mail_window.coin_gold += gold;
  7367. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  7368. ret = true;
  7369. }
  7370. }
  7371. else if (plat > 0) {
  7372. if (player->RemoveCoins(plat * 1000000)) {
  7373. mail_window.coin_plat += plat;
  7374. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  7375. ret = true;
  7376. }
  7377. }
  7378. if (ret) {
  7379. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7380. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7381. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7382. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7383. Item* item = master_item_list.GetItem(mail_window.char_item_id);
  7384. if(item)
  7385. {
  7386. packet->setDataByName("stack", mail_window.stack);
  7387. item->stack_count = mail_window.stack;
  7388. if (version < 860)
  7389. packet->setItemByName("item", item, player, 0, -1);
  7390. else if (version < 1193)
  7391. packet->setItemByName("item", item, player, 0, 0);
  7392. else
  7393. packet->setItemByName("item", item, player, 0, 2);
  7394. }
  7395. else
  7396. {
  7397. packet->setDataByName("end_tag2", GetItemPacketType(GetVersion()));
  7398. packet->setDataByName("end_tag3", 0xFF);
  7399. }
  7400. //packet->PrintPacket();
  7401. QueuePacket(packet->serialize());
  7402. }
  7403. else
  7404. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  7405. safe_delete(packet);
  7406. }
  7407. MMailWindowMutex.unlock();
  7408. }
  7409. else
  7410. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7411. return ret;
  7412. }
  7413. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  7414. bool ret = false;
  7415. if (GetMailTransaction()) {
  7416. MMailWindowMutex.lock();
  7417. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7418. if (packet) {
  7419. if (copper > 0) {
  7420. player->AddCoins(copper);
  7421. mail_window.coin_copper -= copper;
  7422. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  7423. ret = true;
  7424. }
  7425. else if (silver > 0) {
  7426. player->AddCoins(silver * 100);
  7427. mail_window.coin_silver -= silver;
  7428. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  7429. ret = true;
  7430. }
  7431. else if (gold > 0) {
  7432. player->AddCoins(gold * 10000);
  7433. mail_window.coin_gold -= gold;
  7434. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  7435. ret = true;
  7436. }
  7437. else if (plat > 0) {
  7438. player->AddCoins(plat * 1000000);
  7439. mail_window.coin_plat -= plat;
  7440. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  7441. ret = true;
  7442. }
  7443. if (ret) {
  7444. packet->setDataByName("coin_copper", mail_window.coin_copper);
  7445. packet->setDataByName("coin_silver", mail_window.coin_silver);
  7446. packet->setDataByName("coin_gold", mail_window.coin_gold);
  7447. packet->setDataByName("coin_plat", mail_window.coin_plat);
  7448. packet->setDataByName("stack", 0);
  7449. packet->setDataByName("packettype", 0x2BFE);
  7450. packet->setDataByName("packetsubtype", 0xFF);
  7451. packet->setDataByName("unknown2", 0);
  7452. QueuePacket(packet->serialize());
  7453. }
  7454. safe_delete(packet);
  7455. }
  7456. MMailWindowMutex.unlock();
  7457. }
  7458. else
  7459. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7460. return ret;
  7461. }
  7462. void Client::TakeMailAttachments(int32 mail_id) {
  7463. if (GetMailTransaction()) {
  7464. Mail* mail = player->GetMail(mail_id);
  7465. if (mail) {
  7466. int64 amount = 0;
  7467. if (mail->coin_copper > 0) {
  7468. amount += mail->coin_copper;
  7469. mail->coin_copper = 0;
  7470. }
  7471. if (mail->coin_silver > 0) {
  7472. amount += mail->coin_silver * 100;
  7473. mail->coin_silver = 0;
  7474. }
  7475. if (mail->coin_gold > 0) {
  7476. amount += mail->coin_gold * 10000;
  7477. mail->coin_gold = 0;
  7478. }
  7479. if (mail->coin_plat > 0) {
  7480. amount += mail->coin_plat * 1000000;
  7481. mail->coin_plat = 0;
  7482. }
  7483. if (mail->char_item_id > 0) {
  7484. AddItem(mail->char_item_id, mail->stack);
  7485. mail->char_item_id = 0;
  7486. mail->stack = 0;
  7487. }
  7488. /* 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
  7489. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  7490. find it in any packet logs.*/
  7491. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  7492. if (packet) {
  7493. packet->setDataByName("unknown", 0x03);
  7494. packet->setDataByName("coin_copper", mail->coin_copper);
  7495. packet->setDataByName("coin_silver", mail->coin_silver);
  7496. packet->setDataByName("coin_gold", mail->coin_gold);
  7497. packet->setDataByName("coin_plat", mail->coin_plat);
  7498. packet->setDataByName("stack", 0);
  7499. packet->setDataByName("packettype", 0x2BFE);
  7500. packet->setDataByName("packetsubtype", 0xFF);
  7501. packet->setDataByName("unknown2", 0);
  7502. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  7503. DumpPacket(packet->serialize());
  7504. QueuePacket(packet->serialize());
  7505. safe_delete(packet);
  7506. }*/
  7507. database.SavePlayerMail(mail);
  7508. if (amount > 0)
  7509. player->AddCoins(amount);
  7510. SendMailList();
  7511. }
  7512. }
  7513. else
  7514. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  7515. }
  7516. void Client::ResetSendMail(bool cancel, bool needslock) {
  7517. if(cancel && mail_transaction)
  7518. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  7519. if(needslock)
  7520. MMailWindowMutex.lock();
  7521. if(cancel)
  7522. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  7523. if(!cancel)
  7524. mail_transaction = 0;
  7525. mail_window.coin_copper = 0;
  7526. mail_window.coin_silver = 0;
  7527. mail_window.coin_gold = 0;
  7528. mail_window.coin_plat = 0;
  7529. mail_window.char_item_id = 0;
  7530. mail_window.stack = 0;
  7531. if(mail_window.item){
  7532. if(cancel)
  7533. AddItem(mail_window.item);
  7534. else
  7535. safe_delete(mail_window.item);
  7536. }
  7537. mail_window.item = nullptr;
  7538. if(needslock)
  7539. MMailWindowMutex.unlock();
  7540. }
  7541. bool Client::GateAllowed() {
  7542. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7543. 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__);
  7544. if (zone)
  7545. return true;
  7546. return false;
  7547. }
  7548. bool Client::BindAllowed() {
  7549. 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__);
  7550. return true;
  7551. }
  7552. bool Client::Bind() {
  7553. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  7554. player->GetPlayerInfo()->SetBindX(player->GetX());
  7555. player->GetPlayerInfo()->SetBindY(player->GetY());
  7556. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  7557. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  7558. return true;
  7559. }
  7560. bool Client::Gate(bool is_spell) {
  7561. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  7562. return false;
  7563. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  7564. if (zone) {
  7565. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  7566. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  7567. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  7568. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  7569. Zone(zone, false, is_spell);
  7570. return true;
  7571. }
  7572. return false;
  7573. }
  7574. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id, bool is_spell) {
  7575. if (!destinations || !spawn) {
  7576. return;
  7577. }
  7578. bool has_map = false;
  7579. if (transport_id > 0)
  7580. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  7581. transport_spawn = spawn;
  7582. vector<TransportDestination*> transport_list;
  7583. vector<TransportDestination*>::iterator itr;
  7584. TransportDestination* destination = 0;
  7585. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  7586. destination = *itr;
  7587. 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)))
  7588. transport_list.push_back(destination);
  7589. }
  7590. if (transport_list.size() == 0 && destination) {
  7591. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7592. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7593. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7594. else
  7595. {
  7596. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7597. if (app)
  7598. QueuePacket(app);
  7599. }
  7600. }
  7601. else {
  7602. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7603. // determine if this is an instanced zone that already exists
  7604. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  7605. if (instance_zone || new_zone) {
  7606. GetPlayer()->SetX(destination->destination_x);
  7607. GetPlayer()->SetY(destination->destination_y);
  7608. GetPlayer()->SetZ(destination->destination_z);
  7609. GetPlayer()->SetHeading(destination->destination_heading);
  7610. if (instance_zone)
  7611. Zone(instance_zone->GetInstanceID(), false, true, is_spell);
  7612. else
  7613. Zone(new_zone, false, is_spell);
  7614. }
  7615. }
  7616. if (destination->message.length() > 0)
  7617. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7618. }
  7619. else if (transport_list.size() > 0) {
  7620. if (!spawn->IsSoundsDisabled())
  7621. PlaySound("mariner_bell");
  7622. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7623. if (packet) {
  7624. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7625. // Put all the destinations the player can go in a new vector
  7626. vector<TransportDestination*> destinations;
  7627. for (int32 i = 0; i < transport_list.size(); i++) {
  7628. destination = transport_list.at(i);
  7629. // Check min level
  7630. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7631. continue;
  7632. // Check max level
  7633. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7634. continue;
  7635. // Check quest complete
  7636. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7637. continue;
  7638. // Check req quest and step
  7639. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7640. continue;
  7641. // 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
  7642. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7643. packet->setDataByName("current_zone", destination->display_name.c_str());
  7644. packet->setDataByName("current_map_x", destination->map_x);
  7645. packet->setDataByName("current_map_y", destination->map_y);
  7646. }
  7647. else {
  7648. destinations.push_back(destination);
  7649. }
  7650. }
  7651. // Use the new vector to create the packet
  7652. destination = 0;
  7653. packet->setArrayLengthByName("num_destinations", destinations.size());
  7654. for (int32 i = 0; i < destinations.size(); i++) {
  7655. destination = destinations.at(i);
  7656. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7657. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7658. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7659. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7660. packet->setArrayDataByName("cost", destination->cost, i);
  7661. if (has_map) {
  7662. packet->setArrayDataByName("map_x", destination->map_x, i);
  7663. packet->setArrayDataByName("map_y", destination->map_y, i);
  7664. }
  7665. }
  7666. if (has_map)
  7667. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7668. EQ2Packet* app = packet->serialize();
  7669. //DumpPacket(app);
  7670. if (destinations.size() > 0)
  7671. QueuePacket(app);
  7672. safe_delete(packet);
  7673. }
  7674. }
  7675. }
  7676. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7677. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7678. if (packet) {
  7679. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7680. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7681. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7682. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7683. int32 cost = packet->getType_int32_ByName("cost");
  7684. vector<TransportDestination*> destinations;
  7685. TransportDestination* destination = 0;
  7686. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7687. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7688. vector<TransportDestination*>::iterator itr;
  7689. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7690. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7691. destination = *itr;
  7692. break;
  7693. }
  7694. }
  7695. SetTemporaryTransportID(0);
  7696. if (!destination)
  7697. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7698. else {
  7699. if (cost == 0 || player->RemoveCoins(cost)) {
  7700. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7701. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7702. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7703. else
  7704. {
  7705. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7706. if (outapp)
  7707. QueuePacket(outapp);
  7708. }
  7709. }
  7710. else {
  7711. GetPlayer()->SetX(destination->destination_x);
  7712. GetPlayer()->SetY(destination->destination_y);
  7713. GetPlayer()->SetZ(destination->destination_z);
  7714. GetPlayer()->SetHeading(destination->destination_heading);
  7715. // Test if where we're going is an Instanced zone
  7716. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7717. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7718. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7719. Zone(new_zone, false);
  7720. }
  7721. }
  7722. if (destination->message.length() > 0)
  7723. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7724. }
  7725. else
  7726. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7727. }
  7728. }
  7729. safe_delete(packet);
  7730. }
  7731. }
  7732. void Client::SendNewSpells(int8 class_id) {
  7733. if (class_id > 0) {
  7734. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7735. vector<Spell*>::iterator itr;
  7736. Spell* spell = 0;
  7737. bool send_updates = false;
  7738. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7739. spell = *itr;
  7740. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7741. send_updates = true;
  7742. SendSpellUpdate(spell);
  7743. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7744. player->UnlockSpell(spell);
  7745. }
  7746. }
  7747. if (send_updates) {
  7748. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7749. if (outapp)
  7750. QueuePacket(outapp);
  7751. }
  7752. safe_delete(spells);
  7753. }
  7754. }
  7755. void Client::SetItemSearch(vector<Item*>* items) {
  7756. if (items) {
  7757. safe_delete(search_items);
  7758. search_items = items;
  7759. }
  7760. }
  7761. vector<Item*>* Client::GetSearchItems() {
  7762. return search_items;
  7763. }
  7764. void Client::SearchStore(int32 page) {
  7765. if (search_items) {
  7766. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7767. if (packet) {
  7768. int32 x = page * 8;
  7769. if (search_items->size() > 8) {
  7770. if ((search_items->size() - x) > 8)
  7771. packet->setArrayLengthByName("num_items", 8);
  7772. else
  7773. packet->setArrayLengthByName("num_items", search_items->size() - x);
  7774. }
  7775. else
  7776. packet->setArrayLengthByName("num_items", search_items->size());
  7777. if (search_items->size() > 0) {
  7778. packet->setArrayLengthByName("num_sellers", 1);
  7779. packet->setArrayDataByName("seller_seller_id", 1);
  7780. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  7781. packet->setDataByName("per_page", 8);
  7782. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  7783. packet->setDataByName("page", page);
  7784. Item* item = 0;
  7785. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  7786. for (int32 i = 0; i < limit; i++, x++) {
  7787. if (x >= search_items->size())
  7788. break;
  7789. item = search_items->at(x);
  7790. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7791. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7792. packet->setArrayDataByName("icon", item->details.icon, i);
  7793. //packet->setArrayDataByName("unknown2b", i, i);
  7794. packet->setArrayDataByName("item_seller_id", 1, i);
  7795. if (item->stack_count == 0)
  7796. packet->setArrayDataByName("quantity", 1, i);
  7797. else
  7798. packet->setArrayDataByName("quantity", item->stack_count, i);
  7799. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7800. std::string tmpStr("");
  7801. tmpStr.append(item->name.c_str());
  7802. tmpStr.append(" (");
  7803. tmpStr.append(std::to_string(item->details.item_id));
  7804. tmpStr.append(")");
  7805. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  7806. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  7807. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  7808. }
  7809. }
  7810. /*EQ2Packet* outapp = packet->serialize();
  7811. DumpPacket(outapp);
  7812. QueuePacket(outapp);*/
  7813. QueuePacket(packet->serialize());
  7814. safe_delete(packet);
  7815. }
  7816. }
  7817. }
  7818. void Client::SetReadyForUpdates() {
  7819. GetPlayer()->SetFullyLoggedIn(true);
  7820. if (!ready_for_updates)
  7821. database.loadCharacterProperties(this);
  7822. ready_for_updates = true;
  7823. }
  7824. void Client::SetReadyForSpawns(bool val) {
  7825. ready_for_spawns = val;
  7826. if (GetPlayer()->GetActivityStatus() > 0) {
  7827. GetPlayer()->SetActivityStatus(0);
  7828. if (GetPlayer()->GetGroupMemberInfo()) {
  7829. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  7830. }
  7831. }
  7832. zone_list.CheckFriendZoned(this);
  7833. }
  7834. void Client::SendChatRelationship(int8 type, const char* name) {
  7835. if (!name) {
  7836. return;
  7837. }
  7838. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7839. if (packet) {
  7840. packet->setDataByName("account_id", GetAccountID());
  7841. packet->setDataByName("type", type);
  7842. packet->setArrayLengthByName("num_names", 1);
  7843. packet->setArrayDataByName("name", name);
  7844. if (type == 0) {
  7845. Client* client = zone_list.GetClientByCharName(name);
  7846. if (client) {
  7847. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  7848. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  7849. }
  7850. }
  7851. QueuePacket(packet->serialize());
  7852. safe_delete(packet);
  7853. }
  7854. }
  7855. void Client::SendFriendList() {
  7856. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7857. if (packet) {
  7858. packet->setDataByName("account_id", GetAccountID());
  7859. map<string, int8>::iterator itr;
  7860. map<string, int8>* friends = player->GetFriends();
  7861. if (friends && friends->size() > 0) {
  7862. Client* client = 0;
  7863. vector<string> names;
  7864. for (itr = friends->begin(); itr != friends->end(); itr++) {
  7865. if (itr->second == 2)
  7866. continue;
  7867. names.push_back(itr->first);
  7868. }
  7869. packet->setArrayLengthByName("num_names", names.size());
  7870. for (int32 i = 0; i < names.size(); i++) {
  7871. client = zone_list.GetClientByCharName(names[i]);
  7872. packet->setArrayDataByName("name", names[i].c_str(), i);
  7873. if (client) {
  7874. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  7875. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  7876. }
  7877. }
  7878. }
  7879. QueuePacket(packet->serialize());
  7880. safe_delete(packet);
  7881. }
  7882. }
  7883. void Client::SendIgnoreList() {
  7884. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7885. if (packet) {
  7886. packet->setDataByName("account_id", GetAccountID());
  7887. packet->setDataByName("type", 2);
  7888. map<string, int8>::iterator itr;
  7889. map<string, int8>* ignored = player->GetIgnoredPlayers();
  7890. if (ignored && ignored->size() > 0) {
  7891. vector<string> names;
  7892. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  7893. if (itr->second == 2)
  7894. continue;
  7895. names.push_back(itr->first);
  7896. }
  7897. packet->setArrayLengthByName("num_names", names.size());
  7898. for (int32 i = 0; i < names.size(); i++)
  7899. packet->setArrayDataByName("name", names[i].c_str(), i);
  7900. }
  7901. QueuePacket(packet->serialize());
  7902. safe_delete(packet);
  7903. }
  7904. }
  7905. void Client::AddWaypoint(string name, int8 type) {
  7906. waypoint_id++;
  7907. WaypointInfo info;
  7908. info.id = waypoint_id;
  7909. info.type = type;
  7910. waypoints[name] = info;
  7911. }
  7912. void Client::SendWaypoints() {
  7913. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7914. if (packet) {
  7915. packet->setArrayLengthByName("num_updates", waypoints.size());
  7916. map<string, WaypointInfo>::iterator itr;
  7917. int16 i = 0;
  7918. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7919. packet->setArrayDataByName("waypoint_name", itr->first.c_str(), i);
  7920. packet->setArrayDataByName("waypoint_category", itr->second.type, i);
  7921. packet->setArrayDataByName("spawn_id", itr->second.id, i);
  7922. i++;
  7923. }
  7924. packet->setDataByName("unknown", 0xFFFFFFFF);
  7925. QueuePacket(packet->serialize());
  7926. safe_delete(packet);
  7927. }
  7928. }
  7929. void Client::SelectWaypoint(int32 id) {
  7930. string found_name = "";
  7931. map<string, WaypointInfo>::iterator itr;
  7932. for (itr = waypoints.begin(); itr != waypoints.end(); itr++) {
  7933. if (itr->second.id == id) {
  7934. found_name = itr->first;
  7935. break;
  7936. }
  7937. }
  7938. if (found_name.length() > 0) {
  7939. Spawn* spawn = current_zone->FindSpawn(player, found_name.c_str());
  7940. ShowPathToTarget(spawn);
  7941. }
  7942. }
  7943. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  7944. if (waypoint_name) {
  7945. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7946. if (packet) {
  7947. packet->setArrayLengthByName("num_updates", 1);
  7948. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  7949. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  7950. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  7951. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  7952. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  7953. packet->setDataByName("unknown", 0xFFFFFFFF);
  7954. QueuePacket(packet->serialize());
  7955. safe_delete(packet);
  7956. }
  7957. }
  7958. }
  7959. void Client::ClearWaypoint() {
  7960. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7961. if (packet) {
  7962. QueuePacket(packet->serialize());
  7963. safe_delete(packet);
  7964. }
  7965. }
  7966. bool Client::ShowPathToTarget(float x, float y, float z, float y_offset) {
  7967. if (current_zone->pathing) {
  7968. if (GetPlayer()->GetMap()) {
  7969. if (x < GetPlayer()->GetMap()->GetMinX() || x > GetPlayer()->GetMap()->GetMaxX())
  7970. return false;
  7971. if (z < GetPlayer()->GetMap()->GetMinZ() || z > GetPlayer()->GetMap()->GetMaxZ())
  7972. return false;
  7973. auto loc = glm::vec3(x, z, y);
  7974. float new_z = GetPlayer()->GetMap()->FindBestZ(loc, nullptr);
  7975. if (new_z != BEST_Z_INVALID) //this is actually y
  7976. y = new_z;
  7977. }
  7978. bool partial = false;
  7979. bool stuck = false;
  7980. PathfinderOptions opts;
  7981. opts.smooth_path = true;
  7982. opts.step_size = 100.0f;//RuleR(Pathing, NavmeshStepSize);
  7983. opts.offset = y_offset + 1.0f;
  7984. opts.flags = PathingNotDisabled ^ PathingZoneLine;
  7985. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7986. if (packet) {
  7987. auto path = current_zone->pathing->FindPath(glm::vec3(player->GetX(), player->GetZ(), player->GetY()), glm::vec3(x, z, y), partial, stuck, opts);
  7988. packet->setArrayLengthByName("num_points", path.size());
  7989. int i = 0;
  7990. for (auto& node : path)
  7991. {
  7992. packet->setArrayDataByName("x", node.pos.x, i);
  7993. packet->setArrayDataByName("y", node.pos.z, i);
  7994. packet->setArrayDataByName("z", node.pos.y, i);
  7995. packet->setDataByName("waypoint_x", x);
  7996. packet->setDataByName("waypoint_y", y);
  7997. packet->setDataByName("waypoint_z", z);
  7998. i++;
  7999. }
  8000. if (i > 0)
  8001. QueuePacket(packet->serialize());
  8002. safe_delete(packet);
  8003. return (i > 0);
  8004. }
  8005. }
  8006. return false;
  8007. }
  8008. bool Client::ShowPathToTarget(Spawn* spawn) {
  8009. if (spawn) {
  8010. return ShowPathToTarget(spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetYOffset());
  8011. }
  8012. return false;
  8013. }
  8014. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  8015. if (waypoint_name) {
  8016. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  8017. if (packet) {
  8018. packet->setArrayLengthByName("num_points", 1);
  8019. packet->setArrayDataByName("x", x, 0);
  8020. packet->setArrayDataByName("y", y, 0);
  8021. packet->setArrayDataByName("z", z, 0);
  8022. packet->setDataByName("waypoint_x", x);
  8023. packet->setDataByName("waypoint_y", y);
  8024. packet->setDataByName("waypoint_z", z);
  8025. packet->setDataByName("waypoint_name", waypoint_name);
  8026. packet->setDataByName("unknown", 0);
  8027. QueuePacket(packet->serialize());
  8028. safe_delete(packet);
  8029. }
  8030. }
  8031. }
  8032. void Client::InspectPlayer(Player* player_to_inspect) {
  8033. if (player_to_inspect) {
  8034. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  8035. if (packet) {
  8036. packet->setDataByName("unknown", 0);
  8037. packet->setSmallStringByName("name", player_to_inspect->GetName());
  8038. packet->setDataByName("race", player_to_inspect->GetRace());
  8039. packet->setDataByName("gender", player_to_inspect->GetGender());
  8040. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  8041. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  8042. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  8043. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  8044. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  8045. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  8046. packet->setDataByName("health", player_to_inspect->GetHP());
  8047. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  8048. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  8049. packet->setDataByName("power", player_to_inspect->GetPower());
  8050. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  8051. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  8052. packet->setDataByName("mitigation", 0);
  8053. packet->setDataByName("unknown1", 0);
  8054. packet->setDataByName("avoidance", player_to_inspect->GetInfoStruct()->get_cur_avoidance());
  8055. packet->setDataByName("unknown2", 0);
  8056. packet->setDataByName("mitigation_percentage", 0);
  8057. packet->setDataByName("strength", player_to_inspect->GetStr());
  8058. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  8059. packet->setDataByName("stamina", player_to_inspect->GetSta());
  8060. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  8061. packet->setDataByName("agility", player_to_inspect->GetAgi());
  8062. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  8063. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  8064. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  8065. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  8066. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  8067. packet->setDataByName("unknown4", 0);
  8068. packet->setDataByName("unknown5", 0);
  8069. packet->setDataByName("unknown6", 0);
  8070. packet->setDataByName("unknown7", 0);
  8071. packet->setDataByName("unknown8", 0);
  8072. packet->setDataByName("unknown9", 0);
  8073. packet->setDataByName("unknown10", 0);
  8074. packet->setDataByName("unknown11", 0);
  8075. packet->setDataByName("unknown12", 0);
  8076. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  8077. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  8078. packet->setDataByName("heat_resist_percentage", 0);
  8079. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  8080. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  8081. packet->setDataByName("cold_resist_percentage", 0);
  8082. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  8083. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  8084. packet->setDataByName("magic_resist_percentage", 0);
  8085. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  8086. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  8087. packet->setDataByName("mental_resist_percentage", 0);
  8088. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  8089. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  8090. packet->setDataByName("divine_resist_percentage", 0);
  8091. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  8092. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  8093. packet->setDataByName("disease_resist_percentage", 0);
  8094. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  8095. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  8096. packet->setDataByName("poison_resist_percentage", 0);
  8097. packet->setArrayLengthByName("num_chars", 0x01FF);
  8098. string biography = player_to_inspect->GetBiography();
  8099. for (size_t i = 0; i < biography.length(); i++)
  8100. packet->setArrayDataByName("biography_char", biography[i], i);
  8101. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  8102. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  8103. if (pw)
  8104. packet->setItemByName("primary", pw, player_to_inspect, 0);
  8105. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  8106. if (sw)
  8107. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  8108. //DumpPacket(packet->serialize());
  8109. QueuePacket(packet->serialize());
  8110. safe_delete(packet);
  8111. }
  8112. }
  8113. }
  8114. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  8115. pending_guild_invite.guild = guild;
  8116. pending_guild_invite.invited_by = invited_by;
  8117. }
  8118. void Client::ShowClaimWindow() {
  8119. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  8120. if (packet) {
  8121. map<int32, Item*>* items = &master_item_list.items;
  8122. map<int32, Item*>::iterator itr;
  8123. int32 i = 0;
  8124. if (items->size() > 10)
  8125. packet->setArrayLengthByName("num_claim_items", 10);
  8126. else
  8127. packet->setArrayLengthByName("num_claim_items", items->size());
  8128. for (itr = items->begin(); itr != items->end(); itr++) {
  8129. if (i == 10)
  8130. break;
  8131. Item* item = itr->second;
  8132. packet->setArrayDataByName("id", i, i);
  8133. packet->setArrayDataByName("not_yet_claimed", 1, i);
  8134. packet->setArrayDataByName("num_remaining", 5, i);
  8135. packet->setArrayDataByName("one_per_character", 1, i);
  8136. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  8137. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  8138. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  8139. packet->setArrayDataByName("category", "Scott's Shit", i);
  8140. packet->setArrayDataByName("icon", item->details.icon, i);
  8141. packet->setArrayDataByName("item_id", item->details.item_id, i);
  8142. i++;
  8143. }
  8144. packet->setDataByName("unknown3", 1);
  8145. QueuePacket(packet->serialize());
  8146. safe_delete(packet);
  8147. }
  8148. }
  8149. void Client::ShowGuildSearchWindow() {
  8150. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  8151. if (packet) {
  8152. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  8153. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  8154. packet->setArrayLengthByName("num_guilds", guilds->size());
  8155. int32 i = 0;
  8156. while (itr.Next()) {
  8157. Guild* guild = itr.second;
  8158. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  8159. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  8160. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  8161. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  8162. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  8163. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  8164. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  8165. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  8166. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  8167. packet->setArrayDataByName("unknown7", 0x02, i);
  8168. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  8169. i++;
  8170. }
  8171. QueuePacket(packet->serialize());
  8172. safe_delete(packet);
  8173. }
  8174. }
  8175. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  8176. PacketStruct* packet;
  8177. vector<int8>* slot_data;
  8178. vector<int8>::iterator itr;
  8179. int32 slots = 0;
  8180. assert(item);
  8181. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  8182. return;
  8183. }
  8184. slot_data = &item->slot_data;
  8185. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  8186. if (version >= 1188)
  8187. slots = *itr;
  8188. else
  8189. slots += (int8)pow(2.0, *itr);
  8190. }
  8191. packet->setDataByName("slot", slots);
  8192. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  8193. if (slots == 2) {
  8194. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  8195. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  8196. }
  8197. else {
  8198. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  8199. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  8200. }
  8201. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  8202. if (slots == 4) {
  8203. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  8204. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8205. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  8206. }
  8207. else if (slots == 7) {
  8208. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  8209. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  8210. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8211. }
  8212. else {
  8213. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  8214. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  8215. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  8216. }
  8217. packet->setDataByName("icon", item->details.icon);
  8218. packet->setDataByName("item_id", item->details.item_id);
  8219. packet->setDataByName("item_crc", crc);
  8220. packet->setDataByName("unknown2", 0xFFFFFFFF);
  8221. packet->setDataByName("unknown4", 0xFFFFFFFF);
  8222. packet->setDataByName("unknown5", 0xFF, 9);
  8223. packet->setDataByName("unknown5", 0xFF, 10);
  8224. QueuePacket(packet->serialize());
  8225. safe_delete(packet);
  8226. }
  8227. void Client::SendCollectionList() {
  8228. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  8229. map<int32, Collection*>::iterator itr;
  8230. vector<struct CollectionItem*>* collection_items;
  8231. Collection* collection;
  8232. struct CollectionItem* collection_item;
  8233. PacketStruct* packet = 0;
  8234. int16 i = 0, j;
  8235. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  8236. return;
  8237. packet->setArrayLengthByName("num_collections", collections->size());
  8238. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8239. collection = itr->second;
  8240. collection_items = collection->GetCollectionItems();
  8241. packet->setArrayDataByName("unknown", 1, i);
  8242. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  8243. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  8244. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  8245. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8246. packet->setArrayDataByName("level", collection->GetLevel(), i);
  8247. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  8248. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  8249. for (j = 0; j < collection_items->size(); j++) {
  8250. collection_item = collection_items->at(j);
  8251. Item* item = master_item_list.GetItem(collection_item->item);
  8252. if (item) {
  8253. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  8254. if (version < 955)
  8255. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  8256. else
  8257. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  8258. }
  8259. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  8260. }
  8261. i++;
  8262. }
  8263. packet->setDataByName("new_collection_flag", 1);
  8264. QueuePacket(packet->serialize());
  8265. safe_delete(packet);
  8266. }
  8267. bool Client::SendCollectionsForItem(Item* item) {
  8268. map<int32, Collection*> collections_to_send;
  8269. map<int32, Collection*>* collections;
  8270. map<int32, Collection*>::iterator itr;
  8271. vector<struct CollectionItem*>* collection_items;
  8272. Collection* collection;
  8273. struct CollectionItem* collection_item;
  8274. PacketStruct* packet;
  8275. int16 i;
  8276. assert(item);
  8277. /* get any collections required by this item that the player already has */
  8278. collections = player->GetCollectionList()->GetCollections();
  8279. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8280. collection = itr->second;
  8281. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  8282. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  8283. collections_to_send[collection->GetID()] = collection;
  8284. }
  8285. }
  8286. /* get any collections required by this item that the player does not have and send it to the client */
  8287. collections = master_collection_list.GetCollections();
  8288. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8289. collection = itr->second;
  8290. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  8291. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  8292. return false;
  8293. }
  8294. packet->setArrayLengthByName("num_collections", 1);
  8295. packet->setArrayDataByName("unknown", 1, 0);
  8296. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  8297. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  8298. packet->setArrayDataByName("completed", 0, 0);
  8299. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  8300. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  8301. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  8302. packet->setArrayDataByName("unknown3", 0x28, 0);
  8303. collection_items = collection->GetCollectionItems();
  8304. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  8305. for (i = 0; i < collection_items->size(); i++) {
  8306. collection_item = collection_items->at(i);
  8307. Item* item2 = master_item_list.GetItem(collection_item->item);
  8308. if (item2) {
  8309. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  8310. if (version < 955)
  8311. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  8312. else
  8313. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  8314. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  8315. }
  8316. }
  8317. packet->setDataByName("new_collection_flag", 0);
  8318. QueuePacket(packet->serialize());
  8319. safe_delete(packet);
  8320. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  8321. collections_to_send[collection->GetID()] = collection;
  8322. }
  8323. }
  8324. /* send the client a list of collections that should be filtered for this item */
  8325. if (collections_to_send.size() > 0) {
  8326. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  8327. return false;
  8328. }
  8329. i = 0;
  8330. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  8331. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  8332. collection = itr->second;
  8333. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  8334. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  8335. i++;
  8336. }
  8337. packet->setDataByName("item_icon", item->details.icon);
  8338. packet->setDataByName("item_name", item->name.c_str());
  8339. packet->setDataByName("item_id", item->details.item_id);
  8340. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  8341. QueuePacket(packet->serialize());
  8342. safe_delete(packet);
  8343. }
  8344. return collections_to_send.size() > 0;
  8345. }
  8346. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  8347. Collection* collection;
  8348. struct CollectionItem* collection_item;
  8349. PacketStruct* packet;
  8350. char tmp[200] = { 0 };
  8351. assert(item);
  8352. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  8353. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  8354. /* get the item struct that represents the item for this collection */
  8355. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8356. SendCollectionList();
  8357. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8358. return;
  8359. }
  8360. /* sanity check */
  8361. if (collection_item->found) {
  8362. SendCollectionList();
  8363. 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());
  8364. return;
  8365. }
  8366. }
  8367. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  8368. collection = new Collection(collection);
  8369. /* get the item struct that represents the item for this collection */
  8370. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  8371. SendCollectionList();
  8372. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  8373. safe_delete(collection);
  8374. return;
  8375. }
  8376. /* add the new collection to the player's collection list */
  8377. if (!player->GetCollectionList()->AddCollection(collection)) {
  8378. SendCollectionList();
  8379. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  8380. safe_delete(collection);
  8381. return;
  8382. }
  8383. }
  8384. else {
  8385. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  8386. return;
  8387. }
  8388. collection_item->found = 1;
  8389. collection->SetSaveNeeded(true);
  8390. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  8391. SendCollectionList();
  8392. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  8393. return;
  8394. }
  8395. packet->setDataByName("collection_id", collection_id);
  8396. packet->setDataByName("collection_item_num", collection_item->index);
  8397. packet->setDataByName("add", 1);
  8398. QueuePacket(packet->serialize());
  8399. Item* item2 = master_item_list.GetItem(collection_item->item);
  8400. if (item2) {
  8401. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8402. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  8403. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  8404. }
  8405. safe_delete(packet);
  8406. RemoveItem(item, 1);
  8407. SendCollectionList();
  8408. }
  8409. void Client::DisplayCollectionComplete(Collection* collection) {
  8410. vector<struct CollectionRewardItem*>* reward_items;
  8411. vector<struct CollectionRewardItem*>* selectable_reward_items;
  8412. struct CollectionRewardItem* reward_item;
  8413. PacketStruct* packet;
  8414. int32 i;
  8415. assert(collection);
  8416. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  8417. return;
  8418. }
  8419. reward_items = collection->GetRewardItems();
  8420. selectable_reward_items = collection->GetSelectableRewardItems();
  8421. packet->setDataByName("title", "Quest Reward!");
  8422. packet->setDataByName("name", collection->GetName());
  8423. packet->setDataByName("description", collection->GetCategory());
  8424. packet->setDataByName("level", collection->GetLevel());
  8425. packet->setDataByName("max_coin", collection->GetRewardCoin());
  8426. packet->setDataByName("min_coin", collection->GetRewardCoin());
  8427. //packet->setDataByName("status_points", quest->GetStatusPoints());
  8428. packet->setArrayLengthByName("num_rewards", reward_items->size());
  8429. for (i = 0; i < reward_items->size(); i++) {
  8430. reward_item = reward_items->at(i);
  8431. if(!reward_item->item)
  8432. {
  8433. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8434. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8435. continue;
  8436. }
  8437. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  8438. if (version < 860)
  8439. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  8440. else if (version < 1193)
  8441. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  8442. else
  8443. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  8444. }
  8445. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  8446. for (i = 0; i < selectable_reward_items->size(); i++) {
  8447. reward_item = selectable_reward_items->at(i);
  8448. if(!reward_item->item)
  8449. {
  8450. LogWrite(DATABASE__ERROR, 0, "Database", "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8451. Message(CHANNEL_COLOR_RED, "DisplayCollectionComplete Collection %s (%u) num_select_rewards has missing item in slot %u", collection->GetName(), collection->GetID(), i);
  8452. continue;
  8453. }
  8454. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  8455. if (version < 860)
  8456. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  8457. else if (version < 1193)
  8458. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  8459. else
  8460. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  8461. }
  8462. QueuePacket(packet->serialize());
  8463. safe_delete(packet);
  8464. }
  8465. void Client::HandInCollections() {
  8466. map<int32, Collection*>* collections;
  8467. map<int32, Collection*>::iterator itr;
  8468. Collection* collection;
  8469. /* only show 1 collection reward dialog at a time */
  8470. if (player->GetPendingCollectionReward()) {
  8471. return;
  8472. }
  8473. collections = player->GetCollectionList()->GetCollections();
  8474. /* 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
  8475. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  8476. for (itr = collections->begin(); itr != collections->end(); itr++) {
  8477. collection = itr->second;
  8478. if (collection->GetIsReadyToTurnIn()) {
  8479. player->SetPendingCollectionReward(collection);
  8480. DisplayCollectionComplete(collection);
  8481. return;
  8482. }
  8483. }
  8484. }
  8485. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  8486. vector<struct CollectionRewardItem*>* reward_items;
  8487. vector<struct CollectionRewardItem*>::iterator itr;
  8488. struct CollectionRewardItem* reward_item;
  8489. int16 num_slots_needed;
  8490. int16 num_slots;
  8491. assert(collection);
  8492. reward_items = collection->GetRewardItems();
  8493. num_slots_needed = (int16)reward_items->size();
  8494. if (selectable_item_id > 0)
  8495. num_slots_needed++;
  8496. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  8497. if (num_slots < num_slots_needed) {
  8498. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  8499. HandInCollections();
  8500. return;
  8501. }
  8502. /* add manditory items */
  8503. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8504. reward_item = *itr;
  8505. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8506. }
  8507. /* find and add the selectable item if there's one */
  8508. if (selectable_item_id > 0) {
  8509. reward_items = collection->GetSelectableRewardItems();
  8510. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  8511. reward_item = *itr;
  8512. if (reward_item->item->details.item_id == selectable_item_id) {
  8513. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  8514. break;
  8515. }
  8516. }
  8517. }
  8518. if (collection->GetRewardXP() > 0) {
  8519. player->AddXP((int32)collection->GetRewardXP());
  8520. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  8521. }
  8522. if (collection->GetRewardCoin() > 0) {
  8523. player->AddCoins(collection->GetRewardCoin());
  8524. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  8525. }
  8526. collection->SetCompleted(true);
  8527. //update achievements for completeing collection here
  8528. collection->SetSaveNeeded(true);
  8529. SendCollectionList();
  8530. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  8531. player->SetPendingCollectionReward(0);
  8532. HandInCollections();
  8533. }
  8534. void Client::SendRecipeList() {
  8535. PacketStruct* packet = 0;
  8536. if (GetRecipeListSent()) {
  8537. return;
  8538. }
  8539. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  8540. return;
  8541. }
  8542. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  8543. map<int32, Recipe*>::iterator itr;
  8544. Recipe* recipe;
  8545. int16 i = 0;
  8546. packet->setArrayLengthByName("num_recipes", recipes->size());
  8547. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  8548. recipe = itr->second;
  8549. packet->setArrayDataByName("id", recipe->GetID(), i);
  8550. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  8551. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  8552. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  8553. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  8554. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  8555. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  8556. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  8557. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  8558. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  8559. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  8560. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  8561. i++;
  8562. }
  8563. //packet->PrintPacket();
  8564. //DumpPacket(packet->serialize());
  8565. QueuePacket(packet->serialize());
  8566. safe_delete(packet);
  8567. SetRecipeListSent(true);
  8568. }
  8569. void Client::ShowRecipeBook() {
  8570. PacketStruct* packet = 0;
  8571. Spawn* target = 0;
  8572. if (!(target = player->GetTarget())) {
  8573. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  8574. return;
  8575. }
  8576. if (!target->IsObject()) {
  8577. return;
  8578. }
  8579. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  8580. return;
  8581. }
  8582. packet->setDataByName("device", target->GetName());
  8583. packet->setDataByName("unknown1", 1);
  8584. if (((Object*)target)->GetDeviceID() > 0) {
  8585. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  8586. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  8587. packet->setDataByName("unknown2", 8);
  8588. packet->setDataByName("unknown3", deviceID);
  8589. }
  8590. //packet->PrintPacket();
  8591. QueuePacket(packet->serialize());
  8592. safe_delete(packet);
  8593. }
  8594. void Client::SendTitleUpdate() {
  8595. // must call release read lock before leaving function on GetPlayerTitles
  8596. vector<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  8597. vector<Title*>::iterator itr;
  8598. Title* title;
  8599. sint32 i = 0;
  8600. sint32 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  8601. sint32 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  8602. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  8603. if (packet) {
  8604. packet->setArrayLengthByName("num_titles", titles->size());
  8605. for (itr = titles->begin(); itr != titles->end(); itr++) {
  8606. title = *itr;
  8607. packet->setArrayDataByName("title", title->GetName(), i);
  8608. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  8609. i++;
  8610. }
  8611. packet->setDataByName("current_prefix", prefix_index);
  8612. packet->setDataByName("current_suffix", suffix_index);
  8613. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8614. #if EQDEBUG >= 9
  8615. packet->PrintPacket();
  8616. #endif
  8617. QueuePacket(packet->serialize());
  8618. safe_delete(packet);
  8619. SendUpdateTitles(prefix_index, suffix_index);
  8620. }
  8621. player->GetPlayerTitles()->ReleaseReadLock();
  8622. }
  8623. void Client::SendUpdateTitles(sint32 prefix, sint32 suffix) {
  8624. Title* suffix_title = 0;
  8625. Title* prefix_title = 0;
  8626. if (suffix != -1) {
  8627. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  8628. if(suffix_title)
  8629. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  8630. }
  8631. else
  8632. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  8633. if (prefix != -1) {
  8634. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  8635. if(prefix_title)
  8636. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  8637. }
  8638. else
  8639. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  8640. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  8641. }
  8642. void Client::SendLanguagesUpdate(int32 id) {
  8643. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  8644. list<Language*>::iterator itr;
  8645. Language* language;
  8646. int32 i = 0;
  8647. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  8648. if (packet) {
  8649. packet->setArrayLengthByName("num_languages", languages->size());
  8650. for (itr = languages->begin(); itr != languages->end(); itr++) {
  8651. language = *itr;
  8652. packet->setArrayDataByName("language_id", language->GetID(), i);
  8653. i++;
  8654. }
  8655. packet->setDataByName("current_language", id);
  8656. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  8657. #if EQDEBUG >= 9
  8658. packet->PrintPacket();
  8659. #endif
  8660. QueuePacket(packet->serialize());
  8661. safe_delete(packet);
  8662. }
  8663. }
  8664. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  8665. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  8666. if (packet) {
  8667. if (pet_name)
  8668. packet->setDataByName("pet_name", pet_name);
  8669. if (player->GetInfoStruct()->get_pet_behavior() & 1)
  8670. packet->setDataByName("protect_master", 1);
  8671. if (player->GetInfoStruct()->get_pet_behavior() & 2)
  8672. packet->setDataByName("protect_self", 1);
  8673. if (player->GetInfoStruct()->get_pet_movement() == 2)
  8674. packet->setDataByName("stay_follow_toggle", 1);
  8675. packet->setDataByName("pet_type", type);
  8676. QueuePacket(packet->serialize());
  8677. }
  8678. safe_delete(packet);
  8679. }
  8680. bool Client::IsCrafting() {
  8681. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  8682. }
  8683. void Client::SendBiography() {
  8684. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  8685. if (packet) {
  8686. char biography[512];
  8687. if(player->GetInfoStruct()->get_biography().size() < 1)
  8688. {
  8689. safe_delete(packet);
  8690. return;
  8691. }
  8692. else
  8693. {
  8694. int16 size = player->GetInfoStruct()->get_biography().size();
  8695. if(size>511)
  8696. size = 511;
  8697. strncpy(biography, player->GetInfoStruct()->get_biography().c_str(), player->GetInfoStruct()->get_biography().size());
  8698. biography[player->GetInfoStruct()->get_biography().size()] = '\0';
  8699. }
  8700. packet->setDataByName("biography", biography);
  8701. QueuePacket(packet->serialize());
  8702. }
  8703. safe_delete(packet);
  8704. }
  8705. PendingResurrection* Client::GetCurrentRez() {
  8706. return &current_rez;
  8707. }
  8708. Mutex* Client::GetResurrectMutex() {
  8709. return &m_resurrect;
  8710. }
  8711. void Client::SendResurrectionWindow() {
  8712. Spawn* caster = current_rez.caster;
  8713. if (!caster || !player)
  8714. return;
  8715. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8716. if (!packet)
  8717. return;
  8718. char* tmp = new char[512];
  8719. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  8720. packet->setMediumStringByName("text", tmp);
  8721. packet->setMediumStringByName("accept_text", "Yes");
  8722. packet->setMediumStringByName("cancel_text", "No");
  8723. sprintf(tmp, "accept_resurrection %u", player->GetID());
  8724. packet->setMediumStringByName("accept_command", tmp);
  8725. sprintf(tmp, "decline_resurrection %u", player->GetID());
  8726. packet->setMediumStringByName("cancel_command", tmp);
  8727. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  8728. QueuePacket(packet->serialize());
  8729. safe_delete(packet);
  8730. safe_delete_array(tmp);
  8731. }
  8732. void Client::AcceptResurrection() {
  8733. Spawn* caster = current_rez.caster;
  8734. if (!player || !caster)
  8735. return;
  8736. if (player->Alive())
  8737. return;
  8738. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  8739. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  8740. SendResurrectionWindow();
  8741. return;
  8742. }
  8743. player->GetZone()->ResurrectSpawn(player, this);
  8744. current_rez.should_delete = true;
  8745. }
  8746. void Client::SetPendingLastName(string last_name) {
  8747. pending_last_name = new string;
  8748. pending_last_name->assign(last_name);
  8749. }
  8750. string* Client::GetPendingLastName() {
  8751. return pending_last_name;
  8752. }
  8753. void Client::RemovePendingLastName() {
  8754. safe_delete(pending_last_name);
  8755. }
  8756. void Client::SendLastNameConfirmation() {
  8757. if (!pending_last_name)
  8758. return;
  8759. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8760. if (packet) {
  8761. char* text = new char[128];
  8762. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  8763. packet->setDataByName("text", text);
  8764. packet->setDataByName("accept_text", "Yes");
  8765. packet->setDataByName("accept_command", "confirmedlastname");
  8766. packet->setDataByName("cancel_text", "No");
  8767. packet->setDataByName("max_length", 50);
  8768. packet->setDataByName("unknown4", 1);
  8769. packet->setDataByName("unknown5", 1);
  8770. QueuePacket(packet->serialize());
  8771. safe_delete(packet);
  8772. safe_delete_array(text);
  8773. }
  8774. }
  8775. void Client::AddQuestTimer(int32 quest_id) {
  8776. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8777. quest_timers.push_back(quest_id);
  8778. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8779. }
  8780. void Client::RemoveQuestTimer(int32 quest_id) {
  8781. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8782. vector<int32>::iterator itr;
  8783. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  8784. if ((*itr) == quest_id) {
  8785. quest_timers.erase(itr);
  8786. break;
  8787. }
  8788. }
  8789. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8790. }
  8791. void Client::SavePlayerImages() {
  8792. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  8793. // Save the paperdoll image if the server allows it
  8794. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  8795. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8796. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  8797. // Save the head shot if the server allows it
  8798. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  8799. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8800. // Send the head shot to the login server
  8801. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  8802. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  8803. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  8804. memset(packet->pBuffer, 0, size);
  8805. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  8806. pic->account_id = GetAccountID();
  8807. pic->char_id = GetCharacterID();
  8808. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  8809. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8810. loginserver.SendPacket(packet);
  8811. safe_delete(packet);
  8812. }
  8813. }
  8814. safe_delete_array(incoming_paperdoll.image_bytes);
  8815. incoming_paperdoll.current_size_bytes = 0;
  8816. }
  8817. void Client::EndAutoMount() {
  8818. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8819. if (packet) {
  8820. packet->setDataByName("parameter1", 128);
  8821. packet->setDataByName("parameter2", 64);
  8822. packet->setDataByName("value", 1);
  8823. QueuePacket(packet->serialize());
  8824. safe_delete(packet);
  8825. }
  8826. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8827. if (packet) {
  8828. packet->setDataByName("parameter3", 4);
  8829. packet->setDataByName("parameter5", 2);
  8830. packet->setDataByName("value", 0);
  8831. QueuePacket(packet->serialize());
  8832. safe_delete(packet);
  8833. }
  8834. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  8835. if (packet) {
  8836. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  8837. QueuePacket(packet->serialize());
  8838. safe_delete(packet);
  8839. }
  8840. on_auto_mount = false;
  8841. player->SetMount(((Player*)player)->GetTempMount());
  8842. EQ2_Color mount_color = player->GetTempMountColor();
  8843. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  8844. player->SetMountColor(&mount_color);
  8845. player->SetMountSaddleColor(&saddle_color);
  8846. player->SetTempMount(0);
  8847. }
  8848. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  8849. const char* spawn_script = spawn->GetSpawnScript();
  8850. bool should_use_spawn = true;
  8851. if (spawn_script) {
  8852. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  8853. if (state) {
  8854. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  8855. if (state_mutex)
  8856. state_mutex->writelock(__FUNCTION__, __LINE__);
  8857. lua_getglobal(state, "can_use_command");
  8858. if (lua_isfunction(state, -1)) {
  8859. lua_interface->SetSpawnValue(state, spawn);
  8860. lua_interface->SetSpawnValue(state, GetPlayer());
  8861. lua_interface->SetStringValue(state, command ? command : "");
  8862. if (lua_pcall(state, 3, 1, 0) == 0) {
  8863. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  8864. }
  8865. }
  8866. lua_interface->ResetFunctionStack(state);
  8867. if (state_mutex)
  8868. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  8869. }
  8870. }
  8871. return should_use_spawn;
  8872. }
  8873. bool Client::IsCurrentTransmuteID(int32 req_id) {
  8874. return req_id == transmuteID;
  8875. }
  8876. void Client::SetTransmuteID(int32 trans_id) {
  8877. transmuteID = trans_id;
  8878. }
  8879. int32 Client::GetTransmuteID() {
  8880. return transmuteID;
  8881. }
  8882. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  8883. {
  8884. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  8885. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  8886. if (zar)
  8887. {
  8888. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  8889. if (database.IsActiveQuery(charID))
  8890. {
  8891. delayedLogin = true;
  8892. delayedAccountID = account_id;
  8893. delayedAccessKey = access_code;
  8894. delayTimer.Start(500);
  8895. 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);
  8896. return true;
  8897. }
  8898. delayedLogin = false;
  8899. delayTimer.Disable();
  8900. firstlogin = zar->isFirstLogin();
  8901. 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);
  8902. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  8903. GetPlayer()->CalculateOfflineDebtRecovery(GetLastSavedTimeStamp());
  8904. GetPlayer()->vis_changed = false;
  8905. GetPlayer()->info_changed = false;
  8906. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8907. if (pvp_allowed)
  8908. this->GetPlayer()->SetAttackable(1);
  8909. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  8910. Client* client = zone_list.GetClientByCharName(player->GetName());
  8911. if (client) {
  8912. if (client->getConnection())
  8913. client->getConnection()->SendDisconnect(true);
  8914. if (client->GetCurrentZone() && !client->IsZoning()) {
  8915. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  8916. if (client->GetVersion() == version) {
  8917. client->DisableSave();
  8918. client->ReplaceGroupClient(this);
  8919. Player* current_player = GetPlayer();
  8920. SetPlayer(client->GetPlayer());
  8921. GetPlayer()->SetClient(this);
  8922. GetPlayer()->SetReturningFromLD(true);
  8923. SetCurrentZone(GetPlayer()->GetZone());
  8924. GetPlayer()->GetZone()->UpdateClientSpawnMap(GetPlayer(), this);
  8925. client->SetPlayer(current_player);
  8926. GetPlayer()->GetZone()->UpdateClientSpawnMap(current_player, client);
  8927. GetPlayer()->ResetSavedSpawns();
  8928. }
  8929. ZoneServer* tmpZone = client->GetCurrentZone();
  8930. tmpZone->RemoveClientImmediately(client);
  8931. }
  8932. }
  8933. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  8934. if (!GetCurrentZone()) {
  8935. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  8936. ClientPacketFunctions::SendLoginDenied(this);
  8937. }
  8938. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  8939. getConnection()->SetClientVersion(version);
  8940. GetCurrentZone()->SetSpawnStructs(this);
  8941. connected_to_zone = true;
  8942. client_list.Remove(this); //remove from master client list
  8943. GetCurrentZone()->AddClient(this); //add to zones client list
  8944. zone_list.AddClientToMap(player->GetName(), this);
  8945. // 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.
  8946. new_client_login = true;
  8947. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  8948. if (zone_script && lua_interface)
  8949. lua_interface->RunZoneScript(zone_script, "new_client", GetCurrentZone(), GetPlayer());
  8950. }
  8951. else {
  8952. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  8953. ClientPacketFunctions::SendLoginDenied(this);
  8954. return false;
  8955. }
  8956. }
  8957. else {
  8958. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  8959. ClientPacketFunctions::SendLoginDenied(this);
  8960. }
  8961. zone_auth.RemoveAuth(zar);
  8962. }
  8963. else
  8964. {
  8965. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  8966. Disconnect();
  8967. }
  8968. return true;
  8969. }
  8970. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  8971. if (!IsReadyForUpdates())
  8972. return;
  8973. map<int32, SpawnData> info_changes;
  8974. map<int32, SpawnData> pos_changes;
  8975. map<int32, SpawnData> vis_changes;
  8976. map<int32, SpawnData> empty_changes;
  8977. int32 info_size = 0;
  8978. int32 pos_size = 0;
  8979. int32 vis_size = 0;
  8980. int count = 0;
  8981. for (const auto& spawn : spawns) {
  8982. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  8983. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()))
  8984. continue;
  8985. if (spawn->vis_changed)
  8986. {
  8987. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8988. if (vis_change) {
  8989. SpawnData data;
  8990. data.spawn = spawn;
  8991. data.data = vis_change;
  8992. data.size = spawn->vis_packet_size;
  8993. map<int32, SpawnData> tmp_vis_changes;
  8994. tmp_vis_changes[index] = data;
  8995. map<int32, SpawnData> tmp_info_changes;
  8996. map<int32, SpawnData> tmp_pos_changes;
  8997. int32 tmp_info_size = 0;
  8998. int32 tmp_pos_size = 0;
  8999. if (spawn->info_changed) {
  9000. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9001. if (info_change) {
  9002. SpawnData data;
  9003. data.spawn = spawn;
  9004. data.data = info_change;
  9005. data.size = spawn->info_packet_size;
  9006. tmp_info_size = data.size;
  9007. tmp_info_changes[index] = data;
  9008. }
  9009. }
  9010. if (spawn->position_changed) {
  9011. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9012. if (pos_change) {
  9013. SpawnData data;
  9014. data.spawn = spawn;
  9015. data.data = pos_change;
  9016. data.size = spawn->pos_packet_size;
  9017. tmp_pos_size = data.size;
  9018. tmp_pos_changes[index] = data;
  9019. }
  9020. }
  9021. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  9022. for (auto& kv : tmp_info_changes) {
  9023. safe_delete_array(kv.second.data);
  9024. }
  9025. for (auto& kv : tmp_pos_changes) {
  9026. safe_delete_array(kv.second.data);
  9027. }
  9028. for (auto& kv : tmp_vis_changes) {
  9029. safe_delete_array(kv.second.data);
  9030. }
  9031. continue;
  9032. }
  9033. }
  9034. if (spawn->info_changed) {
  9035. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  9036. if (info_change) {
  9037. SpawnData data;
  9038. data.spawn = spawn;
  9039. data.data = info_change;
  9040. data.size = spawn->info_packet_size;
  9041. info_size += spawn->info_packet_size;
  9042. info_changes[index] = data;
  9043. }
  9044. count++;
  9045. }
  9046. if (spawn->position_changed) {
  9047. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  9048. if (pos_change) {
  9049. SpawnData data;
  9050. data.spawn = spawn;
  9051. data.data = pos_change;
  9052. data.size = spawn->pos_packet_size;
  9053. pos_size += spawn->pos_packet_size;
  9054. pos_changes[index] = data;
  9055. }
  9056. count++;
  9057. }
  9058. if (spawn->vis_changed) {
  9059. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  9060. if (vis_change) {
  9061. SpawnData data;
  9062. data.spawn = spawn;
  9063. data.data = vis_change;
  9064. data.size = spawn->vis_packet_size;
  9065. vis_size += spawn->vis_packet_size;
  9066. vis_changes[index] = data;
  9067. }
  9068. count++;
  9069. }
  9070. }
  9071. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  9072. return;
  9073. }
  9074. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  9075. for (auto& kv : info_changes) {
  9076. safe_delete_array(kv.second.data);
  9077. }
  9078. for (auto& kv : pos_changes) {
  9079. safe_delete_array(kv.second.data);
  9080. }
  9081. for (auto& kv : vis_changes) {
  9082. safe_delete_array(kv.second.data);
  9083. }
  9084. }
  9085. 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)
  9086. {
  9087. static const int8 oversized = 255;
  9088. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  9089. int32 size = info_size + pos_size + vis_size + 8;
  9090. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  9091. size += 3;
  9092. size += CheckOverLoadSize(info_size);
  9093. size += CheckOverLoadSize(pos_size);
  9094. size += CheckOverLoadSize(vis_size);
  9095. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  9096. size += 2;
  9097. }
  9098. uchar* tmp = new uchar[size];
  9099. uchar* ptr = tmp;
  9100. memset(tmp, 0, size);
  9101. if (version <= 283) {
  9102. if (size >= 255) {
  9103. size -= 3;
  9104. memcpy(ptr, &oversized, sizeof(int8));
  9105. ptr += sizeof(int8);
  9106. memcpy(ptr, &size, sizeof(int16));
  9107. ptr += sizeof(int16);
  9108. size += 3;
  9109. }
  9110. else {
  9111. size -= 1;
  9112. memcpy(ptr, &size, sizeof(int8));
  9113. ptr += sizeof(int8);
  9114. size += 1;
  9115. }
  9116. }
  9117. else {
  9118. size -= 4;
  9119. memcpy(ptr, &size, sizeof(int32));
  9120. ptr += sizeof(int32);
  9121. size += 4;
  9122. }
  9123. memcpy(ptr, &oversized, sizeof(int8));
  9124. ptr += sizeof(int8);
  9125. memcpy(ptr, &opcode_val, sizeof(int16));
  9126. ptr += sizeof(int16);
  9127. int32 current_time = Timer::GetCurrentTime2();
  9128. memcpy(ptr, &current_time, sizeof(int32));
  9129. ptr += sizeof(int32);
  9130. ptr += DoOverLoad(info_size, ptr);
  9131. for (const auto& kv : info_changes) {
  9132. auto info = kv.second;
  9133. memcpy(ptr, info.data, info.size);
  9134. ptr += info.size;
  9135. }
  9136. ptr += DoOverLoad(pos_size, ptr);
  9137. for (const auto& kv : pos_changes) {
  9138. auto pos = kv.second;
  9139. memcpy(ptr, pos.data, pos.size);
  9140. ptr += pos.size;
  9141. }
  9142. ptr += DoOverLoad(vis_size, ptr);
  9143. for (const auto& kv : vis_changes) {
  9144. auto vis = kv.second;
  9145. memcpy(ptr, vis.data, vis.size);
  9146. ptr += vis.size;
  9147. }
  9148. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  9149. if (packet) {
  9150. /*char blah[64];
  9151. snprintf(blah, 64, "Sending %i", current_time);
  9152. SimpleMessage(4, blah);*/
  9153. QueuePacket(packet);
  9154. }
  9155. delete[] tmp;
  9156. }
  9157. void Client::SendHailCommand(Spawn* spawn)
  9158. {
  9159. // hardcoded 'hail' entity commands
  9160. switch (spawn->secondary_command_list_id)
  9161. {
  9162. case 9:
  9163. case 1262:
  9164. case 1265:
  9165. case 1267:
  9166. {
  9167. EQ2_16BitString* command = new EQ2_16BitString();
  9168. command->data = "";
  9169. command->size = 0;
  9170. commands.Process(COMMAND_HAIL, command, this, spawn);
  9171. safe_delete(command);
  9172. break;
  9173. }
  9174. }
  9175. }
  9176. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  9177. {
  9178. if (GetPlayer()->WasSentSpawn(spawn->GetID())) {
  9179. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  9180. if (packet) {
  9181. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9182. packet->setMediumStringByName("command_name", command);
  9183. packet->setDataByName("distance", distance);
  9184. QueuePacket(packet->serialize());
  9185. safe_delete(packet);
  9186. }
  9187. }
  9188. }
  9189. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  9190. {
  9191. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  9192. return false;
  9193. if (command == "house_spawn_examine")
  9194. {
  9195. uint32 itemID = spawn->GetPickupItemID();
  9196. if (itemID)
  9197. {
  9198. Item* item = master_item_list.GetItem(itemID);
  9199. if (item)
  9200. {
  9201. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  9202. //DumpPacket(app);
  9203. QueuePacket(app);
  9204. }
  9205. }
  9206. return true;
  9207. }
  9208. return false;
  9209. }
  9210. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  9211. {
  9212. if (GetTempPlacementSpawn())
  9213. {
  9214. Spawn* tmp = GetTempPlacementSpawn();
  9215. int32 spawn_group_id = database.GetNextSpawnLocation();
  9216. tmp->SetSpawnLocationID(spawn_group_id);
  9217. float newHeading = place_object->getType_float_ByName("heading") + 180;
  9218. int32 spawnDBID = 0;
  9219. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  9220. {
  9221. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  9222. tmp->SetDatabaseID(spawnDBID);
  9223. }
  9224. else
  9225. {
  9226. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  9227. if (spawnDBID)
  9228. {
  9229. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  9230. tmp->SetDatabaseID(spawnDBID);
  9231. }
  9232. }
  9233. tmp->SetX(place_object->getType_float_ByName("x"));
  9234. tmp->SetY(place_object->getType_float_ByName("y"));
  9235. tmp->SetZ(place_object->getType_float_ByName("z"));
  9236. tmp->SetHeading(newHeading);
  9237. tmp->SetSpawnOrigX(tmp->GetX());
  9238. tmp->SetSpawnOrigY(tmp->GetY());
  9239. tmp->SetSpawnOrigZ(tmp->GetZ());
  9240. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  9241. database.SaveSpawnInfo(tmp);
  9242. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  9243. if (!spawnDBID)
  9244. {
  9245. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  9246. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  9247. }
  9248. return true;
  9249. }
  9250. return false;
  9251. }
  9252. bool Client::PopulateHouseSpawnFinalize()
  9253. {
  9254. if (GetTempPlacementSpawn())
  9255. {
  9256. Spawn* tmp = GetTempPlacementSpawn();
  9257. GetCurrentZone()->AddSpawn(tmp);
  9258. GetCurrentZone()->SendSpawnChanges(tmp, this);
  9259. SetTempPlacementSpawn(nullptr);
  9260. int32 uniqueID = GetPlacementUniqueItemID();
  9261. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  9262. tmp->SetPickupItemID(uniqueItem->details.item_id);
  9263. tmp->SetPickupUniqueItemID(uniqueID);
  9264. if (uniqueItem)
  9265. {
  9266. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  9267. {
  9268. Query query;
  9269. 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);
  9270. }
  9271. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  9272. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  9273. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  9274. SetPlacementUniqueItemID(0);
  9275. }
  9276. return true;
  9277. }
  9278. return false;
  9279. }
  9280. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  9281. {
  9282. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  9283. packet->setDataByName("placement_mode", placementMode);
  9284. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  9285. packet->setDataByName("model_type", spawn->GetModelType());
  9286. packet->setDataByName("unknown", 1); //size
  9287. packet->setDataByName("unknown2", 1); //size 2
  9288. packet->setDataByName("unknown2", .5, 1); //size 3
  9289. packet->setDataByName("unknown2", 3, 2);
  9290. packet->setDataByName("unknown2", unknown2_3, 3);
  9291. packet->setDataByName("max_distance", 500);
  9292. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  9293. QueuePacket(packet->serialize());
  9294. safe_delete(packet);
  9295. }
  9296. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  9297. {
  9298. SetPendingFlightPath(path_id);
  9299. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  9300. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  9301. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  9302. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  9303. if (packet) {
  9304. QueuePacket(packet->serialize());
  9305. safe_delete(packet);
  9306. }
  9307. if (mount_id)
  9308. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  9309. }
  9310. void Client::SendShowBook(Spawn* sender, string title, int8 num_pages, ...)
  9311. {
  9312. if (!sender)
  9313. {
  9314. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9315. return;
  9316. }
  9317. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9318. if (!packet) {
  9319. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9320. return;
  9321. }
  9322. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9323. packet->setDataByName("book_title", title.c_str());
  9324. packet->setDataByName("book_type", "simple");
  9325. packet->setDataByName("unknown2", 1);
  9326. if (GetVersion() > 546)
  9327. packet->setDataByName("unknown5", 1, 4);
  9328. packet->setArrayLengthByName("num_pages", num_pages);
  9329. va_list args;
  9330. va_start(args, num_pages);
  9331. std::string endString("");
  9332. for (int8 p = 0; p < num_pages; p++)
  9333. {
  9334. std::string page = va_arg(args, string);
  9335. switch (GetVersion())
  9336. {
  9337. // release client
  9338. case 283:
  9339. {
  9340. endString.append(page);
  9341. break;
  9342. }
  9343. // DoF trial
  9344. case 546:
  9345. {
  9346. if (p == 0)
  9347. packet->setDataByName("cover_page", page.c_str());
  9348. else
  9349. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  9350. break;
  9351. }
  9352. // all other clients
  9353. default:
  9354. {
  9355. packet->setArrayDataByName("page_text", page.c_str(), p);
  9356. break;
  9357. }
  9358. }
  9359. }
  9360. if (GetVersion() == 283)
  9361. {
  9362. packet->setDataByName("page_text", endString.c_str());
  9363. }
  9364. va_end(args);
  9365. QueuePacket(packet->serialize());
  9366. safe_delete(packet);
  9367. }
  9368. void Client::SendShowBook(Spawn* sender, string title, vector<Item::BookPage*> pages)
  9369. {
  9370. if (!sender)
  9371. {
  9372. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  9373. return;
  9374. }
  9375. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  9376. if (!packet) {
  9377. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  9378. return;
  9379. }
  9380. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  9381. packet->setDataByName("book_title", title.c_str());
  9382. packet->setDataByName("book_type", "simple");
  9383. packet->setDataByName("unknown2", 1);
  9384. if (GetVersion() > 546)
  9385. packet->setDataByName("unknown5", 1, 4);
  9386. packet->setArrayLengthByName("num_pages", pages.size());
  9387. std::string endString("");
  9388. for (int8 p = 0; p < pages.size(); p++)
  9389. {
  9390. Item::BookPage* page = pages[p];
  9391. std::string pageText = string(page->page_text.data);
  9392. switch (GetVersion())
  9393. {
  9394. // release client
  9395. case 283:
  9396. {
  9397. endString.append(pageText);
  9398. break;
  9399. }
  9400. // DoF trial
  9401. case 546:
  9402. {
  9403. if (p == 0)
  9404. packet->setDataByName("cover_page", pageText.c_str());
  9405. else
  9406. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  9407. break;
  9408. }
  9409. // all other clients
  9410. default:
  9411. {
  9412. int8 valign = int8(page->valign);
  9413. int8 halign = int8(page->halign);
  9414. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  9415. packet->setArrayDataByName("page_text_valign", valign, p);
  9416. packet->setArrayDataByName("page_text_halign", halign, p);
  9417. break;
  9418. }
  9419. }
  9420. }
  9421. if (GetVersion() == 283)
  9422. {
  9423. packet->setDataByName("page_text", endString.c_str());
  9424. }
  9425. QueuePacket(packet->serialize());
  9426. safe_delete(packet);
  9427. }
  9428. void Client::ReplaceGroupClient(Client* new_client)
  9429. {
  9430. if (this->GetPlayer()->GetGroupMemberInfo())
  9431. {
  9432. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9433. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9434. if(group)
  9435. {
  9436. group->MGroupMembers.writelock();
  9437. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9438. this->GetPlayer()->GetGroupMemberInfo()->client = new_client;
  9439. this->GetPlayer()->GetGroupMemberInfo()->member = GetPlayer();
  9440. group->MGroupMembers.releasewritelock();
  9441. }
  9442. else
  9443. {
  9444. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9445. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9446. this->GetPlayer()->SetGroupMemberInfo(0);
  9447. }
  9448. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9449. }
  9450. }
  9451. void Client::TempRemoveGroup()
  9452. {
  9453. if (this->GetPlayer()->GetGroupMemberInfo())
  9454. {
  9455. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  9456. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  9457. if(group)
  9458. {
  9459. group->MGroupMembers.writelock();
  9460. rejoin_group_id = this->GetPlayer()->GetGroupMemberInfo()->group_id;
  9461. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9462. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9463. this->GetPlayer()->SetGroupMemberInfo(0);
  9464. group->MGroupMembers.releasewritelock();
  9465. group->RemoveClientReference(this);
  9466. }
  9467. else
  9468. {
  9469. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  9470. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  9471. this->GetPlayer()->SetGroupMemberInfo(0);
  9472. }
  9473. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  9474. }
  9475. }
  9476. void Client::CreateMail(int32 charID, std::string fromName, std::string subjectName, std::string mailBody,
  9477. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9478. {
  9479. Mail mail;
  9480. memset(&mail,0,sizeof(Mail));
  9481. mail.player_to_id = charID;
  9482. mail.player_from = fromName;
  9483. mail.subject = subjectName;
  9484. mail.mail_body = mailBody;
  9485. mail.mail_type = mailType;
  9486. mail.coin_copper = copper;
  9487. mail.coin_silver = silver;
  9488. mail.coin_gold = gold;
  9489. mail.coin_plat = platinum;
  9490. mail.char_item_id = item_id;
  9491. mail.stack = stack_size;
  9492. mail.time_sent = time_sent;
  9493. mail.expire_time = expire_time;
  9494. database.SavePlayerMail(&mail);
  9495. }
  9496. void Client::CreateAndUpdateMail(std::string fromName, std::string subjectName, std::string mailBody,
  9497. int8 mailType, int32 copper, int32 silver, int32 gold, int32 platinum, int32 item_id, int16 stack_size, int32 time_sent, int32 expire_time)
  9498. {
  9499. Mail* mail = new Mail();
  9500. mail->player_to_id = GetCharacterID();
  9501. mail->player_from = fromName;
  9502. mail->subject = subjectName;
  9503. mail->mail_body = mailBody;
  9504. mail->mail_type = mailType;
  9505. mail->coin_copper = copper;
  9506. mail->coin_silver = silver;
  9507. mail->coin_gold = gold;
  9508. mail->coin_plat = platinum;
  9509. mail->char_item_id = item_id;
  9510. mail->stack = stack_size;
  9511. mail->time_sent = time_sent;
  9512. mail->expire_time = expire_time;
  9513. mail->postage_cost = 0;
  9514. mail->save_needed = 1;
  9515. mail->already_read = 0;
  9516. database.SavePlayerMail(mail);
  9517. GetPlayer()->AddMail(mail);
  9518. }
  9519. void Client::SendEquipOrInvUpdateBySlot(int8 slot)
  9520. {
  9521. if(slot < NUM_SLOTS)
  9522. {
  9523. EQ2Packet* app = GetPlayer()->GetEquipmentList()->serialize(GetVersion(), GetPlayer());
  9524. if (app)
  9525. QueuePacket(app);
  9526. }
  9527. else
  9528. {
  9529. EQ2Packet* outapp = GetPlayer()->SendInventoryUpdate(GetVersion());
  9530. if (outapp)
  9531. QueuePacket(outapp);
  9532. }
  9533. }
  9534. void Client::QueueStateCommand(int32 spawn_player_id, int32 state)
  9535. {
  9536. if(spawn_player_id < 1)
  9537. return;
  9538. MQueueStateCmds.writelock();
  9539. queued_state_commands.insert(make_pair(spawn_player_id, state));
  9540. MQueueStateCmds.releasewritelock();
  9541. }
  9542. void Client::ProcessStateCommands()
  9543. {
  9544. if(!IsReadyForUpdates())
  9545. return;
  9546. MQueueStateCmds.writelock();
  9547. map<int32, int32>::iterator itr = queued_state_commands.begin();
  9548. for(; itr != queued_state_commands.end(); itr++)
  9549. ClientPacketFunctions::SendStateCommand(this, itr->first, itr->second);
  9550. queued_state_commands.clear();
  9551. MQueueStateCmds.releasewritelock();
  9552. }
  9553. void Client::PurgeItem(Item* item)
  9554. {
  9555. MConversation.writelock();
  9556. map<int32, Item*>::iterator itr;
  9557. for(itr = conversation_items.begin(); itr != conversation_items.end(); itr++)
  9558. {
  9559. if ( itr->second == item )
  9560. {
  9561. conversation_items.erase(itr);
  9562. break;
  9563. }
  9564. }
  9565. MConversation.releasewritelock();
  9566. }
  9567. void Client::ConsumeFoodDrink(Item* item, int32 slot)
  9568. {
  9569. if(GetPlayer()->StopSaveSpellEffects())
  9570. return;
  9571. if(item) {
  9572. LogWrite(MISC__INFO, 1, "Command", "ItemID: %u, ItemName: %s ItemCount: %i ", item->details.item_id, item->name.c_str(), item->details.count);
  9573. if(item->GetItemScript() && lua_interface){
  9574. lua_interface->RunItemScript(item->GetItemScript(), "cast", item, GetPlayer());
  9575. if (slot == 22)
  9576. Message(CHANNEL_NARRATIVE, "You eat a %s.", item->name.c_str());
  9577. else
  9578. Message(CHANNEL_NARRATIVE, "You drink a %s.", item->name.c_str());
  9579. }
  9580. if (item->details.count > 1) {
  9581. item->details.count -= 1;
  9582. item->save_needed = true;
  9583. }
  9584. else {
  9585. database.DeleteItem(GetPlayer()->GetCharacterID(), item, "EQUIPPED");
  9586. GetPlayer()->GetEquipmentList()->RemoveItem(slot, true);
  9587. }
  9588. GetPlayer()->SetCharSheetChanged(true);
  9589. QueuePacket(player->GetEquipmentList()->serialize(GetVersion(), player));
  9590. }
  9591. }
  9592. void Client::AwardCoins(int64 total_coins, std::string reason)
  9593. {
  9594. if (total_coins > 0) {
  9595. player->AddCoins(total_coins);
  9596. PlaySound("coin_cha_ching");
  9597. char tmp[64] = { 0 };
  9598. string message = "You receive ";
  9599. int32 val = 0;
  9600. if (total_coins >= 1000000) {
  9601. val = total_coins / 1000000;
  9602. total_coins -= 1000000 * val;
  9603. sprintf(tmp, "%u Platinum ", val);
  9604. message.append(tmp);
  9605. memset(tmp, 0, 64);
  9606. }
  9607. if (total_coins >= 10000) {
  9608. val = total_coins / 10000;
  9609. total_coins -= 10000 * val;
  9610. sprintf(tmp, "%u Gold ", val);
  9611. message.append(tmp);
  9612. memset(tmp, 0, 64);
  9613. }
  9614. if (total_coins >= 100) {
  9615. val = total_coins / 100;
  9616. total_coins -= 100 * val;
  9617. sprintf(tmp, "%u Silver ", val);
  9618. message.append(tmp);
  9619. memset(tmp, 0, 64);
  9620. }
  9621. if (total_coins > 0) {
  9622. sprintf(tmp, "%u Copper ", (int32)total_coins);
  9623. message.append(tmp);
  9624. }
  9625. message.append(reason);
  9626. int8 type = CHANNEL_LOOT;
  9627. SimpleMessage(type, message.c_str());
  9628. }
  9629. }
  9630. void Client::TriggerSpellSave()
  9631. {
  9632. int32 interval = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateWaitInterval)->GetInt32();
  9633. // default to not have some bogus value in the rule
  9634. if(interval < 1)
  9635. interval = 100;
  9636. MSaveSpellStateMutex.lock();
  9637. if(!save_spell_state_timer.Enabled())
  9638. {
  9639. save_spell_state_time_bucket = 0;
  9640. save_spell_state_timer.Start(interval, true);
  9641. }
  9642. else
  9643. {
  9644. int32 elapsed_time = save_spell_state_timer.GetElapsedTime();
  9645. save_spell_state_time_bucket += elapsed_time;
  9646. int32 save_wait_cap = rule_manager.GetGlobalRule(R_Spells, PlayerSpellSaveStateCap)->GetInt32();
  9647. // default to not have some bogus value in the rule
  9648. if(save_wait_cap < interval)
  9649. save_wait_cap = interval+1;
  9650. if(save_spell_state_time_bucket >= save_wait_cap)
  9651. {
  9652. // save immediately and disable timer
  9653. GetPlayer()->SaveSpellEffects();
  9654. save_spell_state_timer.Disable();
  9655. }
  9656. }
  9657. MSaveSpellStateMutex.unlock();
  9658. }
  9659. void Client::UpdateSentSpellList() {
  9660. MSpellDetails.readlock(__FUNCTION__, __LINE__);
  9661. std::map<int32, int32>::iterator itr;
  9662. for(itr = sent_spell_details.begin(); itr != sent_spell_details.end(); itr++) {
  9663. Spell* spell = master_spell_list.GetSpell(itr->first, itr->second);
  9664. EQ2Packet* app = spell->SerializeSpell(this, false, false);
  9665. QueuePacket(app);
  9666. }
  9667. MSpellDetails.releasereadlock(__FUNCTION__, __LINE__);
  9668. }
  9669. void Client::SetTempPlacementSpawn(Spawn* tmp) {
  9670. tempPlacementSpawn = tmp;
  9671. hasSentTempPlacementSpawn = false;
  9672. if(tempPlacementSpawn)
  9673. temp_placement_timer.Start();
  9674. else
  9675. temp_placement_timer.Disable();
  9676. }
  9677. void Client::SetPlayer(Player* new_player) {
  9678. if (player && player != new_player)
  9679. zone_list.RemoveClientFromMap(player->GetName(), this);
  9680. player = new_player;
  9681. player->SetClient(this);
  9682. }