client.cpp 312 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857
  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 "Items/Items.h"
  71. #include "Skills.h"
  72. #include "LuaInterface.h"
  73. #include "Quests.h"
  74. #include "Collections/Collections.h"
  75. #include "Achievements/Achievements.h"
  76. #include "Traits/Traits.h"
  77. #include "Recipes/Recipe.h"
  78. #include "Tradeskills/Tradeskills.h"
  79. #include "AltAdvancement/AltAdvancement.h"
  80. #include "Bots/Bot.h"
  81. extern WorldDatabase database;
  82. extern const char* ZONE_NAME;
  83. extern LoginServer loginserver;
  84. extern sint32 numclients;
  85. extern NetConnection net;
  86. extern Commands commands;
  87. extern ClientList client_list;
  88. extern ZoneList zone_list;
  89. extern ZoneAuth zone_auth;
  90. extern MasterItemList master_item_list;
  91. extern MasterSkillList master_skill_list;
  92. extern MasterSpellList master_spell_list;
  93. extern MasterTraitList master_trait_list;
  94. extern MasterQuestList master_quest_list;
  95. extern MasterFactionList master_faction_list;
  96. extern MasterRecipeList master_recipe_list;
  97. extern volatile bool RunLoops;
  98. extern ConfigReader configReader;
  99. extern LuaInterface* lua_interface;
  100. extern World world;
  101. extern Variables variables;
  102. extern Classes classes;
  103. extern Races races;
  104. extern GuildList guild_list;
  105. extern MasterCollectionList master_collection_list;
  106. extern MasterAchievementList master_achievement_list;
  107. extern RuleManager rule_manager;
  108. extern IRC irc;
  109. extern Chat chat;
  110. extern MasterAAList master_aa_list;
  111. extern MasterAAList master_tree_nodes;
  112. extern ChestTrapList chest_trap_list;
  113. using namespace std;
  114. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  115. eqs = ieqs;
  116. ip = eqs->GetrIP();
  117. port = ntohs(eqs->GetrPort());
  118. merchant_transaction = nullptr;
  119. SetMailTransaction(nullptr);
  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. disconnect_timer = 0;
  139. client_zoning = false;
  140. player_pos_changed = false;
  141. ++numclients;
  142. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  143. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  144. remove_from_list = false;
  145. new_client_login = false;
  146. UpdateWindowTitle(0);
  147. num_active_failures = 0;
  148. player = new Player();
  149. combine_spawn = 0;
  150. lua_debug = false;
  151. ready_for_spawns = false;
  152. ready_for_updates = false;
  153. lua_debug_timer.Disable();
  154. transport_spawn = 0;
  155. MBuyBack.SetName("Client::MBuyBack");
  156. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  157. MDeletePlayer.SetName("Client::MDeletePlayer");
  158. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  159. search_items = 0;
  160. version = 0;
  161. next_conversation_id = 0;
  162. pending_guild_invite.guild = 0;
  163. pending_guild_invite.invited_by = 0;
  164. m_recipeListSent = false;
  165. m_resurrect.SetName("Client::m_resurrect");
  166. current_rez.expire_timer = 0;
  167. current_rez.should_delete = true;
  168. pending_last_name = 0;
  169. should_target = false;
  170. initial_spawns_sent = false;
  171. MQuestTimers.SetName("Client::quest_timers");
  172. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  173. on_auto_mount = false;
  174. should_load_spells = true;
  175. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  176. delayedLogin = false;
  177. delayedAccountID = 0;
  178. delayedAccessKey = 0;
  179. delayTimer.Disable();
  180. tempPlacementSpawn = nullptr;
  181. placement_unique_item_id = 0;
  182. SetHasOwnerOrEditAccess(false);
  183. temporary_transport_id = 0;
  184. }
  185. Client::~Client() {
  186. if (current_zone && player) {
  187. if (player->GetGroupMemberInfo() && (player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  188. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  189. world.GetGroupManager()->ClearPendingInvite(player);
  190. }
  191. if (lua_interface)
  192. lua_interface->RemoveDebugClients(this);
  193. if (player)
  194. zone_list.RemoveClientFromMap(player->GetName(), this);
  195. //let the stream factory know were done with this stream
  196. if (eqs) {
  197. eqs->Close();
  198. try {
  199. eqs->ReleaseFromUse();
  200. }
  201. catch (...) {}
  202. }
  203. eqs = NULL;
  204. //safe_delete(autobootup_timeout);
  205. safe_delete(disconnect_timer);
  206. safe_delete(camp_timer);
  207. safe_delete(CLE_keepalive_timer);
  208. safe_delete(connect);
  209. --numclients;
  210. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  211. if (player && !player->GetPendingDeletion())
  212. safe_delete(player);
  213. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  214. safe_delete(search_items);
  215. safe_delete(current_rez.expire_timer);
  216. safe_delete(pending_last_name);
  217. safe_delete_array(incoming_paperdoll.image_bytes);
  218. if (GetTempPlacementSpawn())
  219. {
  220. Spawn* tmp = GetTempPlacementSpawn();
  221. delete tmp;
  222. SetTempPlacementSpawn(nullptr);
  223. }
  224. UpdateWindowTitle(0);
  225. }
  226. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  227. if (eqs) {
  228. if (!eqs->CheckActive()) {
  229. client_list.Remove(this);
  230. eqs = 0;
  231. }
  232. }
  233. if (app && eqs && version > 0)
  234. eqs->EQ2QueuePacket(app, attemptedCombine);
  235. else {
  236. safe_delete(app);
  237. }
  238. }
  239. void Client::PopulateSkillMap() {
  240. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  241. if (app)
  242. QueuePacket(app);
  243. else {
  244. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  245. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  246. }
  247. }
  248. void Client::SendLoginInfo() {
  249. if (firstlogin) {
  250. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  251. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  252. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  253. PopulateSkillMap();
  254. // 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!
  255. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  256. }
  257. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  258. database.ToggleCharacterOnline(this, 1);
  259. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  260. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  261. if (count == 0) {
  262. LogWrite(CCLIENT__WARNING, 0, "Client", "No character skills found!");
  263. database.UpdateStartingSkills(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  264. database.LoadCharacterSkills(GetCharacterID(), player);
  265. }
  266. count = database.LoadCharacterTitles(GetCharacterID(), player);
  267. if (count == 0) {
  268. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  269. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  270. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  271. }
  272. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  273. if (count == 0)
  274. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  275. count = database.LoadCharacterSpells(GetCharacterID(), player);
  276. if (count == 0) {
  277. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character spells found!");
  278. database.UpdateStartingSpells(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  279. database.LoadCharacterSpells(GetCharacterID(), player);
  280. }
  281. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  282. if (count == 0)
  283. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  284. ClientPacketFunctions::SendLoginAccepted(this);
  285. //ClientPacketFunctions::SendAbilities ( this );
  286. ClientPacketFunctions::SendCommandNamePacket(this);
  287. ClientPacketFunctions::SendQuickBarInit(this);
  288. // we only need to send the MOTD if it is the first time the person is logging in.
  289. if (firstlogin) {
  290. ClientPacketFunctions::SendMOTD(this);
  291. ClientPacketFunctions::SendCharacterMacros(this);
  292. zone_list.CheckFriendList(this);
  293. }
  294. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  295. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  296. {
  297. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  298. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  299. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  300. }
  301. database.LoadPlayerFactions(this);
  302. database.LoadCharacterQuests(this);
  303. database.LoadPlayerMail(this);
  304. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  305. SendQuestJournal(true);
  306. master_aa_list.DisplayAA(this, 0, 3);
  307. SendCollectionList();
  308. SendBiography();
  309. map<int32, Quest*>::iterator itr;
  310. Quest* quest = 0;
  311. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  312. quest = itr->second;
  313. if (quest->IsTracked()) {
  314. quest->SetTracked(false);
  315. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  316. quest->SetTracked(true);
  317. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  318. }
  319. }
  320. // SendAchievementsList();
  321. /*Guild* guild = player->GetGuild();
  322. if (guild) {
  323. guild->UpdateGuildMemberInfo(GetPlayer());
  324. if (firstlogin)
  325. guild->SendGuildMOTD(this);
  326. guild->SendGuildUpdate(this);
  327. guild->SendGuildMember(GetPlayer(), firstlogin);
  328. guild->SendGuildEventList(this);
  329. guild->SendGuildBankEventList(this);
  330. guild->SendAllGuildEvents(this);
  331. guild->SendGuildMemberList(this);
  332. }*/
  333. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  334. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  335. if (outapp) {
  336. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  337. //DumpPacket(outapp);
  338. QueuePacket(outapp);
  339. }
  340. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  341. ClientPacketFunctions::SendCommandList(this);
  342. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  343. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  344. ClientPacketFunctions::SendInstanceList(this);
  345. SendZoneInfo();
  346. /*Spell* spell = 0;
  347. vector<QuickBarItem*>::iterator itr;
  348. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  349. if((*itr)->type == 1){
  350. spell = master_spell_list.GetSpell((*itr)->id);
  351. if(spell)
  352. QueuePacket(spell->serialize(this, false, 0x20));
  353. }
  354. }*/
  355. }
  356. void Client::SendPlayerDeathWindow()
  357. {
  358. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  359. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  360. vector<RevivePoint*>::iterator itr;
  361. if (results && results->size() > 0)
  362. {
  363. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  364. if (packet)
  365. {
  366. packet->setArrayLengthByName("location_count", results->size());
  367. RevivePoint* point = 0;
  368. int32 i = 0;
  369. for (itr = results->begin(); itr != results->end(); itr++, i++)
  370. {
  371. point = *itr;
  372. if (point)
  373. {
  374. packet->setArrayDataByName("location_id", point->id, i);
  375. //zone_name = database.GetZoneName(point->zone_id);
  376. string zone_name = database.GetZoneDescription(point->zone_id);
  377. if (zone_name.length() > 0)
  378. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  379. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  380. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  381. }
  382. if (point->id == 0xFFFFFFFF)//tmp location
  383. safe_delete(point);
  384. }
  385. // done with the revive points so lets free up the pointer
  386. safe_delete(results);
  387. #if EQDEBUG >= 3
  388. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  389. packet->PrintPacket();
  390. #endif
  391. EQ2Packet* outapp = packet->serialize();
  392. QueuePacket(outapp);
  393. safe_delete(packet);
  394. }
  395. }
  396. }
  397. void Client::DisplayDeadWindow()
  398. {
  399. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  400. player->SetHP(0);
  401. player->SetPower(0);
  402. GetCurrentZone()->TriggerCharSheetTimer();
  403. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  404. if (packet)
  405. {
  406. packet->setDataByName("parameter1", 8);
  407. packet->setDataByName("value", 1);
  408. QueuePacket(packet->serialize());
  409. packet->setDataByName("parameter1", 16);
  410. QueuePacket(packet->serialize());
  411. safe_delete(packet);
  412. }
  413. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  414. if (packet)
  415. {
  416. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  417. QueuePacket(packet->serialize());
  418. safe_delete(packet);
  419. }
  420. SendPlayerDeathWindow();
  421. }
  422. void Client::HandlePlayerRevive(int32 point_id)
  423. {
  424. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  425. if (packet)
  426. {
  427. packet->setDataByName("parameter1", 8);
  428. QueuePacket(packet->serialize());
  429. packet->setDataByName("parameter1", 16);
  430. QueuePacket(packet->serialize());
  431. safe_delete(packet);
  432. }
  433. SimpleMessage(CHANNEL_COLOR_REVIVE, "You regain consciousness!");
  434. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  435. if (packet)
  436. {
  437. QueuePacket(packet->serialize());
  438. safe_delete(packet);
  439. }
  440. float x, y, z, heading;
  441. RevivePoint* revive_point = 0;
  442. if (point_id != 0xFFFFFFFF)
  443. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  444. string zone_desc;
  445. const char* location_name = "Unknown";
  446. //revive at zone safe coords
  447. if (!revive_point)
  448. {
  449. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  450. x = GetCurrentZone()->GetSafeX();
  451. y = GetCurrentZone()->GetSafeY();
  452. z = GetCurrentZone()->GetSafeZ();
  453. heading = GetCurrentZone()->GetSafeHeading();
  454. zone_desc = GetCurrentZone()->GetZoneDescription();
  455. location_name = "Zone Safe Point";
  456. Zone(GetCurrentZone()->GetZoneName(), false);
  457. }
  458. else
  459. {
  460. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  461. x = revive_point->x;
  462. y = revive_point->y;
  463. z = revive_point->z;
  464. heading = revive_point->heading;
  465. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  466. location_name = revive_point->location_name.c_str();
  467. Zone(GetCurrentZone()->GetZoneName(), false);
  468. }
  469. player->SetResurrecting(true);
  470. player->SetX(x);
  471. player->SetY(y);
  472. player->SetZ(z);
  473. player->SetHeading(heading);
  474. player->SetHP(player->GetTotalHP());
  475. player->SetPower(player->GetTotalPower());
  476. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  477. zone_desc.c_str(),
  478. player->GetX(),
  479. player->GetY(),
  480. player->GetZ(),
  481. player->GetHeading(),
  482. player->GetHP(),
  483. player->GetPower(),
  484. location_name);
  485. //player->ClearEverything();
  486. Save();
  487. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  488. {
  489. string* zone_name = database.GetZoneName(revive_point->zone_id);
  490. if (!zone_name || zone_name->length() == 0)
  491. {
  492. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  493. x = GetCurrentZone()->GetSafeX();
  494. y = GetCurrentZone()->GetSafeY();
  495. z = GetCurrentZone()->GetSafeZ();
  496. heading = GetCurrentZone()->GetSafeHeading();
  497. location_name = "Zone Safe Point";
  498. }
  499. else
  500. {
  501. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  502. location_name = revive_point->location_name.c_str();
  503. player->ClearEverything();
  504. Zone(zone_name->c_str(), false);
  505. }
  506. safe_delete(zone_name);
  507. }
  508. zone_desc = GetCurrentZone()->GetZoneDescription();
  509. Message(CHANNEL_COLOR_REVIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  510. player->SetSpawnType(4);
  511. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  512. if (packet)
  513. {
  514. QueuePacket(packet->serialize());
  515. safe_delete(packet);
  516. }
  517. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  518. if (packet)
  519. {
  520. packet->setDataByName("x", x);
  521. packet->setDataByName("y", y);
  522. packet->setDataByName("z", z);
  523. QueuePacket(packet->serialize());
  524. safe_delete(packet);
  525. }
  526. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  527. if (packet)
  528. {
  529. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  530. packet->setDataByName("unknown2", 255);
  531. QueuePacket(packet->serialize());
  532. safe_delete(packet);
  533. }
  534. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  535. if (packet)
  536. {
  537. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  538. QueuePacket(packet->serialize());
  539. safe_delete(packet);
  540. }
  541. GetCurrentZone()->RemoveSpawn(false, player, false);
  542. m_resurrect.writelock(__FUNCTION__, __LINE__);
  543. if (current_rez.active)
  544. current_rez.should_delete = true;
  545. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  546. }
  547. void Client::SendCharInfo() {
  548. EQ2Packet* app;
  549. player->SetEquippedItemAppearances();
  550. ClientPacketFunctions::SendCharacterData(this);
  551. SendCharPOVGhost();
  552. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  553. if (packet) {
  554. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  555. packet->setDataByName("size", .56);
  556. packet->setDataByName("unknown2", 255);
  557. EQ2Packet* app = packet->serialize();
  558. QueuePacket(app);
  559. safe_delete(packet);
  560. }
  561. //SendAchievementsList();
  562. ClientPacketFunctions::SendCharacterSheet(this);
  563. ClientPacketFunctions::SendTraitList(this);// moved from below
  564. //ClientPacketFunctions::SendAbilities(this);
  565. ClientPacketFunctions::SendSkillBook(this);
  566. if (!player->IsResurrecting()) {
  567. ClientPacketFunctions::SendUpdateSpellBook(this);
  568. }
  569. else {
  570. player->SetResurrecting(false);
  571. }
  572. ClientPacketFunctions::SendLoginCommandMessages(this);
  573. GetCurrentZone()->AddSpawn(player);
  574. //SendCollectionList();
  575. Guild* guild = player->GetGuild();
  576. if (guild)
  577. guild->GuildMemberLogin(this, firstlogin);
  578. app = player->item_list.serialize(GetPlayer(), GetVersion());
  579. if (app) {
  580. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  581. //DumpPacket(app);
  582. QueuePacket(app);
  583. }
  584. app = player->GetEquipmentList()->serialize(GetVersion());
  585. if (app) {
  586. QueuePacket(app);
  587. }
  588. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  589. if (items && items->size() > 0) {
  590. for (int32 i = 0; i < items->size(); i++) {
  591. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  592. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  593. //DumpPacket(outapp);
  594. QueuePacket(outapp);
  595. }
  596. }
  597. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  598. QueuePacket(app);
  599. safe_delete(items);
  600. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  601. if (items && items->size() > 0) {
  602. for (int32 i = 0; i < items->size(); i++)
  603. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  604. }
  605. safe_delete(items);
  606. SendTitleUpdate();
  607. GetPlayer()->ChangePrimaryWeapon();
  608. GetPlayer()->ChangeSecondaryWeapon();
  609. GetPlayer()->ChangeRangedWeapon();
  610. database.LoadBuyBacks(this);
  611. master_aa_list.DisplayAA(this, 0, 0);
  612. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  613. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  614. string zone_motd_send = "Zone MOTD: " + zone_motd;
  615. SimpleMessage(CHANNEL_COLOR_WHITE, zone_motd_send.c_str());
  616. }
  617. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  618. if (zone_script && lua_interface)
  619. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  620. this->client_zoning = false;
  621. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  622. GetCurrentZone()->AddDamagedSpawn(player);
  623. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  624. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  625. if (firstlogin)
  626. firstlogin = false;
  627. player->ClearProcs();
  628. items = player->GetEquippedItemList();
  629. if (items && items->size() > 0) {
  630. for (int32 i = 0; i < items->size(); i++) {
  631. Item* item = items->at(i);
  632. if (item && item->GetItemScript() && lua_interface)
  633. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  634. }
  635. }
  636. //Allow this player to change their last name if they meet the level requirement
  637. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  638. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  639. safe_delete(items);
  640. if (!player->Alive())
  641. DisplayDeadWindow();
  642. ClientPacketFunctions::SendLocalizedTextMessage(this);
  643. if (GetCurrentZone()->GetInstanceID())
  644. {
  645. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  646. if (ph) {
  647. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  648. string name = string(GetPlayer()->GetName());
  649. if (name.compare(ph->player_name) == 0)
  650. SetHasOwnerOrEditAccess(true);
  651. }
  652. }
  653. ClientPacketFunctions::SendHousingList(this);
  654. }
  655. void Client::SendZoneSpawns() {
  656. //Allows us to place spawns almost anywhere
  657. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  658. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  659. QueuePacket(app);
  660. ClientPacketFunctions::SendSkillSlotMappings(this);
  661. ClientPacketFunctions::SendGameWorldTime(this);
  662. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  663. }
  664. void Client::SendCharPOVGhost() {
  665. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  666. if (set_pov) {
  667. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  668. EQ2Packet* app_pov = set_pov->serialize();
  669. QueuePacket(app_pov);
  670. safe_delete(set_pov);
  671. }
  672. }
  673. void Client::SendZoneInfo() {
  674. ZoneServer* zone = GetCurrentZone();
  675. if (zone) {
  676. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  677. QueuePacket(packet);
  678. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  679. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  680. #if EQDEBUG >= 9
  681. fog_packet->PrintPacket();
  682. #endif
  683. if (fog_packet) {
  684. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  685. QueuePacket(fog_packet->serialize());
  686. safe_delete(fog_packet);
  687. }
  688. zone->SendFlightPathsPackets(this);
  689. }
  690. /*
  691. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  692. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  693. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  694. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  695. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  696. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  697. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  698. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  699. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  700. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  701. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  702. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  703. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  704. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  705. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  706. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  707. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  708. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  709. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  710. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  711. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  712. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  713. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  714. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  715. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  716. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  717. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  718. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  719. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  720. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  721. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  722. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  723. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  724. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  725. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  726. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  727. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  728. QueuePacket(appA);
  729. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  730. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  731. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  732. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  733. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  734. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  735. QueuePacket(appB);
  736. */
  737. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  738. SendFriendList();
  739. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  740. SendIgnoreList();
  741. }
  742. void Client::SendDefaultGroupOptions() {
  743. /*
  744. 0 - loot method
  745. 1 - loot items rarity
  746. 2 - Auto split coin
  747. 4 - default yell method
  748. 6 - group autolock
  749. 7 - solo autolock
  750. */
  751. uchar blah7[] = { 0x01,0x01,0x01,0x01,0x00,0x00,0x00 };
  752. EQ2Packet* app7 = new EQ2Packet(OP_DefaultGroupOptionsMsg, blah7, sizeof(blah7));
  753. QueuePacket(app7);
  754. }
  755. bool Client::HandlePacket(EQApplicationPacket* app) {
  756. bool ret = true;
  757. #if EQDEBUG >= 9
  758. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  759. DumpPacket(app, true);
  760. #endif
  761. EmuOpcode opcode = app->GetOpcode();
  762. #if EQDEBUG >= 9
  763. const char* name = app->GetOpcodeName();
  764. if (name)
  765. cout << name;
  766. else
  767. cout << "Unknown";
  768. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  769. DumpPacket(app);
  770. #endif
  771. //if (opcode != OP_UpdatePositionMsg) {
  772. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  773. //}
  774. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  775. {
  776. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  777. }
  778. switch (opcode) {
  779. case _maxEmuOpcode:
  780. break;
  781. case OP_LoginByNumRequestMsg: {
  782. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  783. PacketStruct* request;
  784. request = configReader.getStruct("LoginByNumRequest", 1);
  785. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  786. // test the original location of Version for clients older than 1212
  787. version = request->getType_int16_ByName("version");
  788. if (version >= 1212 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  789. // must be new client data version method, re-fetch the packet
  790. safe_delete(request);
  791. request = configReader.getStruct("LoginByNumRequest", 1212);
  792. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  793. // Xinux suggests using an INT16 here. Our first new version = 57000
  794. version = request->getType_int16_ByName("version");
  795. }
  796. else {
  797. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  798. break;
  799. }
  800. }
  801. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  802. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  803. ClientPacketFunctions::SendLoginDenied(this);
  804. return false;
  805. }
  806. int32 account_id = request->getType_int32_ByName("account_id");
  807. int32 access_code = request->getType_int32_ByName("access_code");
  808. if (!HandleNewLogin(account_id, access_code))
  809. return false;
  810. }
  811. safe_delete(request);
  812. break;
  813. }
  814. case OP_SysClient: {
  815. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  816. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  817. if (!ready_for_updates)
  818. database.loadCharacterProperties(this);
  819. ready_for_updates = true;
  820. break;
  821. }
  822. case OP_MapRequest: {
  823. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  824. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  825. if (packet && app->size > 2 && GetCurrentZone()) {
  826. packet->LoadPacketData(app->pBuffer, app->size);
  827. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  828. if (fog_packet) {
  829. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  830. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  831. fog_packet->setDataByName("unknown1", 1);
  832. fog_packet->setDataByName("unknown3", 1);
  833. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  834. //fog_packet->PrintPacket();
  835. QueuePacket(fog_packet->serialize());
  836. safe_delete(fog_packet);
  837. }
  838. safe_delete(packet);
  839. }
  840. break;
  841. }
  842. case OP_RequestCampMsg: {
  843. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  844. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  845. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  846. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  847. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  848. request->getType_int8_ByName("quit"),
  849. request->getType_int8_ByName("camp_desktop"),
  850. request->getType_int16_ByName("camp_char_select"),
  851. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  852. //DumpPacket(app->pBuffer, app->size);
  853. //request->PrintPacket();
  854. if (!camp_timer) {
  855. int16 camp_time = 20; // default if rule cannot be found
  856. if (GetAdminStatus() >= 100)
  857. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  858. else
  859. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  860. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  861. if (response) {
  862. bool disconnect = false;
  863. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  864. // Command: /camp desktop
  865. // Command: /quit
  866. response->setDataByName("camp_desktop", 1);
  867. disconnect = true;
  868. }
  869. else {
  870. // Command: /camp
  871. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  872. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  873. response->setDataByName("seconds", camp_time);
  874. }
  875. camp_timer = new Timer(camp_time * 1000);
  876. camp_timer->Enable();
  877. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  878. // /camp {char_name}
  879. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  880. }
  881. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  882. // /camp (go back to char selection screen)
  883. response->setDataByName("char_name", " ");
  884. response->setDataByName("camp_char_select", 1);
  885. }
  886. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  887. response->getType_int8_ByName("seconds"),
  888. response->getType_int8_ByName("camp_desktop"),
  889. response->getType_int8_ByName("camp_char_select"),
  890. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  891. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  892. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  893. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  894. //response->PrintPacket();
  895. QueuePacket(response->serialize());
  896. safe_delete(response);
  897. if (disconnect)
  898. Disconnect();
  899. }
  900. }
  901. }
  902. safe_delete(request);
  903. break;
  904. }
  905. case OP_StoodMsg: {
  906. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  907. if (camp_timer)
  908. {
  909. // JA: clear camping flag
  910. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  911. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  912. safe_delete(camp_timer);
  913. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  914. QueuePacket(outapp);
  915. }
  916. player->SetTempVisualState(0);
  917. break;
  918. }
  919. case OP_StandMsg: {
  920. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  921. if (camp_timer)
  922. {
  923. // JA: clear camping flag
  924. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  925. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  926. safe_delete(camp_timer);
  927. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  928. QueuePacket(outapp);
  929. }
  930. player->SetTempVisualState(539);
  931. break;
  932. }
  933. case OP_SitMsg: {
  934. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  935. player->SetTempVisualState(538);
  936. break;
  937. }
  938. case OP_SatMsg: {
  939. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  940. player->SetTempVisualState(540);
  941. break;
  942. }
  943. case OP_QuestJournalOpenMsg:
  944. case OP_QuestJournalInspectMsg: {
  945. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  946. if (app->size < sizeof(int32))
  947. break;
  948. int32 quest_id = 0;
  949. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  950. Quest* quest = GetActiveQuest(quest_id);
  951. if (quest)
  952. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  953. else {
  954. quest = player->GetCompletedQuest(quest_id);
  955. if (quest)
  956. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  957. }
  958. break;
  959. }
  960. case OP_QuestJournalSetVisibleMsg: {
  961. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  962. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  963. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  964. int32 quest_id = packet->getType_int32_ByName("quest_id");
  965. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  966. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  967. if (player_quests) {
  968. if (player_quests->count(quest_id) > 0)
  969. player_quests->at(quest_id)->SetHidden(hidden);
  970. else
  971. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  972. }
  973. else
  974. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  975. safe_delete(packet);
  976. }
  977. break;
  978. }
  979. case OP_MacroUpdateMsg: {
  980. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  981. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  982. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  983. vector<string>* update = new vector<string>;
  984. int8 number = macro_update->getType_int8_ByName("number");
  985. int16 icon = macro_update->getType_int16_ByName("icon");
  986. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  987. int8 count = macro_update->getType_int8_ByName("macro_count");
  988. for (int8 i = 0; i < count; i++) {
  989. char tmp_command[15] = { 0 };
  990. sprintf(tmp_command, "command_%i", i);
  991. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  992. }
  993. if (name.length() == 0)
  994. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  995. else
  996. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  997. safe_delete(update);
  998. safe_delete(macro_update);
  999. }
  1000. break;
  1001. }
  1002. case OP_DialogSelectMsg: {
  1003. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1004. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1005. if (packet) {
  1006. packet->LoadPacketData(app->pBuffer, app->size);
  1007. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1008. int32 response_index = packet->getType_int32_ByName("response");
  1009. if (GetCurrentZone()) {
  1010. Spawn* spawn = conversation_spawns[conversation_id];
  1011. Item* item = conversation_items[conversation_id];
  1012. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1013. if (spawn)
  1014. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1015. else if (item && lua_interface && item->GetItemScript())
  1016. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1017. }
  1018. else
  1019. CloseDialog(conversation_id);
  1020. }
  1021. safe_delete(packet);
  1022. }
  1023. break;
  1024. }
  1025. case OP_CancelMoveObjectModeMsg: {
  1026. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1027. if (GetTempPlacementSpawn())
  1028. {
  1029. Spawn* tmp = GetTempPlacementSpawn();
  1030. GetCurrentZone()->RemoveSpawn(false, tmp);
  1031. delete tmp;
  1032. SetTempPlacementSpawn(nullptr);
  1033. SetPlacementUniqueItemID(0);
  1034. break; // break out early if we are tied to a temp spawn
  1035. }
  1036. // if we are moving some other object? other use-cases not covered
  1037. break;
  1038. }
  1039. case OP_PositionMoveableObject: {
  1040. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1041. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1042. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1043. Spawn* spawn = 0;
  1044. if (GetTempPlacementSpawn())
  1045. spawn = GetTempPlacementSpawn();
  1046. else
  1047. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1048. if (!spawn) {
  1049. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1050. break;
  1051. }
  1052. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1053. {
  1054. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1055. break;
  1056. }
  1057. // handles instantiation logic + adding to zone of a new house object
  1058. PopulateHouseSpawn(place_object);
  1059. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1060. char query[256];
  1061. switch (GetSpawnPlacementMode())
  1062. {
  1063. case ServerSpawnPlacementMode::OPEN_HEADING:
  1064. {
  1065. if (spawn && spawn->IsWidget())
  1066. {
  1067. Widget* widget = (Widget*)spawn;
  1068. widget->SetOpenHeading(newHeading);
  1069. widget->SetIncludeHeading(true);
  1070. spawn->position_changed = true;
  1071. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1072. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1073. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1074. }
  1075. else
  1076. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1077. break;
  1078. }
  1079. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1080. {
  1081. if (spawn && spawn->IsWidget())
  1082. {
  1083. Widget* widget = (Widget*)spawn;
  1084. widget->SetClosedHeading(newHeading);
  1085. widget->SetIncludeHeading(true);
  1086. spawn->position_changed = true;
  1087. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1088. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1089. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1090. if (spawn->GetSpawnLocationID())
  1091. {
  1092. Query query;
  1093. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1094. }
  1095. }
  1096. else
  1097. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1098. break;
  1099. }
  1100. default:
  1101. {
  1102. spawn->SetX(place_object->getType_float_ByName("x"));
  1103. spawn->SetY(place_object->getType_float_ByName("y"));
  1104. spawn->SetZ(place_object->getType_float_ByName("z"));
  1105. spawn->SetHeading(newHeading);
  1106. spawn->SetSpawnOrigX(spawn->GetX());
  1107. spawn->SetSpawnOrigY(spawn->GetY());
  1108. spawn->SetSpawnOrigZ(spawn->GetZ());
  1109. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1110. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1111. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1112. else if (spawn->GetSpawnLocationID() > 0)
  1113. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1114. }
  1115. }
  1116. PopulateHouseSpawnFinalize();
  1117. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1118. safe_delete(place_object);
  1119. }
  1120. break;
  1121. }
  1122. case OP_CampAbortedMsg: {
  1123. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1124. if (camp_timer)
  1125. {
  1126. // JA: clear camping flag
  1127. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1128. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1129. safe_delete(camp_timer);
  1130. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1131. QueuePacket(outapp);
  1132. }
  1133. break;
  1134. }
  1135. case OP_DoneLoadingZoneResourcesMsg: {
  1136. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1137. SendZoneSpawns();
  1138. break;
  1139. }
  1140. case OP_DefaultGroupOptionsRequestMsg: {
  1141. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1142. SendDefaultGroupOptions();
  1143. break;
  1144. }
  1145. case OP_DoneLoadingEntityResourcesMsg: {
  1146. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1147. if (!IsReadyForSpawns())
  1148. SetReadyForSpawns(true);
  1149. SendCharInfo();
  1150. pos_update.Start();
  1151. quest_pos_timer.Start();
  1152. break;
  1153. }
  1154. case OP_LootItemsRequestMsg: {
  1155. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1156. HandleLoot(app);
  1157. break;
  1158. }
  1159. case OP_KnowledgeWindowSlotMappingMsg: {
  1160. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1161. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1162. if (packet) {
  1163. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1164. int num_updates = packet->getType_int16_ByName("spell_count");
  1165. int32 spell_id = 0;
  1166. int16 slot_id = 0;
  1167. char tmp_spell_id[15];
  1168. char tmp_slot[15];
  1169. for (int i = 0; i < num_updates; i++) {
  1170. memset(tmp_spell_id, 0, 15);
  1171. memset(tmp_slot, 0, 15);
  1172. sprintf(tmp_spell_id, "spell_id_%i", i);
  1173. sprintf(tmp_slot, "slot_id_%i", i);
  1174. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1175. if (spell_id > 0) {
  1176. slot_id = packet->getType_int16_ByName(tmp_slot);
  1177. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1178. if (spell && spell->slot != slot_id) {
  1179. spell->slot = slot_id;
  1180. spell->save_needed = true;
  1181. }
  1182. }
  1183. }
  1184. }
  1185. safe_delete(packet);
  1186. }
  1187. //SendKnowledgeWindowSlot();
  1188. break;
  1189. }
  1190. case OP_ReadyToZoneMsg: {
  1191. if (!IsReadyForSpawns())
  1192. {
  1193. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1194. }
  1195. else
  1196. {
  1197. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1198. if (client_zoning)
  1199. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1200. else
  1201. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1202. Disconnect();
  1203. }
  1204. break;
  1205. }
  1206. case OP_ClientFellMsg: {
  1207. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1208. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1209. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1210. float height = request->getType_float_ByName("height");
  1211. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1212. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1213. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1214. break;
  1215. }*/
  1216. float safe_height = 13.0f;
  1217. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1218. if (skill)
  1219. safe_height += (skill->current_val + 1) / 5;
  1220. if (height > safe_height) {
  1221. int16 damage = (int16)ceil((height - safe_height) * 125);
  1222. if (height >= 80)
  1223. damage = 30000;
  1224. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1225. if (damage > 0) {
  1226. GetPlayer()->TakeDamage(damage);
  1227. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1228. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1229. if (!GetPlayer()->GetInvulnerable())
  1230. GetPlayer()->SetCharSheetChanged(true);
  1231. 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);
  1232. if (GetPlayer()->GetHP() == 0) {
  1233. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1234. }
  1235. }
  1236. }
  1237. safe_delete(request);
  1238. }
  1239. break;
  1240. }
  1241. case OP_MapFogDataUpdateMsg: {
  1242. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1243. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1244. break;
  1245. }
  1246. case OP_SelectZoneTeleporterDestinatio: {
  1247. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1248. ProcessTeleportLocation(app);
  1249. break;
  1250. }
  1251. case OP_SendLatestRequestMsg: {
  1252. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1253. uchar blah25[] = { 0x01 };
  1254. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1255. QueuePacket(app25);
  1256. break;
  1257. }
  1258. case OP_ShowCreateFromRecipeUIMsg: {
  1259. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1260. break;
  1261. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1262. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1263. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1264. QueuePacket(app);
  1265. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1266. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1267. QueuePacket(app);
  1268. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1269. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1270. ,0xff,0xff,0xff};
  1271. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1272. QueuePacket(app);
  1273. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1274. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1275. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1276. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1277. QueuePacket(app);
  1278. uchar blah5[] ={0x00,0x00};
  1279. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1280. QueuePacket(app);
  1281. break;*/
  1282. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1283. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1284. //QueuePacket(app);
  1285. }
  1286. case OP_BeginItemCreationMsg: {
  1287. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1288. //DumpPacket(app->pBuffer, app->size);
  1289. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1290. if (packet) {
  1291. packet->LoadPacketData(app->pBuffer, app->size);
  1292. int32 item = 0;
  1293. vector<int32> items;
  1294. char tmp_item_id[20];
  1295. item = packet->getType_int32_ByName("primary_component_id");
  1296. if (item > 0)
  1297. items.push_back(item);
  1298. item = 0;
  1299. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1300. for (int8 i = 0; i < build_components; i++) {
  1301. memset(tmp_item_id, 0, 20);
  1302. sprintf(tmp_item_id, "component_id_%i", i);
  1303. item = packet->getType_int32_ByName(tmp_item_id);
  1304. if (item > 0)
  1305. items.push_back(item);
  1306. item = 0;
  1307. }
  1308. item = packet->getType_int32_ByName("fuel_id");
  1309. if (item > 0)
  1310. items.push_back(item);
  1311. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1312. safe_delete(packet);
  1313. }
  1314. break;
  1315. }
  1316. case OP_StopItemCreationMsg: {
  1317. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1318. //DumpPacket(app->pBuffer, app->size);
  1319. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1320. break;
  1321. }
  1322. //case OP_SignalMsg:{
  1323. // LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SignalMsg", opcode, opcode);
  1324. // //if(app->size == 25 && app->pBuffer[0] == 0x17 && app->pBuffer[24] == 0x79)
  1325. // // GetPlayer()->ModifySpellStatus(0, 66, true);
  1326. // if(connected && player->GetHP() == 0)
  1327. // DisplayDeadWindow();
  1328. // break;
  1329. // }
  1330. case OP_EntityVerbsRequestMsg: {
  1331. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1332. HandleVerbRequest(app);
  1333. break;
  1334. }
  1335. case OP_EntityVerbsVerbMsg: {
  1336. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1337. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1338. if (packet) {
  1339. packet->LoadPacketData(app->pBuffer, app->size);
  1340. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1341. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1342. Spawn* spawn = player->GetTarget();
  1343. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1344. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1345. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1346. {
  1347. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1348. if (spawn->IsGroundSpawn())
  1349. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1350. else if (spawn->IsObject())
  1351. ((Object*)spawn)->HandleUse(this, command);
  1352. else if (spawn->IsWidget())
  1353. ((Widget*)spawn)->HandleUse(this, command);
  1354. else if (spawn->IsSign())
  1355. ((Sign*)spawn)->HandleUse(this, command);
  1356. }
  1357. }
  1358. }
  1359. else {
  1360. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1361. if (command.size > 0) {
  1362. string command_name = command.data;
  1363. if (command_name.find(" ") < 0xFFFFFFFF)
  1364. command_name = command_name.substr(0, command_name.find(" "));
  1365. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1366. if (handler != 0xFFFFFFFF) {
  1367. if (command.data == command_name) {
  1368. command.data = "";
  1369. command.size = 0;
  1370. }
  1371. else {
  1372. command.data = command.data.substr(command.data.find(" ") + 1);
  1373. command.size = command.data.length();
  1374. }
  1375. commands.Process(handler, &command, this);
  1376. }
  1377. else {
  1378. if (spawn && spawn->IsNPC()) {
  1379. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1380. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1381. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1382. }
  1383. }
  1384. }
  1385. else
  1386. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1387. }
  1388. }
  1389. }
  1390. safe_delete(packet);
  1391. }
  1392. break;
  1393. }
  1394. case OP_SkillInfoRequest: {
  1395. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1396. HandleSkillInfoRequest(app);
  1397. break;
  1398. }
  1399. case OP_UpdateTargetMsg: {
  1400. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1401. int16 index = 0;
  1402. memcpy(&index, app->pBuffer, sizeof(int16));
  1403. if (index == 0xFFFF)
  1404. GetPlayer()->SetTarget(0);
  1405. else
  1406. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1407. if (GetPlayer()->GetTarget())
  1408. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1409. //player->SetTarget((int16*)app->pBuffer);
  1410. break;
  1411. }
  1412. case OP_ExamineInfoRequestMsg: {
  1413. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1414. HandleExamineInfoRequest(app);
  1415. break;
  1416. }
  1417. case OP_QuickbarUpdateMsg:
  1418. //case OP_QuickbarAddMsg:
  1419. {
  1420. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1421. HandleQuickbarUpdateRequest(app);
  1422. break;
  1423. }
  1424. case OP_PredictionUpdateMsg: {
  1425. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1426. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1427. QueuePacket(app);
  1428. break;
  1429. }
  1430. case OP_RemoteCmdMsg: {
  1431. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1432. if (app->size > 0) {
  1433. EQ2_CommandString remote(app->pBuffer, app->size);
  1434. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1435. #if EQDEBUG >= 9
  1436. DumpPacket(app);
  1437. #endif
  1438. commands.Process(remote.handler, &remote.command, this);
  1439. }
  1440. else //bad client, disconnect
  1441. Disconnect();
  1442. break;
  1443. }
  1444. case OP_CancelSpellCast: {
  1445. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1446. current_zone->Interrupted(player, 0, 0, true);
  1447. SimpleMessage(CHANNEL_COLOR_SPELL_INTERRUPT, "You stop casting.");
  1448. break;
  1449. }
  1450. case OP_UpdatePositionMsg: {
  1451. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1452. int8 offset = 13;
  1453. if (app->pBuffer[0] == 0xFF)
  1454. offset += 2;
  1455. if (app->size > offset) {
  1456. if (player->IsCasting()) {
  1457. float distance = 0;
  1458. float x = player->GetX();
  1459. float y = player->GetY();
  1460. float z = player->GetZ();
  1461. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1462. distance = player->GetDistance(x, y, z, false);
  1463. if (distance > .5)
  1464. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1465. }
  1466. else
  1467. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1468. player_pos_changed = true;
  1469. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1470. //DumpPacket(app);
  1471. }
  1472. break;
  1473. }
  1474. case OP_MailSendMessageMsg: {
  1475. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1476. HandleSentMail(app);
  1477. break;
  1478. }
  1479. case OP_StopTrackingMsg: {
  1480. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1481. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1482. break;
  1483. }
  1484. case OP_BeginTrackingMsg: {
  1485. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1486. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1487. if (packet) {
  1488. packet->LoadPacketData(app->pBuffer, app->size);
  1489. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1490. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1491. if (spawn) {
  1492. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1493. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1494. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1495. }
  1496. safe_delete(packet);
  1497. }
  1498. break;
  1499. }
  1500. case OP_BioUpdateMsg: {
  1501. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1502. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1503. if (packet) {
  1504. packet->LoadPacketData(app->pBuffer, app->size);
  1505. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1506. safe_delete(packet);
  1507. }
  1508. break;
  1509. }
  1510. case OP_RewardPackMsg: {
  1511. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1512. /* 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
  1513. when we come across it (scatman) */
  1514. const char* name = app->GetOpcodeName();
  1515. if (name)
  1516. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1517. else
  1518. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1519. //DumpPacket(app);
  1520. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1521. if (packet) {
  1522. packet->LoadPacketData(app->pBuffer, app->size);
  1523. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1524. /* Player has contacted a guild recruiter */
  1525. if (recruiter_name.length() > 0) {
  1526. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1527. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1528. if (recruiter && guild) {
  1529. Message(CHANNEL_COLOR_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1530. recruiter->Message(CHANNEL_COLOR_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()));
  1531. recruiter->PlaySound("ui_guild_page");
  1532. }
  1533. }
  1534. /* New picture taken for guild recruiting */
  1535. else {
  1536. //DumpPacket(app->pBuffer, app->size);
  1537. int32 guild_id = 0;
  1538. int16 picture_data_size = 0;
  1539. unsigned char* recruiter_picture_data = 0;
  1540. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1541. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1542. Guild* guild = guild_list.GetGuild(guild_id);
  1543. if (guild) {
  1544. GuildMember* gm = guild->GetGuildMember(player);
  1545. if (gm) {
  1546. safe_delete_array(gm->recruiter_picture_data);
  1547. recruiter_picture_data = new unsigned char[picture_data_size];
  1548. for (int16 i = 0; i < picture_data_size; i++)
  1549. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1550. gm->recruiter_picture_data = recruiter_picture_data;
  1551. gm->recruiter_picture_data_size = picture_data_size;
  1552. guild->SetMemberSaveNeeded(true);
  1553. }
  1554. }
  1555. }
  1556. safe_delete(packet);
  1557. }
  1558. break;
  1559. }
  1560. case OP_PetOptions: {
  1561. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1562. Spawn* target = player->GetTarget();
  1563. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1564. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1565. bool change = false;
  1566. packet->LoadPacketData(app->pBuffer, app->size);
  1567. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1568. if (strlen(name.c_str()) != 0) {
  1569. target->SetName(name.c_str());
  1570. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1571. GetCurrentZone()->SendUpdateTitles(target);
  1572. change = true;
  1573. }
  1574. // Check protect self setting and update if needed
  1575. if (packet->getType_int8_ByName("protect_self") == 1) {
  1576. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1577. player->GetInfoStruct()->pet_behavior += 2;
  1578. change = true;
  1579. }
  1580. }
  1581. else {
  1582. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1583. player->GetInfoStruct()->pet_behavior -= 2;
  1584. change = true;
  1585. }
  1586. }
  1587. // Check protect master setting and update if needed
  1588. if (packet->getType_int8_ByName("protect_master") == 1) {
  1589. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1590. player->GetInfoStruct()->pet_behavior += 1;
  1591. change = true;
  1592. }
  1593. }
  1594. else {
  1595. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1596. player->GetInfoStruct()->pet_behavior -= 1;
  1597. change = true;
  1598. }
  1599. }
  1600. // Check stay/follow setting and update if needed
  1601. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1602. if (player->GetInfoStruct()->pet_movement != 2) {
  1603. player->GetInfoStruct()->pet_movement = 2;
  1604. change = true;
  1605. }
  1606. }
  1607. else {
  1608. if (player->GetInfoStruct()->pet_movement != 1) {
  1609. player->GetInfoStruct()->pet_movement = 1;
  1610. change = true;
  1611. }
  1612. }
  1613. // Ranged/Melee settings are not implemented yet
  1614. if (change)
  1615. player->SetCharSheetChanged(true);
  1616. safe_delete(packet);
  1617. }
  1618. break;
  1619. }
  1620. case OP_RecipeBook: {
  1621. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1622. SendRecipeList();
  1623. break;
  1624. }
  1625. case OP_BuyPlayerHouseMsg: {
  1626. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1627. DumpPacket(app);
  1628. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1629. if (packet) {
  1630. packet->LoadPacketData(app->pBuffer, app->size);
  1631. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1632. if (hz) {
  1633. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1634. if (houses.size() > 24)
  1635. {
  1636. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1637. safe_delete(packet);
  1638. break;
  1639. }
  1640. if ((!hz->upkeep_coin && !hz->cost_coin) || player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)) // TODO: Need option to take from bank if player does not have enough coin on them
  1641. {
  1642. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1643. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1644. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1645. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1646. //ClientPacketFunctions::SendHousingList(this);
  1647. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1648. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1649. PlaySound("coin_cha_ching");
  1650. }
  1651. else
  1652. {
  1653. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1654. PlaySound("buy_failed");
  1655. }
  1656. }
  1657. }
  1658. safe_delete(packet);
  1659. break;
  1660. }
  1661. case OP_EnterHouseMsg: {
  1662. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1663. DumpPacket(app);
  1664. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1665. if (packet) {
  1666. packet->LoadPacketData(app->pBuffer, app->size);
  1667. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1668. if (ph) {
  1669. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1670. if (hz) {
  1671. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1672. if (house) {
  1673. Zone(house, true);
  1674. }
  1675. }
  1676. }
  1677. }
  1678. safe_delete(packet);
  1679. break;
  1680. }
  1681. case OP_PayHouseUpkeepMsg: {
  1682. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1683. DumpPacket(app);
  1684. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1685. if (packet) {
  1686. packet->LoadPacketData(app->pBuffer, app->size);
  1687. int64 houseID = packet->getType_int64_ByName("house_id");
  1688. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1689. if (ph)
  1690. {
  1691. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1692. if (!hz)
  1693. {
  1694. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1695. safe_delete(packet);
  1696. break;
  1697. }
  1698. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1699. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1700. {
  1701. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1702. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1703. {
  1704. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1705. PlaySound("buy_failed");
  1706. safe_delete(packet);
  1707. break;
  1708. }
  1709. }
  1710. int64 coinReq = hz->upkeep_coin;
  1711. int64 tmpRecoverCoins = 0;
  1712. bool escrowChange = false;
  1713. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1714. {
  1715. escrowChange = true;
  1716. tmpRecoverCoins = ph->escrow_coins;
  1717. coinReq -= ph->escrow_coins;
  1718. ph->escrow_coins = 0;
  1719. }
  1720. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1721. {
  1722. escrowChange = true;
  1723. // more than enough in escrow, subtract and make our cost 0!
  1724. ph->escrow_coins -= coinReq;
  1725. coinReq = 0;
  1726. }
  1727. // TODO: Need support for upkeep_status, but alas status_points are not implemented!
  1728. if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
  1729. {
  1730. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1731. if (escrowChange)
  1732. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
  1733. ph->upkeep_due = upkeep_due;
  1734. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1735. //ClientPacketFunctions::SendHousingList(this);
  1736. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1737. PlaySound("coin_cha_ching");
  1738. }
  1739. else
  1740. {
  1741. // recover the escrow we were going to use but could not spend due to lack of funds
  1742. if (tmpRecoverCoins)
  1743. ph->escrow_coins += tmpRecoverCoins;
  1744. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
  1745. PlaySound("buy_failed");
  1746. }
  1747. }
  1748. else
  1749. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  1750. }
  1751. safe_delete(packet);
  1752. break;
  1753. }
  1754. case OP_ExitHouseMsg: {
  1755. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1756. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1757. if (instance_id > 0) {
  1758. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1759. if (ph) {
  1760. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1761. if (hz) {
  1762. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1763. // determine if this is an instanced zone that already exists
  1764. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1765. if (instance_zone || new_zone) {
  1766. GetPlayer()->SetX(hz->exit_x);
  1767. GetPlayer()->SetY(hz->exit_y);
  1768. GetPlayer()->SetZ(hz->exit_z);
  1769. GetPlayer()->SetHeading(hz->exit_heading);
  1770. if (instance_zone)
  1771. Zone(instance_zone->GetInstanceID(), false, true);
  1772. else
  1773. Zone(new_zone, false);
  1774. }
  1775. }
  1776. }
  1777. }
  1778. DumpPacket(app);
  1779. break;
  1780. }
  1781. case OP_QuestJournalWaypointMsg: {
  1782. //DumpPacket(app);
  1783. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1784. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1785. if (packet) {
  1786. packet->LoadPacketData(app->pBuffer, app->size);
  1787. int32 quests = packet->getType_int32_ByName("num_quests");
  1788. if (quests > 100) // just picking a number higher than max allowed
  1789. {
  1790. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1791. break;
  1792. }
  1793. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1794. for (int32 i = 0; i < quests; i++) {
  1795. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1796. if (id == 0)
  1797. continue;
  1798. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1799. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1800. if (player->player_quests.count(id) > 0) {
  1801. player->player_quests[id]->SetTracked(tracked);
  1802. player->player_quests[id]->SetSaveNeeded(true);
  1803. }
  1804. }
  1805. safe_delete(packet);
  1806. }
  1807. break;
  1808. }
  1809. case OP_PaperdollImage: {
  1810. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1811. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1812. //First check if this is a new image... delete an existing partial image if one exists
  1813. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1814. if (packet_index == 0) {
  1815. safe_delete_array(incoming_paperdoll.image_bytes);
  1816. incoming_paperdoll.last_received_packet_index = 0;
  1817. incoming_paperdoll.current_size_bytes = 0;
  1818. }
  1819. //return if this packet is not the one we are expecting...
  1820. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1821. safe_delete(packet);
  1822. break;
  1823. }
  1824. //Check how many packets we're supposed to be receiving for this/these images
  1825. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1826. //Check the image type, if this is a new type in the same series of packets we have a new image
  1827. int8 img_type = packet->getType_int8_ByName("image_type");
  1828. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1829. //We have a new image. Save the old data and clear before continuing
  1830. SavePlayerImages();
  1831. }
  1832. incoming_paperdoll.image_type = img_type;
  1833. //Get the size of the image data in this packet
  1834. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1835. if (image_size <= 0 || image_size > 1048576) {
  1836. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1837. safe_delete(packet);
  1838. break;
  1839. }
  1840. //Create a new array
  1841. int32 new_image_size = image_size;
  1842. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1843. if (incoming_paperdoll.image_bytes) {
  1844. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1845. safe_delete_array(incoming_paperdoll.image_bytes);
  1846. }
  1847. //variable i should be the index in the packet of the first PNG file byte
  1848. vector<DataStruct*>* d_structs = packet->getStructs();
  1849. vector<DataStruct*>::iterator itr;
  1850. int32 i = 0;
  1851. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1852. DataStruct* ds = (*itr);
  1853. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1854. i += ds->GetDataSizeInBytes();
  1855. else
  1856. break;
  1857. }
  1858. //Return if this packet is bad and we would read out of bounds
  1859. if (app->size - i < new_image_size) {
  1860. safe_delete(packet);
  1861. safe_delete_array(new_image);
  1862. break;
  1863. }
  1864. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1865. memcpy(tmp, app->pBuffer + i, new_image_size);
  1866. incoming_paperdoll.current_size_bytes += new_image_size;
  1867. incoming_paperdoll.image_bytes = new_image;
  1868. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1869. if (incoming_paperdoll.image_num_packets == 1 ||
  1870. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1871. SavePlayerImages();
  1872. }
  1873. incoming_paperdoll.last_received_packet_index = packet_index;
  1874. }
  1875. safe_delete(packet);
  1876. break;
  1877. }
  1878. case OP_ReadyForTakeOffMsg:
  1879. {
  1880. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1881. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1882. if (GetPendingFlightPath() > 0) {
  1883. if (index != -1) {
  1884. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1885. if (packet) {
  1886. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1887. packet->setDataByName("path_id", index);
  1888. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1889. QueuePacket(packet->serialize());
  1890. safe_delete(packet);
  1891. on_auto_mount = true;
  1892. }
  1893. }
  1894. else {
  1895. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1896. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1897. EndAutoMount();
  1898. }
  1899. SetPendingFlightPath(0);
  1900. }
  1901. else
  1902. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  1903. break;
  1904. }
  1905. case OP_EarlyLandingRequestMsg:
  1906. {
  1907. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  1908. EndAutoMount();
  1909. break;
  1910. }
  1911. case OP_SubmitCharCust:
  1912. {
  1913. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  1914. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  1915. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1916. int8 type = packet->getType_int8_ByName("type");
  1917. if (type == 0) {
  1918. if (player->custNPC) {
  1919. player->custNPCTarget->CustomizeAppearance(packet);
  1920. current_zone->SendSpawnChanges(player->custNPCTarget);
  1921. }
  1922. else {
  1923. player->CustomizeAppearance(packet);
  1924. current_zone->SendSpawnChanges(player);
  1925. }
  1926. }
  1927. }
  1928. if (player->custNPC) {
  1929. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  1930. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  1931. if (player->custNPCTarget->IsBot())
  1932. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  1933. player->custNPC = false;
  1934. player->custNPCTarget = 0;
  1935. player->changed = true;
  1936. player->info_changed = true;
  1937. current_zone->SendSpawnChanges(player, this);
  1938. }
  1939. break;
  1940. }
  1941. default: {
  1942. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  1943. const char* name = app->GetOpcodeName();
  1944. if (name)
  1945. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  1946. else
  1947. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  1948. //DumpPacket(app);
  1949. }
  1950. }
  1951. if (!eqs || !eqs->CheckActive()) {
  1952. return false;
  1953. }
  1954. return ret;
  1955. }
  1956. bool Client::HandleLootItem(Entity* entity, Item* item) {
  1957. if (!item) {
  1958. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  1959. return false;
  1960. }
  1961. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  1962. if (player->item_list.AssignItemToFreeSlot(item)) {
  1963. int8 type = CHANNEL_COLOR_LOOT;
  1964. if (GetVersion() >= 973 && GetVersion() <= 1000)
  1965. type = CHANNEL_COLOR_NEW_LOOT;
  1966. else if (GetVersion() >= 973)
  1967. type = CHANNEL_COLOR_NEWEST_LOOT;
  1968. if (entity)
  1969. Message(type, "You loot \\aITEM %u 0:%s\\/a from the corpse of %s", item->details.item_id, item->name.c_str(), entity->GetName());
  1970. else
  1971. Message(type, "You found a \\aITEM %u 0:%s\\/a", item->details.item_id, item->name.c_str());
  1972. Guild* guild = player->GetGuild();
  1973. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  1974. char adjective[32];
  1975. int8 type;
  1976. memset(adjective, 0, sizeof(adjective));
  1977. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  1978. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  1979. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  1980. }
  1981. else if (item->details.tier >= ITEM_TAG_FABLED) {
  1982. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  1983. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  1984. }
  1985. else {
  1986. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  1987. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  1988. }
  1989. guild->AddNewGuildEvent(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->details.item_id, item->name.c_str());
  1990. guild->SendMessageToGuild(type, "%s has looted the %s \\aITEM %u 0:%s\\/a", player->GetName(), adjective, item->details.item_id, item->name.c_str());
  1991. }
  1992. CheckPlayerQuestsItemUpdate(item);
  1993. return true;
  1994. }
  1995. else
  1996. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  1997. }
  1998. else
  1999. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2000. return false;
  2001. }
  2002. bool Client::HandleLootItem(Entity* entity, int32 item_id) {
  2003. if (!entity) {
  2004. return false;
  2005. }
  2006. return HandleLootItem(entity, entity->LootItem(item_id));
  2007. }
  2008. void Client::HandleLoot(EQApplicationPacket* app) {
  2009. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2010. if (packet) {
  2011. packet->LoadPacketData(app->pBuffer, app->size);
  2012. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2013. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2014. safe_delete(packet);
  2015. int32 item_id = 0;
  2016. Item* item = 0;
  2017. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2018. if (player->HasPendingLootItems(loot_id)) {
  2019. Item* master_item = 0;
  2020. if (loot_all) {
  2021. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2022. if (items) {
  2023. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2024. master_item = items->at(i);
  2025. if (master_item) {
  2026. item = new Item(master_item);
  2027. if (item) {
  2028. loot_all = HandleLootItem(0, item);
  2029. if (loot_all)
  2030. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2031. }
  2032. }
  2033. }
  2034. safe_delete(items);
  2035. }
  2036. }
  2037. else {
  2038. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2039. if (packet) {
  2040. packet->LoadPacketData(app->pBuffer, app->size);
  2041. item_id = packet->getType_int32_ByName("item_id");
  2042. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2043. if (items) {
  2044. for (int32 i = 0; i < items->size(); i++) {
  2045. master_item = items->at(i);
  2046. if (master_item && master_item->details.item_id == item_id) {
  2047. item = new Item(master_item);
  2048. if (item && HandleLootItem(0, item))
  2049. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2050. break;
  2051. }
  2052. }
  2053. safe_delete(items);
  2054. }
  2055. safe_delete(packet);
  2056. }
  2057. }
  2058. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2059. if (outapp)
  2060. QueuePacket(outapp);
  2061. Loot(0, player->GetPendingLootItems(loot_id), (Entity*)spawn);
  2062. }
  2063. else {
  2064. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2065. if (loot_all) {
  2066. while (loot_all && ((item_id = ((Entity*)spawn)->GetLootItemID()) > 0)) {
  2067. loot_all = HandleLootItem((Entity*)spawn, item_id);
  2068. }
  2069. }
  2070. else {
  2071. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2072. if (packet) {
  2073. packet->LoadPacketData(app->pBuffer, app->size);
  2074. item_id = packet->getType_int32_ByName("item_id");
  2075. HandleLootItem((Entity*)spawn, item_id);
  2076. safe_delete(packet);
  2077. }
  2078. }
  2079. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2080. if (outapp)
  2081. QueuePacket(outapp);
  2082. Loot((Entity*)spawn);
  2083. if (!((Entity*)spawn)->HasLoot()) {
  2084. CloseLoot();
  2085. if (((Entity*)spawn)->IsNPC())
  2086. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2087. }
  2088. }
  2089. else {
  2090. if (!spawn) {
  2091. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2092. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2093. }
  2094. else
  2095. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2096. }
  2097. }
  2098. }
  2099. }
  2100. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2101. PacketStruct* request = 0;
  2102. // cout << "Request: \n";
  2103. // DumpPacket(app);
  2104. switch (app->pBuffer[0]) {
  2105. case 0: { //items
  2106. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2107. if (request) {
  2108. request->LoadPacketData(app->pBuffer, app->size);
  2109. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2110. if (!item)
  2111. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2112. if (item) {
  2113. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2114. if (response) {
  2115. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2116. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2117. response->setSmallStringByName("name", item->name.c_str());
  2118. EQ2Packet* app2 = response->serialize();
  2119. //DumpPacket(app2);
  2120. QueuePacket(app2);
  2121. safe_delete(response);
  2122. }
  2123. }
  2124. }
  2125. break;
  2126. }
  2127. case 2: {//spells
  2128. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2129. if (request) {
  2130. request->LoadPacketData(app->pBuffer, app->size);
  2131. int32 id = request->getType_int32_ByName("id");
  2132. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2133. Spell* spell = master_spell_list.GetSpell(id, tier);
  2134. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2135. if (response) {
  2136. response->setDataByName("request_type", 2);
  2137. response->setDataByName("unique_id", tier);
  2138. response->setDataByName("id", id);
  2139. if (spell)
  2140. response->setSmallStringByName("name", spell->GetName());
  2141. else
  2142. response->setSmallStringByName("name", "Unknown Spell");
  2143. EQ2Packet* app2 = response->serialize();
  2144. // DumpPacket(app2);
  2145. QueuePacket(app2);
  2146. safe_delete(response);
  2147. }
  2148. }
  2149. break;
  2150. }
  2151. default: {
  2152. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2153. }
  2154. }
  2155. safe_delete(request);
  2156. }
  2157. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2158. PacketStruct* request = 0;
  2159. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2160. //DumpPacket(app);
  2161. int8 type = app->pBuffer[0];
  2162. if (type == 3) {
  2163. Spell* spell = 0;
  2164. bool trait_display;
  2165. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2166. if (!request) {
  2167. return;
  2168. }
  2169. request->LoadPacketData(app->pBuffer, app->size);
  2170. int32 id = request->getType_int32_ByName("id");
  2171. int32 tier = request->getType_int32_ByName("tier");
  2172. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2173. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2174. if (trait_tier != 0xFFFFFFFF) {
  2175. spell = master_spell_list.GetSpell(id, trait_tier);
  2176. if (!spell) {
  2177. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2178. }
  2179. trait_display = true;
  2180. }
  2181. else {
  2182. spell = master_spell_list.GetSpell(id, tier);
  2183. trait_display = false;
  2184. }
  2185. if (spell && sent_spell_details.count(id) == 0) {
  2186. sent_spell_details[id] = true;
  2187. EQ2Packet* app = spell->SerializeSpell(this, false, trait_display);
  2188. //DumpPacket(app);
  2189. QueuePacket(app);
  2190. }
  2191. }
  2192. else if (type == 0) {
  2193. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2194. if (!request) {
  2195. return;
  2196. }
  2197. request->LoadPacketData(app->pBuffer, app->size);
  2198. int32 id = request->getType_int32_ByName("id");
  2199. Item* item = 0;
  2200. // translate from unique id to spawn id for houses
  2201. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2202. bool wasSpawn = false;
  2203. if (spawn)
  2204. {
  2205. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2206. if (item)
  2207. {
  2208. wasSpawn = true;
  2209. item = new Item(item);
  2210. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2211. }
  2212. }
  2213. if (!item)
  2214. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2215. if (!item)
  2216. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2217. if (!item)
  2218. item = master_item_list.GetItem(id);
  2219. if (item) {// && sent_item_details.count(id) == 0){
  2220. sent_item_details[id] = true;
  2221. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2222. //DumpPacket(app);
  2223. QueuePacket(app);
  2224. if (wasSpawn)
  2225. delete item;
  2226. }
  2227. else {
  2228. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2229. DumpPacket(app);
  2230. }
  2231. }
  2232. else if (type == 1) {
  2233. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2234. if (!request) {
  2235. return;
  2236. }
  2237. request->LoadPacketData(app->pBuffer, app->size);
  2238. int32 id = request->getType_int32_ByName("id");
  2239. int32 unique_id = request->getType_int32_ByName("unique_id");
  2240. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2241. if (!item)
  2242. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2243. if (!item)
  2244. item = master_item_list.GetItem(id);
  2245. if (item) {
  2246. sent_item_details[id] = true;
  2247. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2248. //DumpPacket(app);
  2249. QueuePacket(app);
  2250. }
  2251. else {
  2252. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2253. DumpPacket(app);
  2254. }
  2255. }
  2256. else if (type == 2) {
  2257. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2258. if (!request) {
  2259. return;
  2260. }
  2261. request->LoadPacketData(app->pBuffer, app->size);
  2262. int32 id = request->getType_int32_ByName("item_id");
  2263. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2264. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2265. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2266. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2267. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2268. //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);
  2269. Item* item = master_item_list.GetItem(id);
  2270. if (item) {
  2271. //only display popup for non merchant links
  2272. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2273. //DumpPacket(app);
  2274. QueuePacket(app);
  2275. }
  2276. else {
  2277. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2278. DumpPacket(app);
  2279. }
  2280. }
  2281. else if (type == 4) { //spell effect
  2282. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2283. if (!request) {
  2284. return;
  2285. }
  2286. request->LoadPacketData(app->pBuffer, app->size);
  2287. int32 id = request->getType_int32_ByName("id");
  2288. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2289. SpellEffects* effect = player->GetSpellEffect(id);
  2290. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2291. if (effect) {
  2292. int8 tier = effect->tier;
  2293. Spell* spell = master_spell_list.GetSpell(id, tier);
  2294. if (spell && sent_spell_details.count(id) == 0) {
  2295. sent_spell_details[id] = true;
  2296. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, 0x00, 0x81);
  2297. //DumpPacket(app);
  2298. QueuePacket(app);
  2299. }
  2300. }
  2301. }
  2302. else if (type == 5) { // recipe info
  2303. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2304. if (!request)
  2305. return;
  2306. request->LoadPacketData(app->pBuffer, app->size);
  2307. int32 id = request->getType_int32_ByName("unknown_id");
  2308. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2309. if (recipe) {
  2310. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2311. //DumpPacket(app);
  2312. QueuePacket(app);
  2313. }
  2314. }
  2315. else if (type == 6) { // AA spell info
  2316. Spell* spell = 0;
  2317. //Spell* spell2 = 0;
  2318. //AltAdvanceData* data = 0;
  2319. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2320. if (!request)
  2321. return;
  2322. request->LoadPacketData(app->pBuffer, app->size);
  2323. int32 id = request->getType_int32_ByName("id");
  2324. int32 tier = GetPlayer()->GetSpellTier(id);
  2325. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2326. //data = master_aa_list.GetAltAdvancement(id);
  2327. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2328. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2329. spell = master_spell_list.GetSpell(id, 1);
  2330. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2331. sent_spell_details[spell->GetSpellID()] = true;
  2332. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2333. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2334. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2335. //DumpPacket(app);
  2336. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2337. QueuePacket(app);
  2338. //}
  2339. }
  2340. else {
  2341. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2342. DumpPacket(app);
  2343. }
  2344. safe_delete(request);
  2345. }
  2346. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2347. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2348. if (request) {
  2349. request->LoadPacketData(app->pBuffer, app->size);
  2350. int32 id = request->getType_int32_ByName("id");
  2351. int32 bar = request->getType_int32_ByName("hotbar_number");
  2352. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2353. int32 type = request->getType_int32_ByName("type");
  2354. int8 tier = request->getType_int32_ByName("unique_id");
  2355. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2356. Spell* spell = 0;
  2357. if (type == 0xFFFFFFFF)
  2358. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2359. else {
  2360. if (type == QUICKBAR_NORMAL)
  2361. spell = master_spell_list.GetSpell(id, tier);
  2362. if (spell)
  2363. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2364. else
  2365. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2366. }
  2367. safe_delete(request);
  2368. }
  2369. }
  2370. bool Client::Process(bool zone_process) {
  2371. if (!eqs) {
  2372. return false;
  2373. }
  2374. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2375. return true;
  2376. }
  2377. if (new_client_login) {
  2378. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2379. SendLoginInfo();
  2380. new_client_login = false;
  2381. }
  2382. bool ret = true;
  2383. sockaddr_in to;
  2384. memset((char*)&to, 0, sizeof(to));
  2385. to.sin_family = AF_INET;
  2386. to.sin_port = port;
  2387. to.sin_addr.s_addr = ip;
  2388. /************ Get all packets from packet manager out queue and process them ************/
  2389. EQApplicationPacket* app = 0;
  2390. if (eqs && !eqs->CheckActive()) {
  2391. num_active_failures++;
  2392. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2393. if (num_active_failures > 100) {
  2394. return false;
  2395. }
  2396. return true;
  2397. }
  2398. while (ret && eqs && (app = eqs->PopPacket())) {
  2399. ret = HandlePacket(app);
  2400. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2401. delete app;
  2402. }
  2403. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2404. player->ApplyPassiveSpells();
  2405. //database.LoadCharacterActiveSpells(player);
  2406. player->UnlockAllSpells(true);
  2407. should_load_spells = false;
  2408. }
  2409. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2410. {
  2411. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2412. return false;
  2413. }
  2414. if (quest_updates) {
  2415. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2416. ProcessQuestUpdates();
  2417. }
  2418. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2419. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2420. CheckQuestQueue();
  2421. }
  2422. if (pos_update.Check() && player_pos_changed && IsReadyForUpdates() && ( !disconnect_timer || !disconnect_timer->Enabled())) {
  2423. //GetPlayer()->CalculateLocation();
  2424. client_list.CheckPlayersInvisStatus(this);
  2425. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2426. player_pos_changed = false;
  2427. GetCurrentZone()->CheckTransporters(this);
  2428. }
  2429. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2430. lua_interface->UpdateDebugClients(this);
  2431. if (quest_pos_timer.Check())
  2432. CheckPlayerQuestsLocationUpdate();
  2433. if (camp_timer && camp_timer->Check() && getConnection()) {
  2434. getConnection()->SendDisconnect(false);
  2435. safe_delete(camp_timer);
  2436. disconnect_timer = new Timer(2000);
  2437. disconnect_timer->Start();
  2438. }
  2439. if (player->GetSkills()->HasSkillUpdates()) {
  2440. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2441. if (skills) {
  2442. Skill* skill = 0;
  2443. vector<Skill*>::iterator itr;
  2444. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2445. skill = *itr;
  2446. SkillChanged(skill, skill->previous_val, skill->current_val);
  2447. }
  2448. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2449. if (app) QueuePacket(app);
  2450. safe_delete(skills);
  2451. }
  2452. }
  2453. if (disconnect_timer && disconnect_timer->Check()) {
  2454. safe_delete(disconnect_timer);
  2455. ret = false;
  2456. }
  2457. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2458. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2459. safe_delete(current_rez.expire_timer);
  2460. current_rez.expire_timer = 0;
  2461. current_rez.active = false;
  2462. current_rez.caster = 0;
  2463. current_rez.crit = false;
  2464. current_rez.crit_mod = 0;
  2465. current_rez.expire_timer = 0;
  2466. current_rez.heal_name = "";
  2467. current_rez.hp_perc = 0;
  2468. current_rez.mp_perc = 0;
  2469. current_rez.no_calcs = false;
  2470. current_rez.range = 0;
  2471. current_rez.should_delete = false;
  2472. current_rez.spell_name = "";
  2473. current_rez.spell_visual = 0;
  2474. current_rez.subspell = 0;
  2475. }
  2476. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2477. // Quest timers
  2478. Quest* failed_step = 0;
  2479. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2480. if (quest_timers.size() > 0) {
  2481. vector<int32>::iterator itr;
  2482. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2483. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2484. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2485. Quest* quest = player_quests->at(*itr);
  2486. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2487. failed_step = quest;
  2488. break;
  2489. }
  2490. }
  2491. else {
  2492. quest_timers.erase(itr);
  2493. break;
  2494. }
  2495. }
  2496. }
  2497. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2498. if (failed_step)
  2499. failed_step->StepFailed(failed_step->GetTimerStep());
  2500. if (player->ControlFlagsChanged())
  2501. player->SendControlFlagUpdates(this);
  2502. if (!eqs || (eqs && !eqs->CheckActive()))
  2503. ret = false;
  2504. // redundant to client disconnect
  2505. // if(!ret)
  2506. // Save();
  2507. return ret;
  2508. }
  2509. ClientList::ClientList() {
  2510. MClients.SetName("ClientList::MClients");
  2511. }
  2512. ClientList::~ClientList() {
  2513. }
  2514. void ClientList::ReloadQuests() {
  2515. list<Client*>::iterator client_iter;
  2516. Client* client = 0;
  2517. MClients.readlock(__FUNCTION__, __LINE__);
  2518. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2519. client = *client_iter;
  2520. if (client)
  2521. client->ReloadQuests();
  2522. }
  2523. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2524. }
  2525. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2526. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2527. return;
  2528. list<Client*>::iterator client_iter;
  2529. Client* client = 0;
  2530. MClients.readlock(__FUNCTION__, __LINE__);
  2531. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2532. client = *client_iter;
  2533. if (client == owner || client->GetPlayer() == NULL)
  2534. continue;
  2535. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2536. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2537. }
  2538. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2539. }
  2540. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2541. list<Client*>::iterator client_iter;
  2542. Client* client = 0;
  2543. MClients.readlock(__FUNCTION__, __LINE__);
  2544. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2545. client = *client_iter;
  2546. if (!client->GetPlayer())
  2547. continue;
  2548. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2549. }
  2550. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2551. }
  2552. int32 ClientList::Count() {
  2553. return client_list.size();
  2554. }
  2555. void ClientList::Add(Client* client) {
  2556. MClients.writelock(__FUNCTION__, __LINE__);
  2557. client_list.push_back(client);
  2558. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2559. }
  2560. Client* ClientList::FindByAccountID(int32 account_id) {
  2561. list<Client*>::iterator client_iter;
  2562. Client* client = 0;
  2563. Client* ret = 0;
  2564. MClients.readlock(__FUNCTION__, __LINE__);
  2565. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2566. client = *client_iter;
  2567. if (client->GetAccountID() == account_id) {
  2568. ret = client;
  2569. break;
  2570. }
  2571. }
  2572. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2573. return ret;
  2574. }
  2575. Client* ClientList::FindByName(char* charName) {
  2576. list<Client*>::iterator client_iter;
  2577. Client* client = 0;
  2578. Client* ret = 0;
  2579. MClients.readlock(__FUNCTION__, __LINE__);
  2580. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2581. client = *client_iter;
  2582. if (!client || !client->GetPlayer())
  2583. continue;
  2584. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2585. ret = client;
  2586. break;
  2587. }
  2588. }
  2589. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2590. return ret;
  2591. }
  2592. Client* ClientList::Get(int32 ip, int16 port) {
  2593. list<Client*>::iterator client_iter;
  2594. Client* client = 0;
  2595. Client* ret = 0;
  2596. MClients.readlock(__FUNCTION__, __LINE__);
  2597. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2598. client = *client_iter;
  2599. if (client->GetIP() == ip && client->GetPort() == port) {
  2600. ret = client;
  2601. break;
  2602. }
  2603. }
  2604. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2605. return ret;
  2606. }
  2607. void ClientList::Process() {
  2608. list<Client*>::iterator client_iter;
  2609. list<Client*>::iterator erase_iter;
  2610. Client* client = 0;
  2611. MClients.readlock(__FUNCTION__, __LINE__);
  2612. erase_iter = client_list.end();
  2613. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2614. client = *client_iter;
  2615. // have a sanity check because the client list can sometimes obtain null client pointers
  2616. if (!client || (!client->Process() || client->remove_from_list)) {
  2617. erase_iter = client_iter;
  2618. break;
  2619. }
  2620. }
  2621. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2622. if (erase_iter != client_list.end()) {
  2623. client = *erase_iter;
  2624. MClients.writelock(__FUNCTION__, __LINE__);
  2625. client_list.erase(erase_iter);
  2626. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2627. if (client && !client->remove_from_list) {
  2628. struct in_addr in;
  2629. in.s_addr = client->GetIP();
  2630. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2631. safe_delete(client);
  2632. }
  2633. }
  2634. }
  2635. void ClientList::RemoveConnection(EQStream* eqs) {
  2636. Client* client;
  2637. if (eqs) {
  2638. list<Client*>::iterator client_iter;
  2639. MClients.readlock(__FUNCTION__, __LINE__);
  2640. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2641. client = *client_iter;
  2642. if (client->getConnection() == eqs)
  2643. client->Disconnect(false);
  2644. }
  2645. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2646. }
  2647. }
  2648. bool ClientList::ContainsStream(EQStream* eqs) {
  2649. if (!eqs) {
  2650. return false;
  2651. }
  2652. list<Client*>::iterator client_iter;
  2653. bool ret = false;
  2654. MClients.readlock(__FUNCTION__, __LINE__);
  2655. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2656. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2657. ret = true;
  2658. break;
  2659. }
  2660. }
  2661. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2662. return ret;
  2663. }
  2664. void ClientList::Remove(Client* client, bool remove_data) {
  2665. client->remove_from_list = true;
  2666. if (remove_data) {
  2667. safe_delete(client);
  2668. }
  2669. }
  2670. void Client::SetCurrentZone(int32 id) {
  2671. if (current_zone) {
  2672. //current_zone->GetCombat()->RemoveHate(player);
  2673. current_zone->RemoveSpawn(false, player, false);
  2674. }
  2675. SetCurrentZone(zone_list.Get(id));
  2676. }
  2677. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2678. if (current_zone) {
  2679. //current_zone->GetCombat()->RemoveHate(player);
  2680. current_zone->RemoveSpawn(false, player, false);
  2681. }
  2682. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2683. }
  2684. ZoneServer* Client::GetCurrentZone() {
  2685. return current_zone;
  2686. }
  2687. void Client::SimpleMessage(int8 color, const char* message) {
  2688. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  2689. if (command_packet) {
  2690. command_packet->setDataByName("color", color);
  2691. command_packet->setMediumStringByName("text", message);
  2692. command_packet->setDataByName("unknown02", 0x00ff);
  2693. EQ2Packet* outapp = command_packet->serialize();
  2694. QueuePacket(outapp);
  2695. safe_delete(command_packet);
  2696. }
  2697. }
  2698. void Client::SendSpellUpdate(Spell* spell) {
  2699. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  2700. if (packet) {
  2701. int8 xxx = spell->GetSpellData()->is_aa;
  2702. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  2703. packet->setDataByName("spell_id", spell->GetSpellID());
  2704. packet->setDataByName("unique_id", spell->GetSpellTier());
  2705. packet->setDataByName("spell_name", spell->GetName());
  2706. packet->setDataByName("unknown", xxx);
  2707. packet->setDataByName("display_spell_tier", 1);
  2708. packet->setDataByName("unknown3", 1);
  2709. packet->setDataByName("tier", spell->GetSpellTier());
  2710. packet->setDataByName("icon", spell->GetSpellIcon());
  2711. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  2712. packet->setDataByName("unknown5", 0xFFFFFFFF);
  2713. //packet->PrintPacket();
  2714. EQ2Packet* outapp = packet->serialize();
  2715. //DumpPacket(outapp);
  2716. QueuePacket(outapp);
  2717. safe_delete(packet);
  2718. }
  2719. }
  2720. void Client::Message(int8 type, const char* message, ...) {
  2721. va_list argptr;
  2722. char buffer[4096];
  2723. va_start(argptr, message);
  2724. vsnprintf(buffer, sizeof(buffer), message, argptr);
  2725. va_end(argptr);
  2726. SimpleMessage(type, buffer);
  2727. }
  2728. void Client::Disconnect(bool send_disconnect)
  2729. {
  2730. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  2731. SetConnected(false);
  2732. if (send_disconnect && getConnection())
  2733. getConnection()->SendDisconnect(true);
  2734. this->Save();
  2735. this->GetPlayer()->WritePlayerStatistics();
  2736. eqs = 0;
  2737. }
  2738. bool Client::Summon(const char* search_name) {
  2739. Spawn* target = 0;
  2740. if (search_name || GetPlayer()->GetTarget()) {
  2741. Client* search_client = 0;
  2742. if (search_name) {
  2743. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  2744. if (target && target->IsPlayer())
  2745. search_client = GetCurrentZone()->GetClientBySpawn(target);
  2746. if (!target) {
  2747. search_client = zone_list.GetClientByCharName(string(search_name));
  2748. if (search_client)
  2749. target = search_client->GetPlayer();
  2750. }
  2751. }
  2752. else
  2753. target = GetPlayer()->GetTarget();
  2754. if (target && target != GetPlayer()) {
  2755. target->SetX(GetPlayer()->GetX());
  2756. target->SetY(GetPlayer()->GetY());
  2757. target->SetZ(GetPlayer()->GetZ());
  2758. target->SetHeading(GetPlayer()->GetHeading());
  2759. if (!target->IsPlayer()) {
  2760. target->SetSpawnOrigX(target->GetX());
  2761. target->SetSpawnOrigY(target->GetY());
  2762. target->SetSpawnOrigZ(target->GetZ());
  2763. target->SetSpawnOrigHeading(target->GetHeading());
  2764. }
  2765. target->SetLocation(GetPlayer()->GetLocation());
  2766. }
  2767. else if (target)
  2768. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  2769. if (search_client && search_client != this) {
  2770. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  2771. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  2772. if (search_client->GetCurrentZone() != GetCurrentZone())
  2773. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  2774. else {
  2775. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  2776. if (app)
  2777. search_client->QueuePacket(app);
  2778. }
  2779. }
  2780. }
  2781. if (!target)
  2782. return false;
  2783. else
  2784. return true;
  2785. }
  2786. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  2787. ZoneServer* instance_zone = NULL;
  2788. int8 instanceType = 0;
  2789. // determine if this is a group instanced zone that already exists
  2790. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  2791. if (instance_zone != NULL)
  2792. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  2793. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  2794. {
  2795. // best to check if we already have our own instance!
  2796. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  2797. if (data) {
  2798. // If lockout instances check to see if we are locked out
  2799. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  2800. int32 time = 0;
  2801. // Check success timer
  2802. if (data->last_success_timestamp > 0) {
  2803. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  2804. // Timer has not expired yet can't re enter
  2805. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2806. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  2807. }
  2808. }
  2809. // Check failure timer
  2810. if (data->last_failure_timestamp > 0) {
  2811. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  2812. // Timer has not expired yet
  2813. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  2814. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  2815. }
  2816. }
  2817. // Time > 0 then we are locked out, make the message and send it and return true
  2818. if (time > 0) {
  2819. string time_msg = "";
  2820. int16 hour;
  2821. int8 min;
  2822. int8 sec;
  2823. hour = time / 3600;
  2824. time = time % 3600;
  2825. min = time / 60;
  2826. time = time % 60;
  2827. sec = time;
  2828. if (hour > 0) {
  2829. char temp[10];
  2830. sprintf(temp, " %i", hour);
  2831. time_msg.append(temp);
  2832. time_msg.append(" hour");
  2833. time_msg.append((hour > 1) ? "s" : "");
  2834. }
  2835. if (min > 0) {
  2836. char temp[5];
  2837. sprintf(temp, " %i", min);
  2838. time_msg.append(temp);
  2839. time_msg.append(" minute");
  2840. time_msg.append((min > 1) ? "s" : "");
  2841. }
  2842. // Only add seconds if minutes and hours are 0
  2843. if (hour == 0 && min == 0 && sec > 0) {
  2844. char temp[5];
  2845. sprintf(temp, " %i", sec);
  2846. time_msg.append(temp);
  2847. time_msg.append(" second");
  2848. time_msg.append((sec > 1) ? "s" : "");
  2849. }
  2850. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  2851. return true;
  2852. }
  2853. }
  2854. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  2855. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  2856. // 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
  2857. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  2858. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  2859. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  2860. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  2861. }
  2862. else
  2863. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  2864. data->instance_id = instance_zone->GetInstanceID();
  2865. }
  2866. }
  2867. else {
  2868. switch (instanceType)
  2869. {
  2870. case SOLO_LOCKOUT_INSTANCE:
  2871. case GROUP_LOCKOUT_INSTANCE:
  2872. case RAID_LOCKOUT_INSTANCE:
  2873. {
  2874. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2875. if (instance_zone) {
  2876. // 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
  2877. // so delete `instances` entry for the zone when it shuts down.
  2878. 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());
  2879. if (db_id > 0)
  2880. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  2881. }
  2882. break;
  2883. }
  2884. case SOLO_PERSIST_INSTANCE:
  2885. case GROUP_PERSIST_INSTANCE:
  2886. case RAID_PERSIST_INSTANCE:
  2887. {
  2888. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2889. if (instance_zone) {
  2890. 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());
  2891. if (db_id > 0)
  2892. 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()));
  2893. }
  2894. break;
  2895. }
  2896. case PUBLIC_INSTANCE:
  2897. case TRADESKILL_INSTANCE:
  2898. {
  2899. // if its public/tradeskill, look for a public already setup
  2900. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  2901. if (instance_zone) {
  2902. // Check the current population against the max population, if greater or equal start a new version
  2903. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  2904. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2905. }
  2906. else
  2907. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2908. break;
  2909. }
  2910. case PERSONAL_HOUSE_INSTANCE:
  2911. case GUILD_HOUSE_INSTANCE:
  2912. {
  2913. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  2914. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  2915. // with the OP_EnterHouseMsg opcode
  2916. break;
  2917. }
  2918. case QUEST_INSTANCE:
  2919. {
  2920. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  2921. break;
  2922. /*
  2923. 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`;
  2924. */
  2925. }
  2926. default:
  2927. {
  2928. // NONE
  2929. }
  2930. }
  2931. }
  2932. if (instance_zone != NULL)
  2933. Zone(instance_zone, zone_coords_valid);
  2934. }
  2935. if (instance_zone != NULL)
  2936. return true;
  2937. else
  2938. return false;
  2939. }
  2940. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  2941. Spawn* target = 0;
  2942. if (search_name || GetPlayer()->GetTarget()) {
  2943. Client* search_client = 0;
  2944. if (search_name) {
  2945. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  2946. if (!target) {
  2947. search_client = zone_list.GetClientByCharName(search_name);
  2948. if (search_client)
  2949. target = search_client->GetPlayer();
  2950. }
  2951. if (target)
  2952. GetPlayer()->SetTarget(target);
  2953. }
  2954. else
  2955. target = GetPlayer()->GetTarget();
  2956. if (target && target != GetPlayer()) {
  2957. GetPlayer()->SetX(target->GetX());
  2958. GetPlayer()->SetY(target->GetY());
  2959. GetPlayer()->SetZ(target->GetZ());
  2960. GetPlayer()->SetHeading(target->GetHeading());
  2961. GetPlayer()->SetLocation(target->GetLocation());
  2962. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  2963. }
  2964. else if (target)
  2965. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  2966. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  2967. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  2968. else if (target) {
  2969. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  2970. if (app)
  2971. QueuePacket(app);
  2972. }
  2973. }
  2974. if (!target)
  2975. return false;
  2976. else
  2977. return true;
  2978. }
  2979. bool Client::CheckZoneAccess(const char* zoneName) {
  2980. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  2981. ZoneServer* zone = zone_list.Get(zoneName, false);
  2982. // JA: implemented /zone lock|unlock commands (2012.07.28)
  2983. if (zone && zone->GetZoneLockState())
  2984. {
  2985. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  2986. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  2987. return false;
  2988. }
  2989. sint16 zoneMinStatus = 0;
  2990. int16 zoneMinLevel = 0;
  2991. int16 zoneMaxLevel = 0;
  2992. int16 zoneMinVersion = 0;
  2993. if (!zone)
  2994. {
  2995. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  2996. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  2997. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  2998. return true;
  2999. }
  3000. }
  3001. else
  3002. {
  3003. zoneMinStatus = zone->GetMinimumStatus();
  3004. zoneMinLevel = zone->GetMinimumLevel();
  3005. zoneMaxLevel = zone->GetMaximumLevel();
  3006. zoneMinVersion = zone->GetMinimumVersion();
  3007. }
  3008. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3009. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3010. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3011. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3012. {
  3013. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3014. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3015. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3016. return false;
  3017. }
  3018. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3019. {
  3020. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3021. {
  3022. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3023. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3024. return false;
  3025. }
  3026. }
  3027. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3028. {
  3029. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3030. {
  3031. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3032. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3033. return false;
  3034. }
  3035. }
  3036. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3037. {
  3038. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3039. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3040. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3041. {
  3042. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3043. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3044. return false;
  3045. }
  3046. }
  3047. return true;
  3048. }
  3049. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  3050. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  3051. }
  3052. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  3053. if (!new_zone) {
  3054. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3055. return;
  3056. }
  3057. client_zoning = true;
  3058. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3059. player->SetResurrecting(true);
  3060. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3061. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3062. // Remove players pet from zone if there is one
  3063. player->DismissPet((NPC*)player->GetPet());
  3064. player->DismissPet((NPC*)player->GetCharmedPet());
  3065. player->DismissPet((NPC*)player->GetDeityPet());
  3066. player->DismissPet((NPC*)player->GetCosmeticPet());
  3067. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3068. GetCurrentZone()->RemoveSpawn(false, player, false);
  3069. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3070. SetCurrentZone(new_zone);
  3071. if (player->GetGroupMemberInfo())
  3072. {
  3073. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3074. player->UpdateGroupMemberInfo();
  3075. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3076. }
  3077. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3078. if (set_coords)
  3079. {
  3080. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3081. __FUNCTION__,
  3082. GetCurrentZone()->GetSafeX(),
  3083. GetCurrentZone()->GetSafeY(),
  3084. GetCurrentZone()->GetSafeZ(),
  3085. GetCurrentZone()->GetSafeHeading(),
  3086. new_zone->GetZoneName()
  3087. );
  3088. player->SetX(GetCurrentZone()->GetSafeX());
  3089. player->SetY(GetCurrentZone()->GetSafeY());
  3090. player->SetZ(GetCurrentZone()->GetSafeZ());
  3091. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3092. }
  3093. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3094. Save();
  3095. char* new_zone_ip = 0;
  3096. struct in_addr in;
  3097. in.s_addr = this->GetIP();
  3098. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  3099. new_zone_ip = net.GetInternalWorldAddress();
  3100. else
  3101. new_zone_ip = net.GetWorldAddress();
  3102. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3103. int32 key = Timer::GetUnixTimeStamp();
  3104. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3105. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3106. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3107. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3108. }
  3109. void Client::Zone(const char* new_zone, bool set_coords)
  3110. {
  3111. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3112. Zone(zone_list.Get(new_zone), set_coords);
  3113. }
  3114. float Client::DistanceFrom(Client* client) {
  3115. float ret = 0;
  3116. if (client && client != this) {
  3117. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3118. ret = sqrt(ret);
  3119. }
  3120. return ret;
  3121. }
  3122. void Client::DetermineCharacterUpdates() {
  3123. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3124. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3125. cdu->account_id = GetAccountID();
  3126. cdu->char_id = GetCharacterID();
  3127. int32 timestamp = Timer::GetUnixTimeStamp();
  3128. int8 flag = GetTimeStampFlag();
  3129. if (flag & LEVEL_UPDATE_FLAG)
  3130. {
  3131. cdu->update_field = LEVEL_UPDATE_FLAG;
  3132. cdu->update_data = player->GetLevel();
  3133. loginserver.SendPacket(outpack);
  3134. }
  3135. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3136. if (flag & CLASS_UPDATE_FLAG)
  3137. {
  3138. cdu->update_field = CLASS_UPDATE_FLAG;
  3139. cdu->update_data = player->GetAdventureClass();
  3140. loginserver.SendPacket(outpack);
  3141. }
  3142. if (flag & GENDER_UPDATE_FLAG)
  3143. {
  3144. cdu->update_field = GENDER_UPDATE_FLAG;
  3145. cdu->update_data = player->GetGender();
  3146. loginserver.SendPacket(outpack);
  3147. }
  3148. if (flag & DELETE_UPDATE_FLAG) {
  3149. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3150. }
  3151. safe_delete(outpack); // Zone, armor and name use a different structure
  3152. if (flag & RACE_UPDATE_FLAG)
  3153. {
  3154. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3155. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3156. ru->account_id = GetAccountID();
  3157. ru->char_id = GetCharacterID();
  3158. ru->race = player->GetRace();
  3159. ru->model_type = player->GetModelType();
  3160. loginserver.SendPacket(outpack);
  3161. safe_delete(outpack);
  3162. }
  3163. if (flag & ZONE_UPDATE_FLAG) {
  3164. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3165. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3166. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3167. czu->account_id = GetAccountID();
  3168. czu->char_id = GetCharacterID();
  3169. czu->zone_id = GetCurrentZone()->GetZoneID();
  3170. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3171. czu->zone_length = strlen(zone_file);
  3172. if (czu->zone_length > 64)
  3173. czu->zone_length = 64;
  3174. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3175. loginserver.SendPacket(outpack);
  3176. safe_delete(outpack);
  3177. }
  3178. if (flag & ARMOR_UPDATE_FLAG) {
  3179. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3180. }
  3181. if (flag & NAME_UPDATE_FLAG) {
  3182. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3183. }
  3184. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3185. }
  3186. void Client::Save() {
  3187. if (GetCharacterID() == 0)
  3188. return;
  3189. if (current_zone) {
  3190. DetermineCharacterUpdates();
  3191. UpdateCharacterInstances();
  3192. database.Save(this);
  3193. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3194. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3195. GetPlayer()->ResetQuickbarNeeded();
  3196. }
  3197. database.SaveItems(this);
  3198. database.SaveBuyBacks(this);
  3199. GetPlayer()->SaveHistory();
  3200. GetPlayer()->SaveLUAHistory();
  3201. }
  3202. }
  3203. void Client::UpdateCharacterInstances() {
  3204. if (GetPlayer() != NULL)
  3205. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3206. /*if ( GetPlayer() != NULL )
  3207. {
  3208. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3209. // to use for applying the update to each instances timer
  3210. int32 lastSaveTS = GetLastSavedTimeStamp();
  3211. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3212. int32 diffTS = newSaveTS - lastSaveTS;
  3213. // update instance timers
  3214. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3215. // update with the new timestamp and save the db
  3216. this->SetLastSavedTimeStamp(newSaveTS);
  3217. }*/
  3218. }
  3219. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3220. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3221. if (packet) {
  3222. packet->LoadPacketData(app->pBuffer, app->size);
  3223. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3224. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3225. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3226. vector<EntityCommand*> commands;
  3227. vector<EntityCommand*> delete_commands;
  3228. if (out && spawn) {
  3229. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3230. {
  3231. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3232. if (!spawn->primary_command_list[i]->default_allow_list)
  3233. {
  3234. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3235. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3236. continue;
  3237. }
  3238. else
  3239. {
  3240. // default is allow list, only deny if added to the list as deny (false itr second)
  3241. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3242. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3243. continue;
  3244. }
  3245. commands.push_back(spawn->primary_command_list[i]);
  3246. }
  3247. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3248. commands.push_back(spawn->secondary_command_list[i]);
  3249. if (spawn->IsPlayer()) {
  3250. if (player->IsFriend(spawn->GetName()))
  3251. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3252. else
  3253. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3254. if (player->IsIgnored(spawn->GetName()))
  3255. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3256. else
  3257. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3258. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3259. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3260. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3261. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3262. }
  3263. }
  3264. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3265. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3266. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3267. }
  3268. out->setDataByName("spawn_id", spawn_id);
  3269. out->setArrayLengthByName("num_verbs", commands.size());
  3270. for (int32 i = 0; i < commands.size(); i++) {
  3271. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3272. out->setArrayDataByName("distance", commands[i]->distance, i);
  3273. if (commands[i]->error_text.length() == 0)
  3274. out->setArrayAddToPacketByName("error", false, i);
  3275. else {
  3276. out->setArrayDataByName("display_error", 1, i);
  3277. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3278. }
  3279. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3280. }
  3281. EQ2Packet* outapp = out->serialize();
  3282. //DumpPacket(outapp);
  3283. QueuePacket(outapp);
  3284. safe_delete(out);
  3285. for (int32 i = 0; i < delete_commands.size(); i++) {
  3286. safe_delete(delete_commands[i]);
  3287. }
  3288. }
  3289. safe_delete(packet);
  3290. }
  3291. }
  3292. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3293. if (previous_value != new_value) {
  3294. Message(CHANNEL_COLOR_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3295. char tmp[200] = { 0 };
  3296. 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);
  3297. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75, 0xFF, 0xFF, 0xFF);
  3298. }
  3299. }
  3300. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3301. {
  3302. /* JA notes on the unknown:
  3303. 2 = ding glimmer
  3304. 16 = Achievement Unlocked
  3305. 6 no longer does anything
  3306. */
  3307. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3308. if (packet) {
  3309. packet->setDataByName("unknown", unknown);
  3310. packet->setMediumStringByName("text", text);
  3311. if (type && strlen(type) > 0)
  3312. packet->setMediumStringByName("message_type", type);
  3313. packet->setDataByName("size", size);
  3314. packet->setDataByName("red", red);
  3315. packet->setDataByName("green", green);
  3316. packet->setDataByName("blue", blue);
  3317. QueuePacket(packet->serialize());
  3318. safe_delete(packet);
  3319. }
  3320. }
  3321. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3322. if (new_level < 1) {
  3323. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3324. return;
  3325. }
  3326. if (player->GetLevel() != new_level) {
  3327. player->SetLevel(new_level);
  3328. if (player->GetGroupMemberInfo()) {
  3329. player->UpdateGroupMemberInfo();
  3330. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3331. }
  3332. }
  3333. if (new_level > old_level)
  3334. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3335. if (player->GetPet()) {
  3336. NPC* pet = (NPC*)player->GetPet();
  3337. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3338. pet->SetLevel(new_level);
  3339. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3340. if (command_packet) {
  3341. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3342. command_packet->setDataByName("anim_type", 1753);
  3343. QueuePacket(command_packet->serialize());
  3344. safe_delete(command_packet);
  3345. }
  3346. }
  3347. }
  3348. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3349. if (level_update) {
  3350. level_update->setDataByName("old_level", old_level);
  3351. level_update->setDataByName("new_level", new_level);
  3352. QueuePacket(level_update->serialize());
  3353. safe_delete(level_update);
  3354. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3355. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3356. }
  3357. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3358. if (command_packet) {
  3359. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3360. command_packet->setDataByName("anim_type", 1753);
  3361. QueuePacket(command_packet->serialize());
  3362. safe_delete(command_packet);
  3363. }
  3364. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3365. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3366. SendNewSpells(player->GetAdventureClass());
  3367. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3368. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3369. GetPlayer()->ChangePrimaryWeapon();
  3370. GetPlayer()->ChangeSecondaryWeapon();
  3371. GetPlayer()->ChangeRangedWeapon();
  3372. GetPlayer()->GetInfoStruct()->level = new_level;
  3373. // GetPlayer()->SetLevel(new_level);
  3374. 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__);
  3375. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3376. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3377. GetPlayer()->CalculateBonuses();
  3378. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3379. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3380. InfoStruct* info = player->GetInfoStruct();
  3381. info->agi_base = new_level * 2 + 15;
  3382. info->intel_base = new_level * 2 + 15;
  3383. info->wis_base = new_level * 2 + 15;
  3384. info->str_base = new_level * 2 + 15;
  3385. info->sta_base = new_level * 2 + 15;
  3386. info->cold_base = (int16)(new_level * 1.5 + 10);
  3387. info->heat_base = (int16)(new_level * 1.5 + 10);
  3388. info->disease_base = (int16)(new_level * 1.5 + 10);
  3389. info->mental_base = (int16)(new_level * 1.5 + 10);
  3390. info->magic_base = (int16)(new_level * 1.5 + 10);
  3391. info->divine_base = (int16)(new_level * 1.5 + 10);
  3392. info->poison_base = (int16)(new_level * 1.5 + 10);
  3393. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3394. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3395. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3396. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3397. GetPlayer()->SetCharSheetChanged(true);
  3398. Message(CHANNEL_COLOR_EXP, "You are now level %i!", new_level);
  3399. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3400. int16 new_skill_cap = 5 * new_level;
  3401. PlayerSkillList* player_skills = player->GetSkills();
  3402. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3403. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3404. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3405. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3406. if (new_level > player->GetTSLevel())
  3407. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3408. Guild* guild = GetPlayer()->GetGuild();
  3409. if (guild) {
  3410. int8 event_type = 0;
  3411. if (new_level < 10)
  3412. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3413. else if (new_level == 10)
  3414. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3415. else if (new_level >= 11 && new_level < 20)
  3416. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3417. else if (new_level == 20)
  3418. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3419. else if (new_level >= 21 && new_level < 30)
  3420. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3421. else if (new_level == 30)
  3422. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3423. else if (new_level >= 31 && new_level < 40)
  3424. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3425. else if (new_level == 40)
  3426. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3427. else if (new_level >= 41 && new_level < 50)
  3428. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3429. else if (new_level == 50)
  3430. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3431. else if (new_level >= 51 && new_level < 60)
  3432. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3433. else if (new_level == 60)
  3434. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3435. else if (new_level >= 61 && new_level < 70)
  3436. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3437. else if (new_level == 70)
  3438. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3439. else if (new_level >= 71 && new_level < 80)
  3440. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3441. else if (new_level == 80)
  3442. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3443. 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());
  3444. 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());
  3445. guild->UpdateGuildMemberInfo(GetPlayer());
  3446. guild->SendGuildMember(GetPlayer());
  3447. guild->SendGuildMemberList();
  3448. }
  3449. // Need to send the trait list every time the players level changes
  3450. // Also need to force the char sheet update or else there can be a large delay from when you level
  3451. // to when you are actually able to select traits.
  3452. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3453. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3454. master_aa_list.DisplayAA(this, 0, 0);
  3455. if (GetPlayer()->SpawnedBots.size() > 0) {
  3456. map<int32, int32>::iterator itr;
  3457. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3458. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3459. if (bot && bot->IsBot())
  3460. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3461. }
  3462. }
  3463. }
  3464. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3465. if (new_level < 1) {
  3466. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3467. return;
  3468. }
  3469. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3470. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3471. return;
  3472. }
  3473. if (new_level > old_level)
  3474. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3475. if (player->GetTSLevel() != new_level) {
  3476. player->SetTSLevel(new_level);
  3477. if (player->GetGroupMemberInfo()) {
  3478. player->UpdateGroupMemberInfo();
  3479. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3480. }
  3481. }
  3482. // Only tradeskill skills should increace, and then only those related to your class
  3483. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3484. if (level_update) {
  3485. level_update->setDataByName("old_level", old_level);
  3486. level_update->setDataByName("new_level", new_level);
  3487. level_update->setDataByName("type", 1);
  3488. QueuePacket(level_update->serialize());
  3489. safe_delete(level_update);
  3490. }
  3491. // Need to make tradeskill versions of the following
  3492. //SendNewSpells(player->GetAdventureClass());
  3493. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3494. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3495. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3496. if (command_packet) {
  3497. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3498. command_packet->setDataByName("anim_type", 1753);
  3499. QueuePacket(command_packet->serialize());
  3500. safe_delete(command_packet);
  3501. }
  3502. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3503. GetPlayer()->SetTSLevel(new_level);
  3504. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3505. GetPlayer()->SetCharSheetChanged(true);
  3506. Message(CHANNEL_COLOR_WHITE, "Your tradeskill level is now %i!", new_level);
  3507. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3508. PlayerSkillList* player_skills = player->GetSkills();
  3509. int16 specialize_skill_cap = new_level * 5;
  3510. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3511. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3512. int8 ts_class = player->GetTradeskillClass();
  3513. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3514. int32 skill_id_1, skill_id_2, skill_id_3;
  3515. switch (base_ts_class) {
  3516. case ARTISAN:
  3517. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3518. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3519. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3520. break;
  3521. case OUTFITTER:
  3522. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3523. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3524. skill_id_1 = SKILL_ID_TAILORING;
  3525. skill_id_2 = SKILL_ID_METALSHAPING;
  3526. skill_id_3 = SKILL_ID_METALWORKING;
  3527. if (ts_class == TAILOR) {
  3528. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3529. skill_id_1 = 0;
  3530. }
  3531. else if (ts_class == ARMORER) {
  3532. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3533. skill_id_2 = 0;
  3534. }
  3535. else if (ts_class == WEAPONSMITH) {
  3536. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3537. skill_id_3 = 0;
  3538. }
  3539. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3540. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3541. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3542. break;
  3543. case SCHOLAR:
  3544. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3545. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3546. skill_id_1 = SKILL_ID_SCRIBING;
  3547. skill_id_2 = SKILL_ID_CHEMISTRY;
  3548. skill_id_3 = SKILL_ID_ARTIFICING;
  3549. if (ts_class == SAGE) {
  3550. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3551. skill_id_1 = 0;
  3552. }
  3553. else if (ts_class == ALCHEMIST) {
  3554. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3555. skill_id_2 = 0;
  3556. }
  3557. else if (ts_class == JEWELER) {
  3558. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3559. skill_id_3 = 0;
  3560. }
  3561. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3562. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3563. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3564. break;
  3565. case CRAFTSMAN:
  3566. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3567. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3568. skill_id_1 = SKILL_ID_ARTISTRY;
  3569. skill_id_2 = SKILL_ID_FLETCHING;
  3570. skill_id_3 = SKILL_ID_SCULPTING;
  3571. if (ts_class == PROVISIONER) {
  3572. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3573. skill_id_1 = 0;
  3574. }
  3575. else if (ts_class == WOODWORKER) {
  3576. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3577. skill_id_2 = 0;
  3578. }
  3579. else if (ts_class == CARPENTER) {
  3580. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3581. skill_id_3 = 0;
  3582. }
  3583. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3584. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3585. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3586. break;
  3587. default:
  3588. break;
  3589. }
  3590. if (new_level > player->GetAdventureClass())
  3591. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  3592. Guild* guild = GetPlayer()->GetGuild();
  3593. if (guild) {
  3594. int8 event_type = 0;
  3595. if (new_level < 10)
  3596. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  3597. else if (new_level == 10)
  3598. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  3599. else if (new_level >= 11 && new_level < 20)
  3600. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  3601. else if (new_level == 20)
  3602. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  3603. else if (new_level >= 21 && new_level < 30)
  3604. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  3605. else if (new_level == 30)
  3606. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  3607. else if (new_level >= 31 && new_level < 40)
  3608. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  3609. else if (new_level == 40)
  3610. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  3611. else if (new_level >= 41 && new_level < 50)
  3612. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  3613. else if (new_level == 50)
  3614. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  3615. else if (new_level >= 51 && new_level < 60)
  3616. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  3617. else if (new_level == 60)
  3618. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  3619. else if (new_level >= 61 && new_level < 70)
  3620. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  3621. else if (new_level == 70)
  3622. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  3623. else if (new_level >= 71 && new_level < 80)
  3624. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  3625. else if (new_level == 80)
  3626. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  3627. 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());
  3628. 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());
  3629. guild->UpdateGuildMemberInfo(GetPlayer());
  3630. guild->SendGuildMember(GetPlayer());
  3631. guild->SendGuildMemberList();
  3632. }
  3633. // Need to send the trait list every time the players level changes
  3634. // Also need to force the char sheet update or else there can be a large delay from when you level
  3635. // to when you are actually able to select traits.
  3636. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3637. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3638. }
  3639. void Client::SendPendingLoot(int32 total_coins, Entity* entity) {
  3640. if (entity)
  3641. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  3642. }
  3643. void Client::CloseLoot() {
  3644. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  3645. packet->setDataByName("window_id", 4);
  3646. EQ2Packet* outapp = packet->serialize();
  3647. //DumpPacket(outapp);
  3648. QueuePacket(outapp);
  3649. safe_delete(packet);
  3650. }
  3651. string Client::GetCoinMessage(int32 total_coins) {
  3652. if (total_coins == 0) {
  3653. return " 0 Copper";
  3654. }
  3655. char tmp[64] = { 0 };
  3656. string message = "";
  3657. int32 val = 0;
  3658. if (total_coins >= 1000000) {
  3659. val = total_coins / 1000000;
  3660. total_coins -= 1000000 * val;
  3661. sprintf(tmp, " %u Platinum", val);
  3662. message.append(tmp);
  3663. memset(tmp, 0, 64);
  3664. }
  3665. if (total_coins >= 10000) {
  3666. val = total_coins / 10000;
  3667. total_coins -= 10000 * val;
  3668. sprintf(tmp, " %u Gold", val);
  3669. message.append(tmp);
  3670. memset(tmp, 0, 64);
  3671. }
  3672. if (total_coins >= 100) {
  3673. val = total_coins / 100;
  3674. total_coins -= 100 * val;
  3675. sprintf(tmp, " %u Silver", val);
  3676. message.append(tmp);
  3677. memset(tmp, 0, 64);
  3678. }
  3679. if (total_coins > 0) {
  3680. sprintf(tmp, " %u Copper", (int32)total_coins);
  3681. message.append(tmp);
  3682. }
  3683. return message;
  3684. }
  3685. void Client::Loot(int32 total_coins, vector<Item*>* items, Entity* entity) {
  3686. if (!entity) {
  3687. CloseLoot();
  3688. return;
  3689. }
  3690. if (total_coins > 0) {
  3691. player->AddCoins(total_coins);
  3692. //PlaySound("coin_cha_ching");
  3693. string message = "";
  3694. if (entity->GetHP() == 0) {
  3695. message = "You loot ";
  3696. entity->SetLootCoins(0);
  3697. }
  3698. else
  3699. message = "You receive ";
  3700. message.append(GetCoinMessage(total_coins));
  3701. if (entity->GetHP() == 0)
  3702. message.append(" from the corpse of ").append(entity->GetName());
  3703. int8 type = CHANNEL_COLOR_LOOT;
  3704. if (GetVersion() >= 1208)
  3705. type = CHANNEL_LOOT;
  3706. else if (GetVersion() >= 973)
  3707. type = CHANNEL_COLOR_NEW_LOOT;
  3708. SimpleMessage(type, message.c_str());
  3709. }
  3710. if (!items || items->size() == 0)
  3711. CloseLoot();
  3712. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  3713. if (packet) {
  3714. vector<Item*>::iterator itr;
  3715. int32 packet_size = 0;
  3716. if (items && items->size() > 0) {
  3717. packet->setDataByName("loot_count", items->size());
  3718. packet->setDataByName("display", 1);
  3719. }
  3720. packet->setDataByName("unknown2", 1);
  3721. if (version >= 1096)
  3722. packet->setDataByName("unknown3", 0x78);
  3723. else
  3724. packet->setDataByName("unknown3", 0x3C);
  3725. packet->setDataByName("loot_id", entity->GetID());
  3726. EQ2Packet* tmpPacket = packet->serialize();
  3727. packet_size += tmpPacket->size;
  3728. uchar* data = 0;
  3729. if (items && items->size() > 0) {
  3730. data = new uchar[items->size() * 1000 + packet_size];
  3731. memset(data, 0, items->size() * 1000 + packet_size);
  3732. }
  3733. else {
  3734. data = new uchar[packet_size];
  3735. memset(data, 0, packet_size);
  3736. }
  3737. uchar* ptr = data;
  3738. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  3739. ptr += tmpPacket->size;
  3740. safe_delete(tmpPacket);
  3741. Item* item = 0;
  3742. if (items && items->size() > 0) {
  3743. for (itr = items->begin(); itr != items->end(); itr++) {
  3744. item = *itr;
  3745. memcpy(ptr, &item->details.item_id, sizeof(int32));
  3746. ptr += sizeof(int32);
  3747. packet_size += sizeof(int32);
  3748. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  3749. int8 offset = 0;
  3750. if (GetVersion() >= 1188) {
  3751. offset = 13;
  3752. }
  3753. else if (GetVersion() >= 860) {
  3754. offset = 11;
  3755. }
  3756. else {
  3757. offset = 10;
  3758. }
  3759. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  3760. ptr += tmpPacket->size - offset;
  3761. packet_size += tmpPacket->size - offset;
  3762. safe_delete(tmpPacket);
  3763. }
  3764. }
  3765. packet_size -= sizeof(int32);
  3766. memcpy(data, &packet_size, sizeof(int32));
  3767. packet_size += sizeof(int32);
  3768. EQ2Packet* outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  3769. //DumpPacket(outapp);
  3770. QueuePacket(outapp);
  3771. safe_delete_array(data);
  3772. safe_delete(packet);
  3773. }
  3774. }
  3775. void Client::Loot(Entity* entity, bool attemptDisarm) {
  3776. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  3777. int32 total_coins = entity->GetLootCoins();
  3778. entity->LockLoot();
  3779. Loot(total_coins, entity->GetLootItems(), entity);
  3780. entity->UnlockLoot();
  3781. OpenChest(entity, attemptDisarm);
  3782. }
  3783. else
  3784. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  3785. }
  3786. void Client::OpenChest(Entity* entity, bool attemptDisarm)
  3787. {
  3788. if (!entity)
  3789. return;
  3790. int8 chest_difficulty = 0;
  3791. int32 state = 0;
  3792. // Check for the chest and set the action state
  3793. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  3794. string modelName;
  3795. if (entity->GetModelType() == 4034) {
  3796. // small chest, open with copper coins
  3797. // does not include traps, however can be disarmed
  3798. chest_difficulty = 1;
  3799. state = 11899;
  3800. modelName.append("Small Chest");
  3801. }
  3802. else if (entity->GetModelType() == 5864) {
  3803. // treasure chest, open with silver coins
  3804. chest_difficulty = 2;
  3805. state = 11901;
  3806. modelName.append("Treasure Chest");
  3807. }
  3808. else if (entity->GetModelType() == 5865) {
  3809. // ornate chest, open with gold coins
  3810. chest_difficulty = 3;
  3811. state = 11900;
  3812. modelName.append("Ornate Chest");
  3813. }
  3814. else if (entity->GetModelType() == 4015) {
  3815. // exquisite chest, open with gold coins and jewels as well as a glow effect
  3816. chest_difficulty = 5;
  3817. state = 11898;
  3818. modelName.append("Exquisite Chest");
  3819. }
  3820. bool firstChestOpen = false;
  3821. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  3822. {
  3823. ChestTrap::ChestTrapInfo nextTrap;
  3824. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  3825. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  3826. firstChestOpen = true;
  3827. entity->SetTrapTriggered(true);
  3828. if (ret)
  3829. {
  3830. if (disarmSkill && attemptDisarm)
  3831. {
  3832. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  3833. {
  3834. CastGroupOrSelf(entity, nextTrap.spell_id, nextTrap.spell_tier,
  3835. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3836. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3837. }
  3838. else
  3839. {
  3840. Message(CHANNEL_COLOR_WHITE, "You disarm the trap on %s", modelName.c_str());
  3841. }
  3842. // despite fail/succeed we should always try to increase skill if disarm is available
  3843. GetPlayer()->GetSkillByName("Disarm Trap", true);
  3844. }
  3845. else // no disarm skill, always fail
  3846. {
  3847. CastGroupOrSelf(entity, nextTrap.spell_id, nextTrap.spell_tier,
  3848. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  3849. Message(CHANNEL_COLOR_WHITE, "You trigger the trap on %s!", modelName.c_str());
  3850. }
  3851. }
  3852. }
  3853. else if (!entity->HasTrapTriggered())
  3854. {
  3855. firstChestOpen = true;
  3856. entity->SetTrapTriggered(true);
  3857. }
  3858. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  3859. // for those in range the SendStateCommand will cause it to animate open.
  3860. // TODO: when player enters radius that does not have visual state, update visual state
  3861. if (firstChestOpen)
  3862. entity->SetVisualState(state, false);
  3863. GetCurrentZone()->SendStateCommand(entity, state);
  3864. }
  3865. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  3866. {
  3867. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  3868. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  3869. if (source == NULL)
  3870. source = (Entity*)GetPlayer();
  3871. if (spell)
  3872. {
  3873. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  3874. if (gmi && gmi->group_id)
  3875. {
  3876. deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(gmi->group_id);
  3877. for (int8 i = 0; i < members->size(); i++) {
  3878. Entity* member = members->at(i)->member;
  3879. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  3880. continue;
  3881. // if we have a radius provided then check if the group member is outside the radius or not
  3882. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  3883. continue;
  3884. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  3885. }
  3886. }
  3887. else
  3888. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  3889. }
  3890. }
  3891. Spawn* Client::GetBanker() {
  3892. return banker;
  3893. }
  3894. void Client::SetBanker(Spawn* in_banker) {
  3895. banker = in_banker;
  3896. }
  3897. void Client::Bank(Spawn* banker, bool cancel) {
  3898. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  3899. if (!cancel)
  3900. SetBanker(banker);
  3901. else
  3902. SetBanker(0);
  3903. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  3904. if (packet) {
  3905. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  3906. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  3907. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  3908. int32 coins1, coins2;
  3909. coins1 = ((int32*)&coins)[0];
  3910. coins2 = ((int32*)&coins)[1];
  3911. packet->setDataByName("bank_coins", coins1);
  3912. packet->setDataByName("bank_coins2", coins2);
  3913. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  3914. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  3915. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  3916. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  3917. if (!cancel)
  3918. packet->setDataByName("display", 1);
  3919. QueuePacket(packet->serialize());
  3920. safe_delete(packet);
  3921. }
  3922. }
  3923. }
  3924. void Client::BankWithdrawal(int64 amount) {
  3925. bool cheater = false;
  3926. if (GetBanker() && amount > 0) {
  3927. string withdrawal = "";
  3928. char withdrawal_data[512] = { 0 };
  3929. int32 tmp = 0;
  3930. if (amount >= 1000000) {
  3931. tmp = amount / 1000000;
  3932. if (tmp > GetPlayer()->GetBankCoinsPlat())
  3933. cheater = true;
  3934. else {
  3935. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  3936. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  3937. amount -= (int64)tmp * 1000000;
  3938. sprintf(withdrawal_data, "%u Platinum ", tmp);
  3939. withdrawal.append(withdrawal_data);
  3940. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3941. }
  3942. }
  3943. if (!cheater && amount >= 10000) {
  3944. tmp = amount / 10000;
  3945. if (tmp > GetPlayer()->GetBankCoinsGold())
  3946. cheater = true;
  3947. else {
  3948. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  3949. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  3950. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  3951. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  3952. }
  3953. else
  3954. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  3955. amount -= tmp * 10000;
  3956. sprintf(withdrawal_data, "%u Gold ", tmp);
  3957. withdrawal.append(withdrawal_data);
  3958. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3959. }
  3960. }
  3961. if (!cheater && amount >= 100) {
  3962. tmp = amount / 100;
  3963. if (tmp > GetPlayer()->GetBankCoinsSilver())
  3964. cheater = true;
  3965. else {
  3966. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  3967. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  3968. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  3969. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  3970. }
  3971. else
  3972. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  3973. amount -= tmp * 100;
  3974. sprintf(withdrawal_data, "%u Silver ", tmp);
  3975. withdrawal.append(withdrawal_data);
  3976. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  3977. }
  3978. }
  3979. if (!cheater) {
  3980. if (amount > 0) {
  3981. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  3982. withdrawal.append(withdrawal_data);
  3983. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  3984. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  3985. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  3986. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  3987. }
  3988. else
  3989. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  3990. }
  3991. if (withdrawal.length() > 0) {
  3992. withdrawal.append("withdrawn ");
  3993. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  3994. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  3995. withdrawal.append(withdrawal_data);
  3996. SimpleMessage(CHANNEL_COLOR_REVIVE, withdrawal.c_str());
  3997. }
  3998. }
  3999. else
  4000. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4001. player->SetCharSheetChanged(true);
  4002. Bank(banker);
  4003. }
  4004. }
  4005. void Client::BankDeposit(int64 amount) {
  4006. bool cheater = false;
  4007. if (GetBanker() && amount > 0) {
  4008. int32 tmp = 0;
  4009. char deposit_data[512] = { 0 };
  4010. string deposit = "";
  4011. if (amount >= 1000000) {
  4012. tmp = amount / 1000000;
  4013. if (tmp > GetPlayer()->GetCoinsPlat())
  4014. cheater = true;
  4015. else {
  4016. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  4017. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  4018. amount -= (int64)tmp * 1000000;
  4019. sprintf(deposit_data, "%u Platinum ", tmp);
  4020. deposit.append(deposit_data);
  4021. memset(deposit_data, 0, sizeof(deposit_data));
  4022. }
  4023. }
  4024. if (!cheater && amount >= 10000) {
  4025. tmp = amount / 10000;
  4026. if (tmp > GetPlayer()->GetCoinsGold())
  4027. cheater = true;
  4028. else {
  4029. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  4030. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  4031. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  4032. }
  4033. else
  4034. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  4035. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  4036. amount -= tmp * 10000;
  4037. sprintf(deposit_data, "%u Gold ", tmp);
  4038. deposit.append(deposit_data);
  4039. memset(deposit_data, 0, sizeof(deposit_data));
  4040. }
  4041. }
  4042. if (!cheater && amount >= 100) {
  4043. tmp = amount / 100;
  4044. if (tmp > GetPlayer()->GetCoinsSilver())
  4045. cheater = true;
  4046. else {
  4047. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  4048. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  4049. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  4050. }
  4051. else
  4052. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  4053. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  4054. amount -= tmp * 100;
  4055. sprintf(deposit_data, "%u Silver ", tmp);
  4056. deposit.append(deposit_data);
  4057. memset(deposit_data, 0, sizeof(deposit_data));
  4058. }
  4059. }
  4060. if (!cheater) {
  4061. if (amount > 0) {
  4062. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4063. deposit.append(deposit_data);
  4064. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  4065. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  4066. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  4067. }
  4068. else
  4069. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  4070. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  4071. }
  4072. if (deposit.length() > 0) {
  4073. deposit.append("deposited ");
  4074. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4075. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4076. deposit.append(deposit_data);
  4077. SimpleMessage(CHANNEL_COLOR_REVIVE, deposit.c_str());
  4078. }
  4079. }
  4080. else
  4081. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4082. player->SetCharSheetChanged(true);
  4083. Bank(banker);
  4084. }
  4085. }
  4086. void Client::AddPendingQuestReward(Quest* quest) {
  4087. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4088. quest_pending_reward.push_back(quest);
  4089. quest_updates = true;
  4090. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4091. }
  4092. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4093. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4094. quest_pending_updates[quest_id][step_id] = progress;
  4095. quest_updates = true;
  4096. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4097. }
  4098. void Client::ProcessQuestUpdates() {
  4099. if (quest_pending_updates.size() > 0) {
  4100. map<int32, map<int32, int32> > tmp_quest_updates;
  4101. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4102. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4103. quest_pending_updates.clear();
  4104. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4105. map<int32, map<int32, int32> >::iterator quest_itr;
  4106. map<int32, int32>::iterator step_itr;
  4107. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4108. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4109. if (step_itr->second == 0xFFFFFFFF) {
  4110. SetStepComplete(quest_itr->first, step_itr->first);
  4111. player->SendQuestRequiredSpawns(quest_itr->first);
  4112. }
  4113. else
  4114. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4115. }
  4116. }
  4117. }
  4118. if (quest_pending_reward.size() > 0) {
  4119. vector<Quest*>::iterator itr;
  4120. vector<Quest*> tmp_quest_rewards;
  4121. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4122. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4123. quest_pending_reward.clear();
  4124. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4125. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4126. GiveQuestReward(*itr);
  4127. }
  4128. }
  4129. quest_updates = false;
  4130. }
  4131. void Client::CheckQuestQueue() {
  4132. MQuestQueue.writelock();
  4133. last_update_time = 0;
  4134. vector<QueuedQuest*>::iterator itr;
  4135. QueuedQuest* queued_quest = 0;
  4136. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4137. queued_quest = *itr;
  4138. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4139. safe_delete(queued_quest);
  4140. }
  4141. quest_queue.clear();
  4142. MQuestQueue.releasewritelock();
  4143. }
  4144. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4145. Quest* quest = player->SetStepComplete(quest_id, step);
  4146. if (quest) {
  4147. SendQuestUpdate(quest);
  4148. GetCurrentZone()->SendQuestUpdates(this);
  4149. }
  4150. }
  4151. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4152. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4153. if (quest) {
  4154. SendQuestUpdate(quest);
  4155. GetCurrentZone()->SendQuestUpdates(this);
  4156. }
  4157. }
  4158. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4159. bool hadUpdates = false;
  4160. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4161. if (quest_updates) {
  4162. for (int32 i = 0; i < quest_updates->size(); i++)
  4163. {
  4164. SendQuestUpdate(quest_updates->at(i));
  4165. hadUpdates = true;
  4166. }
  4167. }
  4168. safe_delete(quest_updates);
  4169. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4170. if (quest_failures) {
  4171. for (int32 i = 0; i < quest_failures->size(); i++)
  4172. {
  4173. SendQuestFailure(quest_failures->at(i));
  4174. hadUpdates = true;
  4175. }
  4176. }
  4177. safe_delete(quest_failures);
  4178. if (hadUpdates)
  4179. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4180. }
  4181. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4182. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4183. if (quest_updates) {
  4184. for (int32 i = 0; i < quest_updates->size(); i++)
  4185. SendQuestUpdate(quest_updates->at(i));
  4186. GetCurrentZone()->SendQuestUpdates(this);
  4187. }
  4188. safe_delete(quest_updates);
  4189. }
  4190. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4191. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4192. if (quest_updates) {
  4193. for (int32 i = 0; i < quest_updates->size(); i++)
  4194. SendQuestUpdate(quest_updates->at(i));
  4195. }
  4196. safe_delete(quest_updates);
  4197. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4198. if (quest_failures) {
  4199. for (int32 i = 0; i < quest_failures->size(); i++)
  4200. SendQuestFailure(quest_failures->at(i));
  4201. }
  4202. safe_delete(quest_failures);
  4203. }
  4204. void Client::CheckPlayerQuestsLocationUpdate() {
  4205. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4206. if (quest_updates) {
  4207. for (int32 i = 0; i < quest_updates->size(); i++)
  4208. SendQuestUpdate(quest_updates->at(i));
  4209. }
  4210. safe_delete(quest_updates);
  4211. }
  4212. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4213. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4214. if (quest_updates) {
  4215. for (int32 i = 0; i < quest_updates->size(); i++)
  4216. SendQuestUpdate(quest_updates->at(i));
  4217. }
  4218. safe_delete(quest_updates);
  4219. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4220. if (quest_failures) {
  4221. for (int32 i = 0; i < quest_failures->size(); i++)
  4222. SendQuestFailure(quest_failures->at(i));
  4223. }
  4224. safe_delete(quest_failures);
  4225. }
  4226. void Client::AddPendingQuest(Quest* quest) {
  4227. player->pending_quests[quest->GetQuestID()] = quest;
  4228. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4229. //DumpPacket(outapp);
  4230. QueuePacket(outapp);
  4231. }
  4232. Quest* Client::GetActiveQuest(int32 quest_id) {
  4233. if (player->player_quests.count(quest_id) > 0) {
  4234. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4235. return player->player_quests[quest_id];
  4236. }
  4237. return 0;
  4238. }
  4239. Quest* Client::GetPendingQuest(int32 id) {
  4240. if (player->pending_quests.count(id) > 0) {
  4241. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4242. return player->pending_quests[id];
  4243. }
  4244. return 0;
  4245. }
  4246. void Client::RemovePendingQuest(Quest* quest) {
  4247. player->pending_quests.erase(quest->GetQuestID());
  4248. }
  4249. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4250. if (!quest || !progress) {
  4251. return;
  4252. }
  4253. map<int32, int32>::iterator itr;
  4254. QuestStep* step = 0;
  4255. player->SetZone(GetCurrentZone());
  4256. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4257. step = quest->GetQuestStep(itr->first);
  4258. if (step && itr->second > 0) {
  4259. step->SetStepProgress(itr->second);
  4260. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4261. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4262. }
  4263. }
  4264. }
  4265. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4266. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4267. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4268. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4269. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4270. }
  4271. player->player_quests[quest->GetQuestID()] = quest;
  4272. quest->SetPlayer(player);
  4273. current_quest_id = quest->GetQuestID();
  4274. if (send_packets && quest->GetQuestGiver() > 0)
  4275. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4276. if (lua_interface && call_accepted)
  4277. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4278. if (send_packets) {
  4279. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4280. //SendQuestJournal();
  4281. SendQuestJournalUpdate(quest);
  4282. // sent twice to match live
  4283. quest->SetTracked(false);
  4284. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4285. quest->SetTracked(true);
  4286. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4287. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4288. }
  4289. //This isn't during a load screen, so update spawns with required quests
  4290. if (call_accepted)
  4291. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4292. }
  4293. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4294. if (current_quest_id == id)
  4295. current_quest_id = 0;
  4296. if (player->player_quests.count(id) > 0) {
  4297. if (delete_quest) {
  4298. player->player_quests[id]->SetDeleted(true);
  4299. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4300. }
  4301. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4302. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4303. if (send_update) {
  4304. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4305. SendQuestJournal();
  4306. }
  4307. player->RemoveQuest(id, delete_quest);
  4308. if (send_update) {
  4309. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4310. SendQuestJournal();
  4311. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4312. }
  4313. }
  4314. }
  4315. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4316. if (quest) {
  4317. QuestStep* quest_step = quest->GetQuestStep(step);
  4318. if (quest_step) {
  4319. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4320. quest_step->WasUpdated(false);
  4321. }
  4322. }
  4323. }
  4324. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4325. QueuedQuest* item = new QueuedQuest;
  4326. item->quest = quest;
  4327. item->step = step;
  4328. item->display_quest_helper = display_quest_helper;
  4329. MQuestQueue.writelock();
  4330. quest_queue.push_back(item);
  4331. last_update_time = Timer::GetCurrentTime2();
  4332. MQuestQueue.releasewritelock();
  4333. }
  4334. void Client::SendQuestFailure(Quest* quest) {
  4335. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4336. if (failures) {
  4337. QuestStep* step = 0;
  4338. for (int32 i = 0; i < failures->size(); i++) {
  4339. step = failures->at(i);
  4340. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4341. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4342. SendQuestJournal();
  4343. }
  4344. failures->clear();
  4345. }
  4346. }
  4347. void Client::SendQuestUpdate(Quest* quest) {
  4348. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4349. if (updates) {
  4350. QuestStep* step = 0;
  4351. for (int32 i = 0; i < updates->size(); i++) {
  4352. step = updates->at(i);
  4353. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4354. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4355. if (step->WasUpdated()) {
  4356. SendQuestJournal();
  4357. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4358. }
  4359. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4360. }
  4361. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction())
  4362. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4363. if (quest->GetCompleted()) {
  4364. if (quest->GetQuestReturnNPC() > 0)
  4365. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4366. if (quest->GetCompletedFlag())
  4367. quest->SetCompletedFlag(false);
  4368. }
  4369. updates->clear();
  4370. }
  4371. }
  4372. void Client::SendQuestJournal(bool all_quests, Client* client) {
  4373. if (!client)
  4374. client = this;
  4375. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id);
  4376. if (packet) {
  4377. EQ2Packet* outapp = packet->serialize();
  4378. //DumpPacket(outapp);
  4379. client->QueuePacket(outapp);
  4380. safe_delete(packet);
  4381. }
  4382. }
  4383. void Client::SendQuestJournalUpdate(Quest* quest) {
  4384. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC());
  4385. if (packet) {
  4386. QueuePacket(packet->serialize());
  4387. safe_delete(packet);
  4388. }
  4389. }
  4390. void Client::ReloadQuests() {
  4391. vector<int32> ids = player->GetQuestIDs();
  4392. Quest* quest = 0;
  4393. for (int32 i = 0; i < ids.size(); i++) {
  4394. quest = master_quest_list.GetQuest(ids[i]);
  4395. if (quest)
  4396. AddPlayerQuest(quest, false);
  4397. else
  4398. RemovePlayerQuest(ids[i]);
  4399. }
  4400. }
  4401. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4402. bool found_quest = false;
  4403. vector<Quest*>::iterator itr;
  4404. vector<Item*>* items = 0;
  4405. Quest* quest = 0;
  4406. MPendingQuestAccept.lock();
  4407. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4408. quest = *itr;
  4409. items = quest->GetSelectableRewardItems();
  4410. if (items && items->size() > 0) {
  4411. for (int32 i = 0; i < items->size(); i++) {
  4412. if (items->at(i)->details.item_id == item_id) {
  4413. found_quest = true;
  4414. break;
  4415. }
  4416. }
  4417. }
  4418. else if (item_id == 0)
  4419. found_quest = true;
  4420. if (found_quest) {
  4421. pending_quest_accept.erase(itr);
  4422. break;
  4423. }
  4424. }
  4425. MPendingQuestAccept.unlock();
  4426. if (found_quest)
  4427. return quest;
  4428. return 0;
  4429. }
  4430. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4431. int8 num_slots_needed = 0;
  4432. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4433. Item* master_item = 0;
  4434. if (item_id > 0) {
  4435. num_slots_needed++;
  4436. master_item = master_item_list.GetItem(item_id);
  4437. }
  4438. vector<Item*>* items = quest->GetRewardItems();
  4439. if (items && items->size() > 0)
  4440. num_slots_needed += items->size();
  4441. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4442. if (master_item)
  4443. AddItem(item_id);
  4444. if (items && items->size() > 0) {
  4445. for (int32 i = 0; i < items->size(); i++)
  4446. AddItem(new Item(items->at(i)));
  4447. }
  4448. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4449. if (outapp)
  4450. QueuePacket(outapp);
  4451. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4452. map<int32, sint32>::iterator itr;
  4453. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4454. int32 faction_id = itr->first;
  4455. sint32 amount = itr->second;
  4456. if (amount > 0)
  4457. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4458. else
  4459. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4460. }
  4461. }
  4462. else {
  4463. MPendingQuestAccept.lock();
  4464. pending_quest_accept.push_back(quest);
  4465. MPendingQuestAccept.unlock();
  4466. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4467. DisplayQuestComplete(quest);
  4468. }
  4469. }
  4470. void Client::DisplayQuestComplete(Quest* quest) {
  4471. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  4472. if (packet) {
  4473. packet->setDataByName("title", "Quest Reward!");
  4474. packet->setDataByName("name", quest->GetName());
  4475. packet->setDataByName("description", quest->GetDescription());
  4476. packet->setDataByName("level", quest->GetLevel());
  4477. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  4478. int8 difficulty = 0;
  4479. if ((string)quest->GetType() == "Tradeskill")
  4480. difficulty = player->GetTSArrowColor(quest->GetLevel());
  4481. else
  4482. difficulty = player->GetArrowColor(quest->GetLevel());
  4483. packet->setDataByName("difficulty", difficulty);
  4484. int64 rewarded_coin = 0;
  4485. if (quest->GetCoinsReward() > 0) {
  4486. if (quest->GetCoinsRewardMax() > 0)
  4487. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  4488. else
  4489. rewarded_coin = quest->GetCoinsReward();
  4490. }
  4491. quest->SetGeneratedCoin(rewarded_coin);
  4492. packet->setDataByName("max_coin", rewarded_coin);
  4493. packet->setDataByName("min_coin", rewarded_coin);
  4494. packet->setDataByName("status_points", quest->GetStatusPoints());
  4495. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  4496. vector<Item*>* items = quest->GetRewardItems();
  4497. if (items) {
  4498. packet->setArrayLengthByName("num_rewards", items->size());
  4499. for (int32 i = 0; i < items->size(); i++) {
  4500. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  4501. if (version < 860)
  4502. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  4503. else if (version < 1193)
  4504. packet->setItemArrayDataByName("item", items->at(i), player, i);
  4505. else
  4506. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  4507. }
  4508. }
  4509. if (items2 && items2->size() > 0) {
  4510. packet->setArrayLengthByName("num_select_rewards", items2->size());
  4511. for (int32 i = 0; i < items2->size(); i++) {
  4512. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  4513. if (version < 860)
  4514. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  4515. else if (version < 1193)
  4516. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  4517. else
  4518. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  4519. }
  4520. }
  4521. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4522. if (reward_factions && reward_factions->size() > 0) {
  4523. packet->setArrayLengthByName("num_factions", reward_factions->size());
  4524. map<int32, sint32>::iterator itr;
  4525. int16 index = 0;
  4526. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4527. int32 faction_id = itr->first;
  4528. sint32 amount = itr->second;
  4529. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  4530. if (faction_name) {
  4531. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  4532. packet->setArrayDataByName("amount", amount, index);
  4533. }
  4534. index++;
  4535. }
  4536. }
  4537. EQ2Packet* outapp = packet->serialize();
  4538. // DumpPacket(outapp);
  4539. QueuePacket(outapp);
  4540. safe_delete(packet);
  4541. }
  4542. }
  4543. void Client::DisplayRandomizeFeatures(int32 flags) {
  4544. SimpleMessage(CHANNEL_COLOR_WHITE, "Showing Active Randomize Features:");
  4545. if (flags > 0) {
  4546. if (flags & RANDOMIZE_GENDER)
  4547. SimpleMessage(CHANNEL_COLOR_WHITE, "- Gender");
  4548. if (flags & RANDOMIZE_RACE)
  4549. SimpleMessage(CHANNEL_COLOR_WHITE, "- Race");
  4550. if (flags & RANDOMIZE_MODEL_TYPE)
  4551. SimpleMessage(CHANNEL_COLOR_WHITE, "- Model");
  4552. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  4553. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair");
  4554. if (flags & RANDOMIZE_HAIR_TYPE)
  4555. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair");
  4556. if (flags & RANDOMIZE_WING_TYPE)
  4557. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing");
  4558. if (flags & RANDOMIZE_CHEEK_TYPE)
  4559. SimpleMessage(CHANNEL_COLOR_WHITE, "- Cheek");
  4560. if (flags & RANDOMIZE_CHIN_TYPE)
  4561. SimpleMessage(CHANNEL_COLOR_WHITE, "- Chin");
  4562. if (flags & RANDOMIZE_EAR_TYPE)
  4563. SimpleMessage(CHANNEL_COLOR_WHITE, "- Ear");
  4564. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  4565. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eyebrow");
  4566. if (flags & RANDOMIZE_EYE_TYPE)
  4567. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye");
  4568. if (flags & RANDOMIZE_LIP_TYPE)
  4569. SimpleMessage(CHANNEL_COLOR_WHITE, "- Lip");
  4570. if (flags & RANDOMIZE_NOSE_TYPE)
  4571. SimpleMessage(CHANNEL_COLOR_WHITE, "- Nose");
  4572. if (flags & RANDOMIZE_EYE_COLOR)
  4573. SimpleMessage(CHANNEL_COLOR_WHITE, "- Eye Color");
  4574. if (flags & RANDOMIZE_HAIR_COLOR1)
  4575. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color1");
  4576. if (flags & RANDOMIZE_HAIR_COLOR2)
  4577. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color2");
  4578. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  4579. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Color Highlights");
  4580. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  4581. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color");
  4582. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  4583. SimpleMessage(CHANNEL_COLOR_WHITE, "- Facial Hair Color Highlights");
  4584. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  4585. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Color");
  4586. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  4587. SimpleMessage(CHANNEL_COLOR_WHITE, "- Hair Type Highlights");
  4588. if (flags & RANDOMIZE_SKIN_COLOR)
  4589. SimpleMessage(CHANNEL_COLOR_WHITE, "- Skin Color");
  4590. if (flags & RANDOMIZE_WING_COLOR1)
  4591. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color1");
  4592. if (flags & RANDOMIZE_WING_COLOR2)
  4593. SimpleMessage(CHANNEL_COLOR_WHITE, "- Wing Color2");
  4594. }
  4595. else
  4596. {
  4597. SimpleMessage(CHANNEL_COLOR_WHITE, "- No Randomization Set.");
  4598. }
  4599. }
  4600. void Client::GiveQuestReward(Quest* quest) {
  4601. current_quest_id = 0;
  4602. MPendingQuestAccept.lock();
  4603. pending_quest_accept.push_back(quest);
  4604. MPendingQuestAccept.unlock();
  4605. quest->IncrementCompleteCount();
  4606. player->AddCompletedQuest(quest);
  4607. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4608. SendQuestJournal();
  4609. player->RemoveQuest(quest->GetQuestID(), false);
  4610. DisplayQuestComplete(quest);
  4611. if (quest->GetExpReward() > 0) {
  4612. int16 level = player->GetLevel();
  4613. int32 xp = quest->GetExpReward();
  4614. if (player->AddXP(xp)) {
  4615. Message(CHANNEL_COLOR_EXP, "You gain %u experience!", (int32)xp);
  4616. if (player->GetLevel() != level)
  4617. ChangeLevel(level, player->GetLevel());
  4618. player->SetCharSheetChanged(true);
  4619. }
  4620. }
  4621. if (quest->GetTSExpReward() > 0) {
  4622. int8 ts_level = player->GetTSLevel();
  4623. int32 xp = quest->GetTSExpReward();
  4624. if (player->AddTSXP(xp)) {
  4625. Message(CHANNEL_COLOR_EXP, "You gain %u tradeskill experience!", (int32)xp);
  4626. if (player->GetTSLevel() != ts_level)
  4627. ChangeTSLevel(ts_level, player->GetTSLevel());
  4628. player->SetCharSheetChanged(true);
  4629. }
  4630. }
  4631. int64 total_coins = quest->GetGeneratedCoin();
  4632. if (total_coins > 0) {
  4633. player->AddCoins(total_coins);
  4634. PlaySound("coin_cha_ching");
  4635. char tmp[64] = { 0 };
  4636. string message = "You receive ";
  4637. int32 val = 0;
  4638. if (total_coins >= 1000000) {
  4639. val = total_coins / 1000000;
  4640. total_coins -= 1000000 * val;
  4641. sprintf(tmp, "%u Platinum ", val);
  4642. message.append(tmp);
  4643. memset(tmp, 0, 64);
  4644. }
  4645. if (total_coins >= 10000) {
  4646. val = total_coins / 10000;
  4647. total_coins -= 10000 * val;
  4648. sprintf(tmp, "%u Gold ", val);
  4649. message.append(tmp);
  4650. memset(tmp, 0, 64);
  4651. }
  4652. if (total_coins >= 100) {
  4653. val = total_coins / 100;
  4654. total_coins -= 100 * val;
  4655. sprintf(tmp, "%u Silver ", val);
  4656. message.append(tmp);
  4657. memset(tmp, 0, 64);
  4658. }
  4659. if (total_coins > 0) {
  4660. sprintf(tmp, "%u Copper ", (int32)total_coins);
  4661. message.append(tmp);
  4662. }
  4663. message.append("for completing ").append(quest->GetName());
  4664. int8 type = CHANNEL_COLOR_LOOT;
  4665. if (GetVersion() >= 973)
  4666. type = CHANNEL_COLOR_NEW_LOOT;
  4667. SimpleMessage(type, message.c_str());
  4668. }
  4669. if (quest->GetQuestGiver() > 0)
  4670. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4671. RemovePlayerQuest(quest->GetQuestID(), true, false);
  4672. }
  4673. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4674. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  4675. if (packet) {
  4676. packet->setDataByName("conversation_id", conversation_id);
  4677. packet->setDataByName("text", text);
  4678. packet->setDataByName("unknown2", 1);
  4679. conversation_map[conversation_id].clear();
  4680. if (conversations) {
  4681. packet->setArrayLengthByName("num_responses", conversations->size());
  4682. for (int32 i = 0; i < conversations->size(); i++) {
  4683. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  4684. if (conversations->at(i).function.length() > 0)
  4685. conversation_map[conversation_id][i] = conversations->at(i).function;
  4686. }
  4687. }
  4688. packet->setDataByName("spawn_id", spawn_id);
  4689. if (mp3) {
  4690. packet->setDataByName("voice", mp3);
  4691. packet->setDataByName("key1", key1);
  4692. packet->setDataByName("key2", key2);
  4693. }
  4694. QueuePacket(packet->serialize());
  4695. safe_delete(packet);
  4696. }
  4697. }
  4698. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  4699. if (!item || !text || !conversations || conversations->size() == 0) {
  4700. return;
  4701. }
  4702. int32 conversation_id = GetConversationID(0, item);
  4703. if (conversation_id == 0) {
  4704. next_conversation_id++;
  4705. conversation_id = next_conversation_id;
  4706. }
  4707. conversation_items[conversation_id] = item;
  4708. if (type == 4)
  4709. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4710. else
  4711. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4712. }
  4713. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  4714. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  4715. return;
  4716. }
  4717. int32 conversation_id = GetConversationID(npc, 0);
  4718. if (conversation_id == 0) {
  4719. next_conversation_id++;
  4720. conversation_id = next_conversation_id;
  4721. }
  4722. conversation_spawns[conversation_id] = npc;
  4723. /* NPCs can start two different types of conversations.
  4724. * Type 1: The chat type with bubbles.
  4725. * Type 2: The dialog type with the blue box. */
  4726. if (type == 1)
  4727. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  4728. else if (type == 2)
  4729. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  4730. else //if (type == 3)
  4731. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  4732. }
  4733. void Client::CloseDialog(int32 conversation_id) {
  4734. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  4735. if (packet) {
  4736. packet->setDataByName("conversation_id", conversation_id);
  4737. QueuePacket(packet->serialize());
  4738. safe_delete(packet);
  4739. }
  4740. conversation_items.erase(conversation_id);
  4741. conversation_spawns.erase(conversation_id);
  4742. }
  4743. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  4744. int32 conversation_id = 0;
  4745. if (spawn) {
  4746. map<int32, Spawn*>::iterator itr;
  4747. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  4748. if (itr->second == spawn) {
  4749. conversation_id = itr->first;
  4750. break;
  4751. }
  4752. }
  4753. }
  4754. else if (item) {
  4755. map<int32, Item*>::iterator itr;
  4756. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  4757. if (itr->second == item) {
  4758. conversation_id = itr->first;
  4759. break;
  4760. }
  4761. }
  4762. }
  4763. return conversation_id;
  4764. }
  4765. Spawn* Client::GetCombineSpawn() {
  4766. return combine_spawn;
  4767. }
  4768. bool Client::ShouldTarget() {
  4769. return should_target;
  4770. }
  4771. void Client::TargetSpawn(Spawn* spawn) {
  4772. should_target = false;
  4773. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  4774. if (packet) {
  4775. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  4776. QueuePacket(packet->serialize());
  4777. safe_delete(packet);
  4778. }
  4779. }
  4780. void Client::CombineSpawns(float radius, Spawn* spawn) {
  4781. combine_spawn = spawn;
  4782. spawn->RemoveSpawnFromGroup(true);
  4783. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  4784. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  4785. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4786. should_target = true;
  4787. }
  4788. void Client::AddCombineSpawn(Spawn* spawn) {
  4789. if (combine_spawn && combine_spawn != spawn && spawn) {
  4790. combine_spawn->AddSpawnToGroup(spawn);
  4791. spawn->AddSpawnToGroup(combine_spawn);
  4792. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4793. }
  4794. else if (spawn)
  4795. combine_spawn = spawn;
  4796. should_target = true;
  4797. }
  4798. void Client::RemoveCombineSpawn(Spawn* spawn) {
  4799. if (combine_spawn && spawn)
  4800. spawn->RemoveSpawnFromGroup();
  4801. if (combine_spawn == spawn)
  4802. combine_spawn->RemoveSpawnFromGroup(true);
  4803. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  4804. if (combine_spawn == spawn)
  4805. combine_spawn = 0;
  4806. }
  4807. void Client::SaveCombineSpawns(const char* name) {
  4808. if (!combine_spawn) {
  4809. return;
  4810. }
  4811. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  4812. if (!spawns) {
  4813. return;
  4814. }
  4815. int32 count = spawns->size();
  4816. int32 spawnLocationID = 0;
  4817. if (count == 1)
  4818. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  4819. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  4820. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  4821. // we remove the spawn inside SaveCombinedSpawnLocation
  4822. //GetCurrentZone()->RemoveSpawn(false, combine_spawn);
  4823. }
  4824. else
  4825. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  4826. safe_delete(spawns);
  4827. combine_spawn = 0;
  4828. }
  4829. bool Client::AddItem(int32 item_id, int16 quantity) {
  4830. Item* master_item = master_item_list.GetItem(item_id);
  4831. Item* item = 0;
  4832. if (master_item)
  4833. item = new Item(master_item);
  4834. if (item) {
  4835. if (quantity > 0)
  4836. item->details.count = quantity;
  4837. return AddItem(item);
  4838. }
  4839. else
  4840. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  4841. return false;
  4842. }
  4843. bool Client::AddItem(Item* item) {
  4844. if (!item) {
  4845. return false;
  4846. }
  4847. if (item->IsBag())
  4848. item->details.bag_id = item->details.unique_id;
  4849. if (player->AddItem(item)) {
  4850. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4851. if (outapp) {
  4852. QueuePacket(outapp);
  4853. //resend bag desc with new item name added
  4854. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  4855. if (outapp)
  4856. QueuePacket(outapp);
  4857. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  4858. DumpPacket(app);
  4859. client->QueuePacket(app);
  4860. */
  4861. }
  4862. CheckPlayerQuestsItemUpdate(item);
  4863. if (item->GetItemScript() && lua_interface)
  4864. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  4865. }
  4866. else {
  4867. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  4868. safe_delete(item);
  4869. return false;
  4870. }
  4871. return true;
  4872. }
  4873. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  4874. Item* master_item = master_item_list.GetItem(item_id);
  4875. Item* item = 0;
  4876. if (master_item)
  4877. item = new Item(master_item);
  4878. if (item) {
  4879. if (quantity > 0)
  4880. item->details.count = quantity;
  4881. return AddItemToBank(item);
  4882. }
  4883. else
  4884. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  4885. return false;
  4886. }
  4887. bool Client::AddItemToBank(Item* item) {
  4888. if (!item) {
  4889. return false;
  4890. }
  4891. if (item->IsBag())
  4892. item->details.bag_id = item->details.unique_id;
  4893. if (player->AddItemToBank(item)) {
  4894. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4895. if (outapp) {
  4896. QueuePacket(outapp);
  4897. //resend bag desc with new item name added
  4898. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  4899. if (outapp)
  4900. QueuePacket(outapp);
  4901. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  4902. DumpPacket(app);
  4903. client->QueuePacket(app);
  4904. */
  4905. }
  4906. CheckPlayerQuestsItemUpdate(item);
  4907. if (item->GetItemScript() && lua_interface)
  4908. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  4909. }
  4910. else {
  4911. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  4912. safe_delete(item);
  4913. return false;
  4914. }
  4915. return true;
  4916. }
  4917. bool Client::RemoveItem(Item* item, int16 quantity) {
  4918. EQ2Packet* outapp;
  4919. bool delete_item = false;
  4920. assert(item);
  4921. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  4922. item->details.count -= quantity;
  4923. item->save_needed = true;
  4924. }
  4925. else {
  4926. database.DeleteItem(character_id, item, 0);
  4927. player->GetPlayerItemList()->RemoveItem(item, false);
  4928. delete_item = true;
  4929. }
  4930. if ((outapp = player->SendInventoryUpdate(version))) {
  4931. QueuePacket(outapp);
  4932. if (item->GetItemScript() && lua_interface)
  4933. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  4934. if (delete_item)
  4935. safe_delete(item);
  4936. return true;
  4937. }
  4938. return false;
  4939. }
  4940. void Client::SetLuaDebugClient(bool val) {
  4941. if (val)
  4942. lua_debug_timer.Start();
  4943. lua_debug = val;
  4944. if (lua_interface && !val) {
  4945. lua_interface->RemoveDebugClients(this);
  4946. lua_debug_timer.Disable();
  4947. }
  4948. }
  4949. void Client::SetMerchantTransaction(Spawn* spawn) {
  4950. merchant_transaction = spawn;
  4951. }
  4952. Spawn* Client::GetMerchantTransaction() {
  4953. return merchant_transaction;
  4954. }
  4955. void Client::SetMailTransaction(Spawn* spawn) {
  4956. mail_transaction = spawn;
  4957. mail_window.coin_copper = 0;
  4958. mail_window.coin_silver = 0;
  4959. mail_window.coin_gold = 0;
  4960. mail_window.coin_plat = 0;
  4961. mail_window.char_item_id = 0;
  4962. }
  4963. Spawn* Client::GetMailTransaction() {
  4964. return mail_transaction;
  4965. }
  4966. void Client::PlaySound(const char* name) {
  4967. if (name) {
  4968. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  4969. if (packet) {
  4970. packet->setMediumStringByName("name", name);
  4971. QueuePacket(packet->serialize());
  4972. safe_delete(packet);
  4973. }
  4974. }
  4975. }
  4976. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  4977. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  4978. if(multiplier){
  4979. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  4980. float diff_low = faction_val - multiplier->faction_min;
  4981. if(diff_low < 0)
  4982. diff_low*=-1;
  4983. float total_diff = multiplier->faction_max - multiplier->faction_min;
  4984. if(total_diff < 0)
  4985. total_diff*=-1;
  4986. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  4987. float total1 = (diff_low/total_diff);
  4988. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  4989. return final_buy_multiplier;
  4990. }*/
  4991. return 1;
  4992. }
  4993. float Client::CalculateSellMultiplier(int32 merchant_id) {
  4994. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  4995. if(multiplier){
  4996. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  4997. float diff_low = faction_val - multiplier->faction_min;
  4998. if(diff_low < 0)
  4999. diff_low*=-1;
  5000. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5001. if(total_diff < 0)
  5002. total_diff*=-1;
  5003. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5004. float total1 = (diff_low/total_diff);
  5005. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5006. return final_sell_multiplier;
  5007. }*/
  5008. return 1;
  5009. }
  5010. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5011. Spawn* spawn = GetMerchantTransaction();
  5012. Guild* guild = GetPlayer()->GetGuild();
  5013. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5014. int32 total_sell_price = 0;
  5015. int32 total_status_sell_price = 0; //for status
  5016. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5017. int32 sell_price = 0;
  5018. int32 status_sell_price = 0; //for status
  5019. Item* master_item = master_item_list.GetItem(item_id);
  5020. Item* item = 0;
  5021. if (unique_id == 0)
  5022. item = player->item_list.GetItemFromID(item_id, quantity);
  5023. else
  5024. item = player->item_list.GetItemFromUniqueID(unique_id);
  5025. if (!item)
  5026. player->item_list.GetItemFromID(item_id);
  5027. if (item && master_item) {
  5028. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5029. if (sell_price > item->sell_price)
  5030. sell_price = item->sell_price;
  5031. if (quantity > item->details.count)
  5032. quantity = item->details.count;
  5033. total_sell_price = sell_price * quantity;
  5034. //------------------------------For Selling Status Items
  5035. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5036. if (status_sell_price > item->sell_status)
  5037. status_sell_price = item->sell_status;
  5038. if (quantity > item->details.count)
  5039. quantity = item->details.count;
  5040. if (player->GetGuild()) {
  5041. total_status_sell_price = status_sell_price * quantity;
  5042. player->GetInfoStruct()->status_points += total_status_sell_price;
  5043. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5044. guild->SendGuildMemberList();
  5045. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5046. }
  5047. if (quantity > 1)
  5048. Message(CHANNEL_COLOR_MERCHANT, "You sell %i \\aITEM %u 0:%s\\/a to %s for %s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5049. else
  5050. Message(CHANNEL_COLOR_MERCHANT, "You sell \\aITEM %u 0:%s\\/a to %s for %s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5051. player->AddCoins(total_sell_price);
  5052. AddBuyBack(unique_id, item_id, quantity, sell_price);
  5053. if (quantity >= item->details.count) {
  5054. database.DeleteItem(GetCharacterID(), item, 0);
  5055. player->item_list.DestroyItem(item->details.index);
  5056. }
  5057. else {
  5058. item->details.count -= quantity;
  5059. item->save_needed = true;
  5060. }
  5061. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5062. if (outapp)
  5063. QueuePacket(outapp);
  5064. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5065. SendSellMerchantList();
  5066. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5067. SendBuyBackList();
  5068. }
  5069. }
  5070. }
  5071. void Client::BuyBack(int32 item_id, int16 quantity) {
  5072. Spawn* spawn = GetMerchantTransaction();
  5073. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5074. deque<BuyBackItem*>::iterator itr;
  5075. BuyBackItem* buyback = 0;
  5076. BuyBackItem* closest = 0;
  5077. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5078. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5079. buyback = *itr;
  5080. if (buyback->unique_id == item_id) {
  5081. closest = buyback;
  5082. quantity = buyback->quantity;
  5083. break;
  5084. }
  5085. }
  5086. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5087. if (closest) {
  5088. Item* item = 0;
  5089. Item* master_item = master_item_list.GetItem(closest->item_id);
  5090. if (master_item) {
  5091. item = new Item(master_item);
  5092. if (closest->quantity >= quantity)
  5093. item->details.count = quantity;
  5094. else
  5095. item->details.count = closest->quantity;
  5096. }
  5097. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  5098. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5099. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  5100. bool removed = false;
  5101. if (closest->quantity == quantity) {
  5102. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5103. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5104. if (*itr == closest) {
  5105. buy_back_items.erase(itr);
  5106. removed = true;
  5107. break;
  5108. }
  5109. }
  5110. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5111. }
  5112. else {
  5113. closest->quantity -= quantity;
  5114. closest->save_needed = true;
  5115. }
  5116. AddItem(item);
  5117. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5118. //if(outapp)
  5119. //QueuePacket(outapp);
  5120. if (removed) {
  5121. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  5122. safe_delete(closest);
  5123. }
  5124. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5125. SendSellMerchantList();
  5126. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5127. SendBuyBackList();
  5128. }
  5129. else
  5130. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  5131. }
  5132. }
  5133. }
  5134. void Client::BuyItem(int32 item_id, int16 quantity) {
  5135. // Get the merchant we are buying from
  5136. Spawn* spawn = GetMerchantTransaction();
  5137. // Make sure the spawn has a merchant list
  5138. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5139. int32 total_buy_price = 0;
  5140. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5141. int32 sell_price = 0;
  5142. Item* master_item = master_item_list.GetItem(item_id);
  5143. Item* item = 0;
  5144. int16 total_available = 0;
  5145. vector<MerchantItemInfo>* temp;
  5146. vector<MerchantItemInfo>::iterator itr;
  5147. MerchantItemInfo* ItemInfo = 0;
  5148. temp = world.GetMerchantList(spawn->GetMerchantID());
  5149. for (itr = temp->begin(); itr != temp->end(); itr++) {
  5150. if ((*itr).item_id == item_id) {
  5151. ItemInfo = &(*itr);
  5152. break;
  5153. }
  5154. }
  5155. if (master_item && ItemInfo) {
  5156. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  5157. quantity = 1;
  5158. total_available = 0xFFFF;
  5159. sell_price = master_item->sell_price;
  5160. }
  5161. else {
  5162. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  5163. sell_price = (int32)(master_item->sell_price * multiplier);
  5164. if (quantity > total_available)
  5165. quantity = total_available;
  5166. }
  5167. total_buy_price = sell_price * quantity;
  5168. item = new Item(master_item);
  5169. item->details.count = quantity;
  5170. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  5171. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5172. safe_delete(item);
  5173. }
  5174. else {
  5175. // Price not set in the merchant_inventory table, use the old method
  5176. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  5177. if (player->RemoveCoins(total_buy_price)) {
  5178. item->SetMaxSellValue(sell_price);
  5179. if (quantity > 1)
  5180. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5181. else
  5182. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5183. AddItem(item);
  5184. CheckPlayerQuestsItemUpdate(item);
  5185. if (item && total_available < 0xFFFF) {
  5186. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5187. SendBuyMerchantList();
  5188. }
  5189. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5190. //if(outapp)
  5191. // QueuePacket(outapp);
  5192. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5193. SendSellMerchantList();
  5194. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5195. PlayLotto(total_buy_price, item->details.item_id);
  5196. }
  5197. else {
  5198. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5199. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5200. PlaySound("buy_failed");
  5201. }
  5202. }
  5203. else {
  5204. // Price set in merchant_inventory table
  5205. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5206. // TODO: need to add support for station cash
  5207. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5208. // Check items
  5209. int16 item_quantity = 0;
  5210. // Default these to true in case price_item_id or price_item2_id was never set
  5211. bool hasItem1 = true;
  5212. bool hasItem2 = true;
  5213. Item* tempItem1 = 0;
  5214. Item* tempItem2 = 0;
  5215. if (ItemInfo->price_item_id != 0) {
  5216. // Same item for whatever reason lets add the quantities together
  5217. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5218. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5219. else
  5220. item_quantity = ItemInfo->price_item_qty;
  5221. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5222. if (tempItem1) {
  5223. if (tempItem1->details.count < item_quantity)
  5224. hasItem1 = false;
  5225. }
  5226. else {
  5227. hasItem1 = false;
  5228. }
  5229. }
  5230. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5231. // as item1 and we already checked for it so we can skip this check
  5232. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5233. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5234. if (tempItem2) {
  5235. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5236. hasItem2 = false;
  5237. }
  5238. else {
  5239. hasItem2 = false;
  5240. }
  5241. }
  5242. // if we have every thing then remove the price and give the item
  5243. if (hasItem1 && hasItem2) {
  5244. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5245. // TODO: station cash
  5246. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5247. // so there is no need to send it more then that one time
  5248. if (tempItem1) {
  5249. if (tempItem1->details.count > item_quantity) {
  5250. tempItem1->details.count -= item_quantity;
  5251. tempItem1->save_needed = true;
  5252. }
  5253. else {
  5254. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5255. player->item_list.DestroyItem(tempItem1->details.index);
  5256. }
  5257. }
  5258. if (tempItem2) {
  5259. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5260. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5261. tempItem2->save_needed = true;
  5262. }
  5263. else {
  5264. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5265. player->item_list.DestroyItem(tempItem2->details.index);
  5266. }
  5267. }
  5268. // 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
  5269. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5270. item->SetMaxSellValue(sell_price);
  5271. if (quantity > 1)
  5272. Message(CHANNEL_COLOR_MERCHANT, "You buy %i \\aITEM %u 0:%s\\/a from %s for%s.", quantity, master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5273. else
  5274. Message(CHANNEL_COLOR_MERCHANT, "You buy \\aITEM %u 0:%s\\/a from %s for%s.", master_item->details.item_id, master_item->name.c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5275. AddItem(item);
  5276. CheckPlayerQuestsItemUpdate(item);
  5277. if (item && total_available < 0xFFFF) {
  5278. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5279. SendBuyMerchantList();
  5280. }
  5281. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5282. SendSellMerchantList();
  5283. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5284. PlayLotto(total_buy_price, item->details.item_id);
  5285. }
  5286. else {
  5287. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5288. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5289. PlaySound("buy_failed");
  5290. }
  5291. }
  5292. else {
  5293. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase \\aITEM %u 0:%s\\/a.", master_item->details.item_id, master_item->name.c_str());
  5294. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5295. PlaySound("buy_failed");
  5296. }
  5297. }
  5298. }
  5299. }
  5300. }
  5301. }
  5302. void Client::RepairItem(int32 item_id) {
  5303. Spawn* spawn = GetMerchantTransaction();
  5304. if (spawn) {
  5305. Item* item = player->item_list.GetItemFromID(item_id);
  5306. if (!item)
  5307. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5308. if (item) {
  5309. int32 repair_cost = item->CalculateRepairCost();
  5310. if (player->RemoveCoins((int32)repair_cost)) {
  5311. item->generic_info.condition = 100;
  5312. item->save_needed = true;
  5313. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5314. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5315. QueuePacket(item->serialize(version, false, player));
  5316. Message(CHANNEL_COLOR_MERCHANT, "You give %s %s to repair your \\aITEM %u 0:%s\\/a.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->details.item_id, item->name.c_str());
  5317. PlaySound("coin_cha_ching");
  5318. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5319. SendRepairList();
  5320. }
  5321. else {
  5322. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5323. Message(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5324. PlaySound("buy_failed");
  5325. }
  5326. }
  5327. }
  5328. }
  5329. void Client::RepairAllItems() {
  5330. Spawn* spawn = GetMerchantTransaction();
  5331. if (spawn) {
  5332. vector<Item*>* repairable_items = GetRepairableItems();
  5333. if (repairable_items && repairable_items->size() > 0) {
  5334. vector<Item*>::iterator itr;
  5335. int64 total_cost = 0;
  5336. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5337. total_cost += (*itr)->CalculateRepairCost();
  5338. if (player->RemoveCoins((int32)total_cost)) {
  5339. Message(CHANNEL_COLOR_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5340. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5341. Item* item = *itr;
  5342. if (item) {
  5343. item->generic_info.condition = 100;
  5344. item->save_needed = true;
  5345. QueuePacket(item->serialize(version, false, player));
  5346. Message(CHANNEL_COLOR_YELLOW, "Repaired: \\aITEM %u 0:%s\\/a.", item->details.item_id, item->name.c_str());
  5347. }
  5348. }
  5349. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5350. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5351. PlaySound("coin_cha_ching");
  5352. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5353. SendRepairList();
  5354. }
  5355. else {
  5356. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5357. SimpleMessage(CHANNEL_COLOR_MERCHANT, "You do not have enough coin to repair all of your items.");
  5358. PlaySound("buy_failed");
  5359. }
  5360. }
  5361. safe_delete(repairable_items);
  5362. }
  5363. }
  5364. void Client::SendAchievementsList()
  5365. {
  5366. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5367. map<int32, Achievement *>::iterator itr;
  5368. Achievement *achievement;
  5369. vector<AchievementRequirements *> *requirements = 0;
  5370. vector<AchievementRequirements *>::iterator itr2;
  5371. AchievementRequirements *requirement;
  5372. vector<AchievementRewards *> *rewards = 0;
  5373. vector<AchievementRewards *>::iterator itr3;
  5374. AchievementRewards *reward;
  5375. PacketStruct *packet;
  5376. int16 i = 0;
  5377. int16 j = 0;
  5378. int16 k = 0;
  5379. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  5380. return;
  5381. }
  5382. packet->setArrayLengthByName("num_achievements" , achievements->size());
  5383. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  5384. achievement = itr->second;
  5385. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  5386. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  5387. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  5388. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  5389. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  5390. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  5391. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  5392. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  5393. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  5394. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  5395. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  5396. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  5397. requirements = achievement->GetRequirements();
  5398. rewards = achievement->GetRewards();
  5399. j = 0;
  5400. k = 0;
  5401. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  5402. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  5403. requirement = *itr2;
  5404. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  5405. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  5406. j++;
  5407. }
  5408. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  5409. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  5410. reward = *itr3;
  5411. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  5412. k++;
  5413. }
  5414. i++;
  5415. }
  5416. //packet->PrintPacket();
  5417. EQ2Packet* data = packet->serialize();
  5418. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5419. safe_delete(packet);
  5420. safe_delete(data);
  5421. //DumpPacket(app);
  5422. QueuePacket(app);*/
  5423. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  5424. SendAchievementUpdate(true);
  5425. }
  5426. void Client::SendAchievementUpdate(bool first_login) {
  5427. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  5428. map<int32, AchievementUpdate*>::iterator itr;
  5429. AchievementUpdate* update;
  5430. vector<AchievementUpdateItems*>* update_items = 0;
  5431. vector<AchievementUpdateItems*>::iterator itr2;
  5432. AchievementUpdateItems* update_item;
  5433. int16 i = 0;
  5434. int16 j = 0;
  5435. PacketStruct* packet;
  5436. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  5437. return;
  5438. }
  5439. packet->setDataByName("unknown1", first_login ? 1 : 0);
  5440. packet->setArrayLengthByName("num_achievements", updates->size());
  5441. for (itr = updates->begin(); itr != updates->end(); itr++) {
  5442. update = itr->second;
  5443. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  5444. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  5445. update_items = update->GetUpdateItems();
  5446. j = 0;
  5447. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  5448. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  5449. update_item = *itr2;
  5450. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  5451. j++;
  5452. }
  5453. i++;
  5454. }
  5455. //packet->PrintPacket();
  5456. EQ2Packet* data = packet->serialize();
  5457. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5458. safe_delete(packet);
  5459. safe_delete(data);
  5460. //DumpPacket(app);
  5461. QueuePacket(app);
  5462. }
  5463. void Client::SendBuyMerchantList(bool sell) {
  5464. Spawn* spawn = GetMerchantTransaction();
  5465. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5466. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  5467. if (items) {
  5468. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5469. if (packet) {
  5470. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5471. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5472. packet->setArrayLengthByName("num_items", items->size());
  5473. vector<MerchantItemInfo>::iterator itr;
  5474. sint8 item_difficulty = 0;
  5475. int32 sell_price = 0;
  5476. int i = 0;
  5477. int tmp_level = 0;
  5478. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  5479. MerchantItemInfo ItemInfo = *itr;
  5480. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  5481. if (!item)
  5482. continue;
  5483. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5484. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5485. packet->setArrayDataByName("stack_size", item->stack_count, i);
  5486. packet->setArrayDataByName("icon", item->details.icon, i);
  5487. if (item->generic_info.adventure_default_level > 0)
  5488. tmp_level = item->generic_info.adventure_default_level;
  5489. else
  5490. tmp_level = item->generic_info.tradeskill_default_level;
  5491. packet->setArrayDataByName("level", tmp_level, i);
  5492. packet->setArrayDataByName("tier", item->details.tier, i);
  5493. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5494. item_difficulty = player->GetArrowColor(tmp_level);
  5495. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5496. item_difficulty = ARROW_COLOR_WHITE;
  5497. item_difficulty -= 6;
  5498. if (item_difficulty < 0)
  5499. item_difficulty *= -1;
  5500. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5501. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  5502. packet->setArrayDataByName("unknown5", 255, i);
  5503. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  5504. if (GetVersion() <= 1096)
  5505. packet->setArrayDataByName("description", item->description.c_str(), i);
  5506. // If no price set in the merchant_inventory table then use the old method
  5507. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  5508. sell_price = (int32)(item->sell_price * multiplier);
  5509. packet->setArrayDataByName("price", sell_price, i);
  5510. }
  5511. else {
  5512. int8 count = 0;
  5513. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  5514. count++;
  5515. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  5516. count++;
  5517. if (count != 0) {
  5518. packet->setSubArrayLengthByName("num_tokens", count, i);
  5519. int8 index = 0;
  5520. Item* token = 0;
  5521. if (ItemInfo.price_item_id != 0) {
  5522. token = master_item_list.GetItem(ItemInfo.price_item_id);
  5523. if (item) {
  5524. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5525. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  5526. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  5527. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5528. }
  5529. token = 0;
  5530. index++;
  5531. }
  5532. if (ItemInfo.price_item2_id != 0) {
  5533. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  5534. if (item) {
  5535. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  5536. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  5537. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  5538. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  5539. }
  5540. }
  5541. }
  5542. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  5543. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  5544. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  5545. }
  5546. }
  5547. if (sell)
  5548. packet->setDataByName("type", 130);
  5549. else
  5550. packet->setDataByName("type", 2);
  5551. EQ2Packet* outapp = packet->serialize();
  5552. // DumpPacket(outapp);
  5553. QueuePacket(outapp);
  5554. safe_delete(packet);
  5555. }
  5556. safe_delete(items);
  5557. }
  5558. else {
  5559. // Need to send an empty packet in the event there is no item list, otherwise the
  5560. // last item list sent to the player will show for this merchant
  5561. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5562. if (packet) {
  5563. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5564. if (sell)
  5565. packet->setDataByName("type", 130);
  5566. else
  5567. packet->setDataByName("type", 2);
  5568. EQ2Packet* outapp = packet->serialize();
  5569. QueuePacket(outapp);
  5570. safe_delete(packet);
  5571. }
  5572. }
  5573. }
  5574. }
  5575. void Client::SendSellMerchantList(bool sell) {
  5576. Spawn* spawn = GetMerchantTransaction();
  5577. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5578. map<int32, Item*>* items = player->GetItemList();
  5579. if (items) {
  5580. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5581. if (packet) {
  5582. vector<Item*> sellable_items;
  5583. map<int32, Item*>::iterator test_itr;
  5584. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  5585. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  5586. sellable_items.push_back(test_itr->second);
  5587. }
  5588. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5589. packet->setArrayLengthByName("num_items", sellable_items.size());
  5590. vector<Item*>::iterator itr;
  5591. Item* item = 0;
  5592. sint8 item_difficulty = 0;
  5593. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  5594. int32 sell_price = 0;
  5595. Item* master_item = 0;
  5596. int i = 0;
  5597. int tmp_level = 0;
  5598. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  5599. item = *itr;
  5600. master_item = master_item_list.GetItem(item->details.item_id);
  5601. if (master_item)
  5602. sell_price = (int32)(master_item->sell_price * multiplier);
  5603. else
  5604. sell_price = 0;
  5605. if (sell_price > item->sell_price)
  5606. sell_price = item->sell_price;
  5607. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5608. string thename = item->name;
  5609. packet->setArrayDataByName("price", sell_price, i);
  5610. if (player->GetGuild()) {
  5611. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  5612. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  5613. }
  5614. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5615. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  5616. packet->setArrayDataByName("stack_size", item->details.count, i);
  5617. packet->setArrayDataByName("icon", item->details.icon, i);
  5618. if (item->generic_info.adventure_default_level > 0)
  5619. tmp_level = item->generic_info.adventure_default_level;
  5620. else
  5621. tmp_level = item->generic_info.tradeskill_default_level;
  5622. packet->setArrayDataByName("level", item->details.recommended_level, i);
  5623. packet->setArrayDataByName("tier", item->details.tier, i);
  5624. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5625. item_difficulty = player->GetArrowColor(tmp_level);
  5626. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5627. item_difficulty = ARROW_COLOR_WHITE;
  5628. item_difficulty -= 6;
  5629. if (item_difficulty < 0)
  5630. item_difficulty *= -1;
  5631. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5632. if (item->details.count == 1)
  5633. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5634. else
  5635. packet->setArrayDataByName("quantity", item->details.count, i);
  5636. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5637. if (GetVersion() <= 1096)
  5638. packet->setArrayDataByName("description", item->description.c_str(), i);
  5639. }
  5640. if (sell)
  5641. packet->setDataByName("type", 129);
  5642. else
  5643. packet->setDataByName("type", 1);
  5644. packet->setDataByName("unknown8a", 16256, 6);
  5645. packet->setDataByName("unknown8a", 16256, 10);
  5646. //packet->PrintPacket();
  5647. EQ2Packet* outapp = packet->serialize();
  5648. //DumpPacket(outapp);
  5649. QueuePacket(outapp);
  5650. safe_delete(packet);
  5651. }
  5652. safe_delete(items);
  5653. }
  5654. }
  5655. }
  5656. void Client::SendBuyBackList(bool sell) {
  5657. Spawn* spawn = GetMerchantTransaction();
  5658. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5659. deque<BuyBackItem*>::iterator itr;
  5660. int i = 0;
  5661. Item* master_item = 0;
  5662. BuyBackItem* buyback = 0;
  5663. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5664. if (packet) {
  5665. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5666. packet->setArrayLengthByName("num_items", buy_back_items.size());
  5667. sint8 item_difficulty = 0;
  5668. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5669. int tmp_level = 0;
  5670. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  5671. buyback = *itr;
  5672. master_item = master_item_list.GetItem(buyback->item_id);
  5673. if (master_item) {
  5674. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  5675. packet->setArrayDataByName("price", buyback->price, i);
  5676. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  5677. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  5678. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  5679. packet->setArrayDataByName("icon", master_item->details.icon, i);
  5680. if (master_item->generic_info.adventure_default_level > 0)
  5681. tmp_level = master_item->generic_info.adventure_default_level;
  5682. else
  5683. tmp_level = master_item->generic_info.tradeskill_default_level;
  5684. packet->setArrayDataByName("level", tmp_level, i);
  5685. packet->setArrayDataByName("tier", master_item->details.tier, i);
  5686. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  5687. item_difficulty = player->GetArrowColor(tmp_level);
  5688. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5689. item_difficulty = ARROW_COLOR_WHITE;
  5690. item_difficulty -= 6;
  5691. if (item_difficulty < 0)
  5692. item_difficulty *= -1;
  5693. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5694. if (buyback->quantity == 1)
  5695. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5696. else
  5697. packet->setArrayDataByName("quantity", buyback->quantity, i);
  5698. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  5699. if (GetVersion() <= 1096)
  5700. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  5701. }
  5702. }
  5703. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5704. if (sell)
  5705. packet->setDataByName("type", 640);
  5706. else
  5707. packet->setDataByName("type", 512);
  5708. EQ2Packet* outapp = packet->serialize();
  5709. // DumpPacket(outapp);
  5710. QueuePacket(outapp);
  5711. safe_delete(packet);
  5712. }
  5713. }
  5714. }
  5715. void Client::SendRepairList() {
  5716. Spawn* spawn = GetMerchantTransaction();
  5717. if (spawn) {
  5718. vector<Item*>* repairable_items = GetRepairableItems();
  5719. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5720. if (packet) {
  5721. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5722. packet->setArrayLengthByName("num_items", repairable_items->size());
  5723. Item* item = 0;
  5724. sint8 item_difficulty = 0;
  5725. int32 i = 0;
  5726. vector<Item*>::iterator itr;
  5727. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  5728. item = *itr;
  5729. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  5730. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  5731. packet->setArrayDataByName("item_id", item->details.item_id, i);
  5732. packet->setArrayDataByName("stack_size", item->details.count, i);
  5733. packet->setArrayDataByName("icon", item->details.icon, i);
  5734. /*if (item->generic_info.adventure_default_level > 0)
  5735. tmp_level = item->generic_info.adventure_default_level;
  5736. else
  5737. tmp_level = item->generic_info.tradeskill_default_level;
  5738. packet->setArrayDataByName("level", tmp_level, i);*/
  5739. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  5740. packet->setArrayDataByName("tier", item->details.tier, i);
  5741. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  5742. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5743. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5744. item_difficulty = ARROW_COLOR_WHITE;
  5745. item_difficulty -= 6;
  5746. if (item_difficulty < 0)
  5747. item_difficulty *= -1;
  5748. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  5749. if (item->details.count == 1)
  5750. packet->setArrayDataByName("quantity", 0xFFFF, i);
  5751. else
  5752. packet->setArrayDataByName("quantity", item->details.count, i);
  5753. packet->setArrayDataByName("stack_size2", item->details.count, i);
  5754. if (GetVersion() <= 1096)
  5755. packet->setArrayDataByName("description", item->description.c_str(), i);
  5756. }
  5757. packet->setDataByName("type", 96);
  5758. EQ2Packet* outapp = packet->serialize();
  5759. QueuePacket(outapp);
  5760. safe_delete(packet);
  5761. }
  5762. safe_delete(repairable_items);
  5763. }
  5764. }
  5765. void Client::ShowLottoWindow() {
  5766. Spawn* spawn = GetMerchantTransaction();
  5767. if (spawn) {
  5768. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  5769. if (!item_id)
  5770. {
  5771. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  5772. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  5773. return;
  5774. }
  5775. else if (item_id == 0)
  5776. {
  5777. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  5778. return;
  5779. }
  5780. Item* item = master_item_list.GetItem(item_id);
  5781. if (!item) {
  5782. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  5783. return;
  5784. }
  5785. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  5786. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5787. if (packet) {
  5788. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5789. packet->setArrayLengthByName("num_items", 1);
  5790. packet->setArrayDataByName("item_name", item->name.c_str());
  5791. packet->setArrayDataByName("price", item->sell_price);
  5792. packet->setArrayDataByName("item_id", item->details.item_id);
  5793. packet->setArrayDataByName("stack_size", item->details.count);
  5794. packet->setArrayDataByName("icon", item->details.icon);
  5795. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  5796. packet->setArrayDataByName("tier", item->details.tier);
  5797. packet->setArrayDataByName("item_id2", item->details.item_id);
  5798. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  5799. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  5800. item_difficulty = ARROW_COLOR_WHITE;
  5801. item_difficulty -= 6;
  5802. if (item_difficulty < 0)
  5803. item_difficulty *= -1;
  5804. packet->setArrayDataByName("item_difficulty", item_difficulty);
  5805. //if(item->details.count == 1)
  5806. packet->setArrayDataByName("quantity", 0xFFFF);
  5807. //else
  5808. // packet->setArrayDataByName("quantity", item->details.count);
  5809. packet->setArrayDataByName("stack_size2", item->details.count);
  5810. packet->setArrayDataByName("description", item->description.c_str());
  5811. packet->setDataByName("type", 0x00000102);
  5812. QueuePacket(packet->serialize());
  5813. safe_delete(packet);
  5814. }
  5815. }
  5816. }
  5817. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  5818. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  5819. if (packet) {
  5820. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  5821. int32 rolls[6] = { 0 };
  5822. int32 lottery_digits[6] = { 0 };
  5823. int8 num_matches = 0;
  5824. int64 jackpot = 0;
  5825. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  5826. if (!item) {
  5827. return;
  5828. }
  5829. database.DeleteItem(GetCharacterID(), item, 0);
  5830. GetPlayer()->item_list.RemoveItem(item, true);
  5831. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  5832. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  5833. if (!winning_numbers) {
  5834. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  5835. variables.AddVariable(winning_numbers);
  5836. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5837. }
  5838. if (strlen(winning_numbers->GetValue()) != 12) {
  5839. winning_numbers->SetValue("231205182236");
  5840. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5841. }
  5842. try {
  5843. for (int32 i = 0; i < 12; i += 2) {
  5844. char num[4];
  5845. strncpy(num, winning_numbers->GetValue() + i, 2);
  5846. lottery_digits[i / 2] = atoi(num);
  5847. }
  5848. }
  5849. catch (...) {
  5850. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  5851. return;
  5852. }
  5853. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  5854. if (!jackpot_var) {
  5855. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  5856. variables.AddVariable(jackpot_var);
  5857. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5858. }
  5859. try {
  5860. jackpot = atoul(jackpot_var->GetValue());
  5861. if (jackpot < 10000)
  5862. jackpot = 10000;
  5863. }
  5864. catch (...) {
  5865. jackpot = 10000;
  5866. }
  5867. char new_jackpot[128] = { 0 };
  5868. sprintf(new_jackpot, "%llu", jackpot + price);
  5869. jackpot_var->SetValue(new_jackpot);
  5870. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5871. world.PickRandomLottoDigits(rolls);
  5872. packet->setDataByName("roll_digit1", rolls[0]);
  5873. packet->setDataByName("roll_digit2", rolls[1]);
  5874. packet->setDataByName("roll_digit3", rolls[2]);
  5875. packet->setDataByName("roll_digit4", rolls[3]);
  5876. packet->setDataByName("roll_digit5", rolls[4]);
  5877. packet->setDataByName("roll_digit6", rolls[5]);
  5878. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  5879. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  5880. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  5881. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  5882. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  5883. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  5884. QueuePacket(packet->serialize());
  5885. safe_delete(packet);
  5886. for (int32 i = 0; i < 6; i++) {
  5887. for (int32 j = 0; j < 6; j++) {
  5888. if (rolls[i] == lottery_digits[j]) {
  5889. num_matches++;
  5890. break;
  5891. }
  5892. }
  5893. }
  5894. char new_jackpot_str[16];
  5895. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  5896. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  5897. if (num_matches == 6) {
  5898. world.PickRandomLottoDigits(lottery_digits);
  5899. for (int32 i = 0; i < 12; i += 2)
  5900. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  5901. winning_numbers->SetValue(new_jackpot_str);
  5902. jackpot_var->SetValue("10000");
  5903. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  5904. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  5905. }
  5906. }
  5907. }
  5908. void Client::SendGuildCreateWindow() {
  5909. Spawn* spawn = GetPlayer()->GetTarget();
  5910. if (spawn) {
  5911. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  5912. if (packet) {
  5913. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  5914. packet->setArrayLengthByName("num_items", 0);
  5915. packet->setDataByName("type", 0x00008000);
  5916. QueuePacket(packet->serialize());
  5917. safe_delete(packet);
  5918. }
  5919. }
  5920. }
  5921. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  5922. BuyBackItem* item = new BuyBackItem;
  5923. item->item_id = item_id;
  5924. item->unique_id = unique_id;
  5925. item->price = price;
  5926. item->quantity = quantity;
  5927. item->save_needed = save_needed;
  5928. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5929. buy_back_items.push_back(item);
  5930. if (buy_back_items.size() > 10) {
  5931. safe_delete(buy_back_items.front());
  5932. buy_back_items.pop_front();
  5933. }
  5934. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5935. }
  5936. deque<BuyBackItem*>* Client::GetBuyBacks() {
  5937. return &buy_back_items;
  5938. }
  5939. vector<Item*>* Client::GetRepairableItems() {
  5940. vector<Item*>* repairable_items = new vector<Item*>;
  5941. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  5942. map<int32, Item*>* items = player->GetItemList();
  5943. if (equipped_items && equipped_items->size() > 0) {
  5944. for (int32 i = 0; i < equipped_items->size(); i++) {
  5945. Item* item = equipped_items->at(i);
  5946. if (item && item->generic_info.condition < 100)
  5947. repairable_items->push_back(item);
  5948. }
  5949. }
  5950. if (items && items->size() > 0) {
  5951. map<int32, Item*>::iterator itr;
  5952. for (itr = items->begin(); itr != items->end(); itr++) {
  5953. Item* item = itr->second;
  5954. if (item && item->generic_info.condition < 100)
  5955. repairable_items->push_back(item);
  5956. }
  5957. }
  5958. safe_delete(equipped_items);
  5959. safe_delete(items);
  5960. return repairable_items;
  5961. }
  5962. void Client::SendMailList() {
  5963. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  5964. if (kiosk_id > 0) {
  5965. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  5966. if (p) {
  5967. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  5968. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  5969. int16 i = 0;
  5970. p->setDataByName("kiosk_id", kiosk_id);
  5971. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  5972. while (itr.Next()) {
  5973. Mail* mail = itr->second;
  5974. p->setArrayDataByName("mail_id", mail->mail_id, i);
  5975. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  5976. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  5977. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  5978. p->setArrayDataByName("unknown1", 0x0000, i);
  5979. p->setArrayDataByName("already_read", mail->already_read, i);
  5980. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  5981. p->setArrayDataByName("mail_type", mail->mail_type, i);
  5982. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  5983. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  5984. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  5985. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  5986. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  5987. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  5988. p->setArrayDataByName("num_items", mail->stack, i);
  5989. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  5990. p->setArrayDataByName("packetsubtype", 0xFF, i);
  5991. p->setArrayDataByName("unknown2", 0, i);
  5992. //p->setArrayDataByName("item_id", 5, i, 0);
  5993. //Item* item = master_item_list.GetItem(5);
  5994. //if (item)
  5995. // printf("%s\n", item->name.c_str());
  5996. //else
  5997. // printf("no item\n");
  5998. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  5999. i++;
  6000. }
  6001. // GMs send mail for free!
  6002. if (GetAdminStatus() > 0)
  6003. {
  6004. p->setDataByName("postage_cost", 0);
  6005. p->setDataByName("attachment_cost", 0);
  6006. }
  6007. else
  6008. {
  6009. p->setDataByName("postage_cost", 10);
  6010. p->setDataByName("attachment_cost", 50);
  6011. }
  6012. p->setDataByName("unknown3", 0x01F4);
  6013. p->setDataByName("unknown4", 0x01000000);
  6014. QueuePacket(p->serialize());
  6015. safe_delete(p);
  6016. }
  6017. }
  6018. else
  6019. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6020. }
  6021. void Client::DisplayMailMessage(int32 mail_id) {
  6022. Mail* mail = player->GetMail(mail_id);
  6023. if (mail) {
  6024. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6025. if (kiosk_id > 0) {
  6026. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6027. if (update) {
  6028. update->setDataByName("action", 0x03);
  6029. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6030. update->setDataByName("packetsubtype", 0xFF);
  6031. QueuePacket(update->serialize());
  6032. safe_delete(update);
  6033. }
  6034. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  6035. if (packet) {
  6036. packet->setDataByName("kiosk_id", kiosk_id);
  6037. packet->setDataByName("mail_id", mail->mail_id);
  6038. packet->setDataByName("player_to_id", mail->player_to_id);
  6039. packet->setDataByName("player_from", mail->player_from.c_str());
  6040. packet->setDataByName("subject", mail->subject.c_str());
  6041. packet->setDataByName("mail_body", mail->mail_body.c_str());
  6042. packet->setDataByName("unknown1", 1);
  6043. packet->setDataByName("unknown2", 0);
  6044. packet->setDataByName("lock_report_button", 1);
  6045. packet->setDataByName("unknown3", 0xFFFFFFFF);
  6046. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  6047. packet->setDataByName("coin_copper", mail->coin_copper);
  6048. packet->setDataByName("coin_silver", mail->coin_silver);
  6049. packet->setDataByName("coin_gold", mail->coin_gold);
  6050. packet->setDataByName("coin_plat", mail->coin_plat);
  6051. packet->setDataByName("stack", mail->stack);
  6052. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6053. packet->setDataByName("packetsubtype", 0xFF);
  6054. packet->setDataByName("unknown4", 0);
  6055. packet->setDataByName("unknown5", 0);
  6056. packet->setDataByName("unknown6", 0);
  6057. packet->setDataByName("unknown7", 0);
  6058. mail->already_read = true;
  6059. mail->save_needed = true;
  6060. QueuePacket(packet->serialize());
  6061. safe_delete(packet);
  6062. //SendMailList();
  6063. }
  6064. }
  6065. else
  6066. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6067. }
  6068. }
  6069. /* 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
  6070. packet back to the client before the mail actually sent. */
  6071. void Client::HandleSentMail(EQApplicationPacket* app) {
  6072. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  6073. if (packet) {
  6074. packet->LoadPacketData(app->pBuffer, app->size);
  6075. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  6076. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  6077. vector<int32>* ids = 0;
  6078. if (reply_packet) {
  6079. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  6080. if (player_to.length() == 0)
  6081. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  6082. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  6083. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  6084. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  6085. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  6086. else {
  6087. if (player_to.compare("<all>") == 0) {
  6088. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  6089. ids = database.GetAllPlayerIDs();
  6090. else
  6091. SimpleMessage(CHANNEL_COLOR_MAIL, "You may not mail gifts to multiple players.");
  6092. }
  6093. else {
  6094. ids = new vector<int32>;
  6095. ids->push_back(database.GetCharacterID(player_to.c_str()));
  6096. }
  6097. if (ids) {
  6098. for (int32 i = 0; i < ids->size(); i++) {
  6099. int32 player_to_id = ids->at(i);
  6100. if (player_to_id > 0) {
  6101. reply_type = MAIL_SEND_RESULT_SUCCESS;
  6102. Mail* mail = new Mail;
  6103. mail->mail_id = 0;
  6104. mail->player_to_id = player_to_id;
  6105. mail->player_from = string(GetPlayer()->GetName());
  6106. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  6107. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  6108. mail->already_read = 0;
  6109. mail->mail_type = MAIL_TYPE_REGULAR;
  6110. mail->coin_copper = mail_window.coin_copper;
  6111. mail->coin_silver = mail_window.coin_silver;
  6112. mail->coin_gold = mail_window.coin_gold;
  6113. mail->coin_plat = mail_window.coin_plat;
  6114. mail->stack = 0;
  6115. // GM's send mail for free!
  6116. if (GetAdminStatus() > 0)
  6117. {
  6118. mail->postage_cost = 0;
  6119. mail->attachment_cost = 0;
  6120. }
  6121. else
  6122. {
  6123. mail->postage_cost = 10;
  6124. mail->attachment_cost = 50;
  6125. }
  6126. mail->char_item_id = 0;
  6127. mail->time_sent = Timer::GetUnixTimeStamp();
  6128. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  6129. //int16 packettype = packet->getType_int16_ByName("packettype");
  6130. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  6131. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  6132. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  6133. if (postage_cost > 0 || attachment_cost > 0)
  6134. PlaySoundA("coin_cha_ching");*/
  6135. mail->save_needed = false;
  6136. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  6137. if (to_client) {
  6138. to_client->GetPlayer()->AddMail(mail);
  6139. to_client->SimpleMessage(CHANNEL_COLOR_MAIL, "You've got mail! :)");
  6140. }
  6141. database.SavePlayerMail(mail);
  6142. mail_window.coin_copper = 0;
  6143. mail_window.coin_silver = 0;
  6144. mail_window.coin_gold = 0;
  6145. mail_window.coin_plat = 0;
  6146. }
  6147. else
  6148. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  6149. }
  6150. }
  6151. }
  6152. string players_to = "";
  6153. if (ids) {
  6154. for (int32 i = 0; i < ids->size(); i++) {
  6155. if (ids->at(i) != 0)
  6156. players_to.append(database.GetCharacterName(ids->at(i)));
  6157. if (i < (ids->size() - 1))
  6158. players_to.append(", ");
  6159. }
  6160. }
  6161. reply_packet->setDataByName("player_to", players_to.c_str());
  6162. reply_packet->setDataByName("reply_type", reply_type);
  6163. QueuePacket(reply_packet->serialize());
  6164. safe_delete(reply_packet);
  6165. safe_delete(ids);
  6166. }
  6167. safe_delete(packet);
  6168. }
  6169. }
  6170. void Client::DeleteMail(int32 mail_id, bool from_database) {
  6171. player->DeleteMail(mail_id, from_database);
  6172. }
  6173. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6174. bool ret = false;
  6175. if (GetMailTransaction()) {
  6176. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6177. if (packet) {
  6178. if (copper > 0) {
  6179. if (player->RemoveCoins(copper)) {
  6180. mail_window.coin_copper += copper;
  6181. Message(CHANNEL_COLOR_MAIL, "You add %u copper to the mail window.", copper);
  6182. ret = true;
  6183. }
  6184. }
  6185. else if (silver > 0) {
  6186. if (player->RemoveCoins(silver * 100)) {
  6187. mail_window.coin_silver += silver;
  6188. Message(CHANNEL_COLOR_MAIL, "You add %u silver to the mail window.", silver);
  6189. ret = true;
  6190. }
  6191. }
  6192. else if (gold > 0) {
  6193. if (player->RemoveCoins(gold * 10000)) {
  6194. mail_window.coin_gold += gold;
  6195. Message(CHANNEL_COLOR_MAIL, "You add %u gold to the mail window.", gold);
  6196. ret = true;
  6197. }
  6198. }
  6199. else if (plat > 0) {
  6200. if (player->RemoveCoins(plat * 1000000)) {
  6201. mail_window.coin_plat += plat;
  6202. Message(CHANNEL_COLOR_MAIL, "You add %u platinum to the mail window.", plat);
  6203. ret = true;
  6204. }
  6205. }
  6206. if (ret) {
  6207. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6208. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6209. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6210. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6211. packet->setDataByName("stack", 0);
  6212. packet->setDataByName("packettype", GetItemPacketType(version));
  6213. packet->setDataByName("packetsubtype", 0xFF);
  6214. packet->setDataByName("unknown2", 0);
  6215. //packet->PrintPacket();
  6216. QueuePacket(packet->serialize());
  6217. }
  6218. else
  6219. SimpleMessage(CHANNEL_COLOR_MAIL, "You don't have that much money.");
  6220. safe_delete(packet);
  6221. }
  6222. }
  6223. else
  6224. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6225. return ret;
  6226. }
  6227. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6228. bool ret = false;
  6229. if (GetMailTransaction()) {
  6230. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6231. if (packet) {
  6232. if (copper > 0) {
  6233. player->AddCoins(copper);
  6234. mail_window.coin_copper -= copper;
  6235. Message(CHANNEL_COLOR_MAIL, "You remove %u copper from the mail window.", copper);
  6236. ret = true;
  6237. }
  6238. else if (silver > 0) {
  6239. player->AddCoins(silver * 100);
  6240. mail_window.coin_silver -= silver;
  6241. Message(CHANNEL_COLOR_MAIL, "You remove %u silver from the mail window.", silver);
  6242. ret = true;
  6243. }
  6244. else if (gold > 0) {
  6245. player->AddCoins(gold * 10000);
  6246. mail_window.coin_gold -= gold;
  6247. Message(CHANNEL_COLOR_MAIL, "You remove %u gold from the mail window.", gold);
  6248. ret = true;
  6249. }
  6250. else if (plat > 0) {
  6251. player->AddCoins(plat * 1000000);
  6252. mail_window.coin_plat -= plat;
  6253. Message(CHANNEL_COLOR_MAIL, "You remove %u platinum from the mail window.", plat);
  6254. ret = true;
  6255. }
  6256. if (ret) {
  6257. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6258. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6259. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6260. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6261. packet->setDataByName("stack", 0);
  6262. packet->setDataByName("packettype", 0x2BFE);
  6263. packet->setDataByName("packetsubtype", 0xFF);
  6264. packet->setDataByName("unknown2", 0);
  6265. QueuePacket(packet->serialize());
  6266. }
  6267. safe_delete(packet);
  6268. }
  6269. }
  6270. else
  6271. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6272. return ret;
  6273. }
  6274. void Client::TakeMailAttachments(int32 mail_id) {
  6275. if (GetMailTransaction()) {
  6276. Mail* mail = player->GetMail(mail_id);
  6277. if (mail) {
  6278. int64 amount = 0;
  6279. if (mail->coin_copper > 0) {
  6280. amount += mail->coin_copper;
  6281. mail->coin_copper = 0;
  6282. }
  6283. if (mail->coin_silver > 0) {
  6284. amount += mail->coin_silver * 100;
  6285. mail->coin_silver = 0;
  6286. }
  6287. if (mail->coin_gold > 0) {
  6288. amount += mail->coin_gold * 10000;
  6289. mail->coin_gold = 0;
  6290. }
  6291. if (mail->coin_plat > 0) {
  6292. amount += mail->coin_plat * 1000000;
  6293. mail->coin_plat = 0;
  6294. }
  6295. if (mail->char_item_id > 0) {
  6296. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6297. }
  6298. /* 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
  6299. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6300. find it in any packet logs.*/
  6301. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6302. if (packet) {
  6303. packet->setDataByName("unknown", 0x03);
  6304. packet->setDataByName("coin_copper", mail->coin_copper);
  6305. packet->setDataByName("coin_silver", mail->coin_silver);
  6306. packet->setDataByName("coin_gold", mail->coin_gold);
  6307. packet->setDataByName("coin_plat", mail->coin_plat);
  6308. packet->setDataByName("stack", 0);
  6309. packet->setDataByName("packettype", 0x2BFE);
  6310. packet->setDataByName("packetsubtype", 0xFF);
  6311. packet->setDataByName("unknown2", 0);
  6312. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6313. DumpPacket(packet->serialize());
  6314. QueuePacket(packet->serialize());
  6315. safe_delete(packet);
  6316. }*/
  6317. database.SavePlayerMail(mail);
  6318. if (amount > 0)
  6319. player->AddCoins(amount);
  6320. SendMailList();
  6321. }
  6322. }
  6323. else
  6324. SimpleMessage(CHANNEL_COLOR_MAIL, "You are currently not in a mail transaction.");
  6325. }
  6326. void Client::CancelSendMail() {
  6327. SimpleMessage(CHANNEL_COLOR_MAIL, "You cancel sending a letter.");
  6328. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6329. mail_window.coin_copper = 0;
  6330. mail_window.coin_silver = 0;
  6331. mail_window.coin_gold = 0;
  6332. mail_window.coin_plat = 0;
  6333. mail_window.char_item_id = 0;
  6334. }
  6335. bool Client::GateAllowed() {
  6336. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6337. 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__);
  6338. if (zone)
  6339. return true;
  6340. return false;
  6341. }
  6342. bool Client::BindAllowed() {
  6343. 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__);
  6344. return true;
  6345. }
  6346. bool Client::Bind() {
  6347. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  6348. player->GetPlayerInfo()->SetBindX(player->GetX());
  6349. player->GetPlayerInfo()->SetBindY(player->GetY());
  6350. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  6351. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  6352. return true;
  6353. }
  6354. bool Client::Gate() {
  6355. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  6356. return false;
  6357. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6358. if (zone) {
  6359. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  6360. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  6361. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  6362. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  6363. Zone(zone, false);
  6364. return true;
  6365. }
  6366. return false;
  6367. }
  6368. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  6369. if (!destinations || !spawn) {
  6370. return;
  6371. }
  6372. bool has_map = false;
  6373. if (transport_id > 0)
  6374. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  6375. transport_spawn = spawn;
  6376. vector<TransportDestination*> transport_list;
  6377. vector<TransportDestination*>::iterator itr;
  6378. TransportDestination* destination = 0;
  6379. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  6380. destination = *itr;
  6381. 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)))
  6382. transport_list.push_back(destination);
  6383. }
  6384. if (transport_list.size() == 0 && destination) {
  6385. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6386. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  6387. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  6388. else
  6389. {
  6390. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6391. if (app)
  6392. QueuePacket(app);
  6393. }
  6394. }
  6395. else {
  6396. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6397. // determine if this is an instanced zone that already exists
  6398. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  6399. if (instance_zone || new_zone) {
  6400. GetPlayer()->SetX(destination->destination_x);
  6401. GetPlayer()->SetY(destination->destination_y);
  6402. GetPlayer()->SetZ(destination->destination_z);
  6403. GetPlayer()->SetHeading(destination->destination_heading);
  6404. if (instance_zone)
  6405. Zone(instance_zone->GetInstanceID(), false, true);
  6406. else
  6407. Zone(new_zone, false);
  6408. }
  6409. }
  6410. if (destination->message.length() > 0)
  6411. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6412. }
  6413. else if (transport_list.size() > 0) {
  6414. if (!spawn->IsSoundsDisabled())
  6415. PlaySound("mariner_bell");
  6416. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  6417. if (packet) {
  6418. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  6419. // Put all the destinations the player can go in a new vector
  6420. vector<TransportDestination*> destinations;
  6421. for (int32 i = 0; i < transport_list.size(); i++) {
  6422. destination = transport_list.at(i);
  6423. // Check min level
  6424. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  6425. continue;
  6426. // Check max level
  6427. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  6428. continue;
  6429. // Check quest complete
  6430. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  6431. continue;
  6432. // Check req quest and step
  6433. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  6434. continue;
  6435. // 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
  6436. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  6437. packet->setDataByName("current_zone", destination->display_name.c_str());
  6438. packet->setDataByName("current_map_x", destination->map_x);
  6439. packet->setDataByName("current_map_y", destination->map_y);
  6440. }
  6441. else {
  6442. destinations.push_back(destination);
  6443. }
  6444. }
  6445. // Use the new vector to create the packet
  6446. destination = 0;
  6447. packet->setArrayLengthByName("num_destinations", destinations.size());
  6448. for (int32 i = 0; i < destinations.size(); i++) {
  6449. destination = destinations.at(i);
  6450. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  6451. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  6452. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  6453. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  6454. packet->setArrayDataByName("cost", destination->cost, i);
  6455. if (has_map) {
  6456. packet->setArrayDataByName("map_x", destination->map_x, i);
  6457. packet->setArrayDataByName("map_y", destination->map_y, i);
  6458. }
  6459. }
  6460. if (has_map)
  6461. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  6462. EQ2Packet* app = packet->serialize();
  6463. //DumpPacket(app);
  6464. if (destinations.size() > 0)
  6465. QueuePacket(app);
  6466. safe_delete(packet);
  6467. }
  6468. }
  6469. }
  6470. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  6471. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  6472. if (packet) {
  6473. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  6474. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  6475. int32 unique_id = packet->getType_int32_ByName("unique_id");
  6476. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  6477. int32 cost = packet->getType_int32_ByName("cost");
  6478. vector<TransportDestination*> destinations;
  6479. TransportDestination* destination = 0;
  6480. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  6481. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  6482. vector<TransportDestination*>::iterator itr;
  6483. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  6484. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  6485. destination = *itr;
  6486. break;
  6487. }
  6488. }
  6489. SetTemporaryTransportID(0);
  6490. if (!destination)
  6491. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  6492. else {
  6493. if (cost == 0 || player->RemoveCoins(cost)) {
  6494. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6495. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  6496. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  6497. else
  6498. {
  6499. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6500. if (outapp)
  6501. QueuePacket(outapp);
  6502. }
  6503. }
  6504. else {
  6505. GetPlayer()->SetX(destination->destination_x);
  6506. GetPlayer()->SetY(destination->destination_y);
  6507. GetPlayer()->SetZ(destination->destination_z);
  6508. GetPlayer()->SetHeading(destination->destination_heading);
  6509. // Test if where we're going is an Instanced zone
  6510. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  6511. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  6512. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6513. Zone(new_zone, false);
  6514. }
  6515. }
  6516. if (destination->message.length() > 0)
  6517. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6518. }
  6519. else
  6520. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  6521. }
  6522. }
  6523. safe_delete(packet);
  6524. }
  6525. }
  6526. void Client::SendNewSpells(int8 class_id) {
  6527. if (class_id > 0) {
  6528. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  6529. vector<Spell*>::iterator itr;
  6530. Spell* spell = 0;
  6531. bool send_updates = false;
  6532. for (itr = spells->begin(); itr != spells->end(); itr++) {
  6533. spell = *itr;
  6534. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  6535. send_updates = true;
  6536. SendSpellUpdate(spell);
  6537. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  6538. player->UnlockSpell(spell);
  6539. }
  6540. }
  6541. if (send_updates) {
  6542. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  6543. if (outapp)
  6544. QueuePacket(outapp);
  6545. }
  6546. safe_delete(spells);
  6547. }
  6548. }
  6549. void Client::SetItemSearch(vector<Item*>* items) {
  6550. if (items) {
  6551. safe_delete(search_items);
  6552. search_items = items;
  6553. }
  6554. }
  6555. vector<Item*>* Client::GetSearchItems() {
  6556. return search_items;
  6557. }
  6558. void Client::SearchStore(int32 page) {
  6559. if (search_items) {
  6560. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  6561. if (packet) {
  6562. int32 x = page * 8;
  6563. if (search_items->size() > 8) {
  6564. if ((search_items->size() - x) > 8)
  6565. packet->setArrayLengthByName("num_items", 8);
  6566. else
  6567. packet->setArrayLengthByName("num_items", search_items->size() - x);
  6568. }
  6569. else
  6570. packet->setArrayLengthByName("num_items", search_items->size());
  6571. if (search_items->size() > 0) {
  6572. packet->setArrayLengthByName("num_sellers", 1);
  6573. packet->setArrayDataByName("seller_seller_id", 1);
  6574. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  6575. packet->setDataByName("per_page", 8);
  6576. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  6577. packet->setDataByName("page", page);
  6578. Item* item = 0;
  6579. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  6580. for (int32 i = 0; i < limit; i++, x++) {
  6581. if (x >= search_items->size())
  6582. break;
  6583. item = search_items->at(x);
  6584. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6585. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6586. packet->setArrayDataByName("icon", item->details.icon, i);
  6587. //packet->setArrayDataByName("unknown2b", i, i);
  6588. packet->setArrayDataByName("item_seller_id", 1, i);
  6589. if (item->stack_count == 0)
  6590. packet->setArrayDataByName("quantity", 1, i);
  6591. else
  6592. packet->setArrayDataByName("quantity", item->stack_count, i);
  6593. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6594. std::string tmpStr("");
  6595. tmpStr.append(item->name.c_str());
  6596. tmpStr.append(" (");
  6597. tmpStr.append(std::to_string(item->details.item_id));
  6598. tmpStr.append(")");
  6599. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  6600. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  6601. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  6602. }
  6603. }
  6604. /*EQ2Packet* outapp = packet->serialize();
  6605. DumpPacket(outapp);
  6606. QueuePacket(outapp);*/
  6607. QueuePacket(packet->serialize());
  6608. safe_delete(packet);
  6609. }
  6610. }
  6611. }
  6612. void Client::SetReadyForSpawns(bool val) {
  6613. ready_for_spawns = val;
  6614. if (GetPlayer()->GetActivityStatus() > 0) {
  6615. GetPlayer()->SetActivityStatus(0);
  6616. if (GetPlayer()->GetGroupMemberInfo()) {
  6617. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  6618. }
  6619. }
  6620. zone_list.CheckFriendZoned(this);
  6621. }
  6622. void Client::SendChatRelationship(int8 type, const char* name) {
  6623. if (!name) {
  6624. return;
  6625. }
  6626. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6627. if (packet) {
  6628. packet->setDataByName("account_id", GetAccountID());
  6629. packet->setDataByName("type", type);
  6630. packet->setArrayLengthByName("num_names", 1);
  6631. packet->setArrayDataByName("name", name);
  6632. if (type == 0) {
  6633. Client* client = zone_list.GetClientByCharName(name);
  6634. if (client) {
  6635. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  6636. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  6637. }
  6638. }
  6639. QueuePacket(packet->serialize());
  6640. safe_delete(packet);
  6641. }
  6642. }
  6643. void Client::SendFriendList() {
  6644. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6645. if (packet) {
  6646. packet->setDataByName("account_id", GetAccountID());
  6647. map<string, int8>::iterator itr;
  6648. map<string, int8>* friends = player->GetFriends();
  6649. if (friends && friends->size() > 0) {
  6650. Client* client = 0;
  6651. vector<string> names;
  6652. for (itr = friends->begin(); itr != friends->end(); itr++) {
  6653. if (itr->second == 2)
  6654. continue;
  6655. names.push_back(itr->first);
  6656. }
  6657. packet->setArrayLengthByName("num_names", names.size());
  6658. for (int32 i = 0; i < names.size(); i++) {
  6659. client = zone_list.GetClientByCharName(names[i]);
  6660. packet->setArrayDataByName("name", names[i].c_str(), i);
  6661. if (client) {
  6662. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  6663. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  6664. }
  6665. }
  6666. }
  6667. QueuePacket(packet->serialize());
  6668. safe_delete(packet);
  6669. }
  6670. }
  6671. void Client::SendIgnoreList() {
  6672. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  6673. if (packet) {
  6674. packet->setDataByName("account_id", GetAccountID());
  6675. packet->setDataByName("type", 2);
  6676. map<string, int8>::iterator itr;
  6677. map<string, int8>* ignored = player->GetIgnoredPlayers();
  6678. if (ignored && ignored->size() > 0) {
  6679. vector<string> names;
  6680. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  6681. if (itr->second == 2)
  6682. continue;
  6683. names.push_back(itr->first);
  6684. }
  6685. packet->setArrayLengthByName("num_names", names.size());
  6686. for (int32 i = 0; i < names.size(); i++)
  6687. packet->setArrayDataByName("name", names[i].c_str(), i);
  6688. }
  6689. QueuePacket(packet->serialize());
  6690. safe_delete(packet);
  6691. }
  6692. }
  6693. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  6694. if (waypoint_name) {
  6695. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  6696. if (packet) {
  6697. packet->setArrayLengthByName("num_updates", 1);
  6698. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  6699. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  6700. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  6701. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  6702. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  6703. QueuePacket(packet->serialize());
  6704. safe_delete(packet);
  6705. }
  6706. }
  6707. }
  6708. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  6709. if (waypoint_name) {
  6710. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  6711. if (packet) {
  6712. packet->setArrayLengthByName("num_points", 1);
  6713. packet->setArrayDataByName("x", x, 0);
  6714. packet->setArrayDataByName("y", y, 0);
  6715. packet->setArrayDataByName("z", z, 0);
  6716. packet->setDataByName("waypoint_x", x);
  6717. packet->setDataByName("waypoint_y", y);
  6718. packet->setDataByName("waypoint_z", z);
  6719. packet->setDataByName("waypoint_name", waypoint_name);
  6720. packet->setDataByName("unknown", 0);
  6721. QueuePacket(packet->serialize());
  6722. safe_delete(packet);
  6723. }
  6724. }
  6725. }
  6726. void Client::InspectPlayer(Player* player_to_inspect) {
  6727. if (player_to_inspect) {
  6728. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  6729. if (packet) {
  6730. packet->setDataByName("unknown", 0);
  6731. packet->setSmallStringByName("name", player_to_inspect->GetName());
  6732. packet->setDataByName("race", player_to_inspect->GetRace());
  6733. packet->setDataByName("gender", player_to_inspect->GetGender());
  6734. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  6735. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6736. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  6737. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  6738. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  6739. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  6740. packet->setDataByName("health", player_to_inspect->GetHP());
  6741. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  6742. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  6743. packet->setDataByName("power", player_to_inspect->GetPower());
  6744. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  6745. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  6746. packet->setDataByName("mitigation", 0);
  6747. packet->setDataByName("unknown1", 0);
  6748. packet->setDataByName("avoidance", 0);
  6749. packet->setDataByName("unknown2", 0);
  6750. packet->setDataByName("mitigation_percentage", 0);
  6751. packet->setDataByName("strength", player_to_inspect->GetStr());
  6752. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  6753. packet->setDataByName("stamina", player_to_inspect->GetSta());
  6754. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  6755. packet->setDataByName("agility", player_to_inspect->GetAgi());
  6756. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  6757. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  6758. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  6759. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  6760. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  6761. packet->setDataByName("unknown4", 0);
  6762. packet->setDataByName("unknown5", 0);
  6763. packet->setDataByName("unknown6", 0);
  6764. packet->setDataByName("unknown7", 0);
  6765. packet->setDataByName("unknown8", 0);
  6766. packet->setDataByName("unknown9", 0);
  6767. packet->setDataByName("unknown10", 0);
  6768. packet->setDataByName("unknown11", 0);
  6769. packet->setDataByName("unknown12", 0);
  6770. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  6771. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  6772. packet->setDataByName("heat_resist_percentage", 0);
  6773. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  6774. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  6775. packet->setDataByName("cold_resist_percentage", 0);
  6776. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  6777. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  6778. packet->setDataByName("magic_resist_percentage", 0);
  6779. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  6780. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  6781. packet->setDataByName("mental_resist_percentage", 0);
  6782. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  6783. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  6784. packet->setDataByName("divine_resist_percentage", 0);
  6785. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  6786. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  6787. packet->setDataByName("disease_resist_percentage", 0);
  6788. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  6789. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  6790. packet->setDataByName("poison_resist_percentage", 0);
  6791. packet->setArrayLengthByName("num_chars", 0x01FF);
  6792. string biography = player_to_inspect->GetBiography();
  6793. for (size_t i = 0; i < biography.length(); i++)
  6794. packet->setArrayDataByName("biography_char", biography[i], i);
  6795. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  6796. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  6797. if (pw)
  6798. packet->setItemByName("primary", pw, player_to_inspect, 0);
  6799. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  6800. if (sw)
  6801. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  6802. //DumpPacket(packet->serialize());
  6803. QueuePacket(packet->serialize());
  6804. safe_delete(packet);
  6805. }
  6806. }
  6807. }
  6808. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  6809. pending_guild_invite.guild = guild;
  6810. pending_guild_invite.invited_by = invited_by;
  6811. }
  6812. void Client::ShowClaimWindow() {
  6813. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  6814. if (packet) {
  6815. map<int32, Item*>* items = &master_item_list.items;
  6816. map<int32, Item*>::iterator itr;
  6817. int32 i = 0;
  6818. if (items->size() > 10)
  6819. packet->setArrayLengthByName("num_claim_items", 10);
  6820. else
  6821. packet->setArrayLengthByName("num_claim_items", items->size());
  6822. for (itr = items->begin(); itr != items->end(); itr++) {
  6823. if (i == 10)
  6824. break;
  6825. Item* item = itr->second;
  6826. packet->setArrayDataByName("id", i, i);
  6827. packet->setArrayDataByName("not_yet_claimed", 1, i);
  6828. packet->setArrayDataByName("num_remaining", 5, i);
  6829. packet->setArrayDataByName("one_per_character", 1, i);
  6830. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  6831. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6832. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  6833. packet->setArrayDataByName("category", "Scott's Shit", i);
  6834. packet->setArrayDataByName("icon", item->details.icon, i);
  6835. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6836. i++;
  6837. }
  6838. packet->setDataByName("unknown3", 1);
  6839. QueuePacket(packet->serialize());
  6840. safe_delete(packet);
  6841. }
  6842. }
  6843. void Client::ShowGuildSearchWindow() {
  6844. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  6845. if (packet) {
  6846. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  6847. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  6848. packet->setArrayLengthByName("num_guilds", guilds->size());
  6849. int32 i = 0;
  6850. while (itr.Next()) {
  6851. Guild* guild = itr.second;
  6852. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  6853. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  6854. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  6855. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  6856. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  6857. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  6858. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  6859. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  6860. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  6861. packet->setArrayDataByName("unknown7", 0x02, i);
  6862. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  6863. i++;
  6864. }
  6865. QueuePacket(packet->serialize());
  6866. safe_delete(packet);
  6867. }
  6868. }
  6869. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  6870. PacketStruct* packet;
  6871. vector<int8>* slot_data;
  6872. vector<int8>::iterator itr;
  6873. int32 slots = 0;
  6874. assert(item);
  6875. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  6876. return;
  6877. }
  6878. slot_data = &item->slot_data;
  6879. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  6880. if (version >= 1188)
  6881. slots = *itr;
  6882. else
  6883. slots += (int8)pow(2.0, *itr);
  6884. }
  6885. packet->setDataByName("slot", slots);
  6886. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  6887. if (slots == 2) {
  6888. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  6889. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  6890. }
  6891. else {
  6892. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  6893. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  6894. }
  6895. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  6896. if (slots == 4) {
  6897. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  6898. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  6899. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  6900. }
  6901. else if (slots == 7) {
  6902. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  6903. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  6904. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  6905. }
  6906. else {
  6907. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  6908. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  6909. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  6910. }
  6911. packet->setDataByName("icon", item->details.icon);
  6912. packet->setDataByName("item_id", item->details.item_id);
  6913. packet->setDataByName("item_crc", crc);
  6914. packet->setDataByName("unknown2", 0xFFFFFFFF);
  6915. packet->setDataByName("unknown4", 0xFFFFFFFF);
  6916. packet->setDataByName("unknown5", 0xFF, 9);
  6917. packet->setDataByName("unknown5", 0xFF, 10);
  6918. QueuePacket(packet->serialize());
  6919. safe_delete(packet);
  6920. }
  6921. void Client::SendCollectionList() {
  6922. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  6923. map<int32, Collection*>::iterator itr;
  6924. vector<struct CollectionItem*>* collection_items;
  6925. Collection* collection;
  6926. struct CollectionItem* collection_item;
  6927. PacketStruct* packet = 0;
  6928. int16 i = 0, j;
  6929. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  6930. return;
  6931. packet->setArrayLengthByName("num_collections", collections->size());
  6932. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6933. collection = itr->second;
  6934. collection_items = collection->GetCollectionItems();
  6935. packet->setArrayDataByName("unknown", 1, i);
  6936. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  6937. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  6938. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  6939. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  6940. packet->setArrayDataByName("level", collection->GetLevel(), i);
  6941. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  6942. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  6943. for (j = 0; j < collection_items->size(); j++) {
  6944. collection_item = collection_items->at(j);
  6945. Item* item = master_item_list.GetItem(collection_item->item);
  6946. if (item) {
  6947. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  6948. if (version < 955)
  6949. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  6950. else
  6951. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  6952. }
  6953. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  6954. }
  6955. i++;
  6956. }
  6957. packet->setDataByName("new_collection_flag", 1);
  6958. QueuePacket(packet->serialize());
  6959. safe_delete(packet);
  6960. }
  6961. bool Client::SendCollectionsForItem(Item* item) {
  6962. map<int32, Collection*> collections_to_send;
  6963. map<int32, Collection*>* collections;
  6964. map<int32, Collection*>::iterator itr;
  6965. vector<struct CollectionItem*>* collection_items;
  6966. Collection* collection;
  6967. struct CollectionItem* collection_item;
  6968. PacketStruct* packet;
  6969. int16 i;
  6970. assert(item);
  6971. /* get any collections required by this item that the player already has */
  6972. collections = player->GetCollectionList()->GetCollections();
  6973. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6974. collection = itr->second;
  6975. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  6976. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  6977. collections_to_send[collection->GetID()] = collection;
  6978. }
  6979. }
  6980. /* get any collections required by this item that the player does not have and send it to the client */
  6981. collections = master_collection_list.GetCollections();
  6982. for (itr = collections->begin(); itr != collections->end(); itr++) {
  6983. collection = itr->second;
  6984. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  6985. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  6986. return false;
  6987. }
  6988. packet->setArrayLengthByName("num_collections", 1);
  6989. packet->setArrayDataByName("unknown", 1, 0);
  6990. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  6991. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  6992. packet->setArrayDataByName("completed", 0, 0);
  6993. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  6994. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  6995. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  6996. packet->setArrayDataByName("unknown3", 0x28, 0);
  6997. collection_items = collection->GetCollectionItems();
  6998. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  6999. for (i = 0; i < collection_items->size(); i++) {
  7000. collection_item = collection_items->at(i);
  7001. Item* item2 = master_item_list.GetItem(collection_item->item);
  7002. if (item2) {
  7003. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  7004. if (version < 955)
  7005. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  7006. else
  7007. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  7008. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  7009. }
  7010. }
  7011. packet->setDataByName("new_collection_flag", 0);
  7012. QueuePacket(packet->serialize());
  7013. safe_delete(packet);
  7014. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  7015. collections_to_send[collection->GetID()] = collection;
  7016. }
  7017. }
  7018. /* send the client a list of collections that should be filtered for this item */
  7019. if (collections_to_send.size() > 0) {
  7020. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  7021. return false;
  7022. }
  7023. i = 0;
  7024. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  7025. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  7026. collection = itr->second;
  7027. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7028. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  7029. i++;
  7030. }
  7031. packet->setDataByName("item_icon", item->details.icon);
  7032. packet->setDataByName("item_name", item->name.c_str());
  7033. packet->setDataByName("item_id", item->details.item_id);
  7034. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  7035. QueuePacket(packet->serialize());
  7036. safe_delete(packet);
  7037. }
  7038. return collections_to_send.size() > 0;
  7039. }
  7040. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  7041. Collection* collection;
  7042. struct CollectionItem* collection_item;
  7043. PacketStruct* packet;
  7044. char tmp[200] = { 0 };
  7045. assert(item);
  7046. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  7047. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  7048. /* get the item struct that represents the item for this collection */
  7049. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7050. SendCollectionList();
  7051. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7052. return;
  7053. }
  7054. /* sanity check */
  7055. if (collection_item->found) {
  7056. SendCollectionList();
  7057. 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());
  7058. return;
  7059. }
  7060. }
  7061. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  7062. collection = new Collection(collection);
  7063. /* get the item struct that represents the item for this collection */
  7064. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7065. SendCollectionList();
  7066. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7067. safe_delete(collection);
  7068. return;
  7069. }
  7070. /* add the new collection to the player's collection list */
  7071. if (!player->GetCollectionList()->AddCollection(collection)) {
  7072. SendCollectionList();
  7073. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  7074. safe_delete(collection);
  7075. return;
  7076. }
  7077. }
  7078. else {
  7079. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  7080. return;
  7081. }
  7082. collection_item->found = 1;
  7083. collection->SetSaveNeeded(true);
  7084. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  7085. SendCollectionList();
  7086. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  7087. return;
  7088. }
  7089. packet->setDataByName("collection_id", collection_id);
  7090. packet->setDataByName("collection_item_num", collection_item->index);
  7091. packet->setDataByName("add", 1);
  7092. QueuePacket(packet->serialize());
  7093. Item* item2 = master_item_list.GetItem(collection_item->item);
  7094. if (item2) {
  7095. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7096. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7097. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  7098. }
  7099. safe_delete(packet);
  7100. RemoveItem(item, 1);
  7101. SendCollectionList();
  7102. }
  7103. void Client::DisplayCollectionComplete(Collection* collection) {
  7104. vector<struct CollectionRewardItem*>* reward_items;
  7105. vector<struct CollectionRewardItem*>* selectable_reward_items;
  7106. struct CollectionRewardItem* reward_item;
  7107. PacketStruct* packet;
  7108. int32 i;
  7109. assert(collection);
  7110. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  7111. return;
  7112. }
  7113. reward_items = collection->GetRewardItems();
  7114. selectable_reward_items = collection->GetSelectableRewardItems();
  7115. packet->setDataByName("title", "Quest Reward!");
  7116. packet->setDataByName("name", collection->GetName());
  7117. packet->setDataByName("description", collection->GetCategory());
  7118. packet->setDataByName("level", collection->GetLevel());
  7119. packet->setDataByName("max_coin", collection->GetRewardCoin());
  7120. packet->setDataByName("min_coin", collection->GetRewardCoin());
  7121. //packet->setDataByName("status_points", quest->GetStatusPoints());
  7122. packet->setArrayLengthByName("num_rewards", reward_items->size());
  7123. for (i = 0; i < reward_items->size(); i++) {
  7124. reward_item = reward_items->at(i);
  7125. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  7126. if (version < 860)
  7127. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  7128. else if (version < 1193)
  7129. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  7130. else
  7131. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  7132. }
  7133. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  7134. for (i = 0; i < selectable_reward_items->size(); i++) {
  7135. reward_item = selectable_reward_items->at(i);
  7136. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  7137. if (version < 860)
  7138. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  7139. else if (version < 1193)
  7140. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  7141. else
  7142. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  7143. }
  7144. QueuePacket(packet->serialize());
  7145. safe_delete(packet);
  7146. }
  7147. void Client::HandInCollections() {
  7148. map<int32, Collection*>* collections;
  7149. map<int32, Collection*>::iterator itr;
  7150. Collection* collection;
  7151. /* only show 1 collection reward dialog at a time */
  7152. if (player->GetPendingCollectionReward()) {
  7153. return;
  7154. }
  7155. collections = player->GetCollectionList()->GetCollections();
  7156. /* 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
  7157. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  7158. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7159. collection = itr->second;
  7160. if (collection->GetIsReadyToTurnIn()) {
  7161. player->SetPendingCollectionReward(collection);
  7162. DisplayCollectionComplete(collection);
  7163. return;
  7164. }
  7165. }
  7166. }
  7167. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  7168. vector<struct CollectionRewardItem*>* reward_items;
  7169. vector<struct CollectionRewardItem*>::iterator itr;
  7170. struct CollectionRewardItem* reward_item;
  7171. int16 num_slots_needed;
  7172. int16 num_slots;
  7173. assert(collection);
  7174. reward_items = collection->GetRewardItems();
  7175. num_slots_needed = (int16)reward_items->size();
  7176. if (selectable_item_id > 0)
  7177. num_slots_needed++;
  7178. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  7179. if (num_slots < num_slots_needed) {
  7180. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  7181. HandInCollections();
  7182. return;
  7183. }
  7184. /* add manditory items */
  7185. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7186. reward_item = *itr;
  7187. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7188. }
  7189. /* find and add the selectable item if there's one */
  7190. if (selectable_item_id > 0) {
  7191. reward_items = collection->GetSelectableRewardItems();
  7192. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7193. reward_item = *itr;
  7194. if (reward_item->item->details.item_id == selectable_item_id) {
  7195. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7196. break;
  7197. }
  7198. }
  7199. }
  7200. if (collection->GetRewardXP() > 0) {
  7201. player->AddXP((int32)collection->GetRewardXP());
  7202. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7203. }
  7204. if (collection->GetRewardCoin() > 0) {
  7205. player->AddCoins(collection->GetRewardCoin());
  7206. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7207. }
  7208. collection->SetCompleted(true);
  7209. //update achievements for completeing collection here
  7210. collection->SetSaveNeeded(true);
  7211. SendCollectionList();
  7212. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7213. player->SetPendingCollectionReward(0);
  7214. HandInCollections();
  7215. }
  7216. void Client::SendRecipeList() {
  7217. PacketStruct* packet = 0;
  7218. if (GetRecipeListSent()) {
  7219. return;
  7220. }
  7221. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7222. return;
  7223. }
  7224. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7225. map<int32, Recipe*>::iterator itr;
  7226. Recipe* recipe;
  7227. int16 i = 0;
  7228. packet->setArrayLengthByName("num_recipes", recipes->size());
  7229. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7230. recipe = itr->second;
  7231. packet->setArrayDataByName("id", recipe->GetID(), i);
  7232. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7233. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  7234. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  7235. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  7236. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  7237. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  7238. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  7239. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  7240. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  7241. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  7242. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  7243. i++;
  7244. }
  7245. //packet->PrintPacket();
  7246. //DumpPacket(packet->serialize());
  7247. QueuePacket(packet->serialize());
  7248. safe_delete(packet);
  7249. SetRecipeListSent(true);
  7250. }
  7251. void Client::ShowRecipeBook() {
  7252. PacketStruct* packet = 0;
  7253. Spawn* target = 0;
  7254. if (!(target = player->GetTarget())) {
  7255. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  7256. return;
  7257. }
  7258. if (!target->IsObject()) {
  7259. return;
  7260. }
  7261. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  7262. return;
  7263. }
  7264. packet->setDataByName("device", target->GetName());
  7265. packet->setDataByName("unknown1", 1);
  7266. if (((Object*)target)->GetDeviceID() > 0) {
  7267. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  7268. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  7269. packet->setDataByName("unknown2", 8);
  7270. packet->setDataByName("unknown3", deviceID);
  7271. }
  7272. //packet->PrintPacket();
  7273. QueuePacket(packet->serialize());
  7274. safe_delete(packet);
  7275. }
  7276. void Client::SendTitleUpdate() {
  7277. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  7278. list<Title*>::iterator itr;
  7279. Title* title;
  7280. int16 i = 0;
  7281. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  7282. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  7283. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  7284. if (packet) {
  7285. packet->setArrayLengthByName("num_titles", titles->size());
  7286. for (itr = titles->begin(); itr != titles->end(); itr++) {
  7287. title = *itr;
  7288. packet->setArrayDataByName("title", title->GetName(), i);
  7289. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  7290. i++;
  7291. }
  7292. packet->setDataByName("current_prefix", prefix_index);
  7293. packet->setDataByName("current_suffix", suffix_index);
  7294. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7295. #if EQDEBUG >= 9
  7296. packet->PrintPacket();
  7297. #endif
  7298. QueuePacket(packet->serialize());
  7299. safe_delete(packet);
  7300. SendUpdateTitles(prefix_index, suffix_index);
  7301. }
  7302. }
  7303. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  7304. Title* suffix_title = 0;
  7305. Title* prefix_title = 0;
  7306. if (suffix != -1) {
  7307. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  7308. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  7309. }
  7310. else
  7311. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  7312. if (prefix != -1) {
  7313. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  7314. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  7315. }
  7316. else
  7317. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  7318. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  7319. }
  7320. void Client::SendLanguagesUpdate(int32 id) {
  7321. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  7322. list<Language*>::iterator itr;
  7323. Language* language;
  7324. int32 i = 0;
  7325. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  7326. if (packet) {
  7327. packet->setArrayLengthByName("num_languages", languages->size());
  7328. for (itr = languages->begin(); itr != languages->end(); itr++) {
  7329. language = *itr;
  7330. packet->setArrayDataByName("language_id", language->GetID(), i);
  7331. i++;
  7332. }
  7333. packet->setDataByName("current_language", id);
  7334. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7335. #if EQDEBUG >= 9
  7336. packet->PrintPacket();
  7337. #endif
  7338. QueuePacket(packet->serialize());
  7339. safe_delete(packet);
  7340. }
  7341. }
  7342. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  7343. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  7344. if (packet) {
  7345. if (pet_name)
  7346. packet->setDataByName("pet_name", pet_name);
  7347. if (player->GetInfoStruct()->pet_behavior & 1)
  7348. packet->setDataByName("protect_master", 1);
  7349. if (player->GetInfoStruct()->pet_behavior & 2)
  7350. packet->setDataByName("protect_self", 1);
  7351. if (player->GetInfoStruct()->pet_movement == 2)
  7352. packet->setDataByName("stay_follow_toggle", 1);
  7353. packet->setDataByName("pet_type", type);
  7354. QueuePacket(packet->serialize());
  7355. }
  7356. safe_delete(packet);
  7357. }
  7358. bool Client::IsCrafting() {
  7359. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  7360. }
  7361. void Client::SendBiography() {
  7362. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  7363. if (packet) {
  7364. if (strlen(player->GetInfoStruct()->biography) > 0)
  7365. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  7366. QueuePacket(packet->serialize());
  7367. }
  7368. safe_delete(packet);
  7369. }
  7370. PendingResurrection* Client::GetCurrentRez() {
  7371. return &current_rez;
  7372. }
  7373. Mutex* Client::GetResurrectMutex() {
  7374. return &m_resurrect;
  7375. }
  7376. void Client::SendResurrectionWindow() {
  7377. Spawn* caster = current_rez.caster;
  7378. if (!caster || !player)
  7379. return;
  7380. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7381. if (!packet)
  7382. return;
  7383. char* tmp = new char[512];
  7384. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  7385. packet->setMediumStringByName("text", tmp);
  7386. packet->setMediumStringByName("accept_text", "Yes");
  7387. packet->setMediumStringByName("cancel_text", "No");
  7388. sprintf(tmp, "accept_resurrection %u", player->GetID());
  7389. packet->setMediumStringByName("accept_command", tmp);
  7390. sprintf(tmp, "decline_resurrection %u", player->GetID());
  7391. packet->setMediumStringByName("cancel_command", tmp);
  7392. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  7393. QueuePacket(packet->serialize());
  7394. safe_delete(packet);
  7395. safe_delete_array(tmp);
  7396. }
  7397. void Client::AcceptResurrection() {
  7398. Spawn* caster = current_rez.caster;
  7399. if (!player || !caster)
  7400. return;
  7401. if (player->Alive())
  7402. return;
  7403. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  7404. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  7405. SendResurrectionWindow();
  7406. return;
  7407. }
  7408. player->GetZone()->ResurrectSpawn(player, this);
  7409. current_rez.should_delete = true;
  7410. }
  7411. void Client::SetPendingLastName(string last_name) {
  7412. pending_last_name = new string;
  7413. pending_last_name->assign(last_name);
  7414. }
  7415. string* Client::GetPendingLastName() {
  7416. return pending_last_name;
  7417. }
  7418. void Client::RemovePendingLastName() {
  7419. safe_delete(pending_last_name);
  7420. }
  7421. void Client::SendLastNameConfirmation() {
  7422. if (!pending_last_name)
  7423. return;
  7424. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7425. if (packet) {
  7426. char* text = new char[128];
  7427. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  7428. packet->setDataByName("text", text);
  7429. packet->setDataByName("accept_text", "Yes");
  7430. packet->setDataByName("accept_command", "confirmedlastname");
  7431. packet->setDataByName("cancel_text", "No");
  7432. packet->setDataByName("unknown2", 50);
  7433. packet->setDataByName("unknown4", 1);
  7434. packet->setDataByName("unknown5", 1);
  7435. QueuePacket(packet->serialize());
  7436. safe_delete(packet);
  7437. safe_delete_array(text);
  7438. }
  7439. }
  7440. void Client::AddQuestTimer(int32 quest_id) {
  7441. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7442. quest_timers.push_back(quest_id);
  7443. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7444. }
  7445. void Client::RemoveQuestTimer(int32 quest_id) {
  7446. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  7447. vector<int32>::iterator itr;
  7448. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  7449. if ((*itr) == quest_id) {
  7450. quest_timers.erase(itr);
  7451. break;
  7452. }
  7453. }
  7454. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  7455. }
  7456. void Client::SavePlayerImages() {
  7457. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  7458. // Save the paperdoll image if the server allows it
  7459. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  7460. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7461. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  7462. // Save the head shot if the server allows it
  7463. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  7464. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7465. // Send the head shot to the login server
  7466. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  7467. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  7468. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  7469. memset(packet->pBuffer, 0, size);
  7470. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  7471. pic->account_id = GetAccountID();
  7472. pic->char_id = GetCharacterID();
  7473. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  7474. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  7475. loginserver.SendPacket(packet);
  7476. safe_delete(packet);
  7477. }
  7478. }
  7479. safe_delete_array(incoming_paperdoll.image_bytes);
  7480. incoming_paperdoll.current_size_bytes = 0;
  7481. }
  7482. void Client::EndAutoMount() {
  7483. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7484. if (packet) {
  7485. packet->setDataByName("parameter1", 128);
  7486. packet->setDataByName("parameter2", 64);
  7487. packet->setDataByName("value", 1);
  7488. QueuePacket(packet->serialize());
  7489. safe_delete(packet);
  7490. }
  7491. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  7492. if (packet) {
  7493. packet->setDataByName("parameter3", 4);
  7494. packet->setDataByName("parameter5", 2);
  7495. packet->setDataByName("value", 0);
  7496. QueuePacket(packet->serialize());
  7497. safe_delete(packet);
  7498. }
  7499. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  7500. if (packet) {
  7501. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  7502. QueuePacket(packet->serialize());
  7503. safe_delete(packet);
  7504. }
  7505. on_auto_mount = false;
  7506. player->SetMount(((Player*)player)->GetTempMount());
  7507. EQ2_Color mount_color = player->GetTempMountColor();
  7508. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  7509. player->SetMountColor(&mount_color);
  7510. player->SetMountSaddleColor(&saddle_color);
  7511. player->SetTempMount(0);
  7512. }
  7513. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  7514. const char* spawn_script = spawn->GetSpawnScript();
  7515. bool should_use_spawn = true;
  7516. if (spawn_script) {
  7517. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  7518. if (state) {
  7519. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  7520. if (state_mutex)
  7521. state_mutex->writelock(__FUNCTION__, __LINE__);
  7522. lua_getglobal(state, "can_use_command");
  7523. if (lua_isfunction(state, -1)) {
  7524. lua_interface->SetSpawnValue(state, spawn);
  7525. lua_interface->SetSpawnValue(state, GetPlayer());
  7526. lua_interface->SetStringValue(state, command ? command : "");
  7527. if (lua_pcall(state, 3, 1, 0) == 0) {
  7528. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  7529. }
  7530. }
  7531. lua_interface->ResetFunctionStack(state);
  7532. if (state_mutex)
  7533. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  7534. }
  7535. }
  7536. return should_use_spawn;
  7537. }
  7538. bool Client::IsCurrentTransmuteID(int32 req_id) {
  7539. return req_id == transmuteID;
  7540. }
  7541. void Client::SetTransmuteID(int32 trans_id) {
  7542. transmuteID = trans_id;
  7543. }
  7544. int32 Client::GetTransmuteID() {
  7545. return transmuteID;
  7546. }
  7547. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  7548. {
  7549. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  7550. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  7551. if (zar)
  7552. {
  7553. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  7554. if (database.IsActiveQuery(charID))
  7555. {
  7556. delayedLogin = true;
  7557. delayedAccountID = account_id;
  7558. delayedAccessKey = access_code;
  7559. delayTimer.Start(500);
  7560. 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);
  7561. return true;
  7562. }
  7563. delayedLogin = false;
  7564. delayTimer.Disable();
  7565. firstlogin = zar->isFirstLogin();
  7566. 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);
  7567. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  7568. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  7569. if (pvp_allowed)
  7570. this->GetPlayer()->SetAttackable(1);
  7571. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  7572. Client* client = zone_list.GetClientByCharName(player->GetName());
  7573. if (client) {
  7574. if (client->getConnection())
  7575. client->getConnection()->SendDisconnect();
  7576. if (client->GetCurrentZone() && !client->IsZoning()) {
  7577. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  7578. if (client->GetVersion() == version) {
  7579. Player* current_player = GetPlayer();
  7580. SetPlayer(client->GetPlayer());
  7581. client->SetPlayer(current_player);
  7582. client->GetPlayer()->SetPendingDeletion(true);
  7583. GetPlayer()->SetPendingDeletion(false);
  7584. GetPlayer()->ResetSavedSpawns();
  7585. GetPlayer()->SetReturningFromLD(true);
  7586. GetPlayer()->GetZone()->RemoveDelayedSpawnRemove(GetPlayer());
  7587. }
  7588. client->GetCurrentZone()->RemoveClientImmediately(client);
  7589. }
  7590. }
  7591. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  7592. if (!GetCurrentZone()) {
  7593. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  7594. ClientPacketFunctions::SendLoginDenied(this);
  7595. }
  7596. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  7597. getConnection()->SetClientVersion(version);
  7598. GetCurrentZone()->SetSpawnStructs(this);
  7599. connected_to_zone = true;
  7600. client_list.Remove(this); //remove from master client list
  7601. new_client_login = true;
  7602. GetCurrentZone()->AddClient(this); //add to zones client list
  7603. world.RejoinGroup(this);
  7604. zone_list.AddClientToMap(player->GetName(), this);
  7605. }
  7606. else {
  7607. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  7608. ClientPacketFunctions::SendLoginDenied(this);
  7609. return false;
  7610. }
  7611. }
  7612. else {
  7613. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  7614. ClientPacketFunctions::SendLoginDenied(this);
  7615. }
  7616. zone_auth.RemoveAuth(zar);
  7617. }
  7618. else
  7619. {
  7620. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  7621. Disconnect();
  7622. }
  7623. return true;
  7624. }
  7625. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  7626. if (!IsReadyForUpdates())
  7627. return;
  7628. map<int32, SpawnData> info_changes;
  7629. map<int32, SpawnData> pos_changes;
  7630. map<int32, SpawnData> vis_changes;
  7631. map<int32, SpawnData> empty_changes;
  7632. int32 info_size = 0;
  7633. int32 pos_size = 0;
  7634. int32 vis_size = 0;
  7635. int count = 0;
  7636. for (const auto& spawn : spawns) {
  7637. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  7638. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  7639. continue;
  7640. if (spawn->vis_changed)
  7641. {
  7642. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7643. if (vis_change) {
  7644. SpawnData data;
  7645. data.spawn = spawn;
  7646. data.data = vis_change;
  7647. data.size = spawn->vis_packet_size;
  7648. map<int32, SpawnData> tmp_vis_changes;
  7649. tmp_vis_changes[index] = data;
  7650. map<int32, SpawnData> tmp_info_changes;
  7651. map<int32, SpawnData> tmp_pos_changes;
  7652. int32 tmp_info_size = 0;
  7653. int32 tmp_pos_size = 0;
  7654. if (spawn->info_changed) {
  7655. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7656. if (info_change) {
  7657. SpawnData data;
  7658. data.spawn = spawn;
  7659. data.data = info_change;
  7660. data.size = spawn->info_packet_size;
  7661. tmp_info_size = data.size;
  7662. tmp_info_changes[index] = data;
  7663. }
  7664. }
  7665. if (spawn->position_changed) {
  7666. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7667. if (pos_change) {
  7668. SpawnData data;
  7669. data.spawn = spawn;
  7670. data.data = pos_change;
  7671. data.size = spawn->pos_packet_size;
  7672. tmp_pos_size = data.size;
  7673. tmp_pos_changes[index] = data;
  7674. }
  7675. }
  7676. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  7677. continue;
  7678. }
  7679. }
  7680. if (spawn->info_changed) {
  7681. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  7682. if (info_change) {
  7683. SpawnData data;
  7684. data.spawn = spawn;
  7685. data.data = info_change;
  7686. data.size = spawn->info_packet_size;
  7687. info_size += spawn->info_packet_size;
  7688. info_changes[index] = data;
  7689. }
  7690. count++;
  7691. }
  7692. if (spawn->position_changed) {
  7693. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  7694. if (pos_change) {
  7695. SpawnData data;
  7696. data.spawn = spawn;
  7697. data.data = pos_change;
  7698. data.size = spawn->pos_packet_size;
  7699. pos_size += spawn->pos_packet_size;
  7700. pos_changes[index] = data;
  7701. }
  7702. count++;
  7703. }
  7704. if (spawn->vis_changed) {
  7705. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  7706. if (vis_change) {
  7707. SpawnData data;
  7708. data.spawn = spawn;
  7709. data.data = vis_change;
  7710. data.size = spawn->vis_packet_size;
  7711. vis_size += spawn->vis_packet_size;
  7712. vis_changes[index] = data;
  7713. }
  7714. count++;
  7715. }
  7716. }
  7717. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  7718. return;
  7719. }
  7720. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  7721. for (auto& kv : info_changes) {
  7722. safe_delete_array(kv.second.data);
  7723. }
  7724. for (auto& kv : pos_changes) {
  7725. safe_delete_array(kv.second.data);
  7726. }
  7727. for (auto& kv : vis_changes) {
  7728. safe_delete_array(kv.second.data);
  7729. }
  7730. }
  7731. 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)
  7732. {
  7733. static const int8 oversized = 255;
  7734. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  7735. int32 size = info_size + pos_size + vis_size + 11;
  7736. size += CheckOverLoadSize(info_size);
  7737. size += CheckOverLoadSize(pos_size);
  7738. size += CheckOverLoadSize(vis_size);
  7739. uchar* tmp = new uchar[size];
  7740. uchar* ptr = tmp;
  7741. memset(tmp, 0, size);
  7742. size -= 4;
  7743. memcpy(ptr, &size, sizeof(int32));
  7744. size += 4;
  7745. ptr += sizeof(int32);
  7746. memcpy(ptr, &oversized, sizeof(int8));
  7747. ptr += sizeof(int8);
  7748. memcpy(ptr, &opcode_val, sizeof(int16));
  7749. ptr += sizeof(int16);
  7750. int32 current_time = Timer::GetCurrentTime2();
  7751. memcpy(ptr, &current_time, sizeof(int32));
  7752. ptr += sizeof(int32);
  7753. ptr += DoOverLoad(info_size, ptr);
  7754. for (const auto& kv : info_changes) {
  7755. auto info = kv.second;
  7756. memcpy(ptr, info.data, info.size);
  7757. ptr += info.size;
  7758. }
  7759. ptr += DoOverLoad(pos_size, ptr);
  7760. for (const auto& kv : pos_changes) {
  7761. auto pos = kv.second;
  7762. memcpy(ptr, pos.data, pos.size);
  7763. ptr += pos.size;
  7764. }
  7765. ptr += DoOverLoad(vis_size, ptr);
  7766. for (const auto& kv : vis_changes) {
  7767. auto vis = kv.second;
  7768. memcpy(ptr, vis.data, vis.size);
  7769. ptr += vis.size;
  7770. }
  7771. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  7772. // DumpPacket(packet->pBuffer, packet->size);
  7773. if (packet) {
  7774. QueuePacket(packet);
  7775. }
  7776. delete[] tmp;
  7777. }
  7778. void Client::SendHailCommand(Spawn* spawn)
  7779. {
  7780. // hardcoded 'hail' entity commands
  7781. switch (spawn->secondary_command_list_id)
  7782. {
  7783. case 9:
  7784. case 1262:
  7785. case 1265:
  7786. case 1267:
  7787. {
  7788. EQ2_16BitString* command = new EQ2_16BitString();
  7789. command->data = "";
  7790. command->size = 0;
  7791. commands.Process(COMMAND_HAIL, command, this, spawn);
  7792. safe_delete(command);
  7793. break;
  7794. }
  7795. }
  7796. }
  7797. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  7798. {
  7799. if (GetPlayer()->WasSentSpawn(spawn->GetID()) && GetPlayer()->WasSpawnRemoved(spawn) == false) {
  7800. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  7801. if (packet) {
  7802. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7803. packet->setMediumStringByName("command_name", command);
  7804. packet->setDataByName("distance", distance);
  7805. QueuePacket(packet->serialize());
  7806. safe_delete(packet);
  7807. }
  7808. }
  7809. }
  7810. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  7811. {
  7812. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  7813. return false;
  7814. if (command == "house_spawn_examine")
  7815. {
  7816. uint32 itemID = spawn->GetPickupItemID();
  7817. if (itemID)
  7818. {
  7819. Item* item = master_item_list.GetItem(itemID);
  7820. if (item)
  7821. {
  7822. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  7823. //DumpPacket(app);
  7824. QueuePacket(app);
  7825. }
  7826. }
  7827. return true;
  7828. }
  7829. return false;
  7830. }
  7831. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  7832. {
  7833. if (GetTempPlacementSpawn())
  7834. {
  7835. Spawn* tmp = GetTempPlacementSpawn();
  7836. int32 spawn_group_id = database.GetNextSpawnLocation();
  7837. tmp->SetSpawnLocationID(spawn_group_id);
  7838. float newHeading = place_object->getType_float_ByName("heading") + 180;
  7839. int32 spawnDBID = 0;
  7840. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  7841. {
  7842. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  7843. tmp->SetDatabaseID(spawnDBID);
  7844. }
  7845. else
  7846. {
  7847. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  7848. if (spawnDBID)
  7849. {
  7850. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  7851. tmp->SetDatabaseID(spawnDBID);
  7852. }
  7853. }
  7854. tmp->SetX(place_object->getType_float_ByName("x"));
  7855. tmp->SetY(place_object->getType_float_ByName("y"));
  7856. tmp->SetZ(place_object->getType_float_ByName("z"));
  7857. tmp->SetHeading(newHeading);
  7858. tmp->SetSpawnOrigX(tmp->GetX());
  7859. tmp->SetSpawnOrigY(tmp->GetY());
  7860. tmp->SetSpawnOrigZ(tmp->GetZ());
  7861. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  7862. database.SaveSpawnInfo(tmp);
  7863. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  7864. if (!spawnDBID)
  7865. {
  7866. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  7867. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  7868. }
  7869. return true;
  7870. }
  7871. return false;
  7872. }
  7873. bool Client::PopulateHouseSpawnFinalize()
  7874. {
  7875. if (GetTempPlacementSpawn())
  7876. {
  7877. Spawn* tmp = GetTempPlacementSpawn();
  7878. GetCurrentZone()->AddSpawn(tmp);
  7879. GetCurrentZone()->SendSpawnChanges(tmp, this);
  7880. SetTempPlacementSpawn(nullptr);
  7881. int32 uniqueID = GetPlacementUniqueItemID();
  7882. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  7883. tmp->SetPickupItemID(uniqueItem->details.item_id);
  7884. tmp->SetPickupUniqueItemID(uniqueID);
  7885. if (uniqueItem)
  7886. {
  7887. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  7888. {
  7889. Query query;
  7890. 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);
  7891. }
  7892. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  7893. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  7894. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  7895. SetPlacementUniqueItemID(0);
  7896. }
  7897. return true;
  7898. }
  7899. return false;
  7900. }
  7901. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  7902. {
  7903. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  7904. packet->setDataByName("placement_mode", placementMode);
  7905. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7906. packet->setDataByName("model_type", spawn->GetModelType());
  7907. packet->setDataByName("unknown", 1); //size
  7908. packet->setDataByName("unknown2", 1); //size 2
  7909. packet->setDataByName("unknown2", .5, 1); //size 3
  7910. packet->setDataByName("unknown2", 3, 2);
  7911. packet->setDataByName("unknown2", unknown2_3, 3);
  7912. packet->setDataByName("max_distance", 500);
  7913. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7914. QueuePacket(packet->serialize());
  7915. safe_delete(packet);
  7916. }
  7917. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  7918. {
  7919. SetPendingFlightPath(path_id);
  7920. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  7921. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  7922. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  7923. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  7924. if (packet) {
  7925. QueuePacket(packet->serialize());
  7926. safe_delete(packet);
  7927. }
  7928. if (mount_id)
  7929. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  7930. }