client.cpp 287 KB

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