client.cpp 291 KB

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