12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219 |
- /*
- 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 <regex>
- #include "Commands/Commands.h"
- #include "Zone/pathfinder_interface.h"
- #include "NPC_AI.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 "Bots/Bot.h"
- #ifdef WIN32
- #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?
- #define NO_CATCH 1
- 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, bool incoming_clients) {
- incoming_clients = 0;
-
- if(incoming_clients)
- IncrementIncomingClients();
-
- MIncomingClients.SetName("ZoneServer::MIncomingClients");
- 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);
-
- pathing = nullptr;
- strcpy(zonesky_file,"");
-
- reloading = true;
- watchdogTimestamp = Timer::GetCurrentTime2();
- MPendingSpawnRemoval.SetName("ZoneServer::MPendingSpawnRemoval");
- lifetime_client_count = 0;
- }
- 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(true);
- transport_spawns.clear();
- safe_delete(tradeskillMgr);
- MMasterZoneLock->lock();
- MMasterSpawnLock.writelock(__FUNCTION__, __LINE__);
- DeleteData(true);
- RemoveLocationProximities();
- RemoveLocationGrids();
- DeleteSpawns(true);
-
- DeleteGlobalSpawns();
- DeleteFlightPaths();
- MMasterSpawnLock.releasewritelock(__FUNCTION__, __LINE__);
- MMasterZoneLock->unlock();
- 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 (pathing != nullptr)
- delete pathing;
- if (movementMgr != nullptr)
- delete movementMgr;
- // moved to the bottom as we want spawns deleted first, this used to be above Spawn deletion which is a big no no
- safe_delete(spellProcess);
- LogWrite(ZONE__INFO, 0, "Zone", "Completed zone shutdown of '%s'", zone_name);
- --numzones;
- UpdateWindowTitle(0);
- zone_list.Remove(this);
- zone_list.RemoveClientZoneReference(this);
- safe_delete(MMasterZoneLock);
- }
- void ZoneServer::IncrementIncomingClients() {
- MIncomingClients.writelock(__FUNCTION__, __LINE__);
- incoming_clients++;
- MIncomingClients.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DecrementIncomingClients() {
- MIncomingClients.writelock(__FUNCTION__, __LINE__);
- if(incoming_clients)
- incoming_clients--;
- MIncomingClients.releasewritelock(__FUNCTION__, __LINE__);
- }
- 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());
- queue_updates.Start(rule_manager.GetGlobalRule(R_Zone, SpawnUpdateTimer)->GetInt16());
- LogWrite(ZONE__DEBUG, 0, "Zone", "QueueUpdateTimer(inherits 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());
-
- world.LoadRegionMaps(zoneName);
-
- world.LoadMaps(zoneName);
-
- pathing = IPathfinder::Load(zoneName);
- movementMgr = new MobMovementManager();
- 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_create(&ZoneThread, NULL, ZoneLoop, this);
- pthread_detach(ZoneThread);
- pthread_create(&SpawnThread, NULL, SpawnLoop, this);
- pthread_detach(SpawnThread);
- #endif
- }
- void ZoneServer::CancelThreads() {
- #ifdef WIN32
- LogWrite(WORLD__ERROR, 1, "World", "Zone %s is hung, however CancelThreads is unsupported for WIN32.", GetZoneName());
- #else
- pthread_cancel(ZoneThread);
- pthread_cancel(SpawnThread);
- #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);
-
- if(spawn->IsEntity())
- ((Entity*)spawn)->RemoveSpellBonus(nullptr, true);
- }
- 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{
- RemoveSpawnSupportFunctions(spawn, true);
- 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
- 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()){
- bool dispatched = false;
- spawn->SetDeletedSpawn(true);
- if(spawn->IsBot())
- {
- ((Bot*)spawn)->Camp(true);
- dispatched = true;
- }
- else if(spawn->IsPet())
- {
- Entity* owner = ((Entity*)spawn)->GetOwner();
- if(owner)
- {
- owner->DismissPet((Entity*)spawn);
- dispatched = true;
- }
- }
-
- if(!dispatched)
- 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, true);
- 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)
- {
- // reload spirit shards for the current zone
- database.LoadSpiritShards(this);
- 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;
- spawn->SetDeletedSpawn(true);
- SendRemoveSpawn(client, spawn, packet);
- }
- }
- safe_delete(spawns);
- if(in_spawn)
- in_spawn->SetDeletedSpawn(true);
- 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__);
- }
- bool ZoneServer::PrepareSpawnID(Player* player, Spawn* spawn){
- return player->SetSpawnMap(spawn);
- }
- 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->IsReadyForSpawns()))
- 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(PrepareSpawnID(client->GetPlayer(), spawn)) {
- if (closest_spawns.count(spawn_iter->second) == 0)
- closest_spawns[spawn_iter->second] = new vector<Spawn*>();
- closest_spawns[spawn_iter->second]->push_back(spawn);
- }
- }
- }
- }
- }
- vector<Spawn*>::iterator spawn_iter2;
- map<float, vector<Spawn*>* >::iterator itr;
- for (itr = closest_spawns.begin(); itr != closest_spawns.end(); ) {
- for (spawn_iter2 = itr->second->begin(); spawn_iter2 != itr->second->end(); spawn_iter2++) {
- spawn = *spawn_iter2;
- if(!client->IsReloadingZone() || (client->IsReloadingZone() && spawn != client->GetPlayer()))
- SendSpawn(spawn, client);
-
- if (client->ShouldTarget() && client->GetCombineSpawn() == spawn)
- client->TargetSpawn(spawn);
- }
- vector<Spawn*>* vect = itr->second;
- map<float, vector<Spawn*>* >::iterator tmpitr = itr;
- itr++;
- closest_spawns.erase(tmpitr);
- safe_delete(vect);
- }
- }
- 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()->IsRemovingSpawn(spawn->GetID()) &&
- client->GetPlayer()->WasSpawnRemoved(spawn) == false &&
- (spawn_range_map.Get(client)->Get(spawn->GetID()) > REMOVE_SPAWN_DISTANCE &&
- !spawn->IsSign() && !spawn->IsObject() && !spawn->IsWidget() && !spawn->IsTransportSpawn())){
- 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::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::RemovePendingDelete(Spawn* spawn) {
- if (!spawn)
- return;
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- if (spawn_delete_list.count(spawn) > 0)
- {
- spawn_delete_list.erase(spawn);
- }
- MSpawnDeleteList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::DeleteSpawns(bool delete_all) {
- MSpawnDeleteList.writelock(__FUNCTION__, __LINE__);
- MPendingSpawnRemoval.readlock(__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){
- // we haven't removed it from the spawn list yet..
- if(!delete_all && m_pendingSpawnRemove.count(itr->first->GetID()))
- continue;
-
- spawn = itr->first;
- if (spawn && movementMgr != nullptr) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- // delete brain if it has one
- if(spawn->IsNPC()) {
- NPC* tmpNPC = (NPC*)spawn;
- if(tmpNPC->Brain())
- tmpNPC->SetBrain(nullptr);
- }
- erase_itr = itr++;
- spawn_delete_list.erase(erase_itr);
-
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- std::map<int32, Spawn*>::iterator sitr = spawn_list.find(spawn->GetID());
- if(sitr != spawn_list.end()) {
- spawn_list.erase(sitr);
- }
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
-
- safe_delete(spawn);
- }
- else
- itr++;
- }
- }
- MPendingSpawnRemoval.releasereadlock(__FUNCTION__, __LINE__);
- 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
- SetWatchdogTime(Timer::GetCurrentTime2());
- #ifndef NO_CATCH
- try
- {
- #endif
- while (zoneID == 0) { //this is loaded by world
- SetWatchdogTime(Timer::GetCurrentTime2());
- 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 Spirit Shard data...");
- database.LoadSpiritShards(this);
- LogWrite(NPC__INFO, 0, "NPC", "-Load Spirit Shard data complete!");
- 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;
- world.RemoveReloadingSubSystem("Spawns");
- }
- 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__);
- Map* zonemap = world.GetMap(std::string(GetZoneName()),0);
- while (zonemap != nullptr && zonemap->IsMapLoading())
- {
- SetWatchdogTime(Timer::GetCurrentTime2());
- // Client loop
- ClientProcess();
- Sleep(10);
- }
- 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() && connected_clients.size(true) == 0) {
- //if(lifetime_client_count)
- zoneShuttingDown = true;
- /*else { // allow up to 120 seconds then timeout
- LogWrite(ZONE__WARNING, 0, "Zone", "No clients have connected to zone '%s' and the shutdown timer has counted down -- will delay shutdown for 120 seconds.", GetZoneName());
- shutdownTimer.Start(120000, true);
- lifetime_client_count = 1;
- }*/
- }
- if (reloading_spellprocess){
- MMasterZoneLock->unlock();
- return !zoneShuttingDown;
- }
- // 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();
- world.MWorldTime.readlock(__FUNCTION__, __LINE__);
- int hour = world.GetWorldTimeStruct()->hour;
- int minute = world.GetWorldTimeStruct()->minute;
- world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
- 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();
- // 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;
- // Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them all
- ProcessSpawnRemovals();
-
- 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__);
- }
-
- // Double Check to see if there are any spawn id's that need to be removed from the spawn list, if so remove them before we replace with pending spawns
- // and also potentially further down when we delete the Spawn* in DeleteSpawns(false)
- ProcessSpawnRemovals();
- // 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__);
- if(queue_updates.Check())
- ProcessQueuedStateCommands();
- // 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(spawn, true, true, 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()) && (spawn->IsTransportSpawn() || 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) || (spawn->IsPlayer() && ((Player*)spawn)->IsFullyLoggedIn() == false))
- 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->GetInfoStruct()->get_hp_regen();
- 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_NARRATIVE, "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);
- count++;
- }
- if (!spawn)
- changed_spawns.Remove(spawn_iter->value);
- }
- vector<Client*>::iterator client_itr;
- Client* client = 0;
-
- MClientList.readlock(__FUNCTION__, __LINE__);
- if(clients.size())
- {
- for (client_itr = clients.begin(); client_itr != clients.end(); client_itr++) {
- client = *client_itr;
- if(client)
- 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())){
- 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 && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) in spawn location id %u was skipped due to a missing expansion / holiday flag being met (ZoneServer::ProcessSpawnLocation)", spawnlocation->entities[i]->spawn_id, spawnlocation->entities[i]->spawn_location_id);
- safe_delete(spawn);
- spawn = 0;
- continue;
- }
- else if (!spawn)
- {
- LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by spawn location to zone %s with location id %u, spawn id %u, spawn type %u.", GetZoneName(), spawnlocation->entities[i]->spawn_location_id, spawnlocation->entities[i]->spawn_id, spawnlocation->entities[i]->spawn_type);
- 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(spawn && spawn->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) in spawn location id %u was skipped due to a missing expansion / holiday flag being met (ZoneServer::ProcessInstanceSpawnLocation)", spawnlocation->entities[i]->spawn_id, spawnlocation->entities[i]->spawn_location_id);
- safe_delete(spawn);
- spawn = 0;
- continue;
- }
- 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, Spawn* killer){
- // this function is ran twice, first on spawn of mob, then at death of mob (gray mob check and no_drop_quest_completed_id check)
- // first we see if the skipping of gray mobs loot is enabled, then we move all non body drops
- if(killer)
- {
- int8 skip_loot_gray_mob_flag = rule_manager.GetGlobalRule(R_Loot, SkipLootGrayMob)->GetInt8();
- if(skip_loot_gray_mob_flag) {
- Player* player = 0;
- if(killer->IsPlayer())
- player = (Player*)killer;
- else if(killer->IsPet()) {
- Spawn* owner = ((Entity*)killer)->GetOwner();
- if(owner->IsPlayer())
- player = (Player*)owner;
- }
- if(player) {
- int8 difficulty = player->GetArrowColor(npc->GetLevel());
- if(difficulty == ARROW_COLOR_GRAY) {
- npc->ClearNonBodyLoot();
- }
- }
- }
- }
- // check for starting loot of Spawn and death of Spawn loot (no_drop_quest_completed_id)
- vector<int32> loot_tables = GetSpawnLootList(npc->GetDatabaseID(), GetZoneID(), npc->GetLevel(), race_types_list.GetRaceType(npc->GetModelType()), npc);
- 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 killer is assigned this is on-death, we already assigned coin
- if(!killer && 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 no killer is provided, then we are instantiating the spawn loot, quest related loot should be added on death of the spawn to check against spawn/group members
- if(drop->no_drop_quest_completed_id && killer == nullptr)
- continue;
- else if(!drop->no_drop_quest_completed_id && killer) // skip since this doesn't have a quest id attached and we are doing after-math of death loot additions
- continue;
- else if(killer && drop->no_drop_quest_completed_id) // check if the player already completed quest related to item
- {
- Player* player = nullptr;
- if(killer->IsPlayer())
- {
- player = (Player*)killer;
- // player has already completed the quest
- if(player->GetCompletedQuest(drop->no_drop_quest_completed_id) && !player->GetGroupMemberInfo())
- {
- LogWrite(PLAYER__DEBUG, 0, "Player", "%s: Player has completed quest %u, skipping loot item %u", npc->GetName(), drop->no_drop_quest_completed_id, drop->item_id);
- continue;
- }
- else if(player->GetGroupMemberInfo() && world.GetGroupManager()->HasGroupCompletedQuest(player->GetGroupMemberInfo()->group_id, drop->no_drop_quest_completed_id))
- {
- LogWrite(PLAYER__DEBUG, 0, "Player", "%s: Group %u has completed quest %u, skipping loot item %u", npc->GetName(), player->GetGroupMemberInfo()->group_id, drop->no_drop_quest_completed_id, drop->item_id);
- continue;
- }
- }
- else
- {
- LogWrite(PLAYER__DEBUG, 0, "Player", "%s: Killer is not a player, skipping loot item %u", npc->GetName(), drop->item_id);
- continue;
- }
- }
- 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 && !npc->IsOmittedByDBFlag()){
- 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);
- //devn00b add overrides for some spawns
- if(spawnentry->hp_override > 0)
- npc->SetHP(spawnentry->hp_override);
- if(spawnentry->lvl_override > 0)
- npc->SetLevel(spawnentry->lvl_override);
- if(spawnentry->mp_override > 0)
- npc->SetPower(spawnentry->mp_override);
- 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__);
- }
- bool ZoneServer::CallSpawnScript(Spawn* npc, int8 type, Spawn* spawn, const char* message, bool is_door_open, sint32 input_value, sint32* return_value){
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Enter %s", __FUNCTION__);
- if(!npc)
- return false;
- 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();
- }
- }
- }
- }
- bool result = false;
- if(lua_interface && script){
- result = true; // default to true, if we don't match a switch case, return false in default case
- 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:{
- result = 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:{
- result = lua_interface->RunSpawnScript(script, "healthchanged", npc, spawn, 0, false, input_value, return_value);
- 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;
- }
- case SPAWN_SCRIPT_USEDOOR: {
- result = lua_interface->RunSpawnScript(script, "usedoor", npc, spawn, "", is_door_open);
- break;
- }
- case SPAWN_SCRIPT_BOARD: {
- result = lua_interface->RunSpawnScript(script, "board", npc, spawn);
- break;
- }
- case SPAWN_SCRIPT_DEBOARD: {
- result = lua_interface->RunSpawnScript(script, "deboard", npc, spawn);
- break;
- }
- default:
- {
- result = false;
- break;
- }
- }
- }
- LogWrite(SPAWN__TRACE, 0, "Spawn", "Exit %s", __FUNCTION__);
- return result;
- }
- 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 && !sign->IsOmittedByDBFlag()){
- 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 && !widget->IsOmittedByDBFlag()){
- 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 && !object->IsOmittedByDBFlag()){
- 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 && !spawn->IsOmittedByDBFlag()){
- 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) {
- if(!spawn->IsPlayer()) // we already set it on loadCharacter
- spawn->SetZone(this);
- spawn->position_changed = false;
- spawn->info_changed = false;
- spawn->vis_changed = false;
- spawn->changed = false;
-
- // 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__);
-
- 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()->set_rain(rain);
- ((Player*)spawn)->SetCharSheetChanged(true);
- }
-
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->AddMob((Entity*)spawn);
- }
- AddSpawnProximities(spawn);
- spawn->SetAddedToWorldTimestamp(Timer::GetCurrentTime2());
- }
- void ZoneServer::AddClient(Client* client){
- MClientList.writelock(__FUNCTION__, __LINE__);
- lifetime_client_count++;
- DecrementIncomingClients();
- 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())
- {
- world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
- GroupMemberInfo* gmi = client->GetPlayer()->GetGroupMemberInfo();
- int32 group_id = 0;
- if (gmi) {
- group_id = gmi->group_id;
- }
- world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
- if (group_id) {
- int32 size = world.GetGroupManager()->GetGroupSize(group_id);
- if (size > 1) {
- bool send_left_message = size > 2;
- // removegroupmember can delete the gmi, so make sure we still have a group_id after
- world.GetGroupManager()->RemoveGroupMember(group_id, client->GetPlayer());
- if (send_left_message)
- world.GetGroupManager()->GroupMessage(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());
- //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());
- }
-
- ((Entity*)client->GetPlayer())->DismissAllPets();
- //}
- }
- 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)
- ((Bot*)spawn)->Camp();
- }
- LogWrite(ZONE__DEBUG, 0, "Zone", "Calling clients.Remove(client)...");
- MClientList.writelock(__FUNCTION__, __LINE__);
- std::vector<Client*>::iterator itr2 = find(clients.begin(), clients.end(), client);
- if (itr2 != clients.end())
- clients.erase(itr2);
- 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);
-
- client->GetPlayer()->DeleteSpellEffects(true);
-
- if(client->getConnection()) {
- client->getConnection()->ResetSessionAttempts();
- client->getConnection()->SetState(EQStreamState::WAIT_CLOSE);
- }
- RemoveSpawn(client->GetPlayer(), false, true, true, true, true);
- 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)
- {
- 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);
- }
- }
- void ZoneServer::ClientProcess()
- {
- if(connected_clients.size(true) == 0)
- {
- MIncomingClients.readlock(__FUNCTION__, __LINE__);
- bool shutdownDelayCheck = shutdownDelayTimer.Check();
- if((!IsCityZone() && !AlwaysLoaded() && !shutdownTimer.Enabled()) || shutdownDelayCheck)
- {
- if(incoming_clients && !shutdownDelayTimer.Enabled()) {
- LogWrite(ZONE__INFO, 0, "Zone", "Incoming clients (%u) expected for %s, delaying shutdown timer...", incoming_clients, GetZoneName());
- int32 timerDelay = rule_manager.GetGlobalRule(R_Zone, ShutdownDelayTimer)->GetInt32();
- if(timerDelay < 10) {
- LogWrite(ZONE__INFO, 0, "Zone", "Overriding %s shutdown delay timer as other clients are incoming, value %u too short, setting to 10...", GetZoneName(), timerDelay);
- timerDelay = 10;
- }
- shutdownDelayTimer.Start(timerDelay, true);
- }
- else if(!incoming_clients || shutdownDelayCheck) {
- LogWrite(ZONE__INFO, 0, "Zone", "Starting zone shutdown timer for %s...", GetZoneName());
- shutdownTimer.Start();
- }
- }
- MIncomingClients.releasereadlock(__FUNCTION__, __LINE__);
- return;
- }
- shutdownTimer.Disable();
- shutdownDelayTimer.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(client->getConnection() && client->getConnection()->HasSessionAttempts()) {
- printf("Client has an attempt to reconnect..\n");
- continue;
- }
- 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());
- }
- }
- }
- UpdateClientSpawnMap(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());
- }
- }
- UpdateClientSpawnMap(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, bool send_to_sender){
- 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() && (send_to_sender || from != client->GetPlayer()) && 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", client->GetMessageChannelColor(channel));
- if (from && ((from == client->GetPlayer()) || (client->GetPlayer()->WasSentSpawn(from->GetID()))))
- 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);
- EQ2Packet* outapp = packet->serialize();
- DumpPacket(outapp);
- client->QueuePacket(outapp);
- 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()->get_xp_vitality() < 100){
- if((client->GetPlayer()->GetInfoStruct()->get_xp_vitality() + amount) > 100)
- client->GetPlayer()->GetInfoStruct()->set_xp_vitality(100);
- else
- client->GetPlayer()->GetInfoStruct()->add_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());
- if(!client->GetPlayer()->IsSendingSpawn(spawn->GetID())) {
- safe_delete(outapp);
- }
- else {
- 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, true);
- client->GetPlayer()->SetSpawnSentState(spawn, SpawnState::SPAWN_STATE_SENT_WAIT);
- }
- /*
- 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
- */
- if(spawn->IsEntity() && spawn->HasTrapTriggered())
- client->QueueStateCommand(client->GetPlayer()->GetIDWithPlayerSpawn(spawn), spawn->GetTrapState());
- }
- 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;
- }
- Client* ZoneServer::GetClientByCharID(int32 charid) {
- Client* ret = 0;
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- if ((*itr)->GetCharacterID() == charid) {
- 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()->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()))
- 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);
- }
- }
- 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 || (client && client->GetPlayer() == spawn))
- return false;
- spawn->RemoveSpawnFromPlayer(client->GetPlayer());
- // 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->ResetData();
- packet->setDataByName("spawn_index", index);
- spawn->RemoveSpawnFromPlayer(client->GetPlayer());
- if(delete_spawn)
- packet->setDataByName("delete", 1);
-
- client->QueuePacket(packet->serialize());
- return true;
- }
- return false;*/
- return true;
- }
- 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, const 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::StopSpawnScriptTimer(Spawn* spawn, std::string functionName){
- 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(timer->spawn == spawn->GetID() && (functionName == "" || timer->function == functionName) && remove_spawn_script_timers_list.count(timer) == 0) {
- itr = spawn_script_timers.erase(itr);
- safe_delete(timer);
- }
- }
- }
- MRemoveSpawnScriptTimersList.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScriptTimers.releasewritelock(__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(remove_spawn_script_timers_list.count(timer) == 0 &&
- timer->current_count < timer->max_count && current_time >= timer->timer){
- timer->current_count++;
- SpawnScriptTimer tmpTimer;
- tmpTimer.current_count = timer->current_count;
- tmpTimer.function = timer->function;
- tmpTimer.player = timer->player;
- tmpTimer.spawn = timer->spawn;
- tmpTimer.max_count = timer->max_count;
- call_timers.push_back(tmpTimer);
- }
- 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++){
- SpawnScriptTimer tmpTimer = (SpawnScriptTimer)*itr;
- CallSpawnScript(GetSpawnByID(tmpTimer.spawn), SPAWN_SCRIPT_TIMER, tmpTimer.player > 0 ? GetSpawnByID(tmpTimer.player) : 0, tmpTimer.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(Spawn* spawn, bool delete_spawn, bool respawn, bool lock, bool erase_from_spawn_list, bool lock_spell_process)
- {
- LogWrite(ZONE__DEBUG, 3, "Zone", "Processing RemoveSpawn function for %s (%i)...", spawn->GetName(),spawn->GetID());
- 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 && (client->GetVersion() > 283 || !client->IsZoning() || client->GetPlayer() != spawn)) { //don't send destroy ghost of 283 client when zoning
- if (client->GetPlayer()->HasTarget() && client->GetPlayer()->GetTarget() == spawn)
- client->GetPlayer()->SetTarget(0);
- if(client->GetPlayer()->WasSentSpawn(spawn->GetID()) || client->GetPlayer()->IsSendingSpawn(spawn->GetID()))
- 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);
-
- spawn->RemoveSpawnProximities();
- RemoveSpawnProximities(spawn);
- if (movementMgr != nullptr && spawn->IsEntity()) {
- movementMgr->RemoveMob((Entity*)spawn);
- }
- RemoveSpawnSupportFunctions(spawn, lock_spell_process);
- 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());
-
- spawn->SetDeletedSpawn(true);
- // we will remove the spawn ptr and entry in the spawn_list later.. it is not safe right now (lua? client process? spawn process? etc? too many factors)
- if(erase_from_spawn_list)
- AddPendingSpawnRemove(spawn->GetID());
- 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());
- }
- }
- else
- {
- int32 spawnLocationID = spawn->GetSpawnLocationID();
- int32 spawnRespawnTime = spawn->GetRespawnTime();
- 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(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 != 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()))
- SendSpawnChanges(spawn, client, false, true);
- }
- else{
- client->GetCurrentZone()->SendAllSpawnsForVisChange(client);
- }
- }
- 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())) {
- SendSpawnChanges(spawn, client, false, true);
- // Attempt to slow down the packet spam sent to the client
- // who the bloody fuck put a Sleep here
- //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())) {
- 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())) {
- 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__);
- PlayerGroup* group = world.GetGroupManager()->GetGroup(player->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- deque<GroupMemberInfo*>::iterator itr;
- bool skipGrayMob = false;
-
- for (itr = members->begin(); itr != members->end(); itr++) {
- GroupMemberInfo* gmi = *itr;
- if (gmi->client) {
- Player* group_member = gmi->client->GetPlayer();
- if(group_member && group_member->GetArrowColor(victim->GetLevel()) == ARROW_COLOR_GRAY) {
- skipGrayMob = true;
- break;
- }
- }
- }
- for (itr = members->begin(); !skipGrayMob && 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_REWARD, "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);
- }
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- 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_REWARD, "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();
- bool hasfaction = database.VerifyFactionID(player->GetCharacterID(), spawn->GetFactionID());
- //if 0 they dont have an entry in the db for this faction. if one they do and we can skip it.
- if(hasfaction == 0) {
- //Find out the default for this faction
- sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(spawn->GetFactionID());
- //add the default faction for the player.
- player->SetFactionValue(spawn->GetFactionID(), defaultfaction);
- //save the character so the new default gets written to the db.
- client->Save();
- }
- 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_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_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_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_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))
- {
- bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),spawn->GetFactionID());
- if(hasfaction == 0) {
- //they do not have the faction. Lets get the default value and feed it in.
- sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(spawn->GetFactionID());
- //add the default faction for the player.
- player->SetFactionValue(spawn->GetFactionID(), defaultfaction);
- }
- update_result = player->GetFactions()->DecreaseFaction(*itr);
- faction = master_faction_list.GetFaction(*itr);
- if(faction && update_result)
- client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
- else if(faction)
- client->Message(CHANNEL_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, true);
- 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())
- {
- // add any special quest related loot (no_drop_quest_completed)
- if(dead->IsNPC() && killer && killer != dead)
- AddLoot((NPC*)dead, killer);
-
- ((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);
- ((Entity*)dead)->HandleDeathExperienceDebt(killer);
- if(client) {
- if(client->GetPlayer()->DamageEquippedItems(10, client))
- client->QueuePacket(client->GetPlayer()->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer()));
- 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()) {
- dead->SetLootCoins(0);
- dead->ClearLoot();
- }
- // If dead has loot attempt to drop a chest
- if (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_REWARD, "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);
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- if (zone_script && lua_interface)
- lua_interface->RunZoneScript(zone_script, "spawn_killed", this, dead, 0, 0, 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(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 && 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:
- if (client->GetVersion() > 546)
- packet = configReader.getStruct("WS_HearMultipleDamage", client->GetVersion());
- else
- packet = configReader.getStruct("WS_HearSimpleDamage", 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:
- if (client->GetVersion() > 546)
- packet = configReader.getStruct("WS_HearSpellDamage", client->GetVersion());
- else
- packet = configReader.getStruct("WS_HearSimpleDamage", 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) {
- if (client->GetVersion() > 546) {
- packet->setSubstructDataByName("header", "packet_type", type1);
- packet->setSubstructDataByName("header", "result_type", type2);
- packet->setDataByName("damage_type", damage_type);
- packet->setDataByName("damage", damage);
- }
- else {
- switch (type2) {
- case DAMAGE_PACKET_RESULT_MISS:
- packet->setSubstructDataByName("header", "result_type", 1);
- break;
- case DAMAGE_PACKET_RESULT_DODGE:
- packet->setSubstructDataByName("header", "result_type", 2);
- break;
- case DAMAGE_PACKET_RESULT_PARRY:
- packet->setSubstructDataByName("header", "result_type", 3);
- break;
- case DAMAGE_PACKET_RESULT_RIPOSTE:
- packet->setSubstructDataByName("header", "result_type", 4);
- break;
- case DAMAGE_PACKET_RESULT_BLOCK:
- packet->setSubstructDataByName("header", "result_type", 5);
- break;
- case DAMAGE_PACKET_RESULT_INVULNERABLE:
- packet->setSubstructDataByName("header", "result_type", 7);
- break;
- case DAMAGE_PACKET_RESULT_RESIST:
- packet->setSubstructDataByName("header", "result_type", 9);
- break;
- case DAMAGE_PACKET_RESULT_REFLECT:
- packet->setSubstructDataByName("header", "result_type", 10);
- break;
- case DAMAGE_PACKET_RESULT_IMMUNE:
- packet->setSubstructDataByName("header", "result_type", 11);
- break;
- }
- packet->setArrayLengthByName("num_dmg", 1);
- packet->setSubstructDataByName("header", "defender_proxy", client->GetPlayer()->GetIDWithPlayerSpawn(victim));
- packet->setArrayDataByName("damage_type", damage_type);
- packet->setArrayDataByName("damage", damage);
- }
- if (!attacker)
- packet->setSubstructDataByName("header", "attacker", 0xFFFFFFFF);
- else
- packet->setSubstructDataByName("header", "attacker", client->GetPlayer()->GetIDWithPlayerSpawn(attacker));
- packet->setSubstructDataByName("header", "defender", client->GetPlayer()->GetIDWithPlayerSpawn(victim));
- if (spell_name) {
- packet->setDataByName("spell", 1);
- packet->setDataByName("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 && 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 && 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, bool fizzle){
- 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()))
- continue;
- packet = configReader.getStruct(fizzle ? "WS_SpellFizzle" : "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, Spawn* caster) {
- 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) {
- if (!caster) {
- packet->setDataByName("spawn_id", 0xFFFFFFFF);
- packet->setDataByName("invoker_id", 0xFFFFFFFF);
- }
- else {
- int32 caster_id = client->GetPlayer()->GetIDWithPlayerSpawn(caster);
- packet->setDataByName("spawn_id", caster_id);
- packet->setDataByName("invoker_id", caster_id);
- }
- packet->setArrayLengthByName("num_targets", 1);
- packet->setArrayDataByName("target", client->GetPlayer()->GetIDWithPlayerSpawn(target));
- 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", 1);
- 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()->WasSentSpawn(target_id))
- 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){
- int8 count = 0;
- while (LoadingData && count <= 6000) { //sleep for max of 60 seconds (60000ms) while the maps are loading
- count++;
- Sleep(10);
- }
- count = 0;
- int16 size = 0;
- //give the spawn thread a tad bit of time to add the pending_spawns to spawn_list (up to 10 seconds)
- while (count < 1000) {
- MPendingSpawnListAdd.readlock(__FUNCTION__, __LINE__);
- size = pending_spawn_list_add.size();
- MPendingSpawnListAdd.releasereadlock(__FUNCTION__, __LINE__);
- if (size == 0)
- break;
- Sleep(10);
- count++;
- }
- 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) {
- if(spawn == client->GetPlayer() && (client->IsReloadingZone() || client->GetPlayer()->IsReturningFromLD()))
- {
- if(!client->GetPlayer()->SetSpawnMap(spawn))
- continue;
- }
-
- 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;
- }
- ZoneInfoSlideStruct* ZoneServer::GenerateSlideStruct(float unknown1a, float unknown1b, int32 unknown2a, int32 unknown2b, int32 unknown3, int32 unknown4, const char* slide, const char* voiceover, int32 key1, int32 key2) {
- ZoneInfoSlideStructInfo* info = new ZoneInfoSlideStructInfo();
- memset(info, 0, sizeof(ZoneInfoSlideStructInfo));
- info->unknown1[0] = unknown1a;
- info->unknown1[1] = unknown1b;
- info->unknown2[0] = unknown2a;
- info->unknown2[1] = unknown2b;
- info->unknown3 = unknown3;
- info->unknown4 = unknown4;
- int8 length = strlen(slide);
- if (length >= 128)
- length = 127;
- strncpy(info->slide, slide, length);
- length = strlen(voiceover);
- if (length >= 128)
- length = 127;
- strncpy(info->voiceover, voiceover, length);
- info->key1 = key1;
- info->key2 = key2;
- ZoneInfoSlideStruct* ret = new ZoneInfoSlideStruct();
- ret->info = info;
- return ret;
- }
- void ZoneServer::AddZoneInfoSlideStructTransitionInfo(ZoneInfoSlideStruct* info, int32 x, int32 y, float zoom, float transition_time) {
- ZoneInfoSlideStructTransitionInfo* transition_info = new ZoneInfoSlideStructTransitionInfo();
- transition_info->transition_x = x;
- transition_info->transition_y = y;
- transition_info->transition_zoom = zoom;
- transition_info->transition_time = transition_time;
- info->slide_transition_info.push_back(transition_info);
- }
- vector<ZoneInfoSlideStruct*>* ZoneServer::GenerateTutorialSlides() {
- vector<ZoneInfoSlideStruct*>* slides = new vector<ZoneInfoSlideStruct*>();
- ZoneInfoSlideStruct* slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt01_final001.dds", "voiceover/english/antonia_intro/antonia_intro_001_64.mp3", 2519553957, 1010319376);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.5, 16);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt02_final001.dds", "voiceover/english/antonia_intro/antonia_intro_002_64.mp3", 567178266, 3055063399);
- AddZoneInfoSlideStructTransitionInfo(slide, 600, 365, 1.60000002384186, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 800, 370, 1.39999997615814, 9);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.20000004768372, 8);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt03_final001.dds", "voiceover/english/antonia_intro/antonia_intro_003_64.mp3", 3171561318, 593374281);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.20000004768372, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 750, 320, 1.60000002384186, 10);
- AddZoneInfoSlideStructTransitionInfo(slide, 575, 265, 2.29999995231628, 10);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt04_final001.dds", "voiceover/english/antonia_intro/antonia_intro_004_64.mp3", 1959944485, 4285605574);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 2.5, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 420, 1.70000004768372, 8);
- AddZoneInfoSlideStructTransitionInfo(slide, 675, 390, 2.20000004768372, 11);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt05_final001.dds", "voiceover/english/antonia_intro/antonia_intro_005_64.mp3", 609693392, 260295215);
- AddZoneInfoSlideStructTransitionInfo(slide, 750, 500, 2.79999995231628, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 720, 300, 2.5, 9);
- AddZoneInfoSlideStructTransitionInfo(slide, 975, 270, 2.20000004768372, 9);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt06_final001.dds", "voiceover/english/antonia_intro/antonia_intro_006_64.mp3", 3056613203, 775201556);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.89999997615814, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 475, 1, 24);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt07_final001.dds", "voiceover/english/antonia_intro/antonia_intro_007_64.mp3", 3113327662, 1299367895);
- AddZoneInfoSlideStructTransitionInfo(slide, 1400, 420, 2.40000009536743, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 1200, 375, 1.70000004768372, 7);
- AddZoneInfoSlideStructTransitionInfo(slide, 800, 225, 2.29999995231628, 7);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt08_final001.dds", "voiceover/english/antonia_intro/antonia_intro_008_64.mp3", 2558791235, 2674773065);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1.5, 27);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt09_final001.dds", "voiceover/english/antonia_intro/antonia_intro_009_64.mp3", 4029296401, 1369011033);
- AddZoneInfoSlideStructTransitionInfo(slide, 715, 305, 2.40000009536743, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 730, 325, 1.79999995231628, 6);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 395, 1.5, 5);
- AddZoneInfoSlideStructTransitionInfo(slide, 1360, 330, 1.79999995231628, 9);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt10_final001.dds", "voiceover/english/antonia_intro/antonia_intro_010_64.mp3", 3055524517, 3787058332);
- AddZoneInfoSlideStructTransitionInfo(slide, 670, 675, 2.20000004768372, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 710, 390, 1.79999995231628, 7);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 415, 1.60000002384186, 5.5);
- AddZoneInfoSlideStructTransitionInfo(slide, 1250, 675, 1.79999995231628, 8);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt11_final001.dds", "voiceover/english/antonia_intro/antonia_intro_011_64.mp3", 3525586740, 812068950);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 2, 19);
- slides->push_back(slide);
- slide = GenerateSlideStruct(0.5, 0.5, 15, 15, 1842, 1012, "images/slideshows/boat_06p_tutorial02/lore_chapt12_final001.dds", "voiceover/english/antonia_intro/antonia_intro_012_64.mp3", 3493874350, 2037661816);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 2, 0);
- AddZoneInfoSlideStructTransitionInfo(slide, 920, 495, 1, 43);
- slides->push_back(slide);
- return slides;
- }
- EQ2Packet* ZoneServer::GetZoneInfoPacket(Client* client){
- // this takes place when we get the LoginInfo for returning LD players
- if(!client->GetPlayer()->IsReturningFromLD())
- UpdateClientSpawnMap(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());
- if ((GetZoneFile() && strcmp("boat_06p_tutorial02", GetZoneFile()) == 0) && client->GetPlayer()->GetX() == this->GetSafeX() && client->GetPlayer()->GetY() == this->GetSafeY() && client->GetPlayer()->GetZ() == this->GetSafeZ()) { //basically the only time the player will see this is if their zone in coords are the exact same as the safe coords (they haven't moved)
- vector<ZoneInfoSlideStruct*>* slides = GenerateTutorialSlides();
- if (slides) {
- packet->setArrayLengthByName("num_slides", slides->size());
- ZoneInfoSlideStruct* slide = 0;
- for (int8 i = 0; i < slides->size(); i++) {
- slide = slides->at(i);
- packet->setArrayDataByName("unknown1", slide->info->unknown1[0], i, 0);
- packet->setArrayDataByName("unknown1", slide->info->unknown1[1], i, 1);
- packet->setArrayDataByName("unknown2", slide->info->unknown2[0], i, 0);
- packet->setArrayDataByName("unknown2", slide->info->unknown2[1], i, 1);
- packet->setArrayDataByName("unknown3", slide->info->unknown3, i);
- packet->setArrayDataByName("unknown4", slide->info->unknown4, i);
- packet->setArrayDataByName("slide", slide->info->slide, i);
- packet->setArrayDataByName("voiceover", slide->info->voiceover, i);
- packet->setArrayDataByName("key1", slide->info->key1, i);
- packet->setArrayDataByName("key2", slide->info->key2, i);
- packet->setSubArrayLengthByName("num_transitions", slide->slide_transition_info.size(), i);
- for (int8 x = 0; x < slide->slide_transition_info.size(); x++) {
- packet->setSubArrayDataByName("transition_x", slide->slide_transition_info[x]->transition_x, i, x);
- packet->setSubArrayDataByName("transition_y", slide->slide_transition_info[x]->transition_y, i, x);
- packet->setSubArrayDataByName("transition_zoom", slide->slide_transition_info[x]->transition_zoom, i, x);
- packet->setSubArrayDataByName("transition_time", slide->slide_transition_info[x]->transition_time, i, x);
- safe_delete(slide->slide_transition_info[x]);
- }
- safe_delete(slide->info);
- safe_delete(slide);
- }
- }
- safe_delete(slides);
- }
- packet->setDataByName("underworld", underworld);
-
- // 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;
- }
- QueueDefaultCommand(spawn->GetID(), std::string(command), distance);
- if (strlen(command)>0)
- spawn->SetPrimaryCommand(command, command, distance);
- }
- 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, bool call_expire_function, bool lock_spell_process){
- if(spellProcess)
- spellProcess->RemoveSpellTimersFromSpawn(spawn, remove_all, delete_recast, call_expire_function, lock_spell_process);
- }
- 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, LuaSpell* customSpell, int16 custom_cast_time, bool in_heroic_opp){
- if(spellProcess)
- spellProcess->ProcessSpell(this, spell, caster, target, lock, harvest_spell, customSpell, custom_cast_time, in_heroic_opp);
- }
- void ZoneServer::ProcessEntityCommand(EntityCommand* entity_command, Entity* caster, Spawn* target, bool lock) {
- if (target && target->GetSpawnScript()) {
- Player* player = 0;
- if (caster && caster->IsPlayer())
- player = (Player*)caster;
- CallSpawnScript(target, SPAWN_SCRIPT_CUSTOM, player, entity_command->command.c_str());
- }
- if (spellProcess)
- spellProcess->ProcessEntityCommand(this, entity_command, caster, target, lock);
- }
- void ZoneServer::RemoveSpawnSupportFunctions(Spawn* spawn, bool lock_spell_process) {
- if(!spawn)
- return;
- LogWrite(ZONE__DEBUG, 7, "Zone", "Processing RemoveSpawnSupportFunctions...");
- if(spawn->IsPlayer() && spawn->GetZone())
- spawn->GetZone()->RemovePlayerPassenger(((Player*)spawn)->GetCharacterID());
- if(spawn->IsEntity())
- RemoveSpellTimersFromSpawn((Entity*)spawn, true, true, true, lock_spell_process);
- 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());
- }
- 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* origEmote = visual_states.FindEmote(name, originator->GetVersion());
- if(!origEmote){
- 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;
- }
- Emote* emote = origEmote;
- PacketStruct* packet = 0;
- char* emoteResponse = 0;
- vector<Client*>::iterator client_itr;
-
- int32 cur_client_version = originator->GetVersion();
- map<int32, Emote*> emote_version_range;
- 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;
- // establish appropriate emote for the version used by the client
- if (client->GetVersion() != originator->GetVersion())
- {
- map<int32, Emote*>::iterator rangeitr = emote_version_range.find(client->GetVersion());
- if (rangeitr == emote_version_range.end())
- {
- Emote* tmp_new_emote = visual_states.FindEmote(name, client->GetVersion());
- if (tmp_new_emote)
- {
- emote_version_range.insert(make_pair(client->GetVersion(), tmp_new_emote));
- emote = tmp_new_emote;
- } // else its missing just use the current clients default
- }
- else // we have an existing emote already cached
- emote = rangeitr->second;
- }
- else // since the client and originator client match use the original emote
- emote = origEmote;
- 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() && 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::FindSpawn(Client* client, char* regSearchStr)
- {
- if (!regSearchStr || strlen(regSearchStr) < 1)
- {
- client->SimpleMessage(CHANNEL_COLOR_RED, "Bad ZoneServer::FindSpawn(Client*, char* regSearchStr) attempt, regSearchStr is NULL or empty.");
- return;
- }
- string resString = string(regSearchStr);
- try
- {
- std::regex pre_re_check("^[a-zA-Z0-9_ ]+$");
- bool output = std::regex_match(resString, pre_re_check);
- if (output)
- {
- string newStr(".*");
- newStr.append(regSearchStr);
- newStr.append(".*");
- resString = newStr;
- }
- }
- catch (...)
- {
- client->SimpleMessage(CHANNEL_COLOR_RED, "Try/Catch ZoneServer::FindSpawn(Client*, char* regSearchStr) failure.");
- return;
- }
- client->Message(CHANNEL_NARRATIVE, "RegEx Search Spawn List: %s", regSearchStr);
- client->Message(CHANNEL_NARRATIVE, "Database ID | Spawn Name | X , Y , Z");
- client->Message(CHANNEL_NARRATIVE, "========================");
- map<int32, Spawn*>::iterator itr;
- MSpawnList.readlock(__FUNCTION__, __LINE__);
- int32 spawnsFound = 0;
- std::regex re(resString, std::regex_constants::icase);
- for (itr = spawn_list.begin(); itr != spawn_list.end(); itr++) {
- Spawn* spawn = itr->second;
- if (!spawn || !spawn->GetName())
- continue;
- bool output = false;
- try {
- output = std::regex_match(string(spawn->GetName()), re);
- }
- catch (...)
- {
- continue;
- }
- if (output)
- {
- client->Message(CHANNEL_NARRATIVE, "%i | %s | %f , %f , %f", spawn->GetDatabaseID(), spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
- spawnsFound++;
- }
- }
- client->Message(CHANNEL_NARRATIVE, "========================", spawnsFound);
- client->Message(CHANNEL_NARRATIVE, "%u Results Found.", spawnsFound);
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- 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;
- PlayerGroup* group = world.GetGroupManager()->GetGroup(killer->GetGroupMemberInfo()->group_id);
- if (group)
- {
- group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
- deque<GroupMemberInfo*>* members = group->GetMembers();
- 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());
- }
- }
- }
- group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
- }
- 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);
- if (client->GetVersion() > 546)
- 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 (current_client->GetVersion() <= 546)
- continue;
- if (!(packet = configReader.getStruct("WS_UpdateTitle", current_client->GetVersion())))
- continue;
- 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());
- spawn->SetTransportSpawn(true);
- 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;
- }
- Spawn* ZoneServer::GetTransportByRailID(sint64 rail_id){
- Spawn* spawn = 0;
- Spawn* closest_spawn = 0;
- MTransportSpawns.readlock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr = transport_spawns.begin();
- while(itr != transport_spawns.end()){
- spawn = GetSpawnByID(*itr);
- //printf("Rail id: %i vs %i\n", spawn ? spawn->GetRailID() : 0, rail_id);
- if(spawn && spawn->GetRailID() == rail_id){
- closest_spawn = spawn;
- break;
- }
- itr++;
- }
- MTransportSpawns.releasereadlock(__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()->set_rain(val);
- client->GetPlayer()->SetCharSheetChanged(true);
- if( val >= 0.75 && !weather_signaled )
- {
- client->SimpleMessage(CHANNEL_NARRATIVE, "It starts to rain.");
- }
- else if( val < 0.75 && weather_signaled )
- {
- client->SimpleMessage(CHANNEL_NARRATIVE, "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()->set_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;
- int32 packet_version = 0;
- MutexList<Client*>::iterator itr = connected_clients.begin();
- while (itr->Next()) {
- client = itr->value;
- player = client->GetPlayer();
- if (player->WasSentSpawn(spawn->GetID())) {
- if (!packet || packet_version != client->GetVersion()) {
- safe_delete(packet);
- packet_version = client->GetVersion();
- packet = configReader.getStruct("WS_DestroyGhostCmd", packet_version);
- }
- 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);
- }
- }
- safe_delete(packet);
- }
- 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::GetSpawnsByRailID(sint64 rail_id) {
- vector<Spawn*> tmp_list;
- Spawn* spawn;
- MTransportSpawns.readlock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr = transport_spawns.begin();
- while(itr != transport_spawns.end()){
- spawn = GetSpawnByID(*itr);
- if(spawn && spawn->GetRailID() == rail_id){
- tmp_list.push_back(spawn);
- }
- itr++;
- }
- MTransportSpawns.releasereadlock(__FUNCTION__, __LINE__);
- return tmp_list;
- }
- void ZoneServer::RemovePlayerPassenger(int32 char_id) {
- vector<Spawn*> tmp_list;
- Spawn* spawn;
- MTransportSpawns.readlock(__FUNCTION__, __LINE__);
- vector<int32>::iterator itr = transport_spawns.begin();
- while(itr != transport_spawns.end()){
- spawn = GetSpawnByID(*itr);
- if(spawn) {
- spawn->RemoveRailPassenger(char_id);
- }
- itr++;
- }
- MTransportSpawns.releasereadlock(__FUNCTION__, __LINE__);
- }
- 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){
- heal_amt = caster->CalculateHealAmount(spawn, heal_amt, crit_mod, &crit);
- power_amt = caster->CalculateHealAmount(spawn, power_amt, crit_mod, &crit);
- }
- //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_NARRATIVE, "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 && 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->IsEntity())
- ((Entity*)spawn)->DismissAllPets();
- }
- MSpawnList.releasereadlock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::RemoveTargetFromSpell(LuaSpell* spell, Spawn* target, bool remove_caster){
- if (spellProcess)
- spellProcess->RemoveTargetFromSpell(spell, target, remove_caster);
- }
- 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(...) {
- zs->spawnthread_active = false;
- zs->initial_spawn_threads_active = 0;
- 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());
- throw;
- }
- throw;
- }
- #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->IsOmittedByDBFlag())
- {
- LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", id);
- safe_delete(ret);
- ret = 0;
- }
- 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, Spawn* spawn) {
- vector<int32> ret;
- int32 returnValue = 0;
- 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;
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- returnValue = 0; // reset since this can override the database setting
- if(zone_script)
- {
- if(lua_interface->RunZoneScriptWithReturn(zone_script, "loot_criteria_level", spawn->GetZone(), spawn, loot->table_id, loot->minLevel, loot->maxLevel, &returnValue) && returnValue == 0)
- continue;
- }
- bool entryAdded = false;
- if (loot->minLevel == 0 && loot->maxLevel == 0 && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- }
-
- if(!entryAdded && returnValue) // DB override via LUA scripting
- 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;
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- returnValue = 0; // reset since this can override the database setting
- if(zone_script)
- {
- if(lua_interface->RunZoneScriptWithReturn(zone_script, "loot_criteria_racial", spawn->GetZone(), spawn, loot->table_id, loot->minLevel, loot->maxLevel, &returnValue) && returnValue == 0)
- continue;
- }
- bool entryAdded = false;
- if (loot->minLevel == 0 && loot->maxLevel == 0 && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- }
- if(!entryAdded && returnValue) // DB override via LUA scripting
- 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;
- const char* zone_script = world.GetZoneScript(this->GetZoneID());
- returnValue = 0; // reset since this can override the database setting
- if(zone_script)
- {
- if(lua_interface->RunZoneScriptWithReturn(zone_script, "loot_criteria_zone", spawn->GetZone(), spawn, loot->table_id, loot->minLevel, loot->maxLevel, &returnValue) && returnValue == 0)
- continue;
- }
- bool entryAdded = false;
- if (loot->minLevel == 0 && loot->maxLevel == 0 && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- else {
- if (spawn_level >= loot->minLevel && spawn_level <= loot->maxLevel && (!loot->loot_tier || spawn->GetLootTier() >= loot->loot_tier) && (entryAdded = true)) // successful plan to add set entryAdded to true
- ret.push_back(loot->table_id);
- }
- if(!entryAdded && returnValue) // DB override via LUA scripting
- 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;
- world.SetReloadingSubsystem("Spawns");
- // 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()))
- 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__);
- }
- // we only call this inside a write lock
- void ZoneServer::RemoveSpawnProximities(Spawn* oldSpawn) {
- Spawn* spawn = 0;
- map<int32, Spawn*>::iterator itr;
- 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
- }
- }
- }
- 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;
- }
- void ZoneServer::AddPendingSpawnRemove(int32 id)
- {
- MPendingSpawnRemoval.writelock(__FUNCTION__, __LINE__);
- m_pendingSpawnRemove.insert(make_pair(id,true));
- MPendingSpawnRemoval.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::ProcessSpawnRemovals()
- {
- MSpawnList.writelock(__FUNCTION__, __LINE__);
- MPendingSpawnRemoval.writelock(__FUNCTION__, __LINE__);
- if (m_pendingSpawnRemove.size() > 0) {
- map<int32,bool>::iterator itr2;
- for (itr2 = m_pendingSpawnRemove.begin(); itr2 != m_pendingSpawnRemove.end(); itr2++)
- spawn_list.erase(itr2->first);
- m_pendingSpawnRemove.clear();
- }
- MPendingSpawnRemoval.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnList.releasewritelock(__FUNCTION__, __LINE__);
- }
- void ZoneServer::AddSpawnToGroup(Spawn* spawn, int32 group_id)
- {
- if( spawn->GetSpawnGroupID() > 0 )
- spawn->RemoveSpawnFromGroup();
- MutexList<int32>* groupList = &spawn_group_map.Get(group_id);
- MutexList<int32>::iterator itr2 = groupList->begin();
-
- while(itr2.Next())
- {
- Spawn* groupSpawn = GetSpawnByID(itr2.value);
- if(groupSpawn)
- {
- // found existing group member to add it in
- spawn->AddSpawnToGroup(groupSpawn);
- break;
- }
- }
- groupList->Add(spawn->GetID());
- spawn->SetSpawnGroupID(group_id);
- }
- void ZoneServer::QueueStateCommandToClients(int32 spawn_id, int32 state)
- {
- if(spawn_id < 1)
- return;
- MLuaQueueStateCmd.lock();
- lua_queued_state_commands.insert(make_pair(spawn_id, state));
- MLuaQueueStateCmd.unlock();
- }
- void ZoneServer::QueueDefaultCommand(int32 spawn_id, std::string command, float distance)
- {
- if(spawn_id < 1)
- return;
- MLuaQueueStateCmd.lock();
- lua_spawn_update_command[spawn_id].insert(make_pair(command,distance));
- MLuaQueueStateCmd.unlock();
- }
- void ZoneServer::ProcessQueuedStateCommands() // in a client list lock only
- {
- vector<Client*>::iterator itr;
- MLuaQueueStateCmd.lock();
- if(lua_queued_state_commands.size() > 0)
- {
- std::map<int32, int32>::iterator statecmds;
- for(statecmds = lua_queued_state_commands.begin(); statecmds != lua_queued_state_commands.end(); statecmds++)
- {
- Spawn* spawn = GetSpawnByID(statecmds->first, false);
- if(!spawn)
- continue;
-
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- if (client && client->GetPlayer()->WasSentSpawn(spawn->GetID()))
- ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), statecmds->second);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- lua_queued_state_commands.clear();
- }
- if(lua_spawn_update_command.size() > 0)
- {
- std::map<int32, std::map<std::string,float>>::iterator updatecmds;
- for(updatecmds = lua_spawn_update_command.begin(); updatecmds != lua_spawn_update_command.end(); updatecmds++)
- {
- Spawn* spawn = GetSpawnByID(updatecmds->first, false);
- if(!spawn)
- continue;
-
- std::map<std::string,float>::iterator innermap;
- for(innermap = lua_spawn_update_command[updatecmds->first].begin(); innermap != lua_spawn_update_command[updatecmds->first].end(); innermap++)
- {
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- if (client && client->GetPlayer()->WasSentSpawn(spawn->GetID()))
- client->SendDefaultCommand(spawn, innermap->first.c_str(), innermap->second);
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
- lua_spawn_update_command[updatecmds->first].clear();
- }
- lua_spawn_update_command.clear();
- }
- MLuaQueueStateCmd.unlock();
- }
- void ZoneServer::UpdateClientSpawnMap(Player* player, Client* client)
- {
- // client may be null when passed
- client_spawn_map.Put(player, client);
- }
- void ZoneServer::RemoveClientsFromZone(ZoneServer* zone) {
- vector<Client*>::iterator itr;
- MClientList.readlock(__FUNCTION__, __LINE__);
- for (itr = clients.begin(); itr != clients.end(); itr++) {
- Client* client = *itr;
- if(client->GetCurrentZone() == zone) {
- client->SetCurrentZone(nullptr);
- }
- if(client->GetZoningDestination() == zone) {
- client->SetZoningDestination(nullptr);
- }
- }
- MClientList.releasereadlock(__FUNCTION__, __LINE__);
- }
|