client.cpp 323 KB

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