123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "../common/debug.h"
- #include <iostream>
- using namespace std;
- #include <string.h>
- #include "../common/misc.h"
- #include <stdio.h>
- #include <time.h>
- #include <stdlib.h>
- #include "Commands/Commands.h"
- #include "Zone/pathfinder_interface.h"
- #ifdef WIN32
- #include <WinSock2.h>
- #include <windows.h>
- #include <dbghelp.h>
- #pragma comment(lib,"imagehlp.lib")
- #else
- #include <sys/socket.h>
- #include <sys/stat.h>
- #ifdef FREEBSD //Timothy Whitman - January 7, 2003
- #include <sys/types.h>
- #endif
- #include <netinet/in.h>
- #include <arpa/inet.h>
- #include <errno.h>
- #include <pthread.h>
- #include <stdarg.h>
- #include "../common/unix.h"
- #define SOCKET_ERROR -1
- #define INVALID_SOCKET -1
- extern int errno;
- #endif
- #include "../common/servertalk.h"
- #include "../common/packet_dump.h"
- #include "WorldDatabase.h"
- #include "races.h"
- #include "classes.h"
- #include "../common/seperator.h"
- #include "../common/EQStream.h"
- #include "../common/EQStreamFactory.h"
- #include "../common/opcodemgr.h"
- #include "zoneserver.h"
- #include "client.h"
- #include "LoginServer.h"
- #include "World.h"
- #include <string>
- #include <assert.h>
- #include "LuaInterface.h"
- #include "Factions.h"
- #include "VisualStates.h"
- #include "ClientPacketFunctions.h"
- #include "SpellProcess.h"
- #include "../common/Log.h"
- #include "Rules/Rules.h"
- #include "Chat/Chat.h"
- #include "Tradeskills/Tradeskills.h"
- #include "RaceTypes/RaceTypes.h"
- #include <algorithm>
- #include <random>
- #include "Zone/SPGrid.h"
- #include "Bots/Bot.h"
- #ifdef WIN32
- #define snprintf _snprintf
- #define vsnprintf _vsnprintf
- #define strncasecmp _strnicmp
- #define strcasecmp _stricmp
- #endif
- // int32 numplayers = 0; // never used?
- // extern bool GetZoneLongName(char* short_name, char** long_name); // never used?
- // extern bool holdzones; // never used?
- // extern volatile bool RunLoops; // never used in the zone server?
- // extern Classes classes; // never used in the zone server?
- extern WorldDatabase database;
- extern sint32 numzones;
- extern ClientList client_list;
- extern LoginServer loginserver;
- extern ZoneList zone_list;
- extern World world;
- extern ConfigReader configReader;
- extern Commands commands;
- extern LuaInterface* lua_interface;
- extern MasterFactionList master_faction_list;
- extern VisualStates visual_states;
- extern RuleManager rule_manager;
- extern Chat chat;
- extern MasterRaceTypeList race_types_list;
- extern MasterSpellList master_spell_list; // temp - remove later
- extern MasterSkillList master_skill_list;
- int32 MinInstanceID = 1000;
- // JA: Moved most default values to Rules and risky initializers to ZoneServer::Init() - 2012.12.07
- ZoneServer::ZoneServer(const char* name) {
- depop_zone = false;
- repop_zone = false;
- respawns_allowed = true;
- instanceID = 0;
- strcpy(zone_name, name);
- zoneID = 0;
- rain = 0;
- cityzone = false;
- always_loaded = false;
- locked = false; // JA: implementing /zone lock|unlock commands
- pNumPlayers = 0;
- LoadingData = true;
- zoneShuttingDown = false;
- ++numzones;
- revive_points = 0;
- zone_motd = "";
- finished_depop = true;
- initial_spawn_threads_active = 0;
- minimumStatus = 0;
- minimumLevel = 0;
- maximumLevel = 0;
- minimumVersion = 0;
- weather_current_severity = 0;
- weather_signaled = false;
- xp_mod = 0;
- isDusk = false;
- dusk_hour = 0;
- dusk_minute = 0;
- dawn_hour = 0;
- dawn_minute = 0;
- reloading_spellprocess = false;
- expansion_flag = 0;
- holiday_flag = 0;
- MMasterZoneLock = new CriticalSection(MUTEX_ATTRIBUTE_RECURSIVE);
-
- Grid = nullptr;
- zonemap = nullptr;
- pathing = nullptr;
- strcpy(zonesky_file,"");
-
- reloading = true;
- }
- ZoneServer::~ZoneServer() {
- zoneShuttingDown = true; //ensure other threads shut down too
- //allow other threads to properly shut down
- while (spawnthread_active || initial_spawn_threads_active > 0){
- if (spawnthread_active)
- LogWrite(ZONE__DEBUG, 7, "Zone", "Zone shutdown waiting on spawn thread");
- if (initial_spawn_threads_active > 0)
- LogWrite(ZONE__DEBUG, 7, "Zone", "Zone shutdown waiting on initial spawn thread");
- Sleep(10);
- }
- LogWrite(ZONE__INFO, 0, "Zone", "Initiating zone shutdown of '%s'", zone_name);
- changed_spawns.clear();
- transport_spawns.clear();
- safe_delete(spellProcess);
- safe_delete(tradeskillMgr);
- MMasterZoneLock->lock();
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- DeleteData(true);
- RemoveLocationProximities();
- RemoveLocationGrids();
- DelayedSpawnRemoval(true);
- DeleteSpawns(true);
-
- DeleteGlobalSpawns();
- DeleteFlightPaths();
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
- MMasterZoneLock->unlock();
- safe_delete(MMasterZoneLock);
- world.UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, -1);
- // If lockout, public, tradeskill, or quest instance delete from db when zone shuts down
- if (InstanceType == SOLO_LOCKOUT_INSTANCE || InstanceType == GROUP_LOCKOUT_INSTANCE || InstanceType == RAID_LOCKOUT_INSTANCE ||
- InstanceType == PUBLIC_INSTANCE || InstanceType == TRADESKILL_INSTANCE || InstanceType == QUEST_INSTANCE) {
- LogWrite(INSTANCE__DEBUG, 0, "Instance", "Non persistent instance shutting down, deleting instance");
- database.DeleteInstance(instanceID);
- }
- if (Grid != nullptr)
- delete Grid;
- if (zonemap != nullptr)
- delete zonemap;
- if (pathing != nullptr)
- delete pathing;
- if (movementMgr != nullptr)
- delete movementMgr;
- LogWrite(ZONE__INFO, 0, "Zone", "Completed zone shutdown of '%s'", zone_name);
- --numzones;
- UpdateWindowTitle(0);
- zone_list.Remove(this);
- }
- void ZoneServer::Init()
- {
- LogWrite(ZONE__INFO, 0, "Zone", "Loading new Zone '%s'", zone_name);
- zone_list.Add(this);
- spellProcess = new SpellProcess();
- tradeskillMgr = new TradeskillMgr();
- /* Dynamic Timers */
- regenTimer.Start(rule_manager.GetGlobalRule(R_Zone, RegenTimer)->GetInt32());
- client_save.Start(rule_manager.GetGlobalRule(R_Zone, ClientSaveTimer)->GetInt32());
- shutdownTimer.Disable();
- spawn_range.Start(rule_manager.GetGlobalRule(R_Zone, CheckAttackPlayer)->GetInt32());
- aggro_timer.Start(rule_manager.GetGlobalRule(R_Zone, CheckAttackNPC)->GetInt32());
- /* Weather stuff */
- InitWeather();
- /* Static Timers */
- // JA - haven't decided yet if these should remain hard-coded. Changing them could break EQ2Emu functionality
- spawn_check_add.Start(1000);
- spawn_check_remove.Start(30000);
- spawn_expire_timer.Start(10000);
- respawn_timer.Start(10000);
- // there was never a starter for these?
- widget_timer.Start(5000);
- tracking_timer.Start(5000);
- movement_timer.Start(100);
- location_prox_timer.Start(1000);
- location_grid_timer.Start(1000);
- charsheet_changes.Start(500);
- // Send game time packet every in game hour (180 sec)
- sync_game_time_timer.Start(180000);
- // Get the dusk and dawn time from the rule manager and store it in the correct variables
- sscanf (rule_manager.GetGlobalRule(R_World, DuskTime)->GetString(), "%d:%d", &dusk_hour, &dusk_minute);
- sscanf (rule_manager.GetGlobalRule(R_World, DawnTime)->GetString(), "%d:%d", &dawn_hour, &dawn_minute);
- spawn_update.Start(rule_manager.GetGlobalRule(R_Zone, SpawnUpdateTimer)->GetInt16());
- LogWrite(ZONE__DEBUG, 0, "Zone", "SpawnUpdateTimer: %ims", rule_manager.GetGlobalRule(R_Zone, SpawnUpdateTimer)->GetInt16());
- spawn_delete_timer = rule_manager.GetGlobalRule(R_Zone, SpawnDeleteTimer)->GetInt32();
- LogWrite(ZONE__DEBUG, 0, "Zone", "SpawnDeleteTimer: %ums", spawn_delete_timer);
- LogWrite(ZONE__DEBUG, 0, "Zone", "Loading zone flight paths");
- database.LoadZoneFlightPaths(this);
- world.UpdateServerStatistic(STAT_SERVER_NUM_ACTIVE_ZONES, 1);
- UpdateWindowTitle(0);
- string zoneName(GetZoneFile());
- if (Grid == nullptr) {
- Grid = new SPGrid(string(GetZoneFile()), 0);
- }
- if (zonemap == nullptr) {
- zonemap = Map::LoadMapFile(zoneName, Grid);
- }
- pathing = IPathfinder::Load(zoneName);
- movementMgr = new MobMovementManager();
- // else
- // LogWrite(ZONE__ERROR, 0, "SPGrid", "ZoneServer::Init() Grid is not null in init, wtf!");
- MMasterSpawnLock.SetName("ZoneServer::MMasterSpawnLock");
- m_npc_faction_list.SetName("ZoneServer::npc_faction_list");
- m_enemy_faction_list.SetName("ZoneServer::enemy_faction_list");
- m_reverse_enemy_faction_list.SetName("ZoneServer::reverse_enemy_faction_list");
- MDeadSpawns.SetName("ZoneServer::dead_spawns");
- MTransportSpawns.SetName("ZoneServer::transport_spawns");
- MSpawnList.SetName("ZoneServer::spawn_list");
- MTransporters.SetName("ZoneServer::m_transportMaps");
- MSpawnGroupAssociation.SetName("ZoneServer::spawn_group_associations");
- MSpawnGroupLocations.SetName("ZoneServer::spawn_group_locations");
- MSpawnLocationGroups.SetName("ZoneServer::spawn_location_groups");
- MSpawnGroupChances.SetName("ZoneServer::spawn_group_chances");
- MTransportLocations.SetName("ZoneServer::transporter_locations");
- MSpawnLocationList.SetName("ZoneServer::spawn_location_list");
- MSpawnDeleteList.SetName("ZoneServer::spawn_delete_list");
- MSpawnScriptTimers.SetName("ZoneServer::spawn_script_timers");
- MRemoveSpawnScriptTimersList.SetName("ZoneServer::remove_spawn_script_timers_list");
- MClientList.SetName("ZoneServer::clients");
- MWidgetTimers.SetName("ZoneServer::widget_timers");
- #ifdef WIN32
- _beginthread(ZoneLoop, 0, this);
- _beginthread(SpawnLoop, 0, this);
- #else
- pthread_t thread;
- pthread_create(&thread, NULL, ZoneLoop, this);
- pthread_detach(thread);
- pthread_t thread2;
- pthread_create(&thread2, NULL, SpawnLoop, this);
- pthread_detach(thread2);
- #endif
- }
- void ZoneServer::InitWeather()
- {
- weather_enabled = rule_manager.GetGlobalRule(R_Zone, WeatherEnabled)->GetBool();
- if( weather_enabled && isWeatherAllowed())
- {
- string tmp;
- // set up weather system when zone starts up
- weather_type = rule_manager.GetGlobalRule(R_Zone, WeatherType)->GetInt8();
- switch(weather_type)
- {
- case 3: tmp = "Chaotic"; break;
- case 2: tmp = "Random"; break;
- case 1: tmp = "Dynamic"; break;
- default: tmp = "Normal"; break;
- }
- LogWrite(ZONE__DEBUG, 0, "Zone", "%s: Setting up '%s' weather", zone_name, tmp.c_str());
- weather_frequency = rule_manager.GetGlobalRule(R_Zone, WeatherChangeFrequency)->GetInt32();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Change weather every %u seconds", zone_name, weather_frequency);
- weather_change_chance = rule_manager.GetGlobalRule(R_Zone, WeatherChangeChance)->GetInt8();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Chance of weather change: %i%%", zone_name, weather_change_chance);
- weather_min_severity = rule_manager.GetGlobalRule(R_Zone, MinWeatherSeverity)->GetFloat();
- weather_max_severity = rule_manager.GetGlobalRule(R_Zone, MaxWeatherSeverity)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Severity min/max is %.2f - %.2f", zone_name, weather_min_severity, weather_max_severity);
- // Allow a random roll to determine if weather should start out severe or calm
- if( MakeRandomInt(1, 100) > 50)
- {
- weather_pattern = 1; // default weather to increase in severity initially
- weather_current_severity = weather_min_severity;
- }
- else
- {
- weather_pattern = 0; // default weather to decrease in severity initially
- weather_current_severity = weather_max_severity;
- }
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Severity set to %.2f, pattern: %i", zone_name, weather_current_severity, weather_pattern);
- weather_change_amount = rule_manager.GetGlobalRule(R_Zone, WeatherChangePerInterval)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather change by %.2f each interval", zone_name, weather_change_amount);
- if( weather_type > 0 )
- {
- weather_dynamic_offset = rule_manager.GetGlobalRule(R_Zone, WeatherDynamicMaxOffset)->GetFloat();
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather Max Offset changes no more than %.2f each interval", zone_name, weather_dynamic_offset);
- }
- else
- weather_dynamic_offset = 0;
- SetRain(weather_current_severity);
- weather_last_changed_time = Timer::GetUnixTimeStamp();
- weatherTimer.Start(rule_manager.GetGlobalRule(R_Zone, WeatherTimer)->GetInt32());
- }
- }
- void ZoneServer::DeleteSpellProcess(){
- //Just get a lock to make sure we aren't already looping the spawnprocess or clientprocess if this is different than the calling thread
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- MMasterZoneLock->lock();
- reloading_spellprocess = true;
- // Remove spells from NPC's
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->IsNPC())
- ((NPC*)spawn)->SetSpells(0);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- MMasterZoneLock->unlock();
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
- DismissAllPets();
- safe_delete(spellProcess);
- }
- void ZoneServer::LoadSpellProcess(){
- spellProcess = new SpellProcess();
- reloading_spellprocess = false;
- // Reload NPC's spells
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->IsNPC())
- ((NPC*)spawn)->SetSpells(GetNPCSpells(((NPC*)spawn)->GetPrimarySpellList(), ((NPC*)spawn)->GetSecondarySpellList()));
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::LockAllSpells(Player* player) {
- if (player && spellProcess) {
- Client* client = GetClientBySpawn(player);
- if (client)
- spellProcess->LockAllSpells(client);
- }
- }
-
- void ZoneServer::UnlockAllSpells(Player* player) {
- if (player && spellProcess) {
- Client* client = GetClientBySpawn(player);
- if (client)
- spellProcess->UnlockAllSpells(client);
- }
- }
- void ZoneServer::DeleteFactionLists() {
- map<int32, vector<int32> *>::iterator faction_itr;
- map<int32, vector<int32> *>::iterator spawn_itr;
- m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- for (faction_itr = enemy_faction_list.begin(); faction_itr != enemy_faction_list.end(); faction_itr++)
- safe_delete(faction_itr->second);
- enemy_faction_list.clear();
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- for (faction_itr = reverse_enemy_faction_list.begin(); faction_itr != reverse_enemy_faction_list.end(); faction_itr++)
- safe_delete(faction_itr->second);
- reverse_enemy_faction_list.clear();
- m_reverse_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- for (spawn_itr = npc_faction_list.begin(); spawn_itr != npc_faction_list.end(); spawn_itr++)
- safe_delete(spawn_itr->second);
- npc_faction_list.clear();
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteData(bool boot_clients){
- Spawn* spawn = 0;
- vector<Spawn*> tmp_player_list; // changed to a vector from a MutexList as this is a local variable and don't need mutex stuff for the list
- // Clear spawn groups
- spawn_group_map.clear();
- // Loop through the spawn list and set the spawn for deletion
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(!boot_clients && spawn->IsPlayer())
- tmp_player_list.push_back(spawn);
- else if(spawn->IsPlayer()){
- Client* client = GetClientBySpawn(spawn);
- if(client)
- client->Disconnect();
- }
- else{
- RemoveHeadingTimer(spawn); // called in RemoveSpawnSupportFunctions()
- RemoveSpawnSupportFunctions(spawn);
- AddPendingDelete(spawn);
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- // Quick hack to prevent a deadlock, RemoveSpawnSupportFunctions() will cancel spells and result in zone->GetSpawnByID()
- // being called which read locks the spawn list and caused a dead lock as the above mutex's were write locked
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- // Clear the spawn list, this was in the mutex above, moved it down so the above mutex could be a read lock
- spawn_list.clear();
- // Moved this up so we only read lock the list once in this list
- vector<Spawn*>::iterator spawn_iter2;
- for (spawn_iter2 = tmp_player_list.begin(); spawn_iter2 != tmp_player_list.end(); spawn_iter2++) {
- spawn_list[(*spawn_iter2)->GetID()] = (*spawn_iter2);
- }
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- // Clear player proximities
- RemovePlayerProximity(0, true);
- spawn_range_map.clear(true);
- if(boot_clients) {
- // Refactor
- vector<Client*>::iterator itr;
- MClientList.writelock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++)
- safe_delete(*itr);
- clients.clear();
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- }
- // Clear and delete spawn locations
- MSpawnLocationList.writelock(__FUNCTION__, __LINE__);
- map<int32, SpawnLocation*>::iterator spawn_location_iter;
- for (spawn_location_iter = spawn_location_list.begin(); spawn_location_iter != spawn_location_list.end(); spawn_location_iter++)
- safe_delete(spawn_location_iter->second);
- spawn_location_list.clear();
- MSpawnLocationList.releasewritelock(__FUNCTION__, __LINE__);
- // If we allow clients to stay in the zone we need to preserve the revive_points, otherwise if the player dies they will crash
- if(revive_points && boot_clients){
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++){
- safe_delete(*revive_iter);
- }
- safe_delete(revive_points);
- }
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- map<int32, set<int32>*>::iterator assoc_itr;
- for (assoc_itr = spawn_group_associations.begin(); assoc_itr != spawn_group_associations.end(); assoc_itr++)
- safe_delete(assoc_itr->second);
- spawn_group_associations.clear();
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- map<int32, map<int32, int32>*>::iterator loc_itr;
- for (loc_itr = spawn_group_locations.begin(); loc_itr != spawn_group_locations.end(); loc_itr++)
- safe_delete(loc_itr->second);
- spawn_group_locations.clear();
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- map<int32, list<int32>*>::iterator group_itr;
- for (group_itr = spawn_location_groups.begin(); group_itr != spawn_location_groups.end(); group_itr++)
- safe_delete(group_itr->second);
- spawn_location_groups.clear();
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
-
- // Clear lists that need more then just a Clear()
- DeleteFactionLists();
- DeleteSpawnScriptTimers(0, true);
- DeleteSpawnScriptTimers();
- ClearDeadSpawns();
- // Clear lists
- heading_timers.clear();
- movement_spawns.clear();
- respawn_timers.clear();
- transport_spawns.clear();
- quick_database_id_lookup.clear();
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- widget_timers.clear();
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- map<int16, PacketStruct*>::iterator struct_itr;
- for (struct_itr = versioned_info_structs.begin(); struct_itr != versioned_info_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_info_structs.clear();
- for (struct_itr = versioned_pos_structs.begin(); struct_itr != versioned_pos_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_pos_structs.clear();
- for (struct_itr = versioned_vis_structs.begin(); struct_itr != versioned_vis_structs.end(); struct_itr++)
- safe_delete(struct_itr->second);
- versioned_vis_structs.clear();
- }
- void ZoneServer::RemoveLocationProximities() {
- MutexList<LocationProximity*>::iterator itr = location_proximities.begin();
- while(itr.Next()){
- safe_delete(itr->value);
- }
- location_proximities.clear();
- }
- RevivePoint* ZoneServer::GetRevivePoint(int32 id){
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++){
- if((*revive_iter)->id == id)
- return *revive_iter;
- }
- return 0;
- }
- vector<RevivePoint*>* ZoneServer::GetRevivePoints(Client* client)
- {
- vector<RevivePoint*>* points = new vector<RevivePoint*>;
- RevivePoint* closest_point = 0;
- // we should not check for revive points if this is null
- if ( revive_points != NULL )
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Got revive point in %s!", __FUNCTION__);
- float closest = 100000;
- float test_closest = 0;
- RevivePoint* test_point = 0;
- vector<RevivePoint*>::iterator revive_iter;
- for(revive_iter=revive_points->begin(); revive_iter != revive_points->end(); revive_iter++)
- {
- test_point = *revive_iter;
- if(test_point)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Test Point Found!");
- test_closest = client->GetPlayer()->GetDistance(test_point->x, test_point->y, test_point->z);
- // should this be changed to list all revive points within max distance or just the closest
- if(test_closest < closest)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "test_closest: %.2f, closest: %.2f", test_closest, closest);
- closest = test_closest;
- closest_point = test_point;
- if(closest <= MAX_REVIVEPOINT_DISTANCE)
- points->push_back(closest_point);
- }
- }
- }
- }
- if(closest_point && points->size() == 0 && closest_point->zone_id == GetZoneID())
- {
- LogWrite(ZONE__WARNING, 0, "Zone", "Nearest Revive Point too far away. Add another!");
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "The closest revive point is quite far away, you might want to ask the server admin for a closer one.");
- points->push_back(closest_point);
- }
- else if(points->size() == 0)
- {
- LogWrite(ZONE__WARNING, 0, "Zone", "No Revive Points set for zoneID %u. Add some!", GetZoneID());
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "There are no revive points for this zone, you might want to ask the server admin for one.");
- closest_point = new RevivePoint;
- closest_point->heading = GetSafeHeading();
- closest_point->id = 0xFFFFFFFF;
- closest_point->location_name = "Zone Safe Point";
- closest_point->zone_id = GetZoneID();
- closest_point->x = GetSafeX();
- closest_point->y = GetSafeY();
- closest_point->z = GetSafeZ();
- points->push_back(closest_point);
- }
- return points;
- }
- void ZoneServer::TriggerCharSheetTimer(){
- charsheet_changes.Trigger();
- }
- void ZoneServer::RegenUpdate(){
- if(damaged_spawns.size(true) == 0)
- return;
- Spawn* spawn = 0;
- MutexList<int32>::iterator spawn_iter = damaged_spawns.begin();
- while(spawn_iter.Next()){
- spawn = GetSpawnByID(spawn_iter->value);
- if(spawn && (((spawn->GetHP() < spawn->GetTotalHP()) && spawn->GetHP()>0) || (spawn->GetPower() < spawn->GetTotalPower()))){
- if(spawn->IsEntity())
- ((Entity*)spawn)->DoRegenUpdate();
- if(spawn->IsPlayer()){
- Client* client = GetClientBySpawn(spawn);
- if(client && client->IsConnected())
- client->QueuePacket(client->GetPlayer()->GetPlayerInfo()->serialize(client->GetVersion()));
- }
- }
- else
- RemoveDamagedSpawn(spawn);
- //Spawn no longer valid, remove it from the list
- if (!spawn)
- damaged_spawns.Remove(spawn_iter->value);
- }
- }
- void ZoneServer::ClearDeadSpawns(){
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- dead_spawns.clear();
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessDepop(bool respawns_allowed, bool repop) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- Spawn* spawn = 0;
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- spawn_expire_timers.clear();
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client)
- continue;
- client->GetPlayer()->SetTarget(0);
- if(repop)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Zone Repop in progress...");
- else{
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Zone Depop in progress...");
- if(respawns_allowed)
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawns will respawn according to their respawn timers.");
- }
- if(!packet || packet_version != client->GetVersion()){
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && !spawn->IsPlayer()){
- SendRemoveSpawn(client, spawn, packet);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- DeleteTransporters();
- safe_delete(packet);
- if(!repop && respawns_allowed){
- spawn_range_map.clear(true);
- MutexList<Spawn*> tmp_player_list; // Local variable, never be on another thread so probably don't need the extra mutex code that comes with a MutexList
- ClearDeadSpawns();
- map<int32, Spawn*>::iterator itr;
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn) {
- if(spawn->GetRespawnTime() > 0 && spawn->GetSpawnLocationID() > 0)
- respawn_timers.Put(spawn->GetSpawnLocationID(), Timer::GetCurrentTime2() + spawn->GetRespawnTime()*1000);
- if(spawn->IsPlayer())
- tmp_player_list.Add(spawn);
- else {
- RemoveSpawnSupportFunctions(spawn);
- AddPendingDelete(spawn);
- }
- }
- }
- spawn_list.clear();
- //add back just the clients
- MutexList<Spawn*>::iterator spawn_iter2 = tmp_player_list.begin();
- while(spawn_iter2.Next()) {
- spawn_list[spawn_iter2->value->GetID()] = spawn_iter2->value;
- }
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- else
- DeleteData(false);
- if(repop)
- LoadingData = true;
- }
- void ZoneServer::Depop(bool respawns, bool repop) {
- respawns_allowed = respawns;
- repop_zone = repop;
- finished_depop = false;
- depop_zone = true;
- }
- bool ZoneServer::AddCloseSpawnsToSpawnGroup(Spawn* spawn, float radius){
- if(!spawn)
- return false;
- Spawn* close_spawn = 0;
- bool ret = true;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- close_spawn = itr->second;
- if(close_spawn && close_spawn != spawn && !close_spawn->IsPlayer() && close_spawn->GetDistance(spawn) <= radius){
- if((spawn->IsNPC() && close_spawn->IsNPC()) || (spawn->IsGroundSpawn() && close_spawn->IsGroundSpawn()) || (spawn->IsObject() && close_spawn->IsObject()) || (spawn->IsWidget() && close_spawn->IsWidget()) || (spawn->IsSign() && close_spawn->IsSign())){
- if(close_spawn->GetSpawnGroupID() == 0){
- spawn->AddSpawnToGroup(close_spawn);
- close_spawn->AddSpawnToGroup(spawn);
- }
- else
- ret = false;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::RepopSpawns(Client* client, Spawn* in_spawn){
- vector<Spawn*>* spawns = in_spawn->GetSpawnGroup();
- PacketStruct* packet = configReader.getStruct("WS_DestroyGhostCmd", client->GetVersion());
- if(spawns){
- if(!packet)
- return;
- Spawn* spawn = 0;
- vector<Spawn*>::iterator itr;
- for(itr = spawns->begin(); itr != spawns->end(); itr++){
- spawn = *itr;
- SendRemoveSpawn(client, spawn, packet);
- }
- }
- safe_delete(spawns);
- SendRemoveSpawn(client, in_spawn, packet);
- spawn_check_add.Trigger();
- safe_delete(packet);
- }
- bool ZoneServer::AggroVictim(NPC* npc, Spawn* victim, Client* client)
- {
- bool isEntity = victim->IsEntity();
- if (npc->HasSpawnGroup()) {
- vector<Spawn*>* groupVec = npc->GetSpawnGroup();
- for (int32 i = 0; i < groupVec->size(); i++) {
- Spawn* group_member = groupVec->at(i);
- if (group_member && !group_member->EngagedInCombat() && group_member->Alive()) {
- CallSpawnScript(group_member, SPAWN_SCRIPT_AGGRO, victim);
- if (isEntity)
- ((NPC*)group_member)->AddHate((Entity*)victim, 50);
- else
- ((NPC*)group_member)->InCombat(true);
- }
- }
- safe_delete(groupVec);
- }
- else
- {
- if (isEntity)
- {
- CallSpawnScript(victim, SPAWN_SCRIPT_AGGRO, victim);
- npc->AddHate((Entity*)victim, 50);
- }
- else
- npc->InCombat(true);
- }
- return true;
- }
- bool ZoneServer::CheckNPCAttacks(NPC* npc, Spawn* victim, Client* client){
- if(!npc || !victim)
- return true;
- if (client) {
- if (client->IsConnected() && npc->CanSeeInvis(client->GetPlayer()) && client->GetPlayer()->GetFactions()->ShouldAttack(npc->GetFactionID()) && npc->AttackAllowed((Entity*)victim, false)) {
- if (!npc->EngagedInCombat() && client->GetPlayer()->GetArrowColor(npc->GetLevel()) != ARROW_COLOR_GRAY) {
- AggroVictim(npc, victim, client);
- }
- }
- }
- else{
- AggroVictim(npc, victim, client);
- }
- return true;
- }
- bool ZoneServer::CheckEnemyList(NPC* npc) {
- vector<int32> *factions;
- vector<int32>::iterator faction_itr;
- vector<int32> *spawns;
- vector<int32>::iterator spawn_itr;
- map<float, Spawn*> attack_spawns;
- map<float, Spawn*> reverse_attack_spawns;
- map<float, Spawn*>::iterator itr;
- int32 faction_id = npc->GetFactionID();
- float distance;
- if (faction_id == 0)
- return true;
- m_enemy_faction_list.readlock(__FUNCTION__, __LINE__);
- if (enemy_faction_list.count(faction_id) > 0) {
- factions = enemy_faction_list[faction_id];
- for (faction_itr = factions->begin(); faction_itr != factions->end(); faction_itr++) {
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(*faction_itr) > 0) {
- spawns = npc_faction_list[*faction_itr];
- spawn_itr = spawns->begin();
- for (spawn_itr = spawns->begin(); spawn_itr != spawns->end(); spawn_itr++) {
- Spawn* spawn = GetSpawnByID(*spawn_itr);
- if (spawn) {
- if ((distance = spawn->GetDistance(npc)) <= npc->GetAggroRadius())
- attack_spawns[distance] = spawn;
- }
- }
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- m_enemy_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.readlock(__FUNCTION__, __LINE__);
- if (reverse_enemy_faction_list.count(faction_id) > 0) {
- factions = reverse_enemy_faction_list[faction_id];
- for (faction_itr = factions->begin(); faction_itr != factions->end(); faction_itr++) {
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(*faction_itr) > 0) {
- spawns = npc_faction_list[*faction_itr];
- spawn_itr = spawns->begin();
- for (spawn_itr = spawns->begin(); spawn_itr != spawns->end(); spawn_itr++) {
- Spawn* spawn = GetSpawnByID(*spawn_itr);
- if (spawn) {
- if ((distance = spawn->GetDistance(npc)) <= npc->GetAggroRadius())
- reverse_attack_spawns[distance] = spawn;
- }
- }
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- m_reverse_enemy_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- if (attack_spawns.size() > 0) {
- for (itr = attack_spawns.begin(); itr != attack_spawns.end(); itr++)
- CheckNPCAttacks(npc, itr->second);
- }
- if (reverse_attack_spawns.size() > 0) {
- for (itr = reverse_attack_spawns.begin(); itr != reverse_attack_spawns.end(); itr++)
- CheckNPCAttacks((NPC*)itr->second, npc);
- }
- return attack_spawns.size() == 0;
- }
- void ZoneServer::RemoveDeadEnemyList(Spawn *spawn)
- {
- int32 faction_id = spawn->GetFactionID();
- vector<int32> *spawns;
- vector<int32>::iterator itr;
- LogWrite(ZONE__DEBUG, 7, "Zone", "Processing RemoveDeadEnemyList...");
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(faction_id) > 0) {
- spawns = npc_faction_list[faction_id];
- for (itr = spawns->begin(); itr != spawns->end(); itr++) {
- if (*itr == spawn->GetID()) {
- spawns->erase(itr);
- break;
- }
- }
- }
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddEnemyList(NPC* npc){
- int32 faction_id = npc->GetFactionID();
- vector<int32> *hostile_factions;
- vector<int32>::iterator itr;
- if(faction_id <= 9)
- return;
- if(!rule_manager.GetGlobalRule(R_Faction, AllowFactionBasedCombat)->GetBool()) {
- LogWrite(FACTION__WARNING, 0, "Faction", "Faction Combat is DISABLED via R_Faction::AllowFactionBasedCombat rule!");
- return;
- }
-
- m_npc_faction_list.readlock(__FUNCTION__, __LINE__);
- if (npc_faction_list.count(faction_id) == 0) {
- if(faction_id > 10) {
- if ((hostile_factions = master_faction_list.GetHostileFactions(faction_id)) != NULL) {
- itr = hostile_factions->begin();
- for (itr = hostile_factions->begin(); itr != hostile_factions->end(); itr++) {
- m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if (enemy_faction_list.count(faction_id) == 0)
- enemy_faction_list[faction_id] = new vector<int32>;
- enemy_faction_list[faction_id]->push_back(*itr);
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- m_reverse_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if(reverse_enemy_faction_list.count(*itr) == 0)
- reverse_enemy_faction_list[*itr] = new vector<int32>;
- reverse_enemy_faction_list[*itr]->push_back(faction_id);
- m_reverse_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- }
- /*m_enemy_faction_list.writelock(__FUNCTION__, __LINE__);
- if(enemy_faction_list.count(1) == 0)
- enemy_faction_list[1] = new vector<int32>;
- enemy_faction_list[1]->push_back(faction_id);
- m_enemy_faction_list.releasewritelock(__FUNCTION__, __LINE__);*/
- }
- m_npc_faction_list.releasereadlock(__FUNCTION__, __LINE__);
- m_npc_faction_list.writelock(__FUNCTION__, __LINE__);
- if(npc_faction_list.count(faction_id) == 0)
- npc_faction_list[faction_id] = new vector<int32>;
- npc_faction_list[faction_id]->push_back(npc->GetID());
- m_npc_faction_list.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckSpawnRange(Client* client, Spawn* spawn, bool initial_login){
- if(client && spawn && (initial_login || client->IsConnected())) {
- if(spawn != client->GetPlayer()) {
- if(spawn_range_map.count(client) == 0)
- spawn_range_map.Put(client, new MutexMap<int32, float >());
- float curDist = spawn->GetDistance(client->GetPlayer());
- if (!client->GetPlayer()->WasSentSpawn(spawn->GetID()) && curDist > SEND_SPAWN_DISTANCE)
- {
- return;
- }
- spawn_range_map.Get(client)->Put(spawn->GetID(), curDist);
- if(!initial_login && client && spawn->IsNPC() && curDist <= ((NPC*)spawn)->GetAggroRadius() && !client->GetPlayer()->GetInvulnerable())
- CheckNPCAttacks((NPC*)spawn, client->GetPlayer(), client);
- }
- if(!initial_login)
- CheckPlayerProximity(spawn, client);
- }
- }
- void ZoneServer::CheckSpawnRange(Spawn* spawn){
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsReadyForSpawns())
- CheckSpawnRange(client, spawn);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PrepareSpawnID(Player* player, Spawn* spawn){
- player->spawn_id++;
- player->player_spawn_id_map[player->spawn_id] = spawn;
- player->player_spawn_reverse_id_map[spawn] = player->spawn_id;
- }
- void ZoneServer::CheckSendSpawnToClient(Client* client, bool initial_login) {
- if (!client) {
- LogWrite(ZONE__ERROR, 0, "Zone", "CheckSendSpawnToClient called with an invalid client");
- return;
- }
- if (!initial_login && !client->GetInitialSpawnsSent() || (!initial_login && !client->IsReadyForUpdates()))
- return;
- Spawn* spawn = 0;
- map<float, vector<Spawn*>* > closest_spawns;
- if(spawn_range_map.count(client) > 0) {
- if(initial_login || client->IsConnected()) {
- MutexMap<int32, float >::iterator spawn_iter = spawn_range_map.Get(client)->begin();
- while(spawn_iter.Next()) {
- spawn = GetSpawnByID(spawn_iter->first, true);
- if(spawn && spawn->GetPrivateQuestSpawn()) {
- if(!spawn->IsPrivateSpawn())
- spawn->AddAllowAccessSpawn(spawn);
- if(spawn->MeetsSpawnAccessRequirements(client->GetPlayer())) {
- if(spawn->IsPrivateSpawn() && !spawn->AllowedAccess(client->GetPlayer()))
- spawn->AddAllowAccessSpawn(client->GetPlayer());
- }
- else if(spawn->AllowedAccess(client->GetPlayer()))
- spawn->RemoveSpawnAccess(client->GetPlayer());
- }
- if(spawn && spawn != client->GetPlayer() && client->GetPlayer()->ShouldSendSpawn(spawn)) {
- if((!initial_login && spawn_iter->second <= SEND_SPAWN_DISTANCE) || (initial_login && (spawn_iter->second <= (SEND_SPAWN_DISTANCE/2) || spawn->IsWidget()))) {
- if(closest_spawns.count(spawn_iter->second) == 0)
- closest_spawns[spawn_iter->second] = new vector<Spawn*>();
- closest_spawns[spawn_iter->second]->push_back(spawn);
- PrepareSpawnID(client->GetPlayer(), spawn);
- }
- }
- }
- }
- vector<Spawn*>::iterator spawn_iter2;
- map<float, vector<Spawn*>* >::iterator itr;
- for(itr = closest_spawns.begin(); itr != closest_spawns.end(); itr++) {
- for(spawn_iter2 = itr->second->begin(); spawn_iter2 != itr->second->end(); spawn_iter2++) {
- spawn = *spawn_iter2;
- client->GetPlayer()->ClearRemovedSpawn(spawn);
- SendSpawn(spawn, client);
- if(client->ShouldTarget() && client->GetCombineSpawn() == spawn)
- client->TargetSpawn(spawn);
- }
- delete itr->second;
- }
- }
- if (initial_login)
- client->SetInitialSpawnsSent(true);
- }
- void ZoneServer::CheckSendSpawnToClient(){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client->IsReadyForSpawns())
- CheckSendSpawnToClient(client);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckRemoveSpawnFromClient(Spawn* spawn) {
- vector<Client*>::iterator itr;
- Client* client = 0;
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client){
- if(!packet || packet_version != client->GetVersion()){
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- if(spawn && spawn != client->GetPlayer() &&
- client->GetPlayer()->WasSentSpawn(spawn->GetID()) &&
- client->GetPlayer()->WasSpawnRemoved(spawn) == false &&
- (spawn_range_map.Get(client)->Get(spawn->GetID()) > REMOVE_SPAWN_DISTANCE &&
- !spawn->IsSign() && !spawn->IsObject() && !spawn->IsWidget())){
- SendRemoveSpawn(client, spawn, packet);
- spawn_range_map.Get(client)->erase(spawn->GetID());
- }
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- bool ZoneServer::CombatProcess(Spawn* spawn) {
- bool ret = true;
- if (spawn && spawn->IsEntity())
- ((Entity*)spawn)->ProcessCombat();
- return ret;
- }
- void ZoneServer::AddDelayedSpawnRemove(Spawn* spawn, int32 time) {
- // this prevents a crash when a zone shuts down with a client in it
- if (zoneShuttingDown)
- return;
- if (delayed_spawn_remove_list.count(spawn->GetID(), true) == 0)
- delayed_spawn_remove_list.Put(spawn->GetID(), Timer::GetCurrentTime2() + time);
- }
- void ZoneServer::RemoveDelayedSpawnRemove(Spawn* spawn) {
- if (delayed_spawn_remove_list.count(spawn->GetID(), true) > 0)
- delayed_spawn_remove_list.erase(spawn->GetID());
- }
- void ZoneServer::DelayedSpawnRemoval(bool force_delete_all) {
- if (delayed_spawn_remove_list.size(true) > 0) {
- MutexMap<int32, int32>::iterator itr = delayed_spawn_remove_list.begin();
- int32 current_time = Timer::GetCurrentTime2();
- Spawn* spawn = 0;
- // Cycle through all spawns scheduled for removal
- while (itr.Next()) {
- // If it is time for removal, or a force delete of all, then remove the spawn
- if (force_delete_all || current_time >= itr->second) {
- spawn = GetSpawnByID(itr->first);
- delayed_spawn_remove_list.erase(itr->first);
- if (spawn) {
- if (spawn->IsEntity()) {
- // Remove pets
- ((Entity*)spawn)->DismissPet((NPC*)((Entity*)spawn)->GetPet());
- ((Entity*)spawn)->DismissPet((NPC*)((Entity*)spawn)->GetCharmedPet());
- ((Entity*)spawn)->DismissPet((NPC*)((Entity*)spawn)->GetDeityPet());
- ((Entity*)spawn)->DismissPet((NPC*)((Entity*)spawn)->GetCosmeticPet());
- }
- if (spawn->IsPlayer())
- RemoveSpawn(false, spawn, false);
- else
- RemoveSpawn(false, spawn);
- }
- }
- }
- }
- }
- void ZoneServer::AddPendingDelete(Spawn* spawn) {
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if(spawn_delete_list.count(spawn) == 0)
- spawn_delete_list.insert(make_pair(spawn, Timer::GetCurrentTime2() + spawn_delete_timer)); //give other threads up to 30 seconds to stop using this spawn reference
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteSpawns(bool delete_all) {
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if(spawn_delete_list.size() > 0){
- map<Spawn*, int32>::iterator itr;
- map<Spawn*, int32>::iterator erase_itr;
- int32 current_time = Timer::GetCurrentTime2();
- Spawn* spawn = 0;
- for (itr = spawn_delete_list.begin(); itr != spawn_delete_list.end(); ) {
- if (delete_all || current_time >= itr->second){
- spawn = itr->first;
- if (spawn && movementMgr != nullptr) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- erase_itr = itr++;
- spawn_delete_list.erase(erase_itr);
- safe_delete(spawn);
- }
- else
- itr++;
- }
- }
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddDamagedSpawn(Spawn* spawn){
- if (spawn)
- damaged_spawns.Add(spawn->GetID());
- }
- void ZoneServer::RemoveDamagedSpawn(Spawn* spawn){
- if (spawn)
- damaged_spawns.Remove(spawn->GetID());
- }
- bool ZoneServer::Process()
- {
- MMasterZoneLock->lock(); //Changing this back to a recursive lock to fix a possible /reload spells crash with multiple zones running - Foof
- #ifndef NO_CATCH
- try
- {
- #endif
- while (zoneID == 0) { //this is loaded by world
- Sleep(10);
- }
- if (LoadingData) {
- if (lua_interface) {
- string tmpScript("ZoneScripts/");
- tmpScript.append(GetZoneName());
- tmpScript.append(".lua");
- struct stat buffer;
- bool fileExists = (stat(tmpScript.c_str(), &buffer) == 0);
- if (fileExists)
- lua_interface->RunZoneScript(tmpScript.c_str(), "preinit_zone_script", this);
- }
- if (reloading) {
- LogWrite(COMMAND__DEBUG, 0, "Command", "-Loading Entity Commands...");
- database.LoadEntityCommands(this);
- LogWrite(NPC__INFO, 0, "NPC", "-Loading NPC data...");
- database.LoadNPCs(this);
- LogWrite(NPC__INFO, 0, "NPC", "-Load NPC data complete!");
- LogWrite(OBJECT__INFO, 0, "Object", "-Loading Object data...");
- database.LoadObjects(this);
- LogWrite(OBJECT__INFO, 0, "Object", "-Load Object data complete!");
- LogWrite(SIGN__INFO, 0, "Sign", "-Loading Sign data...");
- database.LoadSigns(this);
- LogWrite(SIGN__INFO, 0, "Sign", "-Load Sign data complete!");
- LogWrite(WIDGET__INFO, 0, "Widget", "-Loading Widget data...");
- database.LoadWidgets(this);
- LogWrite(WIDGET__INFO, 0, "Widget", "-Load Widget data complete!");
- LogWrite(GROUNDSPAWN__INFO, 0, "GSpawn", "-Loading Groundspawn data...");
- database.LoadGroundSpawns(this);
- database.LoadGroundSpawnEntries(this);
- LogWrite(GROUNDSPAWN__INFO, 0, "GSpawn", "-Load Groundspawn data complete!");
- LogWrite(PET__INFO, 0, "Pet", "-Loading Pet data...");
- database.GetPetNames(this);
- LogWrite(PET__INFO, 0, "Pet", "-Load Pet data complete!");
- LogWrite(LOOT__INFO, 0, "Loot", "-Loading Spawn loot data...");
- database.LoadLoot(this);
- LogWrite(LOOT__INFO, 0, "Loot", "-Loading Spawn loot data complete!");
- LogWrite(TRANSPORT__INFO, 0, "Transport", "-Loading Transporters...");
- database.LoadTransporters(this);
- LogWrite(TRANSPORT__INFO, 0, "Transport", "-Loading Transporters complete!");
- reloading = false;
- }
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- spawn_group_associations.clear();
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- spawn_group_locations.clear();
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- spawn_location_groups.clear();
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupChances.writelock(__FUNCTION__, __LINE__);
- spawn_group_chances.clear();
- MSpawnGroupChances.releasewritelock(__FUNCTION__, __LINE__);
- while (zonemap != nullptr && zonemap->IsMapLoading())
- {
- // Client loop
- ClientProcess();
- Sleep(10);
- }
- if (zonemap != nullptr && Grid != nullptr && !zonemap->IsMapLoaded())
- {
- delete Grid;
- Grid = nullptr;
- }
- DeleteTransporters();
- ReloadTransporters();
- database.LoadSpawns(this);
- ProcessSpawnLocations();
- if (!revive_points)
- revive_points = new vector<RevivePoint*>;
- else {
- while (!revive_points->empty()) {
- safe_delete(revive_points->back());
- revive_points->pop_back();
- }
- }
- database.LoadRevivePoints(revive_points, GetZoneID());
- RemoveLocationGrids();
- database.LoadLocationGrids(this);
- LoadingData = false;
- spawn_range.Trigger();
- spawn_check_add.Trigger();
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (lua_interface && zone_script) {
- RemoveLocationProximities();
- lua_interface->RunZoneScript(zone_script, "init_zone_script", this);
- }
- }
- if(shutdownTimer.Enabled() && shutdownTimer.Check())
- zoneShuttingDown = true;
- if (reloading_spellprocess){
- MMasterZoneLock->unlock();
- return !zoneShuttingDown;
- }
- // Remove LD Player whos LD timer has expired
- if (!zoneShuttingDown)
- DelayedSpawnRemoval(false);
- // client loop
- if(charsheet_changes.Check())
- SendCharSheetChanges();
- // Client loop
- ClientProcess();
- if(spellProcess)
- spellProcess->Process();
- if (tradeskillMgr)
- tradeskillMgr->Process();
-
- // Client loop
- if(client_save.Check())
- SaveClients();
- // Possibility to do a client loop
- if(weather_enabled && weatherTimer.Check())
- ProcessWeather();
- // client related loop, move to main thread?
- if(!zoneShuttingDown)
- ProcessDrowning();
- // client than location_proximities loop, move to main thread
- if (location_prox_timer.Check() && !zoneShuttingDown)
- CheckLocationProximity();
- // client than location_grid loop, move to main thread
- if (location_grid_timer.Check() && !zoneShuttingDown)
- CheckLocationGrids();
- if (sync_game_time_timer.Check() && !zoneShuttingDown)
- SendTimeUpdateToAllClients();
- if(lua_interface)
- lua_interface->Process();
- int hour = world.GetWorldTimeStruct()->hour;
- int minute = world.GetWorldTimeStruct()->minute;
- if (!isDusk && (hour >= 19 || hour < 8)) {//((hour > dusk_hour || hour < dawn_hour) || ((dusk_hour == hour && minute >= dusk_minute) || (hour == dawn_hour && minute < dawn_minute)))) {
- isDusk = true;
- const char* zone_script = world.GetZoneScript(GetZoneID());
- if (lua_interface && zone_script)
- lua_interface->RunZoneScript(zone_script, "dusk", this);
- ProcessSpawnConditional(SPAWN_CONDITIONAL_NIGHT);
- }
- else if (isDusk && hour >= 8 && hour < 19) {//((hour > dawn_hour && hour < dusk_hour) || ((hour == dawn_hour && minute >= dawn_minute) || (hour == dusk_hour && minute < dusk_minute)))) {
- isDusk = false;
- const char* zone_script = world.GetZoneScript(GetZoneID());
- if (lua_interface && zone_script)
- lua_interface->RunZoneScript(zone_script, "dawn", this);
- ProcessSpawnConditional(SPAWN_CONDITIONAL_DAY);
- }
- // damaged spawns loop, spawn related, move to spawn thread?
- if(regenTimer.Check())
- RegenUpdate();
- // heading_timers loop
- if(!zoneShuttingDown)
- CheckHeadingTimers();
- // respawn_timers loop
- if(respawn_timer.Check() && !zoneShuttingDown)
- CheckRespawns();
- // spawn_expire_timers loop
- if (spawn_expire_timer.Check() && !zoneShuttingDown)
- CheckSpawnExpireTimers();
- // widget_timers loop
- if(widget_timer.Check() && !zoneShuttingDown)
- CheckWidgetTimers();
- // spawn_script_timers loop
- if(!zoneShuttingDown)
- CheckSpawnScriptTimers();
- // Check to see if a dead spawn needs to be removed
- CheckDeadSpawnRemoval();
- #ifndef NO_CATCH
- }
- catch(...)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception while running '%s'", GetZoneName());
- zoneShuttingDown = true;
- MMasterZoneLock->unlock();
- return false;
- }
- #endif
- MMasterZoneLock->unlock();
- return (zoneShuttingDown == false);
- }
- bool ZoneServer::SpawnProcess(){
- if(depop_zone) {
- depop_zone = false;
- ProcessDepop(respawns_allowed, repop_zone);
- finished_depop = true;
- }
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- // If the zone is loading data or shutting down don't do anything
- if(!LoadingData && !zoneShuttingDown && !reloading_spellprocess) {
- // Set some bool's for timers
- bool movement = movement_timer.Check();
- bool spawnRange = spawn_range.Check();
- bool checkRemove = spawn_check_remove.Check();
- bool aggroCheck = aggro_timer.Check();
- vector<int32> pending_spawn_list_remove;
- map<int32, Spawn*>::iterator itr;
- if (spawnRange || checkRemove)
- {
- // Loop through the spawn list
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- // Loop throught the list to set up spawns to be sent to clients
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- // if zone is shutting down kill the loop
- if (zoneShuttingDown)
- break;
- Spawn* spawn = itr->second;
- if (spawn) {
- // Checks the range to all clients in the zone
- if (spawnRange)
- CheckSpawnRange(spawn);
- // Checks to see if the spawn needs to be removed from a client
- if (checkRemove)
- CheckRemoveSpawnFromClient(spawn);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- // Broke the spawn loop into 2 so spawns are sent to the client faster, send the spawns to clients now then resume the spawn loop
- // client loop, move to main thread?
- // moved this back to the spawn thread as on the main thread during a depop, done on the spawn thread, spawns would start to pop again
- // might be an issue with other functions moved from the spawn thread to the main thread?
- if(spawn_check_add.Check() && !zoneShuttingDown)
- CheckSendSpawnToClient();
- // send spawn changes, changed_spawns loop
- if (spawn_update.Check() && !zoneShuttingDown) { //check for changed spawns every {Rule:SpawnUpdateTimer} milliseconds (default: 200ms)
- SendSpawnChanges();
- }
- if (movement || aggroCheck)
- {
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- // Break the loop if the zone is shutting down
- if (zoneShuttingDown)
- break;
- Spawn* spawn = itr->second;
- if (spawn) {
- // Process spawn movement
- if (movement) {
- spawn->ProcessMovement(true);
- // update last_movement_update for all spawns (used for time_step)
- spawn->last_movement_update = Timer::GetCurrentTime2();
- if (!aggroCheck)
- CombatProcess(spawn);
- }
- // Makes NPC's KOS to other NPC's or players
- if (aggroCheck)
- {
- ProcessAggroChecks(spawn);
- CombatProcess(spawn);
- }
- }
- else {
- // unable to get a valid spawn, lets add the id to another list to remove from the spawn list after this loop is finished
- pending_spawn_list_remove.push_back(itr->first);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- // Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them all
- if (pending_spawn_list_remove.size() > 0) {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr2;
- for (itr2 = pending_spawn_list_remove.begin(); itr2 != pending_spawn_list_remove.end(); itr2++)
- spawn_list.erase(*itr2);
- pending_spawn_list_remove.clear();
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- // Check to see if there are spawns waiting to be added to the spawn list, if so add them all
- if (pending_spawn_list_add.size() > 0) {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- MPendingSpawnListAdd.writelock(__FUNCTION__, __LINE__);
- list<Spawn*>::iterator itr2;
- for (itr2 = pending_spawn_list_add.begin(); itr2 != pending_spawn_list_add.end(); itr2++) {
- Spawn* spawn = *itr2;
- if (spawn)
- spawn_list[spawn->GetID()] = spawn;
- }
- pending_spawn_list_add.clear();
- MPendingSpawnListAdd.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- if (movementMgr != nullptr)
- movementMgr->Process();
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- // Do other loops for spawns
- // tracking, client loop with spawn loop for each client that is tracking, change to a spawn_range_map loop instead of using the main spawn list?
- //if (tracking_timer.Check())
- //ProcessTracking(); // probably doesn't work as spawn loop iterator is never set
- // Delete unused spawns, do this last
- if(!zoneShuttingDown)
- DeleteSpawns(false);
- // Nothing should come after this
- //LogWrite(PLAYER__ERROR, 0, "Debug", "Spawn loop time %u", Timer::GetCurrentTime2() - time);
- }
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
-
- return (zoneShuttingDown == false);
- }
- void ZoneServer::CheckDeadSpawnRemoval() {
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if(dead_spawns.size() > 0){
- vector<Spawn*> tmp_dead_list;
- int32 current_time = Timer::GetCurrentTime2();
- Spawn* spawn = 0;
- map<int32, int32>::iterator itr = dead_spawns.begin();
- map<int32, int32>::iterator itr_delete;
- while (itr != dead_spawns.end()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn) {
- if(current_time >= itr->second)
- tmp_dead_list.push_back(spawn);
- itr++;
- }
- else {
- itr_delete = itr++;
- dead_spawns.erase(itr_delete);
- }
- }
- for(int i=tmp_dead_list.size()-1;i>=0;i--){
- spawn = tmp_dead_list[i];
- if (!spawn->IsPlayer())
- {
- dead_spawns.erase(spawn->GetID());
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- RemoveSpawn(false, spawn, true, true, true);
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- }
- }
- }
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckRespawns(){
- vector<int32> tmp_respawn_list;
- MutexMap<int32, int32>::iterator itr = respawn_timers.begin();
- while(itr.Next()){
- if(Timer::GetCurrentTime2() >= itr->second)
- tmp_respawn_list.push_back(itr->first);
- }
- for(int i=tmp_respawn_list.size()-1;i>=0;i--){
- if ( IsInstanceZone() )
- {
- if ( database.DeleteInstanceSpawnRemoved(GetInstanceID(),tmp_respawn_list[i]) )
- {
- }
- else
- {
- }
- }
- ProcessSpawnLocation(tmp_respawn_list[i], true);
- respawn_timers.erase(tmp_respawn_list[i]);
- }
- }
- void ZoneServer::CheckSpawnExpireTimers() {
- MutexMap<int32, int32>::iterator itr = spawn_expire_timers.begin();
- while (itr.Next()) {
- Spawn* spawn = GetSpawnByID(itr->first);
- if (spawn) {
- if (Timer::GetCurrentTime2() >= itr.second) {
- spawn_expire_timers.erase(itr.first);
- Despawn(spawn, spawn->GetRespawnTime());
- }
- }
- else
- spawn_expire_timers.erase(itr->first);
- }
- }
- void ZoneServer::AddSpawnExpireTimer(Spawn* spawn, int32 expire_time, int32 expire_offset) {
- if (spawn) {
- int32 actual_expire_time = expire_time;
- if (expire_offset > 0) {
- int32 low = expire_time;
- int32 high = expire_time + expire_offset;
- if (expire_offset < expire_time)
- low = expire_time - expire_offset;
- int32 range = (high - low) + 1;
- actual_expire_time = (low + (int32)((range * rand()) / (RAND_MAX + 1.0)));
- }
- actual_expire_time *= 1000;
- spawn_expire_timers.Put(spawn->GetID(), Timer::GetCurrentTime2() + actual_expire_time);
- }
- }
- void ZoneServer::SaveClient(Client* client){
- client->Save();
- }
- void ZoneServer::SaveClients(){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client->IsConnected()){
- SaveClient(client);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawnVisualState(Spawn* spawn, int16 type){
- if(!spawn)
- return;
- vector<Client*>::iterator itr;
- spawn->SetTempVisualState(type);
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- if(client && client->GetPlayer() != spawn)
- AddChangedSpawn(spawn);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawnChangesByDBID(int32 db_id, Client* client, bool override_changes, bool override_vis_changes){
- Spawn* spawn = GetSpawnByDatabaseID(db_id);
- if(spawn && (spawn->changed || override_changes || override_vis_changes))
- SendSpawnChanges(spawn, client, override_changes, override_vis_changes);
- }
- void ZoneServer::SendSpawnChanges(Spawn* spawn, Client* client, bool override_changes, bool override_vis_changes){
- if(client && client->IsReadyForUpdates() && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn) && client->GetPlayer()->GetDistance(spawn) < SEND_SPAWN_DISTANCE){
- EQ2Packet* outapp = spawn->spawn_update_packet(client->GetPlayer(), client->GetVersion(), override_changes, override_vis_changes);
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- void ZoneServer::SendSpawnChanges(Spawn* spawn){
- MSpawnList.readlock();
- if(spawn && spawn->changed){
- if(!spawn->IsPlayer() || (spawn->IsPlayer() && (spawn->info_changed || spawn->vis_changed))){
- vector<Client*>::iterator itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- client = *itr;
- SendSpawnChanges(spawn, client);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- spawn->changed = false;
- spawn->info_changed = false;
- if(spawn->IsPlayer() == false)
- spawn->position_changed = false;
- spawn->vis_changed = false;
- }
- MSpawnList.releasereadlock();
- }
- Spawn* ZoneServer::FindSpawn(Player* searcher, const char* name){
- if(!searcher || !name)
- return 0;
- Spawn* spawn = 0;
- vector<Spawn*> find_spawn_list;
- vector<Spawn*>::iterator fspawn_iter;
- int8 name_size = strlen(name);
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && !strncasecmp(spawn->GetName(), name, name_size))
- find_spawn_list.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- Spawn* closest = 0;
- float distance = 0;
- float test_distance = 0;
- for(fspawn_iter=find_spawn_list.begin(); fspawn_iter!=find_spawn_list.end(); fspawn_iter++){
- spawn = *fspawn_iter;
- if(spawn && ((((test_distance = searcher->GetDistance(spawn)) < distance)) || !closest)){
- distance = test_distance;
- closest = spawn;
- }
- }
- return closest;
- }
- void ZoneServer::AddChangedSpawn(Spawn* spawn){
- if(!spawn || (spawn->IsPlayer() && !spawn->info_changed && !spawn->vis_changed))
- return;
- if (changed_spawns.count(spawn->GetID()) == 0)
- changed_spawns.Add(spawn->GetID());
- }
- void ZoneServer::RemoveChangedSpawn(Spawn* spawn){
- if (spawn)
- changed_spawns.Remove(spawn->GetID());
- }
- void ZoneServer::AddDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client && drowning_victims.count(client) == 0)
- drowning_victims.Put(client, Timer::GetCurrentTime2());
- }
- void ZoneServer::RemoveDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client)
- drowning_victims.erase(client);
- }
- Client* ZoneServer::GetDrowningVictim(Player* player){
- Client* client = GetClientBySpawn(player);
- if(client && drowning_victims.count(client) > 0)
- return(client);
- return 0;
- }
- void ZoneServer::ProcessDrowning(){
- vector<Client*> dead_list;
- if(drowning_victims.size(true) > 0){
- sint32 damage = 0;
- int32 current_time = Timer::GetCurrentTime2();
- MutexMap<Client*, int32>::iterator itr = drowning_victims.begin();
- while(itr.Next()){
- if(current_time >= itr->second) {
- Client* client = itr->first;
- Player* player = client->GetPlayer();
- drowning_victims.Get(client) = Timer::GetCurrentTime2() + 2000;
- damage = player->GetTotalHP()/20 + player->GetHPRegen();
- player->TakeDamage(damage);
- if(player->GetHP() == 0)
- dead_list.push_back(client);
- player->SetCharSheetChanged(true);
- SendCharSheetChanges(client);
- SendDamagePacket(0, player, DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_DROWN, damage, 0);
- client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You are drowning!");
- }
- }
- }
- if(dead_list.size() > 0){
- vector<Client*>::iterator itr;
- for(itr = dead_list.begin(); itr != dead_list.end(); itr++){
- RemoveDrowningVictim((*itr)->GetPlayer());
- KillSpawn(false, (*itr)->GetPlayer(), 0);
- (*itr)->SimpleMessage(CHANNEL_COLOR_WHITE, "You are sleeping with the fishes! Glug, glug...");
- }
- }
- }
- void ZoneServer::SendSpawnChanges(){
- if (changed_spawns.size() < 1)
- return;
- set<Spawn*> spawns_to_send;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- MutexList<int32>::iterator spawn_iter = changed_spawns.begin();
- int count = 0;
- while(spawn_iter.Next()){
- spawn = GetSpawnByID(spawn_iter->value);
- if(spawn){
- spawns_to_send.insert(spawn);
- }
- if (!spawn)
- changed_spawns.Remove(spawn_iter->value);
- }
- changed_spawns.clear();
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- client->SendSpawnChanges(spawns_to_send);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- for (const auto& spawn : spawns_to_send) {
- spawn->changed = false;
- spawn->position_changed = false;
- spawn->vis_changed = false;
- spawn->info_changed = false;
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendPlayerPositionChanges(Player* player){
- if(player){
- player->position_changed = false;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(player != client->GetPlayer() && client->GetPlayer()->WasSentSpawn(player->GetID()) && client->GetPlayer()->WasSpawnRemoved(player) == false){
- EQ2Packet* outapp = player->player_position_update_packet(client->GetPlayer(), client->GetVersion());
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendCharSheetChanges(){
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++)
- SendCharSheetChanges(*client_itr);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendCharSheetChanges(Client* client){
- if(client && client->IsConnected() && client->GetPlayer()->GetCharSheetChanged()){
- client->GetPlayer()->SetCharSheetChanged(false);
- ClientPacketFunctions::SendCharacterSheet(client);
- }
- }
- int32 ZoneServer::CalculateSpawnGroup(SpawnLocation* spawnlocation, bool respawn)
- {
- int32 group = 0;
- list<int32>* groups_at_location = GetSpawnGroupsByLocation(spawnlocation->placement_id);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(groups_at_location){
- list<int32>::iterator group_location_itr;
- float chance = 0;
- float total_chance = 0;
- map<int32, float> tmp_chances;
- set<int32>* associated_groups = 0;
- for (group_location_itr = groups_at_location->begin(); group_location_itr != groups_at_location->end(); group_location_itr++) {
- if(tmp_chances.count(*group_location_itr) > 0)
- continue;
- associated_groups = GetAssociatedGroups(*group_location_itr);
- if(associated_groups){
- set<int32>::iterator group_itr;
- for (group_itr = associated_groups->begin(); group_itr != associated_groups->end(); group_itr++) {
- chance = GetSpawnGroupChance(*group_itr);
- if(chance > 0){
- total_chance += chance;
- tmp_chances[*group_itr] = chance;
- }
- else
- tmp_chances[*group_itr] = 0;
- }
- }
- else{ //single group, no associations
- chance = GetSpawnGroupChance(*group_location_itr);
- total_chance += chance;
- tmp_chances[*group_location_itr] = chance;
- }
- }
- if(tmp_chances.size() > 1){
- //set the default for any chances not set
- map<int32, float>::iterator itr2;
- for(itr2 = tmp_chances.begin(); itr2 != tmp_chances.end(); itr2++){
- if(itr2->second == 0){
- total_chance += 100/tmp_chances.size();
- tmp_chances[itr2->first] = (float)(100 / tmp_chances.size());
- }
- }
- }
- if(tmp_chances.size() > 1){
- float roll = (float)(rand()%((int32)total_chance));
- map<int32, float>::iterator itr3;
- for (itr3 = tmp_chances.begin(); itr3 != tmp_chances.end(); itr3++){
- if(itr3->second >= roll){
- group = itr3->first;
- break;
- }
- else
- roll -= itr3->second;
- }
- }
- else if(tmp_chances.size() == 1)
- group = tmp_chances.begin()->first;
- }
- if(group > 0){
- map<int32, int32>* locations = GetSpawnLocationsByGroup(group);
- if(locations){
- map<int32, int32>::iterator itr;
- Spawn* spawn = 0;
- Spawn* leader = 0;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- for (itr = locations->begin(); itr != locations->end(); itr++) {
- if(spawn_location_list.count(itr->second) > 0){
- spawn = ProcessSpawnLocation(spawn_location_list[itr->second], respawn);
- if(!leader && spawn)
- leader = spawn;
- if(leader)
- leader->AddSpawnToGroup(spawn);
- if(spawn){
- //if(spawn_group_map.count(group) == 0)
- // spawn_group_map.Put(group, new MutexList<Spawn*>());
- MutexList<int32>* groupList = &spawn_group_map.Get(group);
- groupList->Add(spawn->GetID());
- spawn->SetSpawnGroupID(group);
- }
- }
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return group;
- }
- void ZoneServer::ProcessSpawnLocation(int32 location_id, bool respawn)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- if(spawn_location_list.count(location_id) > 0)
- {
- if(respawn) //see if there are any spawns still in game associated with this spawn's group, if so, dont spawn this
- {
- list<int32>* groups = GetSpawnGroupsByLocation(spawn_location_list[location_id]->placement_id);
- if(groups)
- {
- set<int32>* associated_groups = 0;
- bool should_spawn = true;
- list<int32>::iterator itr;
- for (itr = groups->begin(); itr != groups->end(); itr++) {
- associated_groups = GetAssociatedGroups(*itr);
- if(associated_groups)
- {
- set<int32>::iterator assoc_itr;
- for (assoc_itr = associated_groups->begin(); assoc_itr != associated_groups->end(); assoc_itr++) {
- if(spawn_group_map.count(*assoc_itr) > 0 && spawn_group_map.Get(*assoc_itr).size() > 0)
- should_spawn = false;
- }
- }
- }
- if(should_spawn)
- CalculateSpawnGroup(spawn_location_list[location_id]);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- // need to unlock the list before we exit the function
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- ProcessSpawnLocation(spawn_location_list[location_id], respawn);
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- Spawn* ZoneServer::ProcessSpawnLocation(SpawnLocation* spawnlocation, bool respawn)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(!spawnlocation)
- return 0;
- Spawn* spawn = 0;
- float rand_number = MakeRandomFloat(0, spawnlocation->total_percentage);
- for(int32 i=0;i<spawnlocation->entities.size();i++)
- {
- if(spawnlocation->entities[i]->spawn_percentage == 0)
- continue;
- if (spawnlocation->conditional > 0) {
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_DAY && isDusk)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_NIGHT) == SPAWN_CONDITIONAL_NIGHT && !isDusk)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_NOT_RAINING && rain >= 0.75f)
- continue;
- if ((spawnlocation->conditional & SPAWN_CONDITIONAL_DAY) == SPAWN_CONDITIONAL_RAINING && rain < 0.75f)
- continue;
- }
- if (spawnlocation->entities[i]->spawn_percentage >= rand_number) {
- if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
- spawn = AddNPCSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
- spawn = AddGroundSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
- spawn = AddObjectSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
- spawn = AddWidgetSpawn(spawnlocation, spawnlocation->entities[i]);
- else if (spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
- spawn = AddSignSpawn(spawnlocation, spawnlocation->entities[i]);
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
- database.GetHouseSpawnInstanceData(this, spawn);
- if (!spawn)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn to zone");
- safe_delete(spawn);
- continue;
- }
- if (spawn)
- {
- if(respawn)
- CallSpawnScript(spawn, SPAWN_SCRIPT_RESPAWN);
- else
- CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- }
- break;
- }
- else
- rand_number -= spawnlocation->entities[i]->spawn_percentage;
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- Spawn* ZoneServer::ProcessInstanceSpawnLocation(SpawnLocation* spawnlocation, map<int32,int32>* instNPCs, map<int32,int32>* instGroundSpawns, map<int32,int32>* instObjSpawns, map<int32,int32>* instWidgetSpawns, map<int32,int32>* instSignSpawns, bool respawn)
- {
- if(!spawnlocation)
- return 0;
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Spawn* spawn = 0;
- float rand_number = MakeRandomFloat(0, spawnlocation->total_percentage);
- for(int32 i=0;i<spawnlocation->entities.size();i++)
- {
- if(spawnlocation->entities[i]->spawn_percentage == 0)
- continue;
- int32 spawnTime = 0;
- if(spawnlocation->entities[i]->spawn_percentage >= rand_number)
- {
- if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_NPC &&
- (spawnTime = database.CheckSpawnRemoveInfo(instNPCs,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddNPCSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN &&
- (spawnTime = database.CheckSpawnRemoveInfo(instGroundSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddGroundSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT &&
- (spawnTime = database.CheckSpawnRemoveInfo(instObjSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddObjectSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET &&
- (spawnTime = database.CheckSpawnRemoveInfo(instWidgetSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddWidgetSpawn(spawnlocation, spawnlocation->entities[i]);
- else if(spawnlocation->entities[i]->spawn_type == SPAWN_ENTRY_TYPE_SIGN &&
- (spawnTime = database.CheckSpawnRemoveInfo(instSignSpawns,spawnlocation->entities[i]->spawn_location_id)) > 0)
- spawn = AddSignSpawn(spawnlocation, spawnlocation->entities[i]);
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
- database.GetHouseSpawnInstanceData(this, spawn);
- const char* script = 0;
- for(int x=0;x<3;x++)
- {
- switch(x)
- {
- case 0:
- script = world.GetSpawnEntryScript(spawnlocation->entities[i]->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(spawnlocation->entities[i]->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(spawnlocation->entities[i]->spawn_id);
- break;
- }
- if(spawn && script && lua_interface->GetSpawnScript(script) != 0)
- {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- if(spawn)
- {
- if (respawn)
- CallSpawnScript(spawn, SPAWN_SCRIPT_RESPAWN);
- else
- CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
- if ( spawnTime > 1 )
- {
- spawn->SetRespawnTime(spawnTime);
- }
- }
- break;
- }
- else
- rand_number -= spawnlocation->entities[i]->spawn_percentage;
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- void ZoneServer::ProcessSpawnLocations()
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- map<int32,int32>* instNPCs = NULL;
- map<int32,int32>* instGroundSpawns = NULL;
- map<int32,int32>* instObjSpawns = NULL;
- map<int32,int32>* instWidgetSpawns = NULL;
- map<int32,int32>* instSignSpawns = NULL;
- if ( this->IsInstanceZone() )
- {
- LogWrite(SPAWN__DEBUG, 0, "Spawn", "Processing Instance Removed Spawns...");
- instNPCs = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_NPC );
- instGroundSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_GROUNDSPAWN );
- instObjSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_OBJECT );
- instWidgetSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_WIDGET );
- instSignSpawns = database.GetInstanceRemovedSpawns(this->GetInstanceID() , SPAWN_ENTRY_TYPE_SIGN );
- }
- map<int32, bool> processed_spawn_locations;
- map<int32, SpawnLocation*>::iterator itr;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_location_list.begin(); itr != spawn_location_list.end(); itr++) {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "while spawn_location_list itr (#%u)", spawn_location_list.size());
- if(itr->second && processed_spawn_locations.count(itr->second->placement_id) > 0) //if we processed one spawn in a spawn group, we processed them all for that group
- continue;
- if(itr->second && spawn_location_groups.count(itr->second->placement_id) > 0)
- {
- int32 group_id = CalculateSpawnGroup(itr->second);
- if(group_id)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is group_id");
- set<int32>* associated_groups = GetAssociatedGroups(group_id);
- if(associated_groups)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is associated_groups");
- vector<int32>* associated_locations = GetAssociatedLocations(associated_groups);
- if(associated_locations)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "is associated_locations");
- for(int32 i=0;i<associated_locations->size();i++)
- {
- LogWrite(SPAWN__DEBUG, 5, "Spawn", "Loading processed_spawn_locations...");
- processed_spawn_locations[associated_locations->at(i)] = true;
- }
- safe_delete(associated_locations);
- }
- }
- }
- }
- else
- {
- if ( this->IsInstanceZone() )
- {
- //LogWrite(SPAWN__DEBUG, 5, "Spawn", "ProcessInstanceSpawnLocation (%u)...", itr->second->placement_id);
- ProcessInstanceSpawnLocation(itr->second,instNPCs,instGroundSpawns,instObjSpawns,instWidgetSpawns,instSignSpawns);
- }
- else
- {
- //LogWrite(SPAWN__DEBUG, 5, "Spawn", "ProcessSpawnLocation (%u)...", itr->second->placement_id);
- ProcessSpawnLocation(itr->second);
- }
- }
- }
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(instNPCs);
- safe_delete(instGroundSpawns);
- safe_delete(instObjSpawns);
- safe_delete(instWidgetSpawns);
- safe_delete(instSignSpawns);
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- }
- void ZoneServer::AddLoot(NPC* npc){
- vector<int32> loot_tables = GetSpawnLootList(npc->GetDatabaseID(), GetZoneID(), npc->GetLevel(), race_types_list.GetRaceType(npc->GetModelType()));
- if(loot_tables.size() > 0){
- vector<LootDrop*>* loot_drops = 0;
- vector<LootDrop*>::iterator loot_drop_itr;
- LootTable* table = 0;
- vector<int32>::iterator loot_list_itr;
- float chancecoin = 0;
- float chancetable = 0;
- float chancedrop = 0;
- float chancetally = 0;
- float droptally = 0;
- // the following loop,loops through each table
- for(loot_list_itr = loot_tables.begin(); loot_list_itr != loot_tables.end(); loot_list_itr++){
- table = GetLootTable(*loot_list_itr);
- if(table && table->maxcoin > 0){
- chancecoin = rand()%100;
- if(table->coin_probability >= chancecoin){
- if(table->maxcoin > table->mincoin)
- npc->AddLootCoins(table->mincoin + rand()%(table->maxcoin - table->mincoin));
- }
- }
- int numberchances = 1;
- //if (table->lootdrop_probability == 100){ }
- //else
- //chancetally += table->lootdrop_probability;
- int maxchance = 0;
- if (table) {
- maxchance = table->maxlootitems;
- for (numberchances; numberchances <= maxchance; numberchances++) {
- chancetable = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Table Chance: '%f'", chancetable);
- float droppercenttotal = 0;
- //--------------------------------------------------------------------------------------------------------------------------------------------------------------
- if (table->lootdrop_probability == 100 || table->lootdrop_probability >= chancetable) {
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Probability:%f Table Chance: '%f'", table->lootdrop_probability, chancetable);
- loot_drops = GetLootDrops(*loot_list_itr);
- if (loot_drops && loot_drops->size() > 0) {
- LootDrop* drop = 0;
- int16 count = 0;
- std::shuffle(loot_drops->begin(), loot_drops->end(), std::default_random_engine(Timer::GetCurrentTime2()));
- int16 IC = 0;
- for (loot_drop_itr = loot_drops->begin(); loot_drop_itr != loot_drops->end(); loot_drop_itr++) {
- drop = *loot_drop_itr;
- droppercenttotal += drop->probability;
- }
-
- int droplistsize = loot_drops->size();
- float chancedroptally = 0;
- chancedrop = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- for (loot_drop_itr = loot_drops->begin(); loot_drop_itr != loot_drops->end(); loot_drop_itr++) {
- drop = *loot_drop_itr;
- if (npc->HasLootItemID(drop->item_id))
- continue;
- if (droppercenttotal >= 100)
- droppercenttotal = 100;
- chancedroptally += 100 / droppercenttotal * drop->probability;
- //chancedrop = static_cast <float> (rand()) / (static_cast <float> (RAND_MAX / 100));
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Loot drop: '%i' Chance: %f Prob tally: %f min: %f", drop, chancedrop, chancedroptally, chancedroptally - drop->probability);
- if ((chancedroptally == 100) || ((chancedroptally >= chancedrop) && (chancedroptally - (100 / droppercenttotal * drop->probability)) <= chancedrop)) {
- //LogWrite(PLAYER__DEBUG, 0, "Player", "Loot drop: '%i' Chance: %f Prob: %f We have a loot drop winner", drop, chancedrop, chancedroptally);
- count++;
- npc->AddLootItem(drop->item_id, drop->item_charges);
- //LogWrite(PLAYER__DEBUG, 0, "Player", "loot Count: '%i'",count);
- //LogWrite(MISC__TODO, 1, "TODO", "Auto-Equip new looted items\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- //if(drop->equip_item)
- }
- if (table->maxlootitems > 0 && count >= table->maxlootitems)
- break;
- }
- }
- }
- }
- }
- }
- }
- }
- void ZoneServer::DeterminePosition(SpawnLocation* spawnlocation, Spawn* spawn){
- if(!spawn || !spawnlocation)
- return;
- int offset = 0;
- if(spawnlocation->x_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->x_offset*1000)+1);
- spawn->SetX(spawnlocation->x + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetX(spawnlocation->x);
- if(spawnlocation->y_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->y_offset*1000)+1);
- spawn->SetY(spawnlocation->y + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetY(spawnlocation->y, true, true);
- if(spawnlocation->z_offset > 0){
- //since rand() deals with integers only, we are going to divide by 1000 later so that we can use fractions of integers
- offset = (int)((spawnlocation->z_offset*1000)+1);
- spawn->SetZ(spawnlocation->z + ((float)(rand()%offset - rand()%offset))/1000);
- }
- else
- spawn->SetZ(spawnlocation->z);
- spawn->SetHeading(spawnlocation->heading);
- spawn->SetPitch(spawnlocation->pitch);
- spawn->SetRoll(spawnlocation->roll);
- spawn->SetSpawnOrigX(spawn->GetX());
- spawn->SetSpawnOrigY(spawn->GetY());
- spawn->SetSpawnOrigZ(spawn->GetZ());
- spawn->SetSpawnOrigHeading(spawn->GetHeading());
- spawn->SetSpawnOrigPitch(spawnlocation->pitch);
- spawn->SetSpawnOrigRoll(spawnlocation->roll);
- spawn->appearance.pos.grid_id = spawnlocation->grid_id;
- spawn->SetSpawnLocationPlacementID(spawnlocation->placement_id);
- }
- NPC* ZoneServer::AddNPCSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- NPC* npc = GetNewNPC(spawnentry->spawn_id);
- if(npc){
- DeterminePosition(spawnlocation, npc);
- npc->SetDatabaseID(spawnentry->spawn_id);
- npc->SetSpawnLocationID(spawnentry->spawn_location_id);
- npc->SetSpawnEntryID(spawnentry->spawn_entry_id);
- npc->SetRespawnTime(spawnentry->respawn);
- npc->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(npc, spawnentry->expire_time, spawnentry->expire_offset);
- AddLoot(npc);
- SetSpawnScript(spawnentry, npc);
- CallSpawnScript(npc, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(npc);
- }
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- return npc;
- }
- vector<int32>* ZoneServer::GetAssociatedLocations(set<int32>* groups){
- vector<int32>* ret = 0;
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- if(groups){
- int32 group_id = 0;
- set<int32>::iterator group_itr;
- for (group_itr = groups->begin(); group_itr != groups->end(); group_itr++) {
- if(!ret)
- ret = new vector<int32>();
- group_id = *group_itr;
- MSpawnGroupLocations.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) > 0){
- map<int32, int32>::iterator itr;
- for (itr = spawn_group_locations[group_id]->begin(); itr != spawn_group_locations[group_id]->end(); itr++) {
- ret->push_back(itr->first);
- }
- }
- MSpawnGroupLocations.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- return ret;
- }
- set<int32>* ZoneServer::GetAssociatedGroups(int32 group_id) {
- set<int32>* ret = 0;
- MSpawnGroupAssociation.readlock(__FUNCTION__, __LINE__);
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Enter %s", __FUNCTION__);
- if(spawn_group_associations.count(group_id) > 0)
- ret = spawn_group_associations[group_id];
- LogWrite(SPAWN__TRACE, 1, "Spawn", "Exit %s", __FUNCTION__);
- MSpawnGroupAssociation.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- map<int32, int32>* ZoneServer::GetSpawnLocationsByGroup(int32 group_id) {
- map<int32, int32>* ret = 0;
- MSpawnGroupLocations.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) > 0)
- ret = spawn_group_locations[group_id];
- MSpawnGroupLocations.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- list<int32>* ZoneServer::GetSpawnGroupsByLocation(int32 location_id){
- list<int32>* ret = 0;
- MSpawnLocationGroups.readlock(__FUNCTION__, __LINE__);
- if(spawn_location_groups.count(location_id) > 0)
- ret = spawn_location_groups[location_id];
- MSpawnLocationGroups.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- float ZoneServer::GetSpawnGroupChance(int32 group_id){
- float ret = -1;
- MSpawnGroupChances.readlock(__FUNCTION__, __LINE__);
- if(spawn_group_chances.count(group_id) > 0)
- ret = spawn_group_chances[group_id];
- MSpawnGroupChances.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::AddSpawnGroupChance(int32 group_id, float percent){
- MSpawnGroupChances.writelock(__FUNCTION__, __LINE__);
- spawn_group_chances[group_id] = percent;
- MSpawnGroupChances.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnGroupAssociation(int32 group_id1, int32 group_id2) {
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- //Check if we already have containers for these group ids, if not create them
- if (spawn_group_associations.count(group_id1) == 0)
- spawn_group_associations[group_id1] = new set<int32>;
- if (spawn_group_associations.count(group_id2) == 0)
- spawn_group_associations[group_id2] = new set<int32>;
- //Associate groups 1 and 2 now
- set<int32>* group_1 = spawn_group_associations.find(group_id1)->second;
- set<int32>* group_2 = spawn_group_associations.find(group_id2)->second;
- group_1->insert(group_id2);
- group_2->insert(group_id1);
-
- //Associate the remaining groups together
- set<int32>::iterator itr;
- for (itr = group_1->begin(); itr != group_1->end(); itr++){
- group_2->insert(*itr);
- map<int32, set<int32>*>::iterator assoc_itr = spawn_group_associations.find(*itr);
- if (assoc_itr != spawn_group_associations.end())
- assoc_itr->second->insert(group_id2);
- else {
- set<int32>* new_set = new set<int32>;
- spawn_group_associations[*itr] = new_set;
- new_set->insert(group_id2);
- }
- }
- for (itr = group_2->begin(); itr != group_2->end(); itr++){
- group_1->insert(*itr);
- map<int32, set<int32>*>::iterator assoc_itr = spawn_group_associations.find(*itr);
- if (assoc_itr != spawn_group_associations.end())
- assoc_itr->second->insert(group_id1);
- else {
- set<int32>* new_set = new set<int32>;
- spawn_group_associations[*itr] = new_set;
- new_set->insert(group_id1);
- }
- }
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnGroupLocation(int32 group_id, int32 location_id, int32 spawn_location_id) {
- MSpawnGroupLocations.writelock(__FUNCTION__, __LINE__);
- if(spawn_group_locations.count(group_id) == 0)
- spawn_group_locations[group_id] = new map<int32, int32>();
- (*spawn_group_locations[group_id])[location_id] = spawn_location_id;
- MSpawnGroupLocations.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnLocationGroups.writelock(__FUNCTION__, __LINE__);
- if(spawn_location_groups.count(location_id) == 0)
- spawn_location_groups[location_id] = new list<int32>();
- spawn_location_groups[location_id]->push_back(group_id);
- MSpawnLocationGroups.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnGroupAssociation.writelock(__FUNCTION__, __LINE__);
- if(spawn_group_associations.count(group_id) == 0)
- spawn_group_associations[group_id] = new set<int32>();
- spawn_group_associations[group_id]->insert(group_id);
- MSpawnGroupAssociation.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CallSpawnScript(Spawn* npc, int8 type, Spawn* spawn, const char* message){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(!npc)
- return;
- const char* script = npc->GetSpawnScript();
- if ( script == nullptr || strlen(script) < 1 )
- {
- if (npc->GetZone() != nullptr)
- {
- string tmpScript;
- tmpScript.append("SpawnScripts/");
- tmpScript.append(npc->GetZone()->GetZoneName());
- tmpScript.append("/");
- int count = 0;
- for (int s = 0; s < strlen(npc->GetName()); s++)
- {
- if (isalnum(npc->GetName()[s]))
- {
- tmpScript += npc->GetName()[s];
- count++;
- }
- }
- tmpScript.append(".lua");
- if (count < 1)
- {
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Could not form script name %s..", __FUNCTION__);
- }
- else
- {
- struct stat buffer;
- bool fileExists = (stat(tmpScript.c_str(), &buffer) == 0);
- if (fileExists)
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "No script file described in the database, overriding with SpawnScript at %s", (char*)tmpScript.c_str());
- npc->SetSpawnScript(tmpScript);
- script = npc->GetSpawnScript();
- }
- }
- }
- }
- if(lua_interface && script){
- switch(type){
- case SPAWN_SCRIPT_SPAWN:{
- lua_interface->RunSpawnScript(script, "spawn", npc);
- break;
- }
- case SPAWN_SCRIPT_RESPAWN:{
- lua_interface->RunSpawnScript(script, "respawn", npc);
- break;
- }
- case SPAWN_SCRIPT_ATTACKED:{
- lua_interface->RunSpawnScript(script, "attacked", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_TARGETED:{
- lua_interface->RunSpawnScript(script, "targeted", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HAILED:{
- lua_interface->RunSpawnScript(script, "hailed", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HAILED_BUSY:{
- lua_interface->RunSpawnScript(script, "hailed_busy", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_DEATH:{
- lua_interface->RunSpawnScript(script, "death", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_KILLED:{
- lua_interface->RunSpawnScript(script, "killed", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_AGGRO:{
- lua_interface->RunSpawnScript(script, "aggro", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HEALTHCHANGED:{
- lua_interface->RunSpawnScript(script, "healthchanged", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_RANDOMCHAT:{
- lua_interface->RunSpawnScript(script, "randomchat", npc, 0, message);
- break;
- }
- case SPAWN_SCRIPT_CUSTOM:
- case SPAWN_SCRIPT_TIMER:
- case SPAWN_SCRIPT_CONVERSATION:{
- lua_interface->RunSpawnScript(script, message, npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_CASTED_ON: {
- lua_interface->RunSpawnScript(script, "casted_on", npc, spawn, message);
- break;
- }
- case SPAWN_SCRIPT_AUTO_ATTACK_TICK: {
- lua_interface->RunSpawnScript(script, "auto_attack_tick", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_COMBAT_RESET: {
- lua_interface->RunSpawnScript(script, "CombatReset", npc);
- break;
- }
- case SPAWN_SCRIPT_GROUP_DEAD: {
- lua_interface->RunSpawnScript(script, "group_dead", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_HEAR_SAY: {
- lua_interface->RunSpawnScript(script, "hear_say", npc, spawn, message);
- break;
- }
- case SPAWN_SCRIPT_PRESPAWN: {
- lua_interface->RunSpawnScript(script, "prespawn", npc);
- break;
- }
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- }
- void ZoneServer::DeleteTransporters() {
- MTransportLocations.writelock(__FUNCTION__, __LINE__);
- transporter_locations.clear(); //world takes care of actually deleting the data
- MTransportLocations.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ReloadTransporters(){
- MutexList<LocationTransportDestination*>* locations = GetLocationTransporters(GetZoneID());
- if(locations){
- MutexList<LocationTransportDestination*>::iterator itr = locations->begin();
- while(itr.Next())
- AddTransporter(itr->value);
- }
- }
- void ZoneServer::CheckTransporters(Client* client) {
- MTransportLocations.readlock(__FUNCTION__, __LINE__);
- if(transporter_locations.size() > 0){
- LocationTransportDestination* loc = 0;
- list<LocationTransportDestination*>::iterator itr;
- for (itr = transporter_locations.begin(); itr != transporter_locations.end(); itr++) {
- loc = *itr;
- if(client->GetPlayer()->GetDistance(loc->trigger_x, loc->trigger_y, loc->trigger_z) <= loc->trigger_radius){
- if(loc->destination_zone_id == 0 || loc->destination_zone_id == GetZoneID()){
- EQ2Packet* packet = client->GetPlayer()->Move(loc->destination_x, loc->destination_y, loc->destination_z, client->GetVersion());
- if(packet)
- client->QueuePacket(packet);
- }
- else{
- ZoneServer* new_zone = zone_list.Get(loc->destination_zone_id);
- if(new_zone){
- client->GetPlayer()->SetX(loc->destination_x);
- client->GetPlayer()->SetY(loc->destination_y);
- client->GetPlayer()->SetZ(loc->destination_z);
- client->GetPlayer()->SetHeading(loc->destination_heading);
- client->Zone(new_zone, false);
- }
- }
- break;
- }
- }
- }
- MTransportLocations.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddTransporter(LocationTransportDestination* loc) {
- MTransportLocations.writelock(__FUNCTION__, __LINE__);
- transporter_locations.push_back(loc);
- MTransportLocations.releasewritelock(__FUNCTION__, __LINE__);
- }
- Sign* ZoneServer::AddSignSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Sign* sign = GetNewSign(spawnentry->spawn_id);
- if(sign){
- DeterminePosition(spawnlocation, sign);
- sign->SetDatabaseID(spawnentry->spawn_id);
- sign->SetSpawnLocationID(spawnentry->spawn_location_id);
- sign->SetSpawnEntryID(spawnentry->spawn_entry_id);
- sign->SetRespawnTime(spawnentry->respawn);
- sign->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(sign, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, sign);
- CallSpawnScript(sign, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(sign);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return sign;
- }
- Widget* ZoneServer::AddWidgetSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Widget* widget = GetNewWidget(spawnentry->spawn_id);
- if(widget){
- DeterminePosition(spawnlocation, widget);
- widget->SetDatabaseID(spawnentry->spawn_id);
- widget->SetSpawnLocationID(spawnentry->spawn_location_id);
- widget->SetSpawnEntryID(spawnentry->spawn_entry_id);
- if(!widget->GetIncludeLocation()){
- widget->SetX(widget->GetWidgetX());
- if(widget->GetCloseY() != 0)
- widget->SetY(widget->GetCloseY());
- widget->SetZ(widget->GetWidgetZ());
- }
- widget->SetRespawnTime(spawnentry->respawn);
- widget->SetExpireTime(spawnentry->expire_time);
- widget->SetSpawnOrigHeading(widget->GetHeading());
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(widget, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, widget);
- CallSpawnScript(widget, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(widget);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return widget;
- }
- Object* ZoneServer::AddObjectSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- Object* object = GetNewObject(spawnentry->spawn_id);
- if(object){
- DeterminePosition(spawnlocation, object);
- object->SetDatabaseID(spawnentry->spawn_id);
- object->SetSpawnLocationID(spawnentry->spawn_location_id);
- object->SetSpawnEntryID(spawnentry->spawn_entry_id);
- object->SetRespawnTime(spawnentry->respawn);
- object->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(object, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, object);
- CallSpawnScript(object, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(object);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return object;
- }
- GroundSpawn* ZoneServer::AddGroundSpawn(SpawnLocation* spawnlocation, SpawnEntry* spawnentry){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- GroundSpawn* spawn = GetNewGroundSpawn(spawnentry->spawn_id);
- if(spawn){
- DeterminePosition(spawnlocation, spawn);
- spawn->SetDatabaseID(spawnentry->spawn_id);
- spawn->SetSpawnLocationID(spawnentry->spawn_location_id);
- spawn->SetSpawnEntryID(spawnentry->spawn_entry_id);
- spawn->SetRespawnTime(spawnentry->respawn);
- spawn->SetExpireTime(spawnentry->expire_time);
- if (spawnentry->expire_time > 0)
- AddSpawnExpireTimer(spawn, spawnentry->expire_time, spawnentry->expire_offset);
- SetSpawnScript(spawnentry, spawn);
- CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
- AddSpawn(spawn);
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return spawn;
- }
- void ZoneServer::AddSpawn(Spawn* spawn) {
- spawn->SetZone(this);
- spawn->position_changed = false;
- spawn->info_changed = false;
- spawn->vis_changed = false;
- spawn->changed = false;
- if(!spawn->IsPlayer() || (spawn->IsPlayer() && !((Player*)spawn)->IsReturningFromLD())) {
- // Write locking the spawn list here will cause deadlocks, so instead add it to a temp list that the
- // main spawn thread will put into the spawn_list when ever it has a chance.
- MPendingSpawnListAdd.writelock(__FUNCTION__, __LINE__);
- pending_spawn_list_add.push_back(spawn);
- MPendingSpawnListAdd.releasewritelock(__FUNCTION__, __LINE__);
- }
- else
- ((Player*)spawn)->SetReturningFromLD(false);
- spawn_range.Trigger();
- spawn_check_add.Trigger();
- if (GetInstanceType() == PERSONAL_HOUSE_INSTANCE && spawn->IsObject())
- {
- spawn->AddSecondaryEntityCommand("Examine", 20, "house_spawn_examine", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Move", 20, "move_item", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Pack in Moving Crate", 20, "house_spawn_pack_in_moving_crate", "", 0, 0);
- spawn->AddSecondaryEntityCommand("Pick Up", 20, "pickup", "", 0, 0);
- spawn->SetShowCommandIcon(1);
- }
- if(spawn->IsNPC())
- AddEnemyList((NPC*)spawn);
- if(spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo())
- world.GetGroupManager()->SendGroupUpdate(((Player*)spawn)->GetGroupMemberInfo()->group_id, GetClientBySpawn(spawn));
- if (spawn->IsPlayer()) {
- ((Player*)spawn)->GetInfoStruct()->rain = rain;
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- if (Grid != nullptr) {
- Grid->AddSpawn(spawn);
- }
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->AddMob((Entity*)spawn);
- }
- AddSpawnProximities(spawn);
- spawn->SetAddedToWorldTimestamp(Timer::GetCurrentTime2());
- }
- void ZoneServer::AddClient(Client* client){
- MClientList.writelock(__FUNCTION__, __LINE__);
- clients.push_back(client);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- connected_clients.Add(client);
- }
- void ZoneServer::RemoveClient(Client* client)
- {
- Guild *guild;
- if(client)
- {
- if (client->GetPlayer())
- client_list.RemovePlayerFromInvisHistory(client->GetPlayer()->GetID());
- LogWrite(ZONE__DEBUG, 0, "Zone", "Sending login equipment appearance updates...");
- loginserver.SendImmediateEquipmentUpdatesForChar(client->GetPlayer()->GetCharacterID());
- if (!client->IsZoning())
- {
- if ((guild = client->GetPlayer()->GetGuild()) != NULL)
- guild->GuildMemberLogoff(client->GetPlayer());
- chat.LeaveAllChannels(client);
- }
-
- int32 LD_Timer = rule_manager.GetGlobalRule(R_World, LinkDeadTimer)->GetInt32();
- int32 DisconnectClientTimer = rule_manager.GetGlobalRule(R_World, RemoveDisconnectedClientsTimer)->GetInt32();
- if(!zoneShuttingDown && !client->IsZoning())
- {
- GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
- if (gmi) {
- int32 size = world.GetGroupManager()->GetGroupSize(gmi->group_id);
- if (size > 1) {
- bool send_left_message = size > 2;
- world.GetGroupManager()->RemoveGroupMember(gmi->group_id, client->GetPlayer());
- if (send_left_message)
- world.GetGroupManager()->GroupMessage(gmi->group_id, "%s has left the group.", client->GetPlayer()->GetName());
- }
- }
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to LD/Exit...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- //AddDelayedSpawnRemove(client->GetPlayer(), LD_Timer);
- //connected_clients.Remove(client, true, LD_Timer + DisconnectClientTimer);
- }
- else
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to Camp/Quit...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- }
-
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetCharmedPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetDeityPet());
- client->GetPlayer()->DismissPet((NPC*)client->GetPlayer()->GetCosmeticPet());
- //}
- }
- else
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Removing client '%s' (%u) due to some client zoning...", client->GetPlayer()->GetName(), client->GetPlayer()->GetCharacterID());
- }
- map<int32, int32>::iterator itr;
- for (itr = client->GetPlayer()->SpawnedBots.begin(); itr != client->GetPlayer()->SpawnedBots.end(); itr++) {
- Spawn* spawn = GetSpawnByID(itr->second);
- if (spawn && spawn->IsBot())
- ((Bot*)spawn)->Camp();
- }
- LogWrite(ZONE__DEBUG, 0, "Zone", "Calling clients.Remove(client)...");
- MClientList.writelock(__FUNCTION__, __LINE__);
- clients.erase(find(clients.begin(), clients.end(), client));
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- LogWrite(ZONE__INFO, 0, "Zone", "Scheduling client '%s' for removal.", client->GetPlayer()->GetName());
- LogWrite(MISC__TODO, 1, "TODO", "Put Player Online Status updates in a timer eventually\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- database.ToggleCharacterOnline(client, 0);
-
- RemoveSpawn(false, client->GetPlayer(), false);
- connected_clients.Remove(client, true, DisconnectClientTimer); // changed from a hardcoded 30000 (30 sec) to the DisconnectClientTimer rule
- }
- }
- void ZoneServer::RemoveClientImmediately(Client* client) {
- Guild *guild;
- if(client)
- {
- loginserver.SendImmediateEquipmentUpdatesForChar(client->GetPlayer()->GetCharacterID());
- if(connected_clients.count(client) > 0)
- {
- if (!client->IsZoning() && (guild = client->GetPlayer()->GetGuild()))
- guild->GuildMemberLogoff(client->GetPlayer());
- MClientList.writelock(__FUNCTION__, __LINE__);
- std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
- if (itr != clients.end())
- clients.erase(itr);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- //clients.Remove(client);
- LogWrite(ZONE__INFO, 0, "Zone", "Removing connection for client '%s'.", client->GetPlayer()->GetName());
- connected_clients.Remove(client, true);
- }
- else
- {
- MClientList.writelock(__FUNCTION__, __LINE__);
- std::vector<Client*>::iterator itr = find(clients.begin(), clients.end(), client);
- if (itr != clients.end())
- clients.erase(itr);
- MClientList.releasewritelock(__FUNCTION__, __LINE__);
- //clients.Remove(client, true);
- }
- LogWrite(MISC__TODO, 1, "TODO", "Put Player Online Status updates in a timer eventually\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- database.ToggleCharacterOnline(client, 0);
- }
- }
- void ZoneServer::ClientProcess()
- {
- if(connected_clients.size(true) == 0)
- {
- if(!IsCityZone() && !AlwaysLoaded() && !shutdownTimer.Enabled())
- {
- LogWrite(ZONE__INFO, 0, "Zone", "Starting zone shutdown timers...");
- shutdownTimer.Start();
- }
- return;
- }
- shutdownTimer.Disable();
- Client* client = 0;
- MutexList<Client*>::iterator iterator = connected_clients.begin();
- while(iterator.Next())
- {
- client = iterator->value;
- #ifndef NO_CATCH
- try
- {
- #endif
- if(zoneShuttingDown || !client->Process(true))
- {
- if(!zoneShuttingDown && !client->IsZoning())
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Client is disconnecting in %s (camping = %s)", __FUNCTION__, (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 ? "false" : "true");
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 )
- {
- //only set LD flag if we're disconnecting but not camping/quitting
- client->GetPlayer()->SetActivityStatus(client->GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_LINKDEAD);
- if(client->GetPlayer()->GetGroupMemberInfo())
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Telling client's group they are disconnecting");
- world.GetGroupManager()->GroupMessage(client->GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", client->GetPlayer()->GetName());
- }
- }
- }
- client_spawn_map.Put(client->GetPlayer(), 0);
- client->Disconnect();
- RemoveClient(client);
- }
- #ifndef NO_CATCH
- }
- catch(...)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception caught when in ZoneServer::ClientProcess() for zone '%s'!\n%s, %i", GetZoneName(), __FUNCTION__, __LINE__);
- try{
- if(!client->IsZoning())
- {
- if( (client->GetPlayer()->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0 )
- {
- client->GetPlayer()->SetActivityStatus(client->GetPlayer()->GetActivityStatus() + ACTIVITY_STATUS_LINKDEAD);
- if(client->GetPlayer()->GetGroupMemberInfo())
- world.GetGroupManager()->GroupMessage(client->GetPlayer()->GetGroupMemberInfo()->group_id, "%s has gone Linkdead.", client->GetPlayer()->GetName());
- }
- }
- client_spawn_map.Put(client->GetPlayer(), 0);
- client->Disconnect();
- RemoveClient(client);
- }
- catch(...){
- LogWrite(ZONE__ERROR, 0, "Zone", "Exception caught when in ZoneServer::ClientProcess(), second try\n%s, %i", __FUNCTION__, __LINE__);
- }
- }
- #endif
- }
- }
- void ZoneServer::SimpleMessage(int8 type, const char* message, Spawn* from, float distance){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(from && client && client->IsConnected() && from->GetDistance(client->GetPlayer()) <= distance){
- client->SimpleMessage(type, message);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleChatMessage(Client* client, Spawn* from, const char* to, int16 channel, const char* message, float distance, const char* channel_name, bool show_bubble, int32 language){
- if((!distance || from->GetDistance(client->GetPlayer()) <= distance) && (!from || !client->GetPlayer()->IsIgnored(from->GetName()))){
- PacketStruct* packet = configReader.getStruct("WS_HearChat", client->GetVersion());
- if(packet){
- if(from)
- packet->setMediumStringByName("from", from->GetName());
- if(client->GetPlayer() != from)
- packet->setMediumStringByName("to", client->GetPlayer()->GetName());
- packet->setDataByName("channel", channel);
- if(from && ((from == client->GetPlayer()) || (client->GetPlayer()->WasSentSpawn(from->GetID()) && !client->GetPlayer()->WasSpawnRemoved(from))))
- packet->setDataByName("from_spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(from));
- else
- packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
- packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
- packet->setMediumStringByName("message", message);
- packet->setDataByName("language", language);
- if (language > 0 && !client->GetPlayer()->HasLanguage(language))
- packet->setDataByName("understood", 0);
- else
- packet->setDataByName("understood", 1);
- show_bubble == true ? packet->setDataByName("show_bubble", 1) : packet->setDataByName("show_bubble", 0);
- if(channel_name)
- packet->setMediumStringByName("channel_name", channel_name);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void ZoneServer::HandleChatMessage(Spawn* from, const char* to, int16 channel, const char* message, float distance, const char* channel_name, bool show_bubble, int32 language){
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- HandleChatMessage(client, from, to, channel, message, distance, channel_name, show_bubble, language);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleBroadcast(const char* message) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- client->SimpleMessage(CHANNEL_BROADCAST, message);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::HandleAnnouncement(const char* message) {
- vector<Client*>::iterator client_itr;
- Client* client = 0;
- int32 words = ::CountWordsInString(message);
- if (words < 5)
- words = 5;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected()) {
- client->SimpleMessage(CHANNEL_BROADCAST, message);
- client->SendPopupMessage(10, message, "ui_harvest_normal", words, 0xFF, 0xFF, 0x00);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendTimeUpdate(Client* client){
- if(client){
- PacketStruct* packet = world.GetWorldTime(client->GetVersion());
- if(packet){
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- void ZoneServer::SendTimeUpdateToAllClients(){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->IsConnected())
- SendTimeUpdate(client);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::UpdateVitality(float amount){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && client->GetPlayer()->GetInfoStruct()->xp_vitality < 100){
- if((client->GetPlayer()->GetInfoStruct()->xp_vitality + amount) > 100)
- client->GetPlayer()->GetInfoStruct()->xp_vitality = 100;
- else
- client->GetPlayer()->GetInfoStruct()->xp_vitality += amount;
- client->GetPlayer()->SetCharSheetChanged(true);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpawn(Spawn* spawn, Client* client){
- EQ2Packet* outapp = spawn->serialize(client->GetPlayer(), client->GetVersion());
- LogWrite(ZONE__DEBUG, 7, "Zone", "%s: Processing SendSpawn for spawn index %u (%s)...", client->GetPlayer()->GetName(), client->GetPlayer()->GetIndexForSpawn(spawn), spawn->GetName());
- if(outapp)
- client->QueuePacket(outapp);
- /*
- vis flags:
- 2 = show icon
- 4 = targetable
- 16 = show name
- 32 = show level/border
- activity_status:
- 4 - linkdead
- 8 - camping
- 16 - LFG
- 32 - LFW
- 2048 - mentoring
- 4096 - displays shield
- 8192 - immunity gained
- 16384 - immunity remaining
- attackable_status
- 1 - no_hp_bar
- 4 - not attackable
- npc_con
- -4 = scowls
- -3 = threatening
- -2 = dubiously
- -1 = apprehensively
- 0 = indifferent
- 1 = amiably
- 2 = kindly
- 3 = warmly
- 4 = ally
- quest_flag
- 1 = new quest
- 2 = update and new quest
- 3 = update
- */
- }
- Client* ZoneServer::GetClientBySpawn(Spawn* spawn){
- return client_spawn_map.Get(spawn);
- }
- Client* ZoneServer::GetClientByName(char* name) {
- Client* ret = 0;
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- if ((*itr)->GetPlayer()) {
- if (strncmp((*itr)->GetPlayer()->GetName(), name, strlen(name)) == 0) {
- ret = *itr;
- break;
- }
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::AddMovementNPC(Spawn* spawn){
- if (spawn)
- movement_spawns.Put(spawn->GetID(), 1);
- }
- void ZoneServer::RemoveMovementNPC(Spawn* spawn){
- if (spawn)
- remove_movement_spawns.Add(spawn->GetID());
- }
- void ZoneServer::PlayFlavor(Client* client, Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language){
- if(!client || !spawn)
- return;
- PacketStruct* packet = configReader.getStruct("WS_PlayFlavor", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("unknown1", 0xFFFFFFFF);
- packet->setDataByName("unknown5", 1, 1);
- packet->setDataByName("unknown5", 1, 6);
- if(mp3){
- packet->setMediumStringByName("mp3", mp3);
- packet->setDataByName("key", key1);
- packet->setDataByName("key", key2, 1);
- }
- packet->setMediumStringByName("name", spawn->GetName());
- if(text)
- packet->setMediumStringByName("text", text);
- if(emote)
- packet->setMediumStringByName("emote", emote);
- if (language != 0)
- packet->setDataByName("language", language);
- //We should probably add Common = language id 0 or 0xFF so admins can customize more..
- if (language == 0 || client->GetPlayer()->HasLanguage(language))
- packet->setDataByName("understood", 1);
- EQ2Packet* app = packet->serialize();
- //DumpPacket(app);
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- void ZoneServer::PlayVoice(Client* client, Spawn* spawn, const char* mp3, int32 key1, int32 key2){
- if(!client || !spawn)
- return;
- PacketStruct* packet = configReader.getStruct("WS_PlayVoice", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setMediumStringByName("mp3", mp3);
- packet->setDataByName("key", key1);
- packet->setDataByName("key", key2, 1);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void ZoneServer::PlayFlavor(Spawn* spawn, const char* mp3, const char* text, const char* emote, int32 key1, int32 key2, int8 language){
- if(!spawn)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->IsConnected() || !client->GetPlayer()->WasSentSpawn(spawn->GetID()) || client->GetPlayer()->WasSpawnRemoved(spawn) || client->GetPlayer()->GetDistance(spawn) > 30)
- continue;
- PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PlayVoice(Spawn* spawn, const char* mp3, int32 key1, int32 key2){
- if(!spawn || !mp3)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->IsConnected() || !client->GetPlayer()->WasSentSpawn(spawn->GetID()) || client->GetPlayer()->WasSpawnRemoved(spawn))
- continue;
- PlayVoice(client, spawn, mp3, key1, key2);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::PlaySoundFile(Client* client, const char* name, float origin_x, float origin_y, float origin_z){
- if(!name)
- return;
- PacketStruct* packet = 0;
- if(client){
- packet = configReader.getStruct("WS_Play3DSound", client->GetVersion());
- if(packet){
- packet->setMediumStringByName("name", name);
- packet->setDataByName("x", origin_x);
- packet->setDataByName("y", origin_y);
- packet->setDataByName("z", origin_z);
- packet->setDataByName("unknown1", 1);
- packet->setDataByName("unknown2", 2.5);
- packet->setDataByName("unknown3", 15);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- else{
- EQ2Packet* outapp = 0;
- int16 packet_version = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client && (!packet || packet_version != client->GetVersion())){
- safe_delete(packet);
- safe_delete(outapp);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_Play3DSound", packet_version);
- if(packet){
- packet->setMediumStringByName("name", name);
- packet->setDataByName("x", origin_x);
- packet->setDataByName("y", origin_y);
- packet->setDataByName("z", origin_z);
- packet->setDataByName("unknown1", 1);
- packet->setDataByName("unknown2", 2.5);
- packet->setDataByName("unknown3", 15);
- outapp = packet->serialize();
- }
- }
- if(outapp && client && client->IsConnected())
- client->QueuePacket(outapp->Copy());
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- safe_delete(outapp);
- }
- }
- void ZoneServer::AddHeadingTimer(Spawn* spawn){
- heading_timers.Put(spawn, Timer::GetCurrentTime2() + 30000);
- }
- void ZoneServer::RemoveHeadingTimer(Spawn* spawn){
- heading_timers.erase(spawn);
- }
- void ZoneServer::CheckHeadingTimers(){
- if(heading_timers.size() > 0){
- MutexMap<Spawn*, int32>::iterator itr = heading_timers.begin();
- Spawn* spawn = 0;
- int32 current_time = Timer::GetCurrentTime2();
- while(itr.Next()){
- if(current_time >= itr->second){
- spawn = itr->first;
- spawn->SetHeading(spawn->GetSpawnOrigHeading());
- spawn->SetTempActionState(-1);
- heading_timers.erase(itr->first);
- }
- }
- }
- }
- bool ZoneServer::HasWidgetTimer(Spawn* widget){
- bool ret = false;
- if (widget) {
- int32 id = widget->GetID();
- map<int32, int32>::iterator itr;
- MWidgetTimers.readlock(__FUNCTION__, __LINE__);
- for (itr = widget_timers.begin(); itr != widget_timers.end(); itr++) {
- if(itr->first == id){
- ret = true;
- break;
- }
- }
- MWidgetTimers.releasereadlock(__FUNCTION__, __LINE__);
- }
- return ret;
- }
- void ZoneServer::CheckWidgetTimers(){
- vector<int32> remove_list;
- map<int32, int32>::iterator itr;
- MWidgetTimers.readlock(__FUNCTION__, __LINE__);
- for (itr = widget_timers.begin(); itr != widget_timers.end(); itr++) {
- if(Timer::GetCurrentTime2() >= itr->second){
- /*Spawn* widget = GetSpawnByID(itr->first);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleTimerUpdate();*/
- remove_list.push_back(itr->first);
- }
- }
- MWidgetTimers.releasereadlock(__FUNCTION__, __LINE__);
- for (int32 i = 0; i < remove_list.size(); i++) {
- Spawn* widget = GetSpawnByID(remove_list[i]);
- if (widget && widget->IsWidget())
- ((Widget*)widget)->HandleTimerUpdate();
- }
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- for(int32 i=0;i<remove_list.size(); i++)
- widget_timers.erase(remove_list[i]);
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddWidgetTimer(Spawn* widget, float time) {
- if (widget && widget->IsWidget()) {
- MWidgetTimers.writelock(__FUNCTION__, __LINE__);
- widget_timers[widget->GetID()] = ((int32)(time * 1000)) + Timer::GetCurrentTime2();
- MWidgetTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- }
- Spawn* ZoneServer::GetSpawnGroup(int32 id){
- Spawn* ret = 0;
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(spawn->GetSpawnGroupID() == id){
- ret = spawn;
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByLocationID(int32 location_id) {
- Spawn* ret = 0;
- Spawn* current_spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- current_spawn = itr->second;
- if (current_spawn && current_spawn->GetSpawnLocationID() == location_id) {
- ret = current_spawn;
- break;
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByDatabaseID(int32 id){
- Spawn* ret = 0;
- if(quick_database_id_lookup.count(id) > 0)
- ret = GetSpawnByID(quick_database_id_lookup.Get(id));
- else{
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++){
- spawn = itr->second;
- if(spawn){
- if(spawn->GetDatabaseID() == id){
- quick_database_id_lookup.Put(id, spawn->GetID());
- ret = spawn;
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- return ret;
- }
- Spawn* ZoneServer::GetSpawnByID(int32 id, bool spawnListLocked) {
- Spawn* ret = 0;
- if (!spawnListLocked )
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- if (spawn_list.count(id) > 0)
- ret = spawn_list[id];
-
- if (!spawnListLocked)
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- bool ZoneServer::SendRemoveSpawn(Client* client, Spawn* spawn, PacketStruct* packet, bool delete_spawn)
- {
- if(!client || !spawn)
- return false;
- int16 index = client->GetPlayer()->GetIndexForSpawn(spawn);
- int32 cur_id = client->GetPlayer()->GetIDWithPlayerSpawn(spawn);
- bool wasRemoved = client->GetPlayer()->WasSpawnRemoved(spawn);
- LogWrite(ZONE__DEBUG, 7, "Zone", "%s: Processing SendRemoveSpawn for spawn index %u (%s)...cur_id: %i, wasremoved:: %i", client->GetPlayer()->GetName(), index, spawn->GetName(), cur_id, wasRemoved);
- if(packet && index > 0 && !wasRemoved)
- {
- packet->setDataByName("spawn_index", index);
- client->GetPlayer()->GetPlayerSpawnMap()->erase(index);
- client->GetPlayer()->GetPlayerSpawnIndexMap()->erase(spawn);
- client->GetPlayer()->player_spawn_id_map.erase(cur_id);
- client->GetPlayer()->player_spawn_reverse_id_map.erase(spawn);
- client->GetPlayer()->RemoveSpawn(spawn); // sets it as removed
- if(delete_spawn)
- packet->setDataByName("delete", 1);
-
- client->QueuePacket(packet->serialize());
- return true;
- }
- return false;
- }
- void ZoneServer::SetSpawnCommand(Spawn* spawn, int8 type, char* value, Client* client){
- //commands
- LogWrite(MISC__TODO, 1, "TODO", "%s does nothing!\n%s, %i", __FUNCTION__, __FILE__, __LINE__);
- }
- void ZoneServer::SetSpawnCommand(int32 spawn_id, int8 type, char* value, Client* client){
- LogWrite(MISC__TODO, 1, "TODO", "%s does nothing!\n%s, %i", __FUNCTION__, __FILE__, __LINE__);
- }
- void ZoneServer::ApplySetSpawnCommand(Client* client, Spawn* target, int8 type, char* value){
- // This will apply the /spawn set command to all the spawns in the zone with the same DB ID, we do not want to set
- // location values (x, y, z, heading, grid) for all spawns in the zone with the same DB ID, only the targeted spawn
- if(type == SPAWN_SET_VALUE_SPAWNENTRY_SCRIPT || type == SPAWN_SET_VALUE_SPAWNLOCATION_SCRIPT || (type >= SPAWN_SET_VALUE_X && type <= SPAWN_SET_VALUE_LOCATION) ||
- type == SPAWN_SET_VALUE_PITCH || type == SPAWN_SET_VALUE_ROLL)
- return;
- Spawn* tmp = 0;
- if(target->IsNPC())
- tmp = GetNPC(target->GetDatabaseID());
- else if(target->IsObject())
- tmp = GetObject(target->GetDatabaseID());
- else if(target->IsGroundSpawn())
- tmp = GetGroundSpawn(target->GetDatabaseID());
- else if(target->IsSign())
- tmp = GetSign(target->GetDatabaseID());
- else if(target->IsWidget())
- tmp = GetWidget(target->GetDatabaseID());
- if(tmp && type == SPAWN_SET_VALUE_SPAWN_SCRIPT)
- tmp->SetSpawnScript(value);
- else if(tmp)
- commands.SetSpawnCommand(client, tmp, type, value); // set the master spawn
- Spawn* spawn = 0;
- // this check needs to be here otherwise every spawn with 0 will be set
- if ( target->GetDatabaseID ( ) > 0 )
- {
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn && spawn->GetDatabaseID() == target->GetDatabaseID()){
- if(type == SPAWN_SET_VALUE_SPAWN_SCRIPT)
- spawn->SetSpawnScript(value);
- else
- commands.SetSpawnCommand(client, spawn, type, value);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::DeleteSpawnScriptTimers(Spawn* spawn, bool all){
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(spawn_script_timers.size() > 0){
- set<SpawnScriptTimer*>::iterator itr;
- SpawnScriptTimer* timer = 0;
- for (itr = spawn_script_timers.begin(); itr != spawn_script_timers.end(); itr++) {
- timer = *itr;
- if((all || timer->spawn == spawn->GetID()) && remove_spawn_script_timers_list.count(timer) == 0)
- remove_spawn_script_timers_list.insert(timer);
- }
- if(all)
- spawn_script_timers.clear();
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteSpawnScriptTimers() {
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(remove_spawn_script_timers_list.size() > 0){
- set<SpawnScriptTimer*>::iterator itr;
- SpawnScriptTimer* timer = 0;
-
- for (itr = remove_spawn_script_timers_list.begin(); itr != remove_spawn_script_timers_list.end(); itr++) {
- timer = *itr;
- spawn_script_timers.erase(timer);
- safe_delete(timer);
- }
- remove_spawn_script_timers_list.clear();
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckSpawnScriptTimers(){
- DeleteSpawnScriptTimers();
- SpawnScriptTimer* timer = 0;
- vector<SpawnScriptTimer*> call_timers;
- MSpawnScriptTimers.readlock(__FUNCTION__, __LINE__);
- MRemoveSpawnScriptTimersList.writelock(__FUNCTION__, __LINE__);
- if(spawn_script_timers.size() > 0){
- int32 current_time = Timer::GetCurrentTime2();
- set<SpawnScriptTimer*>::iterator itr;
- for (itr = spawn_script_timers.begin(); itr != spawn_script_timers.end(); itr++) {
- timer = *itr;
- if(timer->current_count < timer->max_count && current_time >= timer->timer){
- timer->current_count++;
- call_timers.push_back(timer);
- }
- if(timer->current_count >= timer->max_count && remove_spawn_script_timers_list.count(timer) == 0)
- remove_spawn_script_timers_list.insert(timer);
- }
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasereadlock(__FUNCTION__, __LINE__);
- if(call_timers.size() > 0){
- vector<SpawnScriptTimer*>::iterator itr;
- for(itr = call_timers.begin(); itr != call_timers.end(); itr++){
- timer = *itr;
- CallSpawnScript(GetSpawnByID(timer->spawn), SPAWN_SCRIPT_TIMER, timer->player > 0 ? GetSpawnByID(timer->player) : 0, timer->function.c_str());
- }
- }
- }
- void ZoneServer::KillSpawnByDistance(Spawn* spawn, float max_distance, bool include_players, bool send_packet){
- Spawn* test_spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn->IsEntity() && test_spawn != spawn && (!test_spawn->IsPlayer() || include_players)){
- if(test_spawn->GetDistance(spawn) < max_distance)
- KillSpawn(true, test_spawn, spawn, send_packet);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SpawnSetByDistance(Spawn* spawn, float max_distance, string field, string value){
- Spawn* test_spawn = 0;
- int32 type = commands.GetSpawnSetType(field);
- if(type == 0xFFFFFFFF)
- return;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn != spawn && !test_spawn->IsPlayer()){
- if(test_spawn->GetDistance(spawn) < max_distance){
- commands.SetSpawnCommand(0, test_spawn, type, value.c_str());
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnScriptTimer(SpawnScriptTimer* timer){
- MSpawnScriptTimers.writelock(__FUNCTION__, __LINE__);
- spawn_script_timers.insert(timer);
- MSpawnScriptTimers.releasewritelock(__FUNCTION__, __LINE__);
- }
- /*
- void ZoneServer::RemoveFromRangeMap(Client* client){
- spawn_range_map.erase(client);
- }
- */
- void ZoneServer::RemoveSpawn(bool spawnListLocked, Spawn* spawn, bool delete_spawn, bool respawn, bool lock)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Processing RemoveSpawn function for %s (%i)...", spawn->GetName(),spawn->GetID());
- spawn->RemoveSpawnProximities();
- RemoveSpawnProximities(spawnListLocked, spawn);
- if (Grid != nullptr) {
- Grid->RemoveSpawnFromCell(spawn);
- }
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- RemoveSpawnSupportFunctions(spawn);
- if (reloading)
- RemoveDeadEnemyList(spawn);
- if (lock)
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if (dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns.erase(spawn->GetID());
- if (lock)
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- if (spawn_expire_timers.count(spawn->GetID()) > 0)
- spawn_expire_timers.erase(spawn->GetID());
-
- RemoveDelayedSpawnRemove(spawn);
- // Clear the pointer in the spawn list, spawn thread will remove the key
- if (!spawnListLocked)
- MSpawnList.writelock(__FUNCTION__, __LINE__);
-
- spawn_list.erase(spawn->GetID());
-
- if (!spawnListLocked)
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- PacketStruct* packet = 0;
- int16 packet_version = 0;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if (client) {
- if (client->IsConnected() && (!packet || packet_version != client->GetVersion()))
- {
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- if (client->GetPlayer()->HasTarget() && client->GetPlayer()->GetTarget() == spawn)
- client->GetPlayer()->SetTarget(0);
- SendRemoveSpawn(client, spawn, packet, delete_spawn);
- if (spawn_range_map.count(client) > 0)
- spawn_range_map.Get(client)->erase(spawn->GetID());
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- if(respawn && !spawn->IsPlayer() && spawn->GetRespawnTime() > 0 && spawn->GetSpawnLocationID() > 0)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Handle NPC Respawn for '%s'.", spawn->GetName());
- // handle instance spawn db info
- // we don't care if a NPC or a client kills the spawn, we could have events that cause NPCs to kill NPCs.
- if(spawn->GetZone()->GetInstanceID() > 0 && spawn->GetSpawnLocationID() > 0)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Handle NPC Respawn in an Instance.");
- // use respawn time to either insert/update entry (likely insert in this situation)
- if ( spawn->IsNPC() )
- {
- database.CreateInstanceSpawnRemoved(spawn->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_NPC,
- spawn->GetRespawnTime(),spawn->GetZone()->GetInstanceID());
- }
- else if ( spawn->IsObject ( ) )
- {
- database.CreateInstanceSpawnRemoved(spawn->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_OBJECT,
- spawn->GetRespawnTime(),spawn->GetZone()->GetInstanceID());
- }
- safe_delete(spawn);
- }
- else
- {
- int32 spawnLocationID = spawn->GetSpawnLocationID();
- int32 spawnRespawnTime = spawn->GetRespawnTime();
- safe_delete(spawn);
- respawn_timers.Put(spawnLocationID, Timer::GetCurrentTime2() + spawnRespawnTime * 1000);
- }
- }
- // Do we really need the mutex locks and check to dead_spawns as we remove it from dead spawns at the start of this function
- if (lock && !respawn)
- MDeadSpawns.readlock(__FUNCTION__, __LINE__);
- if(!respawn && delete_spawn && dead_spawns.count(spawn->GetID()) == 0)
- AddPendingDelete(spawn);
- if (lock && !respawn)
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- LogWrite(ZONE__DEBUG, 3, "Zone", "Done processing RemoveSpawn function...");
- }
- Spawn* ZoneServer::GetClosestSpawn(Spawn* spawn, int32 spawn_id){
- Spawn* closest_spawn = 0;
- Spawn* test_spawn = 0;
- float closest_distance = 1000000;
- float test_distance = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn && test_spawn->GetDatabaseID() == spawn_id){
- test_distance = test_spawn->GetDistance(spawn);
- if(test_distance < closest_distance){
- closest_distance = test_distance;
- closest_spawn = test_spawn;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return closest_spawn;
- }
- int32 ZoneServer::GetClosestLocation(Spawn* spawn){
- Spawn* closest_spawn = 0;
- Spawn* test_spawn = 0;
- float closest_distance = 1000000;
- float test_distance = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn){
- test_distance = test_spawn->GetDistance(spawn);
- if(test_distance < closest_distance){
- closest_distance = test_distance;
- closest_spawn = test_spawn;
- if(closest_distance < 10)
- break;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- if(closest_spawn)
- return closest_spawn->GetLocation();
- return 0;
- }
- void ZoneServer::SendQuestUpdates(Client* client, Spawn* spawn){
- if(!client)
- return;
- if(spawn){
- if(client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn))
- SendSpawnChanges(spawn, client, false, true);
- }
- else{
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn) {
- spawn->m_requiredQuests.readlock(__FUNCTION__, __LINE__);
- if (spawn && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn) && (client->GetPlayer()->CheckQuestRemoveFlag(spawn) || client->GetPlayer()->CheckQuestFlag(spawn) != 0 || (spawn->GetQuestsRequired()->size() > 0 && client->GetPlayer()->CheckQuestRequired(spawn))))
- SendSpawnChanges(spawn, client, false, true);
- spawn->m_requiredQuests.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendAllSpawnsForLevelChange(Client* client) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, false, true);
- // Attempt to slow down the packet spam sent to the client
- Sleep(5);
- }
- }
- }
- }
- void ZoneServer::SendAllSpawnsForSeeInvisChange(Client* client) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && spawn->IsEntity() && (((Entity*)spawn)->IsInvis() || ((Entity*)spawn)->IsStealthed()) && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, true, true);
- }
- }
- }
- }
- void ZoneServer::SendAllSpawnsForVisChange(Client* client, bool limitToEntities) {
- Spawn* spawn = 0;
- if (spawn_range_map.count(client) > 0) {
- MutexMap<int32, float >::iterator itr = spawn_range_map.Get(client)->begin();
- while (itr.Next()) {
- spawn = GetSpawnByID(itr->first);
- if (spawn && (!limitToEntities || (limitToEntities && spawn->IsEntity())) && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn)) {
- SendSpawnChanges(spawn, client, false, true);
- }
- }
- }
- }
- void ZoneServer::StartZoneSpawnsForLevelThread(Client* client){
- if(zoneShuttingDown)
- return;
- #ifdef WIN32
- _beginthread(SendLevelChangedSpawns, 0, client);
- #else
- pthread_t thread;
- pthread_create(&thread, NULL, SendLevelChangedSpawns, client);
- pthread_detach(thread);
- #endif
- }
- void ZoneServer::ReloadClientQuests(){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client)
- client->ReloadQuests();
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendCalculatedXP(Player* player, Spawn* victim){
- if (player && victim) {
- if (player->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(player->GetGroupMemberInfo()->group_id);
- deque<GroupMemberInfo*>::iterator itr;
- for (itr = members->begin(); itr != members->end(); itr++) {
- GroupMemberInfo* gmi = *itr;
- if (gmi->client) {
- Player* group_member = gmi->client->GetPlayer();
- float xp = group_member->CalculateXP(victim) / members->size();
- if (xp > 0) {
- int16 level = group_member->GetLevel();
- if (group_member->AddXP((int32)xp)) {
- gmi->client->Message(CHANNEL_COLOR_EXP, "You gain %u experience!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience (GroupID %u)", group_member->GetName(), (int32)xp, player->GetGroupMemberInfo()->group_id);
- if(group_member->GetLevel() != level)
- gmi->client->ChangeLevel(level, group_member->GetLevel());
- group_member->SetCharSheetChanged(true);
- }
- }
- }
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else {
- float xp = player->CalculateXP(victim);
- if (xp > 0) {
- Client* client = GetClientBySpawn(player);
- if(!client)
- return;
- int16 level = player->GetLevel();
- if (player->AddXP((int32)xp)) {
- client->Message(CHANNEL_COLOR_EXP, "You gain %u XP!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience.", player->GetName(), (int32)xp);
- if(player->GetLevel() != level)
- client->ChangeLevel(level, player->GetLevel());
- player->SetCharSheetChanged(true);
- }
- }
- }
- }
- }
- void ZoneServer::ProcessFaction(Spawn* spawn, Client* client)
- {
- if(client && !spawn->IsPlayer() && spawn->GetFactionID() > 10)
- {
- bool update_result = false;
- Faction* faction = 0;
- vector<int32>* factions = 0;
- Player* player = client->GetPlayer();
- if(player->GetFactions()->ShouldDecrease(spawn->GetFactionID()))
- {
- update_result = player->GetFactions()->DecreaseFaction(spawn->GetFactionID());
- faction = master_faction_list.GetFaction(spawn->GetFactionID());
- if(faction && update_result)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
- factions = master_faction_list.GetHostileFactions(spawn->GetFactionID());
- if(factions)
- {
- vector<int32>::iterator itr;
- for(itr = factions->begin(); itr != factions->end(); itr++)
- {
- if(player->GetFactions()->ShouldIncrease(*itr))
- {
- update_result = player->GetFactions()->IncreaseFaction(*itr);
- faction = master_faction_list.GetFaction(*itr);
- if(faction && update_result)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
- }
- }
- }
- }
- factions = master_faction_list.GetFriendlyFactions(spawn->GetFactionID());
- if(factions)
- {
- vector<int32>::iterator itr;
- for(itr = factions->begin(); itr != factions->end(); itr++)
- {
- if(player->GetFactions()->ShouldDecrease(*itr))
- {
- update_result = player->GetFactions()->DecreaseFaction(*itr);
- faction = master_faction_list.GetFaction(*itr);
- if(faction && update_result)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_COLOR_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
- }
- }
- }
- EQ2Packet* outapp = client->GetPlayer()->GetFactions()->FactionUpdate(client->GetVersion());
- if(outapp)
- client->QueuePacket(outapp);
- }
- }
- void ZoneServer::Despawn(Spawn* spawn, int32 timer){
- if (spawn && movementMgr != nullptr) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- if(!spawn || spawn->IsPlayer())
- return;
- RemoveSpawnSupportFunctions(spawn);
- if(spawn->IsEntity())
- ((Entity*)spawn)->InCombat(false);
- if(timer == 0)
- timer = 1;
- AddDeadSpawn(spawn, timer);
- }
- void ZoneServer::KillSpawn(bool spawnListLocked, Spawn* dead, Spawn* killer, bool send_packet, int8 damage_type, int16 kill_blow_type)
- {
- MDeadSpawns.readlock(__FUNCTION__, __LINE__);
- if(!dead || this->dead_spawns.count(dead->GetID()) > 0) {
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- MDeadSpawns.releasereadlock(__FUNCTION__, __LINE__);
- PacketStruct* packet = 0;
- Client* client = 0;
- vector<int32>* encounter = 0;
- bool killer_in_encounter = false;
- if(dead->IsEntity())
- {
- ((Entity*)dead)->InCombat(false);
- dead->SetInitialState(16512, false); // This will make aerial npc's fall after death
- dead->SetHP(0);
- dead->SetSpawnType(3);
- dead->appearance.attackable = 0;
- // Remove hate towards dead from all npc's in the zone
- ClearHate((Entity*)dead);
- // Check kill and death procs
- if (killer && dead != killer){
- if (dead->IsEntity())
- ((Entity*)dead)->CheckProcs(PROC_TYPE_DEATH, killer);
- if (killer->IsEntity())
- ((Entity*)killer)->CheckProcs(PROC_TYPE_KILL, dead);
- }
- //Check if caster is alive after death proc called, incase of deathsave
- if (dead->Alive())
- return;
- RemoveSpellTimersFromSpawn(dead, true, !dead->IsPlayer());
- if(dead->IsPlayer())
- {
- ((Player*)dead)->UpdatePlayerStatistic(STAT_PLAYER_TOTAL_DEATHS, 1);
- client = GetClientBySpawn(dead);
- if(client) {
- if(client->GetPlayer()->DamageEquippedItems(10, client))
- client->QueuePacket(client->GetPlayer()->GetEquipmentList()->serialize(client->GetVersion()));
- client->DisplayDeadWindow();
- }
- }
- else if (dead->IsNPC()) {
- encounter = ((NPC*)dead)->Brain()->GetEncounter();
- }
- }
- dead->SetActionState(0);
- dead->SetTempActionState(0);
- // If dead is an npc get the encounter and loop through it giving out the rewards, no rewards for pets
- if (dead->IsNPC() && !dead->IsPet() && !dead->IsBot()) {
- Spawn* spawn = 0;
- int8 size = encounter->size();
- // Needs npc to have access to the encounter list for who is allowed to loot
- NPC* chest = 0;
- if (!((NPC*)dead)->Brain()->PlayerInEncounter()) {
- ((NPC*)dead)->SetLootCoins(0);
- ((NPC*)dead)->GetLootItems()->clear();
- }
- // If dead has loot attempt to drop a chest
- if (((NPC*)dead)->HasLoot()) {
- chest = ((NPC*)dead)->DropChest();
- }
- for (int8 i = 0; i < encounter->size(); i++) {
- spawn = GetSpawnByID(encounter->at(i), spawnListLocked);
- // set a flag to let us know if the killer is in the encounter
- if (!killer_in_encounter && spawn == killer)
- killer_in_encounter = true;
- if (spawn && spawn->IsPlayer()) {
- // Update players total kill count
- ((Player*)spawn)->UpdatePlayerStatistic(STAT_PLAYER_TOTAL_NPC_KILLS, 1);
- // If this was an epic mob kill send the announcement for this player
- if (dead->GetEncounterLevel() >= 10)
- SendEpicMobDeathToGuild((Player*)spawn, dead);
- // Clear hostile spells from the players spell queue
- spellProcess->RemoveSpellFromQueue((Player*)spawn, true);
- // Get the client of the player
- client = GetClientBySpawn(spawn);
- // valid client?
- if (client) {
- // Check for quest kill updates
- client->CheckPlayerQuestsKillUpdate(dead);
- // If the dead mob is not a player and if it had a faction with an ID greater or equal to 10 the send faction changes
- if (!dead->IsPlayer() && dead->GetFactionID() > 10)
- ProcessFaction(dead, client);
- // Send xp...this is currently wrong fix it
- if (spawn != dead && ((Player*)spawn)->GetArrowColor(dead->GetLevel()) >= ARROW_COLOR_GREEN) {
- //SendCalculatedXP((Player*)spawn, dead);
- float xp = ((Player*)spawn)->CalculateXP(dead) / size;
- if (xp > 0) {
- int16 level = spawn->GetLevel();
- if (((Player*)spawn)->AddXP((int32)xp)) {
- client->Message(CHANNEL_COLOR_EXP, "You gain %u XP!", (int32)xp);
- LogWrite(PLAYER__DEBUG, 0, "Player", "Player: %s earned %u experience.", spawn->GetName(), (int32)xp);
- if (spawn->GetLevel() != level)
- client->ChangeLevel(level, spawn->GetLevel());
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
- }
- }
- }
- }
- // If a chest is being dropped add this spawn to the chest's encounter so they can loot it
- if (chest && spawn && spawn->IsEntity())
- chest->Brain()->AddToEncounter((Entity*)spawn);
- }
- // If a chest is being dropped add it to the world and set the timer to remove it.
- if (chest) {
- AddSpawn(chest);
- AddDeadSpawn(chest, 0xFFFFFFFF);
- LogWrite(LOOT__DEBUG, 0, "Loot", "Adding a chest to the world...");
- }
- }
- // Reset client pointer
- client = 0;
- // Killer was not in the encounter, give them the faction hit but no xp
- if (!killer_in_encounter) {
- // make sure the killer is a player and the dead spawn had a faction and wasn't a player
- if (killer && killer->IsPlayer()) {
- if (!dead->IsPlayer() && dead->GetFactionID() > 10) {
- client = GetClientBySpawn(killer);
- if (client)
- ProcessFaction(dead, client);
- }
- // Clear hostile spells from the killers spell queue
- spellProcess->RemoveSpellFromQueue((Player*)killer, true);
- }
- }
- // Reset client pointer
- client = 0;
- vector<Spawn*>* group = dead->GetSpawnGroup();
- if (group && group->size() == 1)
- CallSpawnScript(dead, SPAWN_SCRIPT_GROUP_DEAD, killer);
- safe_delete(group);
- // Remove the support functions for the dead spawn
- RemoveSpawnSupportFunctions(dead);
- // Erase the expire timer if it has one
- if (spawn_expire_timers.count(dead->GetID()) > 0)
- spawn_expire_timers.erase(dead->GetID());
- // If dead is an npc or object call the spawn scrip and handle instance stuff
- if(dead->IsNPC() || dead->IsObject())
- {
- // handle instance spawn db info
- // we don't care if a NPC or a client kills the spawn, we could have events that cause NPCs to kill NPCs.
- if(dead->GetZone()->GetInstanceID() > 0 && dead->GetSpawnLocationID() > 0)
- {
- // use respawn time to either insert/update entry (likely insert in this situation)
- if(dead->IsNPC())
- database.CreateInstanceSpawnRemoved(dead->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_NPC, dead->GetRespawnTime(),dead->GetZone()->GetInstanceID());
- else if ( dead->IsObject ( ) )
- database.CreateInstanceSpawnRemoved(dead->GetSpawnLocationID(),SPAWN_ENTRY_TYPE_OBJECT, dead->GetRespawnTime(),dead->GetZone()->GetInstanceID());
- }
- // Call the spawn scripts death() function
- CallSpawnScript(dead, SPAWN_SCRIPT_DEATH, killer);
- }
-
- int32 victim_id = dead->GetID();
- int32 attacker_id = 0xFFFFFFFF;
- if(killer)
- attacker_id = killer->GetID();
- if(send_packet)
- {
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client->GetPlayer()->WasSentSpawn(victim_id) || (attacker_id != 0xFFFFFFFF && !client->GetPlayer()->WasSentSpawn(attacker_id)) )
- continue;
- else if(client->GetPlayer()->WasSpawnRemoved(dead) || (attacker_id != 0xFFFFFFFF && client->GetPlayer()->WasSpawnRemoved(killer)))
- continue;
- else if(killer && killer->GetDistance(client->GetPlayer()) > HEAR_SPAWN_DISTANCE)
- continue;
- packet = configReader.getStruct("WS_HearDeath", client->GetVersion());
- if(packet)
- {
- if(killer)
- packet->setDataByName("attacker", client->GetPlayer()->GetIDWithPlayerSpawn(killer));
- else
- packet->setDataByName("attacker", 0xFFFFFFFF);
- packet->setDataByName("defender", client->GetPlayer()->GetIDWithPlayerSpawn(dead));
- packet->setDataByName("damage_type", damage_type);
- packet->setDataByName("blow_type", kill_blow_type);
- client->QueuePacket(packet->serialize());
- LogWrite(COMBAT__DEBUG, 0, "Combat", "Zone Killing '%s'", dead->GetName());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- int32 pop_timer = 0xFFFFFFFF;
- if(killer && killer->IsNPC())
- {
- // Call the spawn scripts killed() function
- CallSpawnScript(killer, SPAWN_SCRIPT_KILLED, dead);
- if(!dead->IsPlayer())
- {
- LogWrite(MISC__TODO, 1, "TODO", "Whenever pets are added, check for pet kills\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- // Set the time for the corpse to linger to 5 sec
- //pop_timer = 5000;
- // commented out the timer so in the event the killer is not a player (pet, guard, something else i haven't thought of)
- // the corpse doesn't vanish sooner then it should if it had loot for the players. AddDeadSpawn() will set timers based on if
- // the corpse has loot or not if the timer value (pop_timer) is 0xFFFFFFFF
- }
- }
-
- // If the dead spawns was not a player add it to the dead spawn list
- if (!dead->IsPlayer() && !dead->IsBot())
- AddDeadSpawn(dead, pop_timer);
- // if dead was a player clear hostile spells from its spell queue
- if (dead->IsPlayer())
- spellProcess->RemoveSpellFromQueue((Player*)dead, true);
- if (dead->IsNPC())
- ((NPC*)dead)->Brain()->ClearHate();
- // ResetPetInfo() is called in DismissPet(), might not need to be here
- // Players pet is killed, clear the pet info from char sheet
- /*if (dead->IsNPC() && ((NPC*)dead)->IsPet() && ((NPC*)dead)->GetOwner()->IsPlayer())
- ((Player*)((NPC*)dead)->GetOwner())->ResetPetInfo();*/
- safe_delete(encounter);
- }
- void ZoneServer::SendDamagePacket(Spawn* attacker, Spawn* victim, int8 type1, int8 type2, int8 damage_type, int16 damage, const char* spell_name){
- //Scat: was set but never being used anywhere. i see references to 0xFFFFFFFF below so could be old code not used anymore
- //int32 attacker_id = 0xFFFFFFFF;
- //if(attacker)
- // attacker_id = attacker->GetID();
- PacketStruct* packet = 0;
- Client* client = 0;
- if(attacker && victim && victim->IsPlayer() && victim->GetTarget() == 0){
- client = GetClientBySpawn(victim);
- if(client)
- client->TargetSpawn(attacker);
- }
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client->GetPlayer() != attacker && client->GetPlayer() != victim && ((attacker && client->GetPlayer()->WasSentSpawn(attacker->GetID()) == false) || (victim && client->GetPlayer()->WasSentSpawn(victim->GetID()) == false))))
- continue;
- if((attacker && client->GetPlayer()->WasSpawnRemoved(attacker)) || (victim && client->GetPlayer()->WasSpawnRemoved(victim)))
- continue;
- if(attacker && attacker->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(victim && victim->GetDistance(client->GetPlayer()) > 50)
- continue;
- switch(type1){
- case DAMAGE_PACKET_TYPE_SIPHON_SPELL:
- case DAMAGE_PACKET_TYPE_SIPHON_SPELL2:
- packet = configReader.getStruct("WS_HearSiphonSpellDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_MULTIPLE_DAMAGE:
- packet = configReader.getStruct("WS_HearMultipleDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_SIMPLE_CRIT_DMG:
- case DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE:
- packet = configReader.getStruct("WS_HearSimpleDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE2:
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE3:
- case DAMAGE_PACKET_TYPE_SPELL_CRIT_DMG:
- case DAMAGE_PACKET_TYPE_SPELL_DAMAGE:
- packet = configReader.getStruct("WS_HearSpellDamage", client->GetVersion());
- if (packet)
- packet->setSubstructDataByName("header", "unknown", 5);
- break;
- case DAMAGE_PACKET_TYPE_RANGE_DAMAGE:
- packet = configReader.getStruct("WS_HearRangeDamage", client->GetVersion());
- break;
- case DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG:
- case DAMAGE_PACKET_TYPE_RANGE_SPELL_DMG2:
- packet = configReader.getStruct("WS_HearRangeDamage", client->GetVersion());
- break;
- default:
- LogWrite(ZONE__ERROR, 0, "Zone", "Unknown Damage Packet type: %i in ZoneServer::SendDamagePacket.", type1);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- if(packet){
- packet->setSubstructDataByName("header", "packet_type", type1);
- packet->setSubstructDataByName("header", "result_type", type2);
- if(!attacker)
- packet->setSubstructDataByName("header", "attacker", 0xFFFFFFFF);
- else
- packet->setSubstructDataByName("header", "attacker", client->GetPlayer()->GetIDWithPlayerSpawn(attacker));
- packet->setSubstructDataByName("header", "defender", client->GetPlayer()->GetIDWithPlayerSpawn(victim));
- packet->setDataByName("damage_type", damage_type);
- packet->setDataByName("damage", damage);
- if(spell_name)
- packet->setSmallStringByName("spell_name", spell_name);
- EQ2Packet* app = packet->serialize();
- //DumpPacket(app);
- client->QueuePacket(app);
- safe_delete(packet);
- packet = 0;
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendHealPacket(Spawn* caster, Spawn* target, int16 heal_type, int32 heal_amt, const char* spell_name){
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client->GetPlayer() != caster && ((caster && client->GetPlayer()->WasSentSpawn(caster->GetID()) == false) || (target && client->GetPlayer()->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && client->GetPlayer()->WasSpawnRemoved(caster)) || (caster && client->GetPlayer()->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(target && target->GetDistance(client->GetPlayer()) > 50)
- continue;
-
- PacketStruct* packet = configReader.getStruct("WS_HearHeal", client->GetVersion());
- if (packet) {
- packet->setDataByName("caster", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("heal_amt", heal_amt);
- packet->setDataByName("spellname", spell_name);
- packet->setDataByName("type", heal_type);
- packet->setDataByName("unknown2", 1);
- EQ2Packet* app = packet->serialize();
- client->QueuePacket(app);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendThreatPacket(Spawn* caster, Spawn* target, int32 threat_amt, const char* spell_name) {
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client->GetPlayer() != caster && ((caster && client->GetPlayer()->WasSentSpawn(caster->GetID()) == false) || (target && client->GetPlayer()->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && client->GetPlayer()->WasSpawnRemoved(caster)) || (caster && client->GetPlayer()->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(target && target->GetDistance(client->GetPlayer()) > 50)
- continue;
-
- PacketStruct* packet = configReader.getStruct("WS_HearThreatCmd", client->GetVersion());
- if (packet) {
- packet->setDataByName("spell_name", spell_name);
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("threat_amount", threat_amt);
-
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SendSpellFailedPacket(Client* client, int16 error){
- if(!client)
- return;
- PacketStruct* packet = configReader.getStruct("WS_DisplaySpellFailed", client->GetVersion());
- if(packet){
- /* Temp solution, need to modify the error code before this function and while we still have access to the spell/combat art */
- error = master_spell_list.GetSpellErrorValue(client->GetVersion(), error);
- packet->setDataByName("error_code", error);
- //packet->PrintPacket();
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- void ZoneServer::SendInterruptPacket(Spawn* interrupted, LuaSpell* spell){
- if(!interrupted || !spell)
- return;
-
- EQ2Packet* outapp = 0;
- PacketStruct* packet = 0;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || !client->GetPlayer()->WasSentSpawn(interrupted->GetID()) || client->GetPlayer()->WasSpawnRemoved(interrupted))
- continue;
- packet = configReader.getStruct("WS_Interrupt", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(interrupted));
- packet->setArrayLengthByName("num_targets", spell->targets.size());
- for (int32 i = 0; i < spell->targets.size(); i++)
- packet->setArrayDataByName("target_id", client->GetPlayer()->GetIDWithPlayerSpawn(client->GetPlayer()->GetZone()->GetSpawnByID(spell->targets[i])), i);
- packet->setDataByName("spell_id", spell->spell->GetSpellID());
- outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- void ZoneServer::SendCastSpellPacket(LuaSpell* spell, Entity* caster){
- EQ2Packet* outapp = 0;
- PacketStruct* packet = 0;
- Client* client = 0;
- if(!caster || !spell || !spell->spell || spell->interrupted)
- return;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client)
- continue;
- packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(caster));
- packet->setArrayLengthByName("num_targets", spell->targets.size());
- for (int32 i = 0; i < spell->targets.size(); i++)
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(spell->caster->GetZone()->GetSpawnByID(spell->targets[i])), i);
- packet->setDataByName("spell_visual", spell->spell->GetSpellData()->spell_visual); //result
- packet->setDataByName("cast_time", spell->spell->GetSpellData()->cast_time*.01); //delay
- packet->setDataByName("spell_id", spell->spell->GetSpellID());
- packet->setDataByName("spell_level", 1);
- packet->setDataByName("spell_tier", spell->spell->GetSpellData()->tier);
- outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- safe_delete(packet);
- }
- void ZoneServer::SendCastSpellPacket(int32 spell_visual, Spawn* target) {
- if (target) {
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- Client* client = *client_itr;
- if (!client)
- continue;
- PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("spell_id", 0xFFFFFFFF);
- packet->setDataByName("spell_visual", spell_visual);
- packet->setDataByName("cast_time", 0);
- packet->setDataByName("spell_id", 0);
- packet->setDataByName("spell_level", 0);
- packet->setDataByName("spell_tier", 0);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::SendCastEntityCommandPacket(EntityCommand* entity_command, int32 spawn_id, int32 target_id) {
- if (entity_command) {
- Spawn* spawn = GetSpawnByID(spawn_id);
- Spawn* target = GetSpawnByID(target_id);
- if (!spawn || !target)
- return;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if (!client || !client->GetPlayer()->WasSentSpawn(spawn_id) || client->GetPlayer()->WasSpawnRemoved(spawn) || !client->GetPlayer()->WasSentSpawn(target_id) || client->GetPlayer()->WasSpawnRemoved(target))
- continue;
- PacketStruct* packet = configReader.getStruct("WS_HearCastSpell", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- packet->setDataByName("num_targets", 1);
- packet->setDataByName("spell_visual", entity_command->spell_visual); //result
- packet->setDataByName("cast_time", entity_command->cast_time * 0.01); //delay
- packet->setDataByName("spell_id", 1);
- packet->setDataByName("spell_level", 1);
- packet->setDataByName("spell_tier", 1);
- EQ2Packet* outapp = packet->serialize();
- client->QueuePacket(outapp);
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- }
- void ZoneServer::StartZoneInitialSpawnThread(Client* client){
- if(zoneShuttingDown)
- return;
- #ifdef WIN32
- _beginthread(SendInitialSpawns, 0, client);
- #else
- pthread_t thread;
- pthread_create(&thread, NULL, SendInitialSpawns, client);
- pthread_detach(thread);
- #endif
- }
- void ZoneServer::SendZoneSpawns(Client* client){
- initial_spawn_threads_active++;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- Spawn* spawn = itr->second;
- if (spawn) {
- CheckSpawnRange(client, spawn, true);
- }
- }
- CheckSendSpawnToClient(client, true);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- client->SetConnected(true);
- ClientPacketFunctions::SendFinishedEntitiesList(client);
- initial_spawn_threads_active--;
- }
- vector<Entity*> ZoneServer::GetPlayers(){
- vector<Entity*> ret;
- Client* client = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- ret.push_back(client->GetPlayer());
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- int16 ZoneServer::SetSpawnTargetable(Spawn* spawn, float distance){
- Spawn* test_spawn = 0;
- int16 ret_val = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- test_spawn = itr->second;
- if(test_spawn){
- if(test_spawn->GetDistance(spawn) <= distance){
- test_spawn->SetTargetable(1);
- ret_val++;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret_val;
- }
- int16 ZoneServer::SetSpawnTargetable(int32 spawn_id){
- Spawn* spawn = 0;
- int16 ret_val = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if(spawn){
- if(spawn->GetDatabaseID() == spawn_id){
- spawn->SetTargetable(1);
- ret_val++;
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret_val;
- }
- EQ2Packet* ZoneServer::GetZoneInfoPacket(Client* client){
- client_spawn_map.Put(client->GetPlayer(), client);
- PacketStruct* packet = configReader.getStruct("WS_ZoneInfo", client->GetVersion());
- packet->setSmallStringByName("server1",net.GetWorldName());
- packet->setSmallStringByName("server2",net.GetWorldName());
- packet->setDataByName("unknown1", 1, 1);//1, 1
- int32 expansions = EXPANSION_UNKNOWN + EXPANSION_DOF + EXPANSION_KOS + EXPANSION_EOF + EXPANSION_ROK + EXPANSION_TSO + EXPANSION_DOV;
- //packet->setDataByName("expansions_enabled", 82313211);//expansions 63181
- //packet->setDataByName("expansions_enabled", 552075103);//expansions 63182
- packet->setDataByName("expansions_enabled", 4294967295);//expansions 1096 //612499455 works
- if (client->GetVersion() >= 1193) {
- packet->setDataByName("unknown3", 4294967295, 0); // DOV and down
- packet->setDataByName("unknown3", 4294967295, 1); //COE and up
- packet->setDataByName("unknown3", 4294967295, 2);
- }
- else
- packet->setDataByName("unknown3", 4294967295, 0); // DOV and down
- packet->setSmallStringByName("auction_website", "eq2emulator.net");
- packet->setDataByName("auction_port", 80);
- packet->setSmallStringByName("upload_page", "test_upload.m");
- packet->setSmallStringByName("upload_key", "dsya987yda9");
- packet->setSmallStringByName("zone", GetZoneFile());
- packet->setSmallStringByName("zone2", GetZoneName());
- if ( strlen(GetZoneSkyFile()) > 0 )
- packet->setSmallStringByName("zone_unknown2", GetZoneSkyFile()); // used for the sky map
- packet->setSmallStringByName("zone_desc", GetZoneDescription());
- packet->setSmallStringByName("char_name", client->GetPlayer()->GetName());
-
- packet->setDataByName("x", client->GetPlayer()->GetX());
- packet->setDataByName("y", client->GetPlayer()->GetY());
- packet->setDataByName("z", client->GetPlayer()->GetZ());
-
- // unknown3 can prevent screen shots from being taken if
- //packet->setDataByName("unknown3", 2094661567, 1); // Screenshots allowed with this value
- //packet->setDataByName("unknown3", 3815767999, 1); // Screenshots disabled with this value
- //packet->setDataByName("unknown3", 1, 2);
- /*if (client->GetVersion() >= 63587) {
- packet->setArrayLengthByName("num_exp_feature_bytes", 9);
- packet->setArrayDataByName("exp_feature_bytes", 95, 0);//kos and dof
- packet->setArrayDataByName("exp_feature_bytes", 255, 1);//eof rok tso sf dov coe tov
- packet->setArrayDataByName("exp_feature_bytes", 247, 2);//aom tot ka exp14
- packet->setArrayDataByName("exp_feature_bytes", 32, 3);//rum cellar
- packet->setArrayDataByName("exp_feature_bytes", 140, 4);
- packet->setArrayDataByName("exp_feature_bytes", 62, 5);
- packet->setArrayDataByName("exp_feature_bytes", 0, 6);
- packet->setArrayDataByName("exp_feature_bytes", 45, 7);
- packet->setArrayDataByName("exp_feature_bytes", 128, 8);
- packet->setArrayLengthByName("num_unknown3b_bytes", 9);
- packet->setArrayDataByName("unknown3b_bytes", 95, 0);
- packet->setArrayDataByName("unknown3b_bytes", 255, 1);
- packet->setArrayDataByName("unknown3b_bytes", 247, 2);
- packet->setArrayDataByName("unknown3b_bytes", 237, 3);
- packet->setArrayDataByName("unknown3b_bytes", 143, 4);
- packet->setArrayDataByName("unknown3b_bytes", 255, 5);
- packet->setArrayDataByName("unknown3b_bytes", 255, 6);
- packet->setArrayDataByName("unknown3b_bytes", 255, 7);
- packet->setArrayDataByName("unknown3b_bytes", 128, 8);
- }
- else if (client->GetVersion() >= 63214) {
- packet->setArrayLengthByName("num_exp_feature_bytes", 9);
- packet->setArrayDataByName("exp_feature_bytes", 95, 0);//kos and dof
- packet->setArrayDataByName("exp_feature_bytes", 255, 1);//eof rok tso sf dov coe tov
- packet->setArrayDataByName("exp_feature_bytes", 247, 2);//aom tot ka exp14
- packet->setArrayDataByName("exp_feature_bytes", 32, 3);//rum cellar
- packet->setArrayDataByName("exp_feature_bytes", 140, 4);
- packet->setArrayDataByName("exp_feature_bytes", 62, 5);
- packet->setArrayDataByName("exp_feature_bytes", 0, 6);
- packet->setArrayDataByName("exp_feature_bytes", 45, 7);
- packet->setArrayDataByName("exp_feature_bytes", 128, 8);
- packet->setArrayLengthByName("num_unknown3b_bytes", 9);
- packet->setArrayDataByName("unknown3b_bytes", 95, 0);
- packet->setArrayDataByName("unknown3b_bytes", 255, 1);
- packet->setArrayDataByName("unknown3b_bytes", 247, 2);
- packet->setArrayDataByName("unknown3b_bytes", 237, 3);
- packet->setArrayDataByName("unknown3b_bytes", 143, 4);
- packet->setArrayDataByName("unknown3b_bytes", 255, 5);
- packet->setArrayDataByName("unknown3b_bytes", 255, 6);
- packet->setArrayDataByName("unknown3b_bytes", 255, 7);
- packet->setArrayDataByName("unknown3b_bytes", 128, 8);
- }*/
- if (client->GetVersion() >= 64644) {
- packet->setDataByName("unknown3a", 12598924);
- packet->setDataByName("unknown3b", 3992452959);
- packet->setDataByName("unknown3c", 4294967183);
- packet->setDataByName("unknown2a", 9);
- packet->setDataByName("unknown2b", 9);
- }
- else if (client->GetVersion() >= 63181) {
- packet->setDataByName("unknown3a", 750796556);//63182 73821356
- packet->setDataByName("unknown3b", 3991404383);// 63182 3991404383
- packet->setDataByName("unknown3c", 4278189967);// 63182 4278189967
- packet->setDataByName("unknown2a", 8);// 63182
- packet->setDataByName("unknown2b", 8);// 63182
-
- }
- else{
- //packet->setDataByName("unknown3", 872447025,0);//63181
- //packet->setDataByName("unknown3", 3085434875,1);// 63181
- //packet->setDataByName("unknown3", 2147483633,2);// 63181
- }
-
- packet->setDataByName("year", world.GetWorldTimeStruct()->year);
- packet->setDataByName("month", world.GetWorldTimeStruct()->month);
- packet->setDataByName("day", world.GetWorldTimeStruct()->day);
- packet->setDataByName("hour", world.GetWorldTimeStruct()->hour);
- packet->setDataByName("minute", world.GetWorldTimeStruct()->minute);
- packet->setDataByName("unknown", 0);
- packet->setDataByName("unknown7", 1);
- packet->setDataByName("unknown7", 1, 1);
-
- packet->setDataByName("unknown9", 13);
- //packet->setDataByName("unknown10", 25188959);4294967295
- //packet->setDataByName("unknown10", 25190239);
- packet->setDataByName("unknown10", 25191524);//25191524
- packet->setDataByName("unknown10b", 1);
- packet->setDataByName("permission_level",3);// added on 63182 for now till we figur it out 0=none,1=visitor,2=friend,3=trustee,4=owner
- packet->setDataByName("num_adv", 9);
- packet->setArrayDataByName("adv_name", "adv02_dun_drowned_caverns", 0);
- packet->setArrayDataByName("adv_id", 6, 0);
- packet->setArrayDataByName("adv_name", "adv02_dun_sundered_splitpaw_hub", 1);
- packet->setArrayDataByName("adv_id", 5, 1);
- packet->setArrayDataByName("adv_name", "exp03_rgn_butcherblock", 2);
- packet->setArrayDataByName("adv_id", 8, 2);
- packet->setArrayDataByName("adv_name", "exp03_rgn_greater_faydark", 3);
- packet->setArrayDataByName("adv_id", 7, 3);
- packet->setArrayDataByName("adv_name", "mod01_dun_crypt_of_thaen", 4);
- packet->setArrayDataByName("adv_id", 3, 4);
- packet->setArrayDataByName("adv_name", "mod01_dun_tombs_of_night", 5);
- packet->setArrayDataByName("adv_id", 4, 5);
- packet->setArrayDataByName("adv_name", "nektulos_mini01", 6);
- packet->setArrayDataByName("adv_id", 0, 6);
- packet->setArrayDataByName("adv_name", "nektulos_mini02", 7);
- packet->setArrayDataByName("adv_id", 1, 7);
- packet->setArrayDataByName("adv_name", "nektulos_mini03", 8);
- packet->setArrayDataByName("adv_id", 2, 8);
- LogWrite(MISC__TODO, 0, "TODO", "Put cl_ client commands back in variables (not Rules) so they can be dynamically maintained");
- vector<Variable*>* variables = world.GetClientVariables();
- packet->setArrayLengthByName("num_client_setup", variables->size());
- for(int i=variables->size()-1;i>=0;i--)
- packet->setArrayDataByName("client_cmds", variables->at(i)->GetNameValuePair().c_str(), i);
- // For AoM clients so item link work
- if (client->GetVersion() >= 60114)
- packet->setArrayDataByName("client_cmds", "chat_linkbrackets_item 1", variables->size());
- safe_delete(variables);
- //packet->setDataByName("unknown8", ); story?
- // AA Tabs for 1193+ clients
- if (client->GetVersion() >= 1193) {
- packet->setArrayLengthByName("tab_count", 48);
- int8 i = 0;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":es24a58bd8fcaac8c2:All", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c727bd47a6:Racial Innate", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c75a96e23c:Tradeskill Advancement", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c744f1fd99:Focus Effects", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71edd2a66:Heroic", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c76ee6239f:Shadows", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7e678b977:Prestige", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c77ee422d7:Animalist", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f165af77:Bard", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7421b9375:Brawler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7a03ae7d1:Cleric", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7c9605e9f:Crusader", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f9424168:Druid", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79cb9556c:Enchanter", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c8b6aa4:Predator", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73a43b6dd:Rogue", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c759fe7d15:Sorcerer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ad610aca:Summoner", i);
-
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71e056728:Warrior", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ba864c0b:Assassin", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7b8116aad:Beastlord", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f53feb7b:Berserker", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73d8a70e2:Brigand", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c770c766d6:Bruiser", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79226984b:Coercer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c58bb30:Conjurer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c73dfe68d0:Defiler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c792919a6b:Dirge", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7062e5f55:Fury", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c762c1fdfc:Guardian", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78addfbf4:Illusionist", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7ece054a7:Inquisitor", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7d550d2e7:Monk", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c743cfeaa2:Mystic", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7f63c9c8c:Necromancer", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c70c5de0ae:Paladin", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c79bc97b3a:Ranger", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78fbd2256:Shadowknight", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7781cc625:Shaman", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c77eecdcdb:Swashbuckler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7648d181e:Templar", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c78df47d77:Troubador", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7c78ce0b8:Warden", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c76290dcfa:Warlock", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7d1d52cf5:Wizard", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c71c8f6f4d:Shaper", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c72f6e354d:Channeler", i);
- i++;
- packet->setArrayDataByName("tab_index", i, i);
- packet->setArrayDataByName("tab_name", ":410385c7df8bd37d:Dragon", i);
- }
- packet->setDataByName("unknown_mj", 1);//int8
- packet->setDataByName("unknown_mj1", 335544320);//int32
- packet->setDataByName("unknown_mj2", 4);//int32
- packet->setDataByName("unknown_mj3", 3962504088);//int32
- packet->setDataByName("unknown_mj4", 3985947216);//int32
- packet->setDataByName("unknown_mj5", 1);//int32
- packet->setDataByName("unknown_mj6", 386);//int32
- packet->setDataByName("unknown_mj7", 4294967295);//int32
- packet->setDataByName("unknown_mj8", 2716312211);//int32
- packet->setDataByName("unknown_mj9", 1774338333);//int32
- packet->setDataByName("unknown_mj10", 1);//int32
- packet->setDataByName("unknown_mj11", 391);//int32
- packet->setDataByName("unknown_mj12", 4294967295);//int32
- packet->setDataByName("unknown_mj13", 3168965163);//int32
- packet->setDataByName("unknown_mj14", 4117025286);//int32
- packet->setDataByName("unknown_mj15", 1);//int32
- packet->setDataByName("unknown_mj16", 394);//int32
- packet->setDataByName("unknown_mj17", 4294967295);//int32
- packet->setDataByName("unknown_mj18", 1790669110);//int32
- packet->setDataByName("unknown_mj19", 107158108);//int32
- packet->setDataByName("unknown_mj20", 1);//int32
- packet->setDataByName("unknown_mj21", 393);//int32
- packet->setDataByName("unknown_mj22", 4294967295);//int32
- EQ2Packet* outapp = packet->serialize();
- //packet->PrintPacket();
- //DumpPacket(outapp);
- safe_delete(packet);
- return outapp;
- }
- void ZoneServer::SendUpdateDefaultCommand(Spawn* spawn, const char* command, float distance, Spawn* toPlayer){
- if (spawn == nullptr || command == nullptr)
- return;
- if (toPlayer)
- {
- if (!toPlayer->IsPlayer())
- return;
- Client* client = GetClientBySpawn(toPlayer);
- if (client)
- {
- client->SendDefaultCommand(spawn, command, distance);
- }
- // we don't override the primary command cause that would change ALL clients
- return;
- }
- Client* client = 0;
- PacketStruct* packet = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- client->SendDefaultCommand(spawn, command, distance);
- }
-
- if (strlen(command)>0)
- spawn->SetPrimaryCommand(command, command, distance);
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::CheckPlayerProximity(Spawn* spawn, Client* client){
- if (player_proximities.size() < 1)
- return;
- if(player_proximities.count(spawn->GetID()) > 0){
- PlayerProximity* prox = player_proximities.Get(spawn->GetID());
- if(prox->clients_in_proximity.count(client) == 0 && spawn_range_map.count(client) > 0 && spawn_range_map.Get(client)->count(spawn->GetID()) > 0 && spawn_range_map.Get(client)->Get(spawn->GetID()) < prox->distance){
- prox->clients_in_proximity[client] = true;
- CallSpawnScript(spawn, SPAWN_SCRIPT_CUSTOM, client->GetPlayer(), prox->in_range_lua_function.c_str());
- }
- else if(prox->clients_in_proximity.count(client) > 0 && spawn_range_map.count(client) > 0 && spawn_range_map.Get(client)->count(spawn->GetID()) > 0 && spawn_range_map.Get(client)->Get(spawn->GetID()) > prox->distance){
- if(prox->leaving_range_lua_function.length() > 0)
- CallSpawnScript(spawn, SPAWN_SCRIPT_CUSTOM, client->GetPlayer(), prox->leaving_range_lua_function.c_str());
- prox->clients_in_proximity.erase(client);
- }
- }
- }
- void ZoneServer::AddPlayerProximity(Spawn* spawn, float distance, string in_range_function, string leaving_range_function){
- RemovePlayerProximity(spawn);
- PlayerProximity* prox = new PlayerProximity;
- prox->distance = distance;
- prox->in_range_lua_function = in_range_function;
- prox->leaving_range_lua_function = leaving_range_function;
- player_proximities.Put(spawn->GetID(), prox);
- }
- void ZoneServer::RemovePlayerProximity(Client* client){
- PlayerProximity* prox = 0;
- MutexMap<int32, PlayerProximity*>::iterator itr = player_proximities.begin();
- while(itr.Next()){
- prox = itr->second;
- if(prox->clients_in_proximity.count(client) > 0)
- prox->clients_in_proximity.erase(client);
- }
- }
- void ZoneServer::RemovePlayerProximity(Spawn* spawn, bool all){
- if(all){
- MutexMap<int32, PlayerProximity*>::iterator itr = player_proximities.begin();
- while(itr.Next()){
- player_proximities.erase(itr->first, false, true, 10000);
- }
- }
- else if(player_proximities.count(spawn->GetID()) > 0){
- player_proximities.erase(spawn->GetID(), false, true, 10000);
- }
- }
- void ZoneServer::AddLocationProximity(float x, float y, float z, float max_variation, string in_range_function, string leaving_range_function) {
- LocationProximity* prox = new LocationProximity;
- prox->x = x;
- prox->y = y;
- prox->z = z;
- prox->max_variation = max_variation;
- prox->in_range_lua_function = in_range_function;
- prox->leaving_range_lua_function = leaving_range_function;
- location_proximities.Add(prox);
- }
- void ZoneServer::CheckLocationProximity() {
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (!zone_script)
- return;
- if (location_proximities.size() > 0 && connected_clients.size() > 0) {
- Client* client = 0;
- MutexList<Client*>::iterator iterator = connected_clients.begin();
- while(iterator.Next()){
- client = iterator->value;
- if (client->IsConnected() && client->IsReadyForSpawns() && !client->IsZoning()) {
- try {
- MutexList<LocationProximity*>::iterator itr = location_proximities.begin();
- LocationProximity* prox = 0;
- while(itr.Next()){
- prox = itr->value;
- bool in_range = false;
- float char_x = client->GetPlayer()->GetX();
- float char_y = client->GetPlayer()->GetY();
- float char_z = client->GetPlayer()->GetZ();
- float x = prox->x;
- float y = prox->y;
- float z = prox->z;
- float max_variation = prox->max_variation;
- float total_diff = 0;
- float diff = x - char_x; //Check X
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- diff = z - char_z; //Check Z (we check Z first because it is far more likely to be a much greater variation than y)
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- if(total_diff <= max_variation) { //Check Total
- diff = y - char_y; //Check Y
- if(diff < 0)
- diff *= -1;
- if(diff <= max_variation) {
- total_diff += diff;
- if(total_diff <= max_variation) {
- in_range = true;
- if(lua_interface && prox->in_range_lua_function.length() > 0 && prox->clients_in_proximity.count(client) == 0) { //Check Total
- prox->clients_in_proximity[client] = true;
- lua_interface->RunZoneScript(zone_script, prox->in_range_lua_function.c_str(), this, client->GetPlayer());
- }
- }
- }
- }
- }
- }
- if (!in_range) {
- if(lua_interface && prox->leaving_range_lua_function.length() > 0 && prox->clients_in_proximity.count(client) > 0) {
- lua_interface->RunZoneScript(zone_script, prox->leaving_range_lua_function.c_str(), this, client->GetPlayer());
- prox->clients_in_proximity.erase(client);
- }
- }
- }
- }
- catch (...) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Except caught in ZoneServer::CheckLocationProximity");
- return;
- }
- }
- }
- }
- }
- void ZoneServer::CheckLocationGrids() {
- if (connected_clients.size() > 0 && location_grids.size() > 0) {
- MutexList<Client*>::iterator client_itr = connected_clients.begin();
- while (client_itr.Next()) {
- Client* client = client_itr.value;
- if (!client)
- continue;
- Player* player = client->GetPlayer();
- float x = player->GetX();
- float y = player->GetY();
- float z = player->GetZ();
- int32 grid_id = player->appearance.pos.grid_id;
- MutexList<LocationGrid*>::iterator location_grid_itr = location_grids.begin();
- while (location_grid_itr.Next()) {
- LocationGrid* grid = location_grid_itr.value;
- if (grid->locations.size() > 0 || /*(grid->grid_id == grid_id ||*/ grid->players.count(player) > 0) {
- float x_small = 0;
- float x_large = 0;
- float y_small = 0;
- float y_large = 0;
- float z_small = 0;
- float z_large = 0;
- bool first = true;
- bool in_grid = false;
- MutexList<Location*>::iterator location_itr = grid->locations.begin();
- while (location_itr.Next()) {
- Location* location = location_itr.value;
- if (first) {
- x_small = location->x;
- x_large = location->x;
- if (grid->include_y) {
- y_small = location->y;
- y_large = location->y;
- }
- z_small = location->z;
- z_large = location->z;
- first = false;
- }
- else {
- if (location->x < x_small)
- x_small = location->x;
- else if (location->x > x_large)
- x_large = location->x;
- if (grid->include_y) {
- if (location->y < y_small)
- y_small = location->y;
- else if (location->y > y_large)
- y_large = location->y;
- }
- if (location->z < z_small)
- z_small = location->z;
- else if (location->z > z_large)
- z_large = location->z;
- }
- }
- if (grid->include_y && (x >= x_small && x <= x_large && y >= y_small && y <= y_large && z >= z_small && z <= z_large))
- in_grid = true;
- else if (x >= x_small && x <= x_large && z >= z_small && z <= z_large)
- in_grid = true;
- if (in_grid && grid->players.count(player) == 0) {
- grid->players.Put(player, true);
- bool show_enter_location_popup = true;
- bool discovery_enabled = rule_manager.GetGlobalRule(R_World, EnablePOIDiscovery)->GetBool();
- if( grid->discovery && discovery_enabled && !player->DiscoveredLocation(grid->id) )
- {
- // check if player has already discovered this location
- // if not, process new discovery
- char tmp[200] = {0};
- sprintf(tmp, "\\#FFE400You have discovered\12\\#FFF283%s", grid->name.c_str());
- client->SendPopupMessage(11, tmp, "ui_discovery", 2.25, 0xFF, 0xFF, 0xFF);
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' discovered location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- player->UpdatePlayerHistory(HISTORY_TYPE_DISCOVERY, HISTORY_SUBTYPE_LOCATION, grid->id);
- show_enter_location_popup = false;
- // else, print standard location entry
- }
- if( show_enter_location_popup )
- {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' entering location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- client->SendPopupMessage(10, grid->name.c_str(), 0, 2.5, 255, 255, 0);
- }
- }
- else if (!in_grid && grid->players.count(player) > 0) {
- LogWrite(ZONE__DEBUG, 0, "Zone", "Player '%s' leaving location '%s' (%u)", player->GetName(), grid->name.c_str(), grid->id);
- grid->players.erase(player);
- }
- }
- }
- }
- }
- }
- // Called from a command (client, main zone thread) and the main zone thread
- // so no need for a mutex container
- void ZoneServer::AddLocationGrid(LocationGrid* grid) {
- if (grid)
- location_grids.Add(grid);
- }
- void ZoneServer::RemoveLocationGrids() {
- MutexList<LocationGrid*>::iterator itr = location_grids.begin();
- while (itr.Next())
- itr.value->locations.clear(true);
- location_grids.clear(true);
- }
- void ZoneServer::RemoveSpellTimersFromSpawn(Spawn* spawn, bool remove_all, bool delete_recast){
- if(spellProcess)
- spellProcess->RemoveSpellTimersFromSpawn(spawn, remove_all, delete_recast);
- }
- void ZoneServer::Interrupted(Entity* caster, Spawn* interruptor, int16 error_code, bool cancel, bool from_movement){
- if(spellProcess)
- spellProcess->Interrupted(caster, interruptor, error_code, cancel, from_movement);
- }
- Spell* ZoneServer::GetSpell(Entity* caster){
- Spell* spell = 0;
- if(spellProcess)
- spell = spellProcess->GetSpell(caster);
- return spell;
- }
- void ZoneServer::ProcessSpell(Spell* spell, Entity* caster, Spawn* target, bool lock, bool harvest_spell){
- if(spellProcess)
- spellProcess->ProcessSpell(this, spell, caster, target, lock, harvest_spell);
- }
- void ZoneServer::ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock) {
- if (spellProcess)
- spellProcess->ProcessEntityCommand(this, entity_command, caster, target, lock);
- }
- void ZoneServer::RemoveSpawnSupportFunctions(Spawn* spawn) {
- if(!spawn)
- return;
- LogWrite(ZONE__DEBUG, 7, "Zone", "Processing RemoveSpawnSupportFunctions...");
- if(spawn->IsEntity())
- RemoveSpellTimersFromSpawn((Entity*)spawn, true);
- RemoveDamagedSpawn(spawn);
- spawn->SendSpawnChanges(false);
- RemoveChangedSpawn(spawn);
-
- // Everything inside this if will be nuked during a reload in other spots, no need to do it twice
- if (!reloading) {
- RemoveDeadEnemyList(spawn);
- spawn->changed = true;
- spawn->info_changed = true;
- spawn->vis_changed = true;
- spawn->position_changed = true;
- SendSpawnChanges(spawn);
- if (spawn->GetSpawnGroupID() > 0) {
- int32 group_id = spawn->GetSpawnGroupID();
- spawn->RemoveSpawnFromGroup();
- if (spawn_group_map.count(group_id) > 0)
- spawn_group_map.Get(group_id).Remove(spawn->GetID());
- }
- if (!spawn->IsPlayer()) {
- if(quick_database_id_lookup.count(spawn->GetDatabaseID()) > 0)
- quick_database_id_lookup.erase(spawn->GetDatabaseID());
- }
- RemoveHeadingTimer(spawn);
- DeleteSpawnScriptTimers(spawn);
- RemovePlayerProximity(spawn);
- }
- // We don't use RemoveMovementNPC() here as it caused a hell of a delay during reloads
- // instead we remove it from the list directly
- if (spawn->IsNPC())
- movement_spawns.erase(spawn->GetID());
- }
- void ZoneServer::HandleEmote(Client* originator, string name) {
- if (!originator) {
- LogWrite(ZONE__ERROR, 0, "Zone", "HandleEmote called with an invalid client");
- return;
- }
- Client* client = 0;
- Emote* emote = visual_states.FindEmote(name);
- if(!emote){
- originator->Message(CHANNEL_COLOR_YELLOW, "Unable to find emote '%s'. If this should be a valid emote be sure to submit a /bug report.", name.c_str());
- return;
- }
- PacketStruct* packet = 0;
- char* emoteResponse = 0;
- vector<Client*>::iterator client_itr;
-
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(!client || (client && client->GetPlayer()->IsIgnored(originator->GetPlayer()->GetName())))
- continue;
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- if(packet){
- packet->setDataByName("spawn_id" , client->GetPlayer()->GetIDWithPlayerSpawn(originator->GetPlayer()));
- if(!emoteResponse){
- string message;
- if(originator->GetPlayer()->GetTarget() && originator->GetPlayer()->GetTarget()->GetID() != originator->GetPlayer()->GetID()){
- message = emote->GetTargetedMessageString();
- if(message.find("%t") < 0xFFFFFFFF)
- message.replace(message.find("%t"), 2, originator->GetPlayer()->GetTarget()->GetName());
- }
- if(message.length() == 0)
- message = emote->GetMessageString();
- if(message.find("%g1") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g1"), 3, "his");
- else
- message.replace(message.find("%g1"), 3, "her");
- }
- if(message.find("%g2") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g2"), 3, "him");
- else
- message.replace(message.find("%g2"), 3, "her");
- }
- if(message.find("%g3") < 0xFFFFFFFF){
- if(originator->GetPlayer()->GetGender() == 1)
- message.replace(message.find("%g3"), 3, "he");
- else
- message.replace(message.find("%g3"), 3, "she");
- }
- if(message.length() > 0){
- emoteResponse = new char[message.length() + strlen(originator->GetPlayer()->GetName()) + 10];
- sprintf(emoteResponse,"%s %s", originator->GetPlayer()->GetName(), message.c_str());
- }
- else{
- originator->Message(CHANNEL_COLOR_YELLOW, "%s is not properly configured, be sure to submit a /bug report.", name.c_str());
- safe_delete(packet);
- break;
- }
- }
- packet->setMediumStringByName("emote_msg", emoteResponse);
- packet->setDataByName("anim_type", emote->GetVisualState());
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- safe_delete_array(emoteResponse);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SetupInstance(int32 createdInstanceID) {
- if ( createdInstanceID == 0 ) // if this happens that isn't good!
- instanceID = ++MinInstanceID;
- else // db should pass the good ID
- instanceID = createdInstanceID;
- }
- void ZoneServer::RemoveDeadSpawn(Spawn* spawn){
- AddDeadSpawn(spawn, 0);
- }
- void ZoneServer::AddDeadSpawn(Spawn* spawn, int32 timer){
- MDeadSpawns.writelock(__FUNCTION__, __LINE__);
- if (dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns[spawn->GetID()] = Timer::GetCurrentTime2() + timer;
- else if(timer != 0xFFFFFFFF)
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + timer));
- else{
- if(spawn->IsEntity() && ((Entity*)spawn)->HasLoot()){
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + (15000 * spawn->GetLevel() + 240000)));
- SendUpdateDefaultCommand(spawn, "loot", 10);
- }
- else
- dead_spawns.insert(make_pair(spawn->GetID(), Timer::GetCurrentTime2() + 10000));
- }
- MDeadSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::WritePlayerStatistics() {
- MutexList<Client*>::iterator client_itr = connected_clients.begin();
- while(client_itr.Next())
- client_itr->value->GetPlayer()->WritePlayerStatistics();
- }
- bool ZoneServer::SendRadiusSpawnInfo(Client* client, float radius) {
- if (!client)
- return false;
- Spawn* spawn = 0;
- bool ret = false;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != client->GetPlayer() && !spawn->IsPlayer() && spawn->GetDistance(client->GetPlayer()) <= radius) {
- const char* type = "NPC";
- const char* specialTypeID = "N/A";
- int32 specialID = 0, spawnEntryID = spawn->GetSpawnEntryID();
- if (spawn->IsObject())
- {
- Object* obj = (Object*)spawn;
- specialID = obj->GetID();
- specialTypeID = "GetID";
- type = "Object";
- }
- else if (spawn->IsSign())
- {
- Sign* sign = (Sign*)spawn;
- specialID = sign->GetWidgetID();
- specialTypeID = "WidgetID";
- type = "Sign";
- }
- else if (spawn->IsWidget())
- {
- Widget* widget = (Widget*)spawn;
- specialID = widget->GetWidgetID();
- specialTypeID = "WidgetID";
- if ( specialID == 0xFFFFFFFF )
- specialTypeID = "WidgetID(spawn_widgets entry missing)";
- type = "Widget";
- }
- else if (spawn->IsGroundSpawn())
- {
- GroundSpawn* gs = (GroundSpawn*)spawn;
- specialID = gs->GetGroundSpawnEntryID();
- specialTypeID = "GroundSpawnEntryID";
- type = "GroundSpawn";
- }
- client->Message(CHANNEL_COLOR_RED, "Name: %s (%s), Spawn Table ID: %u, %s: %u", spawn->GetName(), type, spawn->GetDatabaseID(), specialTypeID, specialID);
- client->Message(CHANNEL_COLOR_RED, "Spawn Location ID: %u, Spawn Group ID: %u, SpawnEntryID: %u, Grid ID: %u", spawn->GetSpawnLocationID(), spawn->GetSpawnGroupID(), spawnEntryID, spawn->GetLocation());
- client->Message(CHANNEL_COLOR_RED, "Respawn Time: %u (sec), X: %f, Y: %f, Z: %f Heading: %f", spawn->GetRespawnTime(), spawn->GetX(), spawn->GetY(), spawn->GetZ(), spawn->GetHeading());
- client->Message(CHANNEL_COLOR_YELLOW, "=============================");
- ret = true;
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::AddPlayerTracking(Player* player) {
- if (player && !player->GetIsTracking() && players_tracking.count(player->GetDatabaseID()) == 0) {
- Client* client = GetClientBySpawn(player);
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- player->SetIsTracking(true);
- players_tracking.Put(client->GetCharacterID(), player);
- packet->setDataByName("mode", TRACKING_START);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- }
- void ZoneServer::RemovePlayerTracking(Player* player, int8 mode) {
- if (player && player->GetIsTracking()) {
- Client* client = GetClientBySpawn(player);
- if (client) {
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- player->SetIsTracking(false);
- players_tracking.erase(client->GetCharacterID());
- packet->setDataByName("mode", mode);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- }
- void ZoneServer::ProcessTracking() {
- MutexMap<int32, Player*>::iterator itr = players_tracking.begin();
- while (itr.Next())
- ProcessTracking(GetClientBySpawn(itr->second));
- }
- void ZoneServer::ProcessTracking(Client* client) {
- if (!client)
- return;
- Player* player = client->GetPlayer();
- if (player && player->GetIsTracking()) {
- MutexMap<int32, Spawn*>::iterator spawn_itr;
- PacketStruct* packet = configReader.getStruct("WS_TrackingUpdate", client->GetVersion());
- if (packet) {
- packet->setDataByName("mode", TRACKING_UPDATE);
- packet->setDataByName("type", TRACKING_TYPE_ENTITIES);
- vector<TrackedSpawn*> spawns_tracked;
- while (spawn_itr.Next()) {
- Spawn* spawn = spawn_itr->second;
- float distance = player->GetDistance(spawn);
- if (spawn->IsEntity() && distance <= 80 && spawn != player) {
- TrackedSpawn* ts = new TrackedSpawn;
- ts->spawn = spawn;
- ts->distance = distance;
- /* Add spawns in ascending order from closest to furthest */
- if (spawns_tracked.empty())
- spawns_tracked.push_back(ts);
- else {
- vector<TrackedSpawn*>::iterator tracked_itr;
- bool added = false;
- for (tracked_itr = spawns_tracked.begin(); tracked_itr != spawns_tracked.end(); tracked_itr++) {
- TrackedSpawn* cur_ts = *tracked_itr;
- if (ts->distance <= cur_ts->distance) {
- spawns_tracked.insert(tracked_itr, ts);
- added = true;
- break;
- }
- }
- if (!added)
- spawns_tracked.push_back(ts);
- }
- }
- }
- packet->setArrayLengthByName("num_spawns", spawns_tracked.size());
- for (int32 i = 0; i < spawns_tracked.size(); i++) {
- TrackedSpawn* ts = spawns_tracked[i];
- LogWrite(ZONE__DEBUG, 0, "Zone", "%s (%f)", ts->spawn->GetName(), ts->distance);
- packet->setArrayDataByName("spawn_id", player->GetIDWithPlayerSpawn(ts->spawn), i);
- packet->setArrayDataByName("spawn_name", ts->spawn->GetName(), i);
- if (ts->spawn->IsPlayer())
- packet->setArrayDataByName("spawn_type", TRACKING_SPAWN_TYPE_PC, i);
- else
- packet->setArrayDataByName("spawn_type", TRACKING_SPAWN_TYPE_NPC, i);
- packet->setArrayDataByName("spawn_con_color", player->GetArrowColor(ts->spawn->GetLevel()), i);
- }
- packet->setArrayLengthByName("num_array1", 0);
- //for (int32 i = 0; i < spawns_tracked.size(); i++) {
- //}
- packet->setArrayLengthByName("num_spawns2", spawns_tracked.size());
- for (int32 i = 0; i < spawns_tracked.size(); i++) {
- TrackedSpawn* ts = spawns_tracked[i];
- packet->setArrayDataByName("list_spawn_id", player->GetIDWithPlayerSpawn(ts->spawn), i);
- packet->setArrayDataByName("list_number", i, i);
- }
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- for (int32 i = 0; i < spawns_tracked.size(); i++)
- safe_delete(spawns_tracked[i]);
- }
- }
- }
- void ZoneServer::SendEpicMobDeathToGuild(Player* killer, Spawn* victim) {
- if (killer && victim) {
- LogWrite(MISC__TODO, 1, "TODO" , "Check if player is in raid\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
- if (killer->GetGroupMemberInfo()) {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>::iterator itr;
- deque<GroupMemberInfo*>* members = world.GetGroupManager()->GetGroupMembers(killer->GetGroupMemberInfo()->group_id);
- for (itr = members->begin(); itr != members->end(); itr++) {
- GroupMemberInfo* gmi = *itr;
- if (gmi->client) {
- Player* group_member = gmi->client->GetPlayer();
- if (group_member->GetGuild()) {
- Guild* guild = group_member->GetGuild();
- string message = Guild::GetEpicMobDeathMessage(group_member->GetName(), victim->GetName());
- guild->AddNewGuildEvent(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str(), Timer::GetUnixTimeStamp());
- guild->SendMessageToGuild(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str());
- }
- }
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- }
- else if (killer->GetGuild()) {
- Guild* guild = killer->GetGuild();
- string message = Guild::GetEpicMobDeathMessage(killer->GetName(), victim->GetName());
- guild->AddNewGuildEvent(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str(), Timer::GetUnixTimeStamp());
- guild->SendMessageToGuild(GUILD_EVENT_KILLS_EPIC_MONSTER, message.c_str());
- }
- }
- }
- void ZoneServer::ProcessAggroChecks(Spawn* spawn) {
- if (spawn->GetFactionID() < 1 || spawn->EngagedInCombat())
- return;
- // If faction based combat is not allowed then no need to run the loops so just return out
- if(!rule_manager.GetGlobalRule(R_Faction, AllowFactionBasedCombat)->GetBool())
- return;
- if (spawn && spawn->IsNPC() && spawn->Alive())
- CheckEnemyList((NPC*)spawn);
- }
- void ZoneServer::SendUpdateTitles(Client *client, Title *suffix, Title *prefix) {
- assert(client);
- SendUpdateTitles(client->GetPlayer(), suffix, prefix);
- }
- void ZoneServer::SendUpdateTitles(Spawn *spawn, Title *suffix, Title *prefix) {
- if (!spawn)
- return;
- vector<Client*>::iterator itr;
- PacketStruct *packet;
- Client* current_client;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- current_client = *itr;
- if (!(packet = configReader.getStruct("WS_UpdateTitle", current_client->GetVersion())))
- break;
- packet->setDataByName("player_id", current_client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("player_name", spawn->GetName());
- packet->setDataByName("unknown1", 1, 1);
- if(suffix)
- packet->setDataByName("suffix_title", suffix->GetName());
- else
- packet->setDataByName("suffix_title", spawn->GetSuffixTitle());
- if(prefix)
- packet->setDataByName("prefix_title", prefix->GetName());
- else
- packet->setDataByName("prefix_title", spawn->GetPrefixTitle());
- packet->setDataByName("last_name", spawn->GetLastName());
- packet->setDataByName("sub_title", spawn->GetSubTitle());
- current_client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddTransportSpawn(Spawn* spawn){
- if(!spawn)
- return;
- MTransportSpawns.writelock(__FUNCTION__, __LINE__);
- transport_spawns.push_back(spawn->GetID());
- MTransportSpawns.releasewritelock(__FUNCTION__, __LINE__);
- }
- Spawn* ZoneServer::GetClosestTransportSpawn(float x, float y, float z){
- Spawn* spawn = 0;
- Spawn* closest_spawn = 0;
- float closest_distance = 0.0;
- MTransportSpawns.writelock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr = transport_spawns.begin();
- while(itr != transport_spawns.end()){
- spawn = GetSpawnByID(*itr);
- if(spawn){
- if(closest_distance == 0.0){
- closest_spawn = spawn;
- closest_distance = spawn->GetDistance(x, y, z);
- }
- else if(spawn->GetDistance(x, y, z) < closest_distance){
- closest_spawn = spawn;
- closest_distance = spawn->GetDistance(x, y, z);
- }
- itr++;
- }
- else
- itr = transport_spawns.erase(itr);
- }
- MTransportSpawns.releasewritelock(__FUNCTION__, __LINE__);
- return closest_spawn;
- }
- void ZoneServer::SetRain(float val) {
- rain = val;
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- client->GetPlayer()->GetInfoStruct()->rain = val;
- client->GetPlayer()->SetCharSheetChanged(true);
- if( val >= 0.75 && !weather_signaled )
- {
- client->SimpleMessage(CHANNEL_COLOR_WHITE, "It starts to rain.");
- }
- else if( val < 0.75 && weather_signaled )
- {
- client->SimpleMessage(CHANNEL_COLOR_WHITE, "It stops raining.");
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- if (val >= 0.75 && !weather_signaled) {
- weather_signaled = true;
- ProcessSpawnConditional(SPAWN_CONDITIONAL_RAINING);
- }
- else if (val < 0.75 && weather_signaled) {
- weather_signaled = false;
- ProcessSpawnConditional(SPAWN_CONDITIONAL_NOT_RAINING);
- }
- }
- void ZoneServer::SetWind(float val) {
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- client->GetPlayer()->GetInfoStruct()->wind = val;
- client->GetPlayer()->SetCharSheetChanged(true);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessWeather()
- {
- // if the global rule to disable weather is set, or if the `weather_allowed` field in the zone record == 0, do not process weather
- if( !weather_enabled || !isWeatherAllowed() )
- return;
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Processing weather changes", zone_name);
- float new_weather = 0;
- float weather_offset = 0;
- bool change_weather = false;
- // check to see if it is time to change the weather according to weather_frequency (time between changes)
- if( weather_last_changed_time <= (Timer::GetUnixTimeStamp() - weather_frequency) )
- {
- LogWrite(ZONE__DEBUG, 2, "Zone", "%s: Checking for weather changes", zone_name);
- // reset last changed time (frequency check)
- weather_last_changed_time = Timer::GetUnixTimeStamp();
- // this is the chance a weather change occurs at all at the expired interval
- int8 weather_random = MakeRandomInt(1, 100);
- LogWrite(ZONE__DEBUG, 2, "Zone", "%s: Chance to change weather: %i%%, rolled: %i%% - Change weather: %s", zone_name, weather_change_chance, weather_random, weather_random <= weather_change_chance ? "True" : "False");
- if( weather_random <= weather_change_chance )
- {
- change_weather = true;
- weather_offset = weather_change_amount;
- if( weather_type == 3 ) // chaotic weather patterns, random weather between min/max
- {
- new_weather = MakeRandomFloat(weather_min_severity, weather_max_severity);
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Chaotic weather severity changed to %.2f", zone_name, new_weather);
- weather_pattern = 2;
- }
- else if( weather_type == 2 ) // random weather patterns, combination of normal + dynamic + max_offset
- {
- weather_offset = MakeRandomFloat(weather_change_amount, weather_dynamic_offset);
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Random weather severity changed by %.2f", zone_name, weather_offset);
- int8 weather_alter = weather_change_chance / 10; // the divide is to prevent too many direction changes in a cycle
- weather_random = MakeRandomInt(1, 100); // chance that the weather changes direction (weather_pattern)
- if( weather_random <= weather_alter )
- weather_pattern = ( weather_pattern == 0 ) ? 1 : 0;
- }
- else if( weather_type == 1 ) // dynamic weather patterns, weather may not reach min/max
- {
- int8 weather_alter = weather_change_chance / 10; // the divide is to prevent too many direction changes in a cycle
- weather_random = MakeRandomInt(1, 100); // chance that the weather changes direction (weather_pattern)
- if( weather_random <= weather_alter )
- {
- weather_pattern = ( weather_pattern == 0 ) ? 1 : 0;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Dynamic weather pattern changed to %i", zone_name, weather_pattern);
- }
- }
- else // normal weather patterns, weather starts at min, goes to max, then back down again
- {
- // do nothing (processed below)
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Normal weather severity changed by %.2f", zone_name, weather_offset);
- }
- // when all done, change the weather
- if( change_weather )
- {
- if( weather_pattern == 1 )
- {
- // weather is getting worse, til it reaches weather_max_severity
- new_weather = ( weather_current_severity <= weather_max_severity ) ? weather_current_severity + weather_offset : weather_max_severity;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Increased weather severity by %.2f", zone_name, weather_offset);
- if(new_weather > weather_max_severity)
- {
- new_weather = weather_max_severity - weather_offset;
- weather_pattern = 0;
- }
- }
- else if( weather_pattern == 0 )
- {
- // weather is clearing up, til it reaches weather_min_severity
- new_weather = ( weather_current_severity >= weather_min_severity ) ? weather_current_severity - weather_offset : weather_min_severity;
- LogWrite(ZONE__DEBUG, 3, "Zone", "%s: Decreased weather severity by %.2f", zone_name, weather_offset);
- if(new_weather < weather_min_severity)
- {
- new_weather = weather_min_severity + weather_offset;
- weather_pattern = 1;
- }
- }
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Weather change triggered from %.2f to %.2f", zone_name, weather_current_severity, new_weather);
- this->SetRain(new_weather);
- weather_current_severity = new_weather;
- }
- }
- }
- else
- LogWrite(ZONE__DEBUG, 1, "Zone", "%s: Not time to change weather yet", zone_name);
- }
- void ZoneServer::HidePrivateSpawn(Spawn* spawn) {
- if (!spawn->IsPrivateSpawn())
- return;
- Client* client = 0;
- Player* player = 0;
- PacketStruct* packet = 0;
- MutexList<Client*>::iterator itr = connected_clients.begin();
- while (itr->Next()) {
- client = itr->value;
- player = client->GetPlayer();
- if (player->WasSentSpawn(spawn->GetID()) && !player->WasSpawnRemoved(spawn)) {
- packet = configReader.getStruct("WS_DestroyGhostCmd", client->GetVersion());
- SendRemoveSpawn(client, spawn, packet);
- if(spawn_range_map.count(client) > 0)
- spawn_range_map.Get(client)->erase(spawn->GetID());
- if(player->GetTarget() == spawn)
- player->SetTarget(0);
- }
- }
- }
- SpawnLocation* ZoneServer::GetSpawnLocation(int32 id) {
- SpawnLocation* ret = 0;
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- if (spawn_location_list.count(id) > 0)
- ret = spawn_location_list[id];
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::PlayAnimation(Spawn* spawn, int32 visual_state, Spawn* spawn2, int8 hide_type){
- Client* client = 0;
- PacketStruct* packet = 0;
- Spawn* exclude_spawn = 0;
- if (!spawn)
- return;
- if (spawn2){
- if(hide_type == 1){
- client = GetClientBySpawn(spawn2);
- if(client){
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("anim_type", visual_state);
- client->QueuePacket(packet->serialize());
- }
- return;
- }
- if(hide_type == 2)
- exclude_spawn = spawn2;
- }
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(spawn->GetDistance(client->GetPlayer()) > 50)
- continue;
- if(exclude_spawn == client->GetPlayer())
- continue;
- packet = configReader.getStruct("WS_CannedEmote", client->GetVersion());
- if (packet) {
- packet->setDataByName("spawn_id", client->GetPlayer()->GetIDWithPlayerSpawn(spawn));
- packet->setDataByName("anim_type", visual_state);
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- vector<Spawn*> ZoneServer::GetSpawnsByID(int32 id) {
- vector<Spawn*> tmp_list;
- Spawn* spawn;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && (spawn->GetDatabaseID() == id))
- tmp_list.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return tmp_list;
- }
- vector<Spawn*> ZoneServer::GetAttackableSpawnsByDistance(Spawn* caster, float distance) {
- vector<Spawn*> ret;
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsNPC() && spawn->appearance.attackable > 0 && spawn != caster && spawn->Alive() && spawn->GetDistance(caster, true) <= distance)
- ret.push_back(spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::ResurrectSpawn(Spawn* spawn, Client* client) {
- if(!client || !spawn)
- return;
- PendingResurrection* rez = client->GetCurrentRez();
- if(!rez || !rez->caster)
- return;
- PacketStruct* packet = 0;
- float power_perc = rez->mp_perc;
- float health_perc = rez->hp_perc;
- Spawn* caster_spawn = rez->caster;
- sint32 heal_amt = 0;
- sint32 power_amt = 0;
- bool no_calcs = rez->no_calcs;
- int8 crit_mod = rez->crit_mod;
- Entity* caster = 0;
- InfoStruct* info = 0;
- bool crit = false;
- string heal_spell = rez->heal_name;
- int16 heal_packet_type = 0;
- int16 power_packet_type = 0;
- //Calculations for how much to heal the spawn
- if(health_perc > 0)
- heal_amt = (spawn->GetTotalHP() * (health_perc / 100));
- if(power_perc > 0)
- power_amt = (spawn->GetTotalPower() * (power_perc / 100));
- if(caster_spawn->IsEntity()){
- caster = ((Entity*)caster_spawn);
- info = caster->GetInfoStruct();
- }
- if(!no_calcs && caster){
- //Potency Mod
- heal_amt *= ((caster->stats[ITEM_STAT_POTENCY] / 100) + 1);
- power_amt *= ((caster->stats[ITEM_STAT_POTENCY] / 100) + 1);
- //Ability Mod
- heal_amt += (int32)min((int32)info->ability_modifier, (int32)(heal_amt / 2));
- power_amt += (int32)min((int32)info->ability_modifier, (int32)(power_amt / 2));
- if(!crit_mod || crit_mod == 1){
- if(crit_mod == 1)
- crit = true;
- else {
- // Crit Roll
- float chance = (float)max((float)0, (float)info->crit_chance);
- crit = (MakeRandomFloat(0, 100) <= chance);
- }
- if(crit){
- //Apply total crit multiplier with crit bonus
- heal_amt *= ((info->crit_bonus / 100) + 1.3);
- power_amt *= ((info->crit_bonus / 100) + 1.3);
- }
- }
- }
- //Set this rez as a crit to be passed to subspell (not yet used)
- rez->crit = true;
- //Set Heal amt to 1 if 0 now so the player has health
- if(heal_amt == 0)
- heal_amt = 1;
- if(heal_amt > spawn->GetTotalHP())
- heal_amt = spawn->GetTotalHP();
- if(power_amt > spawn->GetTotalPower())
- power_amt = spawn->GetTotalPower();
- spawn->SetHP(heal_amt);
- if(power_amt > 0)
- spawn->SetPower(power_amt);
- if(client && caster){
- EQ2Packet* move = ((Player*)spawn)->Move(caster->GetX(), caster->GetY(), caster->GetZ(), client->GetVersion());
- if(move)
- client->QueuePacket(move);
- }
- if(crit){
- power_packet_type = HEAL_PACKET_TYPE_CRIT_MANA;
- heal_packet_type = HEAL_PACKET_TYPE_CRIT_HEAL;
- }
- else {
- power_packet_type = HEAL_PACKET_TYPE_SIMPLE_MANA;
- heal_packet_type = HEAL_PACKET_TYPE_SIMPLE_HEAL;
- }
- SendHealPacket(caster, spawn, heal_packet_type, heal_amt, heal_spell.c_str());
- if(power_amt > 0)
- SendHealPacket(caster, spawn, power_packet_type, power_amt, heal_spell.c_str());
- //The following code sets the spawn as alive
- if(dead_spawns.count(spawn->GetID()) > 0)
- dead_spawns.erase(spawn->GetID());
- if(spawn->IsPlayer()){
- spawn->SetSpawnType(4);
- client = GetClientBySpawn(spawn);
- if(client){
- packet = configReader.getStruct("WS_Resurrected", client->GetVersion());
- if(packet){
- client->QueuePacket(packet->serialize());
- }
- packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
- if(packet)
- {
- packet->setDataByName("parameter1", 8);
- client->QueuePacket(packet->serialize());
- packet->setDataByName("parameter1", 16);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- client->SimpleMessage(CHANNEL_COLOR_REVIVE, "You regain consciousness!");
- }
- }
- spawn->SendSpawnChanges(true);
- spawn->SetTempActionState(-1);
- spawn->appearance.attackable = 1;
- }
- void ZoneServer::SendDispellPacket(Entity* caster, Spawn* target, string dispell_name, string spell_name, int8 dispell_type){
- if(!caster || !target)
- return;
- Client* client = 0;
- Player* player = 0;
- PacketStruct* packet = 0;
- vector<Client*>::iterator client_itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++){
- client = *client_itr;
- if(!client || !(player = client->GetPlayer()) || (player != caster && ((caster && player->WasSentSpawn(caster->GetID()) == false) || (target && player->WasSentSpawn(target->GetID()) == false))))
- continue;
- if((caster && player->WasSpawnRemoved(caster)) || (caster && player->WasSpawnRemoved(target)))
- continue;
- if(caster && caster->GetDistance(player) > 50)
- continue;
- if(target && target->GetDistance(player) > 50)
- continue;
- packet = configReader.getStruct("WS_HearDispell", client->GetVersion());
- if(packet){
- packet->setDataByName("spell_name", spell_name.c_str());
- packet->setDataByName("dispell_name", dispell_name.c_str());
- packet->setDataByName("caster", player->GetIDWithPlayerSpawn(caster));
- packet->setDataByName("target", player->GetIDWithPlayerSpawn(target));
- packet->setDataByName("type", dispell_type);
- client->QueuePacket(packet->serialize());
- }
- safe_delete(packet);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DismissAllPets() {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsPet() && ((NPC*)spawn)->GetOwner())
- ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::RemoveTargetFromSpell(LuaSpell* spell, Spawn* target){
- if (spellProcess)
- spellProcess->RemoveTargetFromSpell(spell, target);
- }
- void ZoneServer::ClearHate(Entity* entity) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsNPC() && ((NPC*)spawn)->Brain())
- ((NPC*)spawn)->Brain()->ClearHate(entity);
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- ThreadReturnType ZoneLoop(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("ZoneLoop(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- ZoneServer* zs = (ZoneServer*) tmp;
- while (zs->Process()) {
- if(zs->GetClientCount() == 0)
- Sleep(1000);
- else
- Sleep(10);
- }
- zs->Process(); //run loop once more to clean up some functions
- safe_delete(zs);
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SpawnLoop(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SpawnLoop(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- ZoneServer* zs = (ZoneServer*) tmp;
- #ifndef NO_CATCH
- try {
- #endif
- zs->spawnthread_active = true;
- while (zs->SpawnProcess()) {
- if(zs->GetClientCount() == 0)
- Sleep(1000);
- else
- Sleep(20);
- }
- zs->spawnthread_active = false;
- #ifndef NO_CATCH
- }
- catch(...) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error Processing SpawnLoop, shutting down zone '%s'...", zs->GetZoneName());
- try{
- zs->Shutdown();
- }
- catch(...){
- LogWrite(ZONE__ERROR, 0, "Zone", "Error Processing SpawnLoop while shutting down zone '%s'...", zs->GetZoneName());
- }
- }
- #endif
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SendInitialSpawns(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_ABOVE_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SendInitialSpawns(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- Client* client = (Client*) tmp;
- client->GetCurrentZone()->SendZoneSpawns(client);
- THREAD_RETURN(NULL);
- }
- ThreadReturnType SendLevelChangedSpawns(void* tmp) {
- #ifdef WIN32
- SetThreadPriority(GetCurrentThread(), THREAD_PRIORITY_NORMAL);
- #endif
- if (tmp == 0) {
- ThrowError("SendLevelChangedSpawns(): tmp = 0!");
- THREAD_RETURN(NULL);
- }
- Client* client = (Client*)tmp;
- client->GetCurrentZone()->SendAllSpawnsForLevelChange(client);
- THREAD_RETURN(NULL);
- }
- void ZoneServer::SetSpawnStructs(Client* client) {
- int16 client_ver = client->GetVersion();
- Player* player = client->GetPlayer();
- //Save a copy of the correct spawn substructs for the client's player, save here a copy if we don't have one
- PacketStruct* pos = configReader.getStruct("Substruct_SpawnPositionStruct", client_ver);
- player->SetSpawnPosStruct(pos);
- if (versioned_pos_structs.count(pos->GetVersion()) == 0)
- versioned_pos_structs[pos->GetVersion()] = new PacketStruct(pos, true);
- PacketStruct* vis = configReader.getStruct("Substruct_SpawnVisualizationInfoStruct", client_ver);
- player->SetSpawnVisStruct(vis);
- if (versioned_vis_structs.count(vis->GetVersion()) == 0)
- versioned_vis_structs[vis->GetVersion()] = new PacketStruct(vis, true);
- PacketStruct* info = configReader.getStruct("Substruct_SpawnInfoStruct", client_ver);
- player->SetSpawnInfoStruct(info);
- if (versioned_info_structs.count(info->GetVersion()) == 0)
- versioned_info_structs[info->GetVersion()] = new PacketStruct(info, true);
- PacketStruct* header = configReader.getStruct("WS_SpawnStruct_Header", client_ver);
- player->SetSpawnHeaderStruct(header);
- PacketStruct* footer = configReader.getStruct("WS_SpawnStruct_Footer", client_ver);
- player->SetSpawnFooterStruct(footer);
- PacketStruct* sfooter = configReader.getStruct("WS_SignWidgetSpawnStruct_Footer", client_ver);
- player->SetSignFooterStruct(sfooter);
- PacketStruct* wfooter = configReader.getStruct("WS_WidgetSpawnStruct_Footer", client_ver);
- player->SetWidgetFooterStruct(wfooter);
- }
- Spawn* ZoneServer::GetSpawn(int32 id){
- Spawn* ret = 0;
- if(GetNPC(id))
- ret = GetNewNPC(id);
- else if(this->GetObject(id))
- ret = GetNewObject(id);
- else if(GetWidget(id))
- ret = GetNewWidget(id);
- else if(GetSign(id))
- ret = GetNewSign(id);
- else if(GetGroundSpawn(id))
- ret = GetNewGroundSpawn(id);
- // Unable to find the spawn in the list lets attempt to add it if we are not currently reloading
- else if (!reloading && database.LoadNPC(this, id)) {
- if (GetNPC(id))
- ret = GetNewNPC(id);
- else
- LogWrite(NPC__ERROR, 0, "NPC", "Database inserted npc (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadObject(this, id)) {
- if (this->GetObject(id))
- ret = GetNewObject(id);
- else
- LogWrite(OBJECT__ERROR, 0, "Object", "Database inserted object (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadWidget(this, id)) {
- if (GetWidget(id))
- ret = GetNewWidget(id);
- else
- LogWrite(WIDGET__ERROR, 0, "Widget", "Database inserted widget (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadSign(this, id)) {
- if (GetSign(id))
- ret = GetNewSign(id);
- else
- LogWrite(SIGN__ERROR, 0, "Sign", "Database inserted sign (%u) but was still unable to retrieve it!", id);
- }
- else if (!reloading && database.LoadGroundSpawn(this, id)) {
- if (GetGroundSpawn(id))
- ret = GetNewGroundSpawn(id);
- else
- LogWrite(GROUNDSPAWN__ERROR, 0, "GSpawn", "Database inserted ground spawn (%u) but was still unable to retrieve it!", id);
- }
- if(ret)
- ret->SetID(Spawn::NextID());
- return ret;
- }
- vector<EntityCommand*>* ZoneServer::GetEntityCommandList(int32 id){
- if(entity_command_list.count(id) > 0)
- return entity_command_list[id];
- else
- return 0;
- }
- void ZoneServer::SetEntityCommandList(int32 id, EntityCommand* command) {
- if (entity_command_list.count(id) == 0)
- entity_command_list[id] = new vector<EntityCommand*>;
- entity_command_list[id]->push_back(command);
- }
- EntityCommand* ZoneServer::GetEntityCommand(int32 id, string name) {
- EntityCommand* ret = 0;
- if (entity_command_list.count(id) == 0)
- return ret;
- vector<EntityCommand*>::iterator itr;
- for (itr = entity_command_list[id]->begin(); itr != entity_command_list[id]->end(); itr++) {
- if ((*itr)->name == name) {
- ret = (*itr);
- break;
- }
- }
- return ret;
- }
- void ZoneServer::ClearEntityCommands() {
- if (entity_command_list.size() > 0) {
- map<int32, vector<EntityCommand*>* >::iterator itr;
- for (itr = entity_command_list.begin(); itr != entity_command_list.end(); itr++) {
- vector<EntityCommand*>* entity_commands = itr->second;
- if (entity_commands && entity_commands->size() > 0) {
- vector<EntityCommand*>::iterator v_itr;
- for (v_itr = entity_commands->begin(); v_itr != entity_commands->end(); v_itr++)
- safe_delete(*v_itr);
- entity_commands->clear();
- }
- safe_delete(entity_commands);
- }
- entity_command_list.clear();
- }
- }
- void ZoneServer::AddNPCSpell(int32 list_id, int32 spell_id, int8 tier){
- npc_spell_list[list_id][spell_id] = tier;
- }
- vector<Spell*>* ZoneServer::GetNPCSpells(int32 primary_list, int32 secondary_list){
- vector<Spell*>* ret = 0;
- if(npc_spell_list.count(primary_list) > 0){
- ret = new vector<Spell*>();
- map<int32, int8>::iterator itr;
- Spell* tmpSpell = 0;
- for(itr = npc_spell_list[primary_list].begin(); itr != npc_spell_list[primary_list].end(); itr++){
- tmpSpell = master_spell_list.GetSpell(itr->first, itr->second);
- if(tmpSpell)
- ret->push_back(tmpSpell);
- }
- }
- if(npc_spell_list.count(secondary_list) > 0){
- if(!ret)
- ret = new vector<Spell*>();
- map<int32, int8>::iterator itr;
- Spell* tmpSpell = 0;
- for(itr = npc_spell_list[secondary_list].begin(); itr != npc_spell_list[secondary_list].end(); itr++){
- tmpSpell = master_spell_list.GetSpell(itr->first, itr->second);
- if(tmpSpell)
- ret->push_back(tmpSpell);
- }
- }
- if(ret && ret->size() == 0){
- safe_delete(ret);
- ret = 0;
- }
- return ret;
- }
- void ZoneServer::AddNPCSkill(int32 list_id, int32 skill_id, int16 value){
- npc_skill_list[list_id][skill_id] = value;
- }
- map<string, Skill*>* ZoneServer::GetNPCSkills(int32 primary_list, int32 secondary_list){
- map<string, Skill*>* ret = 0;
- if(npc_skill_list.count(primary_list) > 0){
- ret = new map<string, Skill*>();
- map<int32, int16>::iterator itr;
- Skill* tmpSkill = 0;
- for(itr = npc_skill_list[primary_list].begin(); itr != npc_skill_list[primary_list].end(); itr++){
- tmpSkill = master_skill_list.GetSkill(itr->first);
- if(tmpSkill){
- tmpSkill = new Skill(tmpSkill);
- tmpSkill->current_val = itr->second;
- tmpSkill->max_val = tmpSkill->current_val+5;
- (*ret)[tmpSkill->name.data] = tmpSkill;
- }
- }
- }
- if(npc_skill_list.count(secondary_list) > 0){
- if(!ret)
- ret = new map<string, Skill*>();
- map<int32, int16>::iterator itr;
- Skill* tmpSkill = 0;
- for(itr = npc_skill_list[secondary_list].begin(); itr != npc_skill_list[secondary_list].end(); itr++){
- tmpSkill = master_skill_list.GetSkill(itr->first);
- if(tmpSkill){
- tmpSkill = new Skill(tmpSkill);
- tmpSkill->current_val = itr->second;
- tmpSkill->max_val = tmpSkill->current_val+5;
- (*ret)[tmpSkill->name.data] = tmpSkill;
- }
- }
- }
- if(ret && ret->size() == 0){
- safe_delete(ret);
- ret = 0;
- }
- return ret;
- }
- void ZoneServer::AddNPCEquipment(int32 list_id, int32 item_id){
- npc_equipment_list[list_id].push_back(item_id);
- }
- void ZoneServer::SetNPCEquipment(NPC* npc) {
- if(npc_equipment_list.count(npc->GetEquipmentListID()) > 0){
- Item* tmpItem = 0;
- int8 slot = 0;
- vector<int32>::iterator itr;
- for(itr = npc_equipment_list[npc->GetEquipmentListID()].begin(); itr != npc_equipment_list[npc->GetEquipmentListID()].end(); itr++){
- tmpItem = master_item_list.GetItem(*itr);
- if(tmpItem){
- slot = npc->GetEquipmentList()->GetFreeSlot(tmpItem);
- if(slot < 255){
- tmpItem = new Item(tmpItem);
- npc->GetEquipmentList()->SetItem(slot, tmpItem);
- }
- }
- }
- }
- }
- void ZoneServer::AddNPC(int32 id, NPC* npc) {
- npc_list[id] = npc;
- }
- void ZoneServer::AddWidget(int32 id, Widget* widget) {
- widget_list[id] = widget;
- }
- Widget* ZoneServer::GetWidget(int32 id, bool override_loading) {
- if((!reloading || override_loading) && widget_list.count(id) > 0)
- return widget_list[id];
- else
- return 0;
- }
- Widget* ZoneServer::GetNewWidget(int32 id) {
- if(!reloading && widget_list.count(id) > 0)
- return widget_list[id]->Copy();
- else
- return 0;
- }
- void ZoneServer::LoadGroundSpawnEntries(){
- MGroundSpawnItems.lock();
- database.LoadGroundSpawnEntries(this);
- MGroundSpawnItems.unlock();
- }
- void ZoneServer::LoadGroundSpawnItems() {
- }
- void ZoneServer::AddGroundSpawnEntry(int32 groundspawn_id, int16 min_skill_level, int16 min_adventure_level, int8 bonus_table, float harvest1, float harvest3, float harvest5, float harvest_imbue, float harvest_rare, float harvest10, int32 harvest_coin) {
- GroundSpawnEntry* entry = new GroundSpawnEntry;
- entry->min_skill_level = min_skill_level;
- entry->min_adventure_level = min_adventure_level;
- entry->bonus_table = bonus_table;
- entry->harvest1 = harvest1;
- entry->harvest3 = harvest3;
- entry->harvest5 = harvest5;
- entry->harvest_imbue = harvest_imbue;
- entry->harvest_rare = harvest_rare;
- entry->harvest10 = harvest10;
- entry->harvest_coin = harvest_coin;
- groundspawn_entries[groundspawn_id].push_back(entry);
- }
- void ZoneServer::AddGroundSpawnItem(int32 groundspawn_id, int32 item_id, int8 is_rare, int32 grid_id) {
- GroundSpawnEntryItem* entry = new GroundSpawnEntryItem;
- entry->item_id = item_id;
- entry->is_rare = is_rare;
- entry->grid_id = grid_id;
- groundspawn_items[groundspawn_id].push_back(entry);
- }
- vector<GroundSpawnEntry*>* ZoneServer::GetGroundSpawnEntries(int32 id){
- vector<GroundSpawnEntry*>* ret = 0;
- MGroundSpawnItems.lock();
- if(groundspawn_entries.count(id) > 0)
- ret = &groundspawn_entries[id];
- MGroundSpawnItems.unlock();
- return ret;
- }
- vector<GroundSpawnEntryItem*>* ZoneServer::GetGroundSpawnEntryItems(int32 id){
- vector<GroundSpawnEntryItem*>* ret = 0;
- if(groundspawn_items.count(id) > 0)
- ret = &groundspawn_items[id];
- return ret;
- }
- // TODO - mis-named, should be DeleteGroundSpawnEntries() but this is ok for now :)
- void ZoneServer::DeleteGroundSpawnItems()
- {
- MGroundSpawnItems.lock();
- map<int32, vector<GroundSpawnEntry*> >::iterator groundspawnentry_map_itr;
- vector<GroundSpawnEntry*>::iterator groundspawnentry_itr;
- for(groundspawnentry_map_itr = groundspawn_entries.begin(); groundspawnentry_map_itr != groundspawn_entries.end(); groundspawnentry_map_itr++)
- {
- for(groundspawnentry_itr = groundspawnentry_map_itr->second.begin(); groundspawnentry_itr != groundspawnentry_map_itr->second.end(); groundspawnentry_itr++)
- {
- safe_delete(*groundspawnentry_itr);
- }
- }
- groundspawn_entries.clear();
- map<int32, vector<GroundSpawnEntryItem*> >::iterator groundspawnitem_map_itr;
- vector<GroundSpawnEntryItem*>::iterator groundspawnitem_itr;
- for(groundspawnitem_map_itr = groundspawn_items.begin(); groundspawnitem_map_itr != groundspawn_items.end(); groundspawnitem_map_itr++)
- {
- for(groundspawnitem_itr = groundspawnitem_map_itr->second.begin(); groundspawnitem_itr != groundspawnitem_map_itr->second.end(); groundspawnitem_itr++)
- {
- safe_delete(*groundspawnitem_itr);
- }
- }
- groundspawn_items.clear();
- MGroundSpawnItems.unlock();
- }
- void ZoneServer::AddGroundSpawn(int32 id, GroundSpawn* spawn) {
- groundspawn_list[id] = spawn;
- }
- GroundSpawn* ZoneServer::GetGroundSpawn(int32 id, bool override_loading) {
- if((!reloading || override_loading) && groundspawn_list.count(id) > 0)
- return groundspawn_list[id];
- else
- return 0;
- }
- GroundSpawn* ZoneServer::GetNewGroundSpawn(int32 id) {
- if(!reloading && groundspawn_list.count(id) > 0)
- return groundspawn_list[id]->Copy();
- else
- return 0;
- }
- void ZoneServer::AddLootTable(int32 id, LootTable* table){
- loot_tables[id] = table;
- }
- void ZoneServer::AddLootDrop(int32 id, LootDrop* drop){
- loot_drops[id].push_back(drop);
- }
- void ZoneServer::AddSpawnLootList(int32 spawn_id, int32 id) {
- spawn_loot_list[spawn_id].push_back(id);
- }
- void ZoneServer::ClearSpawnLootList(int32 spawn_id) {
- spawn_loot_list[spawn_id].clear();
- }
- void ZoneServer::AddLevelLootList(GlobalLoot* loot) {
- level_loot_list.push_back(loot);
- }
- void ZoneServer::AddRacialLootList(int16 racial_id, GlobalLoot* loot) {
- racial_loot_list[racial_id].push_back(loot);
- }
- void ZoneServer::AddZoneLootList(int32 zone, GlobalLoot* loot) {
- zone_loot_list[zone].push_back(loot);
- }
- void ZoneServer::ClearLootTables(){
- map<int32,LootTable*>::iterator table_itr;
- for(table_itr = loot_tables.begin(); table_itr != loot_tables.end(); table_itr++){
- safe_delete(table_itr->second);
- }
- map<int32, vector<LootDrop*> >::iterator drop_itr;
- vector<LootDrop*>::iterator drop_itr2;
- for(drop_itr = loot_drops.begin(); drop_itr != loot_drops.end(); drop_itr++){
- for(drop_itr2 = drop_itr->second.begin(); drop_itr2 != drop_itr->second.end(); drop_itr2++){
- safe_delete(*drop_itr2);
- }
- }
- vector<GlobalLoot*>::iterator level_itr;
- for (level_itr = level_loot_list.begin(); level_itr != level_loot_list.end(); level_itr++) {
- safe_delete(*level_itr);
- }
- map<int16, vector<GlobalLoot*> >::iterator race_itr;
- vector<GlobalLoot*>::iterator race_itr2;
- for (race_itr = racial_loot_list.begin(); race_itr != racial_loot_list.end(); race_itr++) {
- for (race_itr2 = race_itr->second.begin(); race_itr2 != race_itr->second.end(); race_itr2++) {
- safe_delete(*race_itr2);
- }
- }
- map<int32, vector<GlobalLoot*> >::iterator zone_itr;
- vector<GlobalLoot*>::iterator zone_itr2;
- for(zone_itr = zone_loot_list.begin(); zone_itr != zone_loot_list.end(); zone_itr++) {
- for (zone_itr2 = zone_itr->second.begin(); zone_itr2 != zone_itr->second.end(); zone_itr2++) {
- safe_delete(*zone_itr2);
- }
- }
- loot_tables.clear();
- loot_drops.clear();
- spawn_loot_list.clear();
- level_loot_list.clear();
- racial_loot_list.clear();
- zone_loot_list.clear();
- }
- vector<int32> ZoneServer::GetSpawnLootList(int32 spawn_id, int32 zone_id, int8 spawn_level, int16 racial_id) {
- vector<int32> ret;
- if(reloading)
- return ret;
- if (spawn_loot_list.count(spawn_id) > 0)
- ret.insert(ret.end(), spawn_loot_list[spawn_id].begin(), spawn_loot_list[spawn_id].end());
- if (level_loot_list.size() > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = level_loot_list.begin(); itr != level_loot_list.end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- if (racial_loot_list.count(racial_id) > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = racial_loot_list[racial_id].begin(); itr != racial_loot_list[racial_id].end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- if (zone_loot_list.count(zone_id) > 0) {
- vector<GlobalLoot*>::iterator itr;
- for (itr = zone_loot_list[zone_id].begin(); itr != zone_loot_list[zone_id].end(); itr++) {
- GlobalLoot* loot = *itr;
- if (loot->minLevel == 0 && loot->maxLevel == 0)
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel)
- ret.push_back(loot->table_id);
- }
- }
- }
- return ret;
- }
- vector<LootDrop*>* ZoneServer::GetLootDrops(int32 table_id){
- if(!reloading && loot_drops.count(table_id) > 0)
- return &(loot_drops[table_id]);
- else
- return 0;
- }
- LootTable* ZoneServer::GetLootTable(int32 table_id){
- return loot_tables[table_id];
- }
- void ZoneServer::AddLocationTransporter(int32 zone_id, string message, float trigger_x, float trigger_y, float trigger_z, float trigger_radius, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading, int32 cost, int32 unique_id){
- LocationTransportDestination* loc = new LocationTransportDestination;
- loc->message = message;
- loc->trigger_x = trigger_x;
- loc->trigger_y = trigger_y;
- loc->trigger_z = trigger_z;
- loc->trigger_radius = trigger_radius;
- loc->destination_zone_id = destination_zone_id;
- loc->destination_x = destination_x;
- loc->destination_y = destination_y;
- loc->destination_z = destination_z;
- loc->destination_heading = destination_heading;
- loc->cost = cost;
- loc->unique_id = unique_id;
- MTransporters.lock();
- if(location_transporters.count(zone_id) == 0)
- location_transporters[zone_id] = new MutexList<LocationTransportDestination*>();
- location_transporters[zone_id]->Add(loc);
- MTransporters.unlock();
- }
- void ZoneServer::AddTransporter(int32 transport_id, int8 type, string name, string message, int32 destination_zone_id, float destination_x, float destination_y, float destination_z, float destination_heading,
- int32 cost, int32 unique_id, int8 min_level, int8 max_level, int32 quest_req, int16 quest_step_req, int32 quest_complete, int32 map_x, int32 map_y, int32 expansion_flag, int32 holiday_flag, int32 min_client_version,
- int32 max_client_version, int32 flight_path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color){
- TransportDestination* transport = new TransportDestination;
- transport->type = type;
- transport->display_name = name;
- transport->message = message;
- transport->destination_zone_id = destination_zone_id;
- transport->destination_x = destination_x;
- transport->destination_y = destination_y;
- transport->destination_z = destination_z;
- transport->destination_heading = destination_heading;
- transport->cost = cost;
- transport->unique_id = unique_id;
- transport->min_level = min_level;
- transport->max_level = max_level;
- transport->req_quest = quest_req;
- transport->req_quest_step = quest_step_req;
- transport->req_quest_complete = quest_complete;
- transport->map_x = map_x;
- transport->map_y = map_y;
- transport->expansion_flag = expansion_flag;
- transport->holiday_flag = holiday_flag;
- transport->min_client_version = min_client_version;
- transport->max_client_version = max_client_version;
- transport->flight_path_id = flight_path_id;
- transport->mount_id = mount_id;
- transport->mount_red_color = mount_red_color;
- transport->mount_green_color = mount_green_color;
- transport->mount_blue_color = mount_blue_color;
- MTransporters.lock();
- transporters[transport_id].push_back(transport);
- MTransporters.unlock();
- }
- void ZoneServer::GetTransporters(vector<TransportDestination*>* returnList, Client* client, int32 transport_id){
- if (!returnList)
- return;
- MTransporters.lock();
- if (transporters.count(transport_id) > 0)
- {
- vector<TransportDestination*> list;
- for (int i = 0; i < transporters[transport_id].size(); i++)
- {
- if (transporters[transport_id][i]->min_client_version && client->GetVersion() < transporters[transport_id][i]->min_client_version)
- continue;
- else if (transporters[transport_id][i]->max_client_version && client->GetVersion() > transporters[transport_id][i]->max_client_version)
- continue;
- if (database.CheckExpansionFlags(this, transporters[transport_id][i]->expansion_flag) && database.CheckHolidayFlags(this, transporters[transport_id][i]->holiday_flag))
- {
- returnList->push_back(transporters[transport_id][i]);
- }
- }
- }
- MTransporters.unlock();
- }
- MutexList<LocationTransportDestination*>* ZoneServer::GetLocationTransporters(int32 zone_id){
- MutexList<LocationTransportDestination*>* ret = 0;
- MTransporters.lock();
- if(location_transporters.count(zone_id) > 0)
- ret = location_transporters[zone_id];
- MTransporters.unlock();
- return ret;
- }
- void ZoneServer::DeleteGlobalTransporters(){
- MTransporters.lock();
- map<int32, vector<TransportDestination*> >::iterator itr;
- vector<TransportDestination*>::iterator transport_vector_itr;
- for(itr = transporters.begin(); itr != transporters.end(); itr++){
- for(transport_vector_itr = itr->second.begin(); transport_vector_itr != itr->second.end(); transport_vector_itr++){
- safe_delete(*transport_vector_itr);
- }
- }
- map<int32, MutexList<LocationTransportDestination*>* >::iterator itr2;
- for(itr2 = location_transporters.begin(); itr2 != location_transporters.end(); itr2++){
- itr2->second->clear(true);
- delete itr2->second;
- }
- transporters.clear();
- location_transporters.clear();
- MTransporters.unlock();
- }
- void ZoneServer::DeleteGlobalSpawns() {
- ClearLootTables();
-
- map<int32, NPC*>::iterator npc_list_iter;
- for(npc_list_iter=npc_list.begin();npc_list_iter!=npc_list.end();npc_list_iter++) {
- safe_delete(npc_list_iter->second);
- }
- npc_list.clear();
- map<int32, Object*>::iterator object_list_iter;
- for(object_list_iter=object_list.begin();object_list_iter!=object_list.end();object_list_iter++) {
- safe_delete(object_list_iter->second);
- }
- object_list.clear();
- map<int32, GroundSpawn*>::iterator groundspawn_list_iter;
- for(groundspawn_list_iter=groundspawn_list.begin();groundspawn_list_iter!=groundspawn_list.end();groundspawn_list_iter++) {
- safe_delete(groundspawn_list_iter->second);
- }
- groundspawn_list.clear();
- map<int32, Widget*>::iterator widget_list_iter;
- for(widget_list_iter=widget_list.begin();widget_list_iter!=widget_list.end();widget_list_iter++) {
- safe_delete(widget_list_iter->second);
- }
- widget_list.clear();
- map<int32, Sign*>::iterator sign_list_iter;
- for(sign_list_iter=sign_list.begin();sign_list_iter!=sign_list.end();sign_list_iter++) {
- safe_delete(sign_list_iter->second);
- }
- sign_list.clear();
- /*map<int32, AppearanceData*>::iterator appearance_list_iter;
- for(appearance_list_iter=npc_appearance_list.begin();appearance_list_iter!=npc_appearance_list.end();appearance_list_iter++) {
- safe_delete(appearance_list_iter->second);
- }
- npc_appearance_list.clear();*/
-
- ClearEntityCommands();
- DeleteGroundSpawnItems();
- DeleteGlobalTransporters();
- DeleteTransporterMaps();
- }
- void ZoneServer::AddTransportMap(int32 id, string name) {
- MTransportMaps.writelock(__FUNCTION__, __LINE__);
- m_transportMaps[id] = name;
- MTransportMaps.releasewritelock(__FUNCTION__, __LINE__);
- }
- bool ZoneServer::TransportHasMap(int32 id) {
- bool ret = false;
- MTransportMaps.readlock(__FUNCTION__, __LINE__);
- ret = m_transportMaps.count(id) > 0;
- MTransportMaps.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- string ZoneServer::GetTransportMap(int32 id) {
- string ret;
- MTransportMaps.readlock(__FUNCTION__, __LINE__);
- if (m_transportMaps.count(id) > 0)
- ret = m_transportMaps[id];
- MTransportMaps.releasereadlock(__FUNCTION__, __LINE__);
- return ret;
- }
- void ZoneServer::DeleteTransporterMaps() {
- MTransportMaps.writelock(__FUNCTION__, __LINE__);
- m_transportMaps.clear();
- MTransportMaps.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ReloadSpawns() {
- if (reloading)
- return;
- reloading = true;
- // Let every one in the zone know what is happening
- HandleBroadcast("Reloading all spawns for this zone.");
- DeleteGlobalSpawns();
- Depop(false, true);
- }
- void ZoneServer::SendStateCommand(Spawn* spawn, int32 state) {
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- if (client && client->GetPlayer()->WasSentSpawn(spawn->GetID()) && !client->GetPlayer()->WasSpawnRemoved(spawn))
- ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), state);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddFlightPath(int32 id, FlightPathInfo* info) {
- if (m_flightPaths.count(id) > 0) {
- LogWrite(ZONE__ERROR, 0, "Zone", "Duplicate flight path (%u)", id);
- safe_delete(info);
- return;
- }
- m_flightPaths[id] = info;
- }
- void ZoneServer::AddFlightPathLocation(int32 id, FlightPathLocation* location) {
- if (m_flightPaths.count(id) == 0) {
- LogWrite(ZONE__ERROR, 0, "Zone", "There is no flight info for this route (%u)", id);
- safe_delete(location);
- return;
- }
- m_flightPathRoutes[id].push_back(location);
- }
- void ZoneServer::DeleteFlightPaths() {
- map<int32, vector<FlightPathLocation*> >::iterator itr;
- vector<FlightPathLocation*>::iterator itr2;
- map<int32, FlightPathInfo*>::iterator itr3;
- for (itr = m_flightPathRoutes.begin(); itr != m_flightPathRoutes.end(); itr++) {
- for (itr2 = itr->second.begin(); itr2 != itr->second.end(); itr2++) {
- safe_delete(*itr2);
- }
- itr->second.clear();
- }
- m_flightPathRoutes.clear();
- for (itr3 = m_flightPaths.begin(); itr3 != m_flightPaths.end(); itr3++) {
- safe_delete(itr3->second);
- }
- m_flightPaths.clear();
- }
- void ZoneServer::SendFlightPathsPackets(Client* client) {
- // Only send a packet if there are flight paths
- if (m_flightPathRoutes.size() > 0) {
- PacketStruct* packet = configReader.getStruct("WS_FlightPathsMsg", client->GetVersion());
- if (packet) {
- int32 num_routes = m_flightPaths.size();
- packet->setArrayLengthByName("number_of_routes", num_routes);
- packet->setArrayLengthByName("number_of_routes2", num_routes);
- packet->setArrayLengthByName("number_of_routes3", num_routes);
- packet->setArrayLengthByName("number_of_routes4", num_routes);
- map<int32, FlightPathInfo*>::iterator itr;
- int32 i = 0;
- for (itr = m_flightPaths.begin(); itr != m_flightPaths.end(); itr++, i++) {
- packet->setArrayDataByName("route_length", m_flightPathRoutes[itr->first].size(), i);
- packet->setArrayDataByName("ground_mount", itr->second->flying ? 0 : 1, i);
- packet->setArrayDataByName("allow_dismount", itr->second->dismount ? 1 : 0, i);
- packet->setSubArrayLengthByName("route_length2", m_flightPathRoutes[itr->first].size(), i);
- vector<FlightPathLocation*>::iterator itr2;
- int32 j = 0;
- for (itr2 = m_flightPathRoutes[itr->first].begin(); itr2 != m_flightPathRoutes[itr->first].end(); itr2++, j++) {
- packet->setSubArrayDataByName("x", (*itr2)->X, i, j);
- packet->setSubArrayDataByName("y", (*itr2)->Y, i, j);
- packet->setSubArrayDataByName("z", (*itr2)->Z, i, j);
- }
- }
- client->QueuePacket(packet->serialize());
- safe_delete(packet);
- }
- }
- }
- int32 ZoneServer::GetFlightPathIndex(int32 id) {
- int32 index = 0;
- map<int32, FlightPathInfo*>::iterator itr;
- for (itr = m_flightPaths.begin(); itr != m_flightPaths.end(); itr++, index++) {
- if (itr->first == id)
- return index;
- }
- return -1;
- }
- float ZoneServer::GetFlightPathSpeed(int32 id) {
- float speed = 1;
- if (m_flightPaths.count(id) > 0)
- speed = m_flightPaths[id]->speed;
- return speed;
- }
- void ZoneServer::ProcessSpawnConditional(int8 condition) {
- MSpawnLocationList.readlock(__FUNCTION__, __LINE__);
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- map<int32, Spawn*>::iterator itr;
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- if (itr->second != NULL) // null itr->second still coming into ProcessSpawnConditional
- {
- SpawnLocation* loc = spawn_location_list[itr->second->GetSpawnLocationID()];
- if (loc && loc->conditional > 0) {
- if ((loc->conditional & condition) != condition) {
- Despawn(itr->second, 0);
- }
- }
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- map<int32, SpawnLocation*>::iterator itr2;
- for (itr2 = spawn_location_list.begin(); itr2 != spawn_location_list.end(); itr2++) {
- SpawnLocation* loc = itr2->second;
- if (loc && loc->conditional > 0 && ((loc->conditional & condition) == condition))
- if (GetSpawnByLocationID(loc->placement_id) == NULL)
- ProcessSpawnLocation(loc);
- }
-
- MSpawnLocationList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnProximities(Spawn* newSpawn) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- MPendingSpawnListAdd.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != newSpawn) {
- if (newSpawn->GetDatabaseID())
- spawn->AddSpawnToProximity(newSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (newSpawn->GetSpawnLocationID())
- spawn->AddSpawnToProximity(newSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- if (spawn->GetDatabaseID())
- newSpawn->AddSpawnToProximity(spawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (spawn->GetSpawnLocationID())
- newSpawn->AddSpawnToProximity(spawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- }
- }
- list<Spawn*>::iterator itr2;
- for (itr2 = pending_spawn_list_add.begin(); itr2 != pending_spawn_list_add.end(); itr2++) {
- spawn = *itr2;
- if (spawn && spawn != newSpawn) {
- if (newSpawn->GetDatabaseID())
- spawn->AddSpawnToProximity(newSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (newSpawn->GetSpawnLocationID())
- spawn->AddSpawnToProximity(newSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- if (spawn->GetDatabaseID())
- newSpawn->AddSpawnToProximity(spawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (spawn->GetSpawnLocationID())
- newSpawn->AddSpawnToProximity(spawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- }
- }
- MPendingSpawnListAdd.releasereadlock(__FUNCTION__, __LINE__);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::RemoveSpawnProximities(bool spawnListLocked, Spawn* oldSpawn) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- if (!spawnListLocked)
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn != oldSpawn) {
- if (oldSpawn->GetDatabaseID())
- spawn->RemoveSpawnFromProximity(oldSpawn->GetDatabaseID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_DATABASE_ID);
- if (oldSpawn->GetSpawnLocationID())
- spawn->RemoveSpawnFromProximity(oldSpawn->GetSpawnLocationID(), Spawn::SpawnProximityType::SPAWNPROXIMITY_LOCATION_ID);
- // don't need to remove oldSpawn proximities, we clear them all out
- }
- }
- if (!spawnListLocked)
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::SetSpawnScript(SpawnEntry* entry, Spawn* spawn)
- {
- if (!entry || !spawn)
- return;
- const char* script = 0;
- for (int x = 0; x < 3; x++)
- {
- switch (x)
- {
- case 0:
- script = world.GetSpawnEntryScript(entry->spawn_entry_id);
- break;
- case 1:
- script = world.GetSpawnLocationScript(entry->spawn_location_id);
- break;
- case 2:
- script = world.GetSpawnScript(entry->spawn_id);
- break;
- }
- if (script && lua_interface && lua_interface->GetSpawnScript(script) != 0)
- {
- spawn->SetSpawnScript(string(script));
- break;
- }
- }
- }
- vector<HouseItem> ZoneServer::GetHouseItems(Client* client)
- {
- if (!client->GetCurrentZone()->GetInstanceID() || !client->HasOwnerOrEditAccess())
- return std::vector<HouseItem>();
- PacketStruct* packet = configReader.getStruct("WS_HouseItemsList", client->GetVersion());
- std::vector<HouseItem> items;
- map<int32, Spawn*>::iterator itr;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsObject() && spawn->GetPickupItemID())
- {
- HouseItem tmpItem;
- tmpItem.item_id = spawn->GetPickupItemID();
- tmpItem.unique_id = spawn->GetPickupUniqueItemID();
- tmpItem.spawn_id = spawn->GetID();
- tmpItem.item = master_item_list.GetItem(spawn->GetPickupItemID());
- if (!tmpItem.item)
- continue;
- items.push_back(tmpItem);
- }
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- return items;
- }
- void ZoneServer::SendHouseItems(Client* client)
- {
- if (!client->GetCurrentZone()->GetInstanceID() || !client->HasOwnerOrEditAccess())
- return;
- PacketStruct* packet = configReader.getStruct("WS_HouseItemsList", client->GetVersion());
- std::vector<HouseItem> items = GetHouseItems(client);
- // setting this to 1 puts it on the door widget
- packet->setDataByName("is_widget_door", 1);
- packet->setArrayLengthByName("num_items", items.size());
- for (int i = 0; i < items.size(); i++)
- {
- HouseItem tmpItem = items[i];
- packet->setArrayDataByName("unique_id", tmpItem.unique_id, i); // unique_id is in fact the item_id...
- packet->setArrayDataByName("item_name", tmpItem.item->name.c_str(), i);
- packet->setArrayDataByName("status_reduction", tmpItem.item->houseitem_info->status_rent_reduction, i);
- // location, 0 = floor, 1 = ceiling
- //packet->setArrayDataByName("location", 1, i, 0);
- // item_state int8
- // 0 = normal (cannot pick up item / move item / toggle visibility)
- // 1 = virtual (toggle visibility available, no move item)
- // 2 = hidden (cannot pick up item / move item / toggle visibility)
- // 3 = virtual/hidden/toggle visibility
- // 4 = none (cannot pick up item / move item / toggle visibility)
- // 5 = none, toggle visibility (cannot pick up item / move item)
- // 8 = none (cannot pick up item / move item / toggle visibility)
- //packet->setArrayDataByName("item_state", tmpvalue, i, 0);
- // makes it so we don't have access to move item/retrieve item
- // cannot use in conjunction with ui_tab_flag1/ui_tab_flag2
- //packet->setArrayDataByName("tradeable", 1, i);
- //packet->setArrayDataByName("item_description", "failboat", i);
- // access to move item/retrieve item, do not use in conjunction with tradeable
- packet->setArrayDataByName("ui_tab_flag1", 1, i, 0);
- packet->setArrayDataByName("ui_tab_flag2", 1, i, 0);
- // both of these can serve as description fields (only one should be used they populate the same area below the item name)
- //packet->setArrayDataByName("first_item_description", "test", i);
- //packet->setArrayDataByName("second_item_description", "Description here!", i);
- packet->setArrayDataByName("icon", tmpItem.item->details.icon, i);
- }
- EQ2Packet* pack = packet->serialize();
- client->QueuePacket(pack);
- safe_delete(packet);
- }
- Spawn* ZoneServer::GetSpawnFromUniqueItemID(int32 unique_id)
- {
- if (!GetInstanceID() || GetInstanceType() != Instance_Type::PERSONAL_HOUSE_INSTANCE)
- return nullptr;
- map<int32, Spawn*>::iterator itr;
- Spawn* spawn = 0;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- spawn = itr->second;
- if (spawn && spawn->IsObject() && spawn->GetPickupUniqueItemID() == unique_id)
- {
- Spawn* tmpSpawn = spawn;
- MSpawnList.releasereadlock();
- return tmpSpawn;
- }
- }
- MSpawnList.releasereadlock();
- return nullptr;
- }
|