client.cpp 294 KB

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