client.cpp 336 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "../common/debug.h"
  17. #include "../common/Log.h"
  18. #include <iostream>
  19. #include <iomanip>
  20. #include <string.h>
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <math.h>
  24. #include <zlib.h>
  25. #include <assert.h>
  26. #include <algorithm>
  27. #include "Player.h"
  28. #include "Commands/Commands.h"
  29. #include "ClientPacketFunctions.h"
  30. #include "../common/ConfigReader.h"
  31. #include "Guilds/Guild.h"
  32. #include "Variables.h"
  33. #include "Rules/Rules.h"
  34. #include "Titles.h"
  35. #include "IRC/IRC.h"
  36. #include "Chat/Chat.h"
  37. #include "SpellProcess.h"
  38. #include "Zone/ChestTrap.h"
  39. //#include "Quests.h"
  40. #ifdef WIN32
  41. #include <WinSock2.h>
  42. #include <windows.h>
  43. #define snprintf _snprintf
  44. #define vsnprintf _vsnprintf
  45. #define strncasecmp _strnicmp
  46. #define strcasecmp _stricmp
  47. #else
  48. #include <sys/socket.h>
  49. #ifdef FREEBSD
  50. #include <sys/types.h>
  51. #endif
  52. #include <netinet/in.h>
  53. #include <arpa/inet.h>
  54. #include <unistd.h>
  55. #endif
  56. #if defined(__GNUC__)
  57. #define _snprintf snprintf
  58. #endif
  59. #include "client.h"
  60. #include "../common/emu_opcodes.h"
  61. #include "../common/packet_dump.h"
  62. #include "WorldDatabase.h"
  63. #include "races.h"
  64. #include "classes.h"
  65. #include "LoginServer.h"
  66. #include "World.h"
  67. #include "../common/EQ2_Common_Structs.h"
  68. #include "net.h"
  69. #include "../common/MiscFunctions.h"
  70. #include "Skills.h"
  71. #include "LuaInterface.h"
  72. #include "Quests.h"
  73. #include "Collections/Collections.h"
  74. #include "Achievements/Achievements.h"
  75. #include "Traits/Traits.h"
  76. #include "Recipes/Recipe.h"
  77. #include "Tradeskills/Tradeskills.h"
  78. #include "AltAdvancement/AltAdvancement.h"
  79. #include "Bots/Bot.h"
  80. extern WorldDatabase database;
  81. extern const char* ZONE_NAME;
  82. extern LoginServer loginserver;
  83. extern sint32 numclients;
  84. extern NetConnection net;
  85. extern Commands commands;
  86. extern ClientList client_list;
  87. extern ZoneList zone_list;
  88. extern ZoneAuth zone_auth;
  89. extern MasterItemList master_item_list;
  90. extern MasterSkillList master_skill_list;
  91. extern MasterSpellList master_spell_list;
  92. extern MasterTraitList master_trait_list;
  93. extern MasterQuestList master_quest_list;
  94. extern MasterFactionList master_faction_list;
  95. extern MasterRecipeList master_recipe_list;
  96. extern volatile bool RunLoops;
  97. extern ConfigReader configReader;
  98. extern LuaInterface* lua_interface;
  99. extern World world;
  100. extern Variables variables;
  101. extern Classes classes;
  102. extern Races races;
  103. extern GuildList guild_list;
  104. extern MasterCollectionList master_collection_list;
  105. extern MasterAchievementList master_achievement_list;
  106. extern RuleManager rule_manager;
  107. extern IRC irc;
  108. extern Chat chat;
  109. extern MasterAAList master_aa_list;
  110. extern MasterAAList master_tree_nodes;
  111. extern ChestTrapList chest_trap_list;
  112. using namespace std;
  113. Client::Client(EQStream* ieqs) : pos_update(125), quest_pos_timer(2000), lua_debug_timer(30000), delayTimer(500), transmuteID(0) {
  114. eqs = ieqs;
  115. ip = eqs->GetrIP();
  116. port = ntohs(eqs->GetrPort());
  117. merchant_transaction = nullptr;
  118. SetMailTransaction(nullptr);
  119. timestamp_flag = 0;
  120. current_quest_id = 0;
  121. last_update_time = 0;
  122. quest_updates = false;
  123. //autobootup_timeout = new Timer(10000);
  124. //autobootup_timeout->Disable();
  125. CLE_keepalive_timer = new Timer(15000);
  126. connect = new Timer(1000);
  127. connect->Disable();
  128. zoneID = 0;
  129. account_name[0] = 0;
  130. character_id = 0;
  131. account_id = 0;
  132. pwaitingforbootup = 0;
  133. current_zone = 0;
  134. connected_to_zone = false;
  135. connected = false;
  136. camp_timer = 0;
  137. disconnect_timer = 0;
  138. client_zoning = false;
  139. player_pos_changed = false;
  140. ++numclients;
  141. if (world.GetServerStatisticValue(STAT_SERVER_MOST_CONNECTIONS) < numclients)
  142. world.UpdateServerStatistic(STAT_SERVER_MOST_CONNECTIONS, numclients, true);
  143. remove_from_list = false;
  144. new_client_login = false;
  145. UpdateWindowTitle(0);
  146. num_active_failures = 0;
  147. player = new Player();
  148. player->SetClient(this);
  149. combine_spawn = 0;
  150. lua_debug = false;
  151. ready_for_spawns = false;
  152. ready_for_updates = false;
  153. lua_debug_timer.Disable();
  154. transport_spawn = 0;
  155. MBuyBack.SetName("Client::MBuyBack");
  156. MPendingQuestAccept.SetName("Client::MPendingQuestAccept");
  157. MDeletePlayer.SetName("Client::MDeletePlayer");
  158. MQuestPendingUpdates.SetName("Client::MQuestPendingUpdates");
  159. search_items = 0;
  160. version = 0;
  161. next_conversation_id = 0;
  162. pending_guild_invite.guild = 0;
  163. pending_guild_invite.invited_by = 0;
  164. m_recipeListSent = false;
  165. m_resurrect.SetName("Client::m_resurrect");
  166. current_rez.expire_timer = 0;
  167. current_rez.should_delete = true;
  168. pending_last_name = 0;
  169. should_target = false;
  170. initial_spawns_sent = false;
  171. MQuestTimers.SetName("Client::quest_timers");
  172. memset(&incoming_paperdoll, 0, sizeof(incoming_paperdoll));
  173. on_auto_mount = false;
  174. should_load_spells = true;
  175. spawnPlacementMode = ServerSpawnPlacementMode::DEFAULT;
  176. delayedLogin = false;
  177. delayedAccountID = 0;
  178. delayedAccessKey = 0;
  179. delayTimer.Disable();
  180. tempPlacementSpawn = nullptr;
  181. placement_unique_item_id = 0;
  182. SetHasOwnerOrEditAccess(false);
  183. temporary_transport_id = 0;
  184. rejoin_group_id = 0;
  185. }
  186. Client::~Client() {
  187. if (current_zone && player) {
  188. if (player->GetGroupMemberInfo())
  189. {
  190. if ((player->GetActivityStatus() & ACTIVITY_STATUS_LINKDEAD) > 0)
  191. world.GetGroupManager()->RemoveGroupMember(player->GetGroupMemberInfo()->group_id, player);
  192. else
  193. TempRemoveGroup();
  194. }
  195. world.GetGroupManager()->ClearPendingInvite(player);
  196. }
  197. if (lua_interface)
  198. lua_interface->RemoveDebugClients(this);
  199. if (player)
  200. zone_list.RemoveClientFromMap(player->GetName(), this);
  201. //let the stream factory know were done with this stream
  202. if (eqs) {
  203. eqs->Close();
  204. try {
  205. eqs->ReleaseFromUse();
  206. }
  207. catch (...) {}
  208. }
  209. eqs = NULL;
  210. //safe_delete(autobootup_timeout);
  211. safe_delete(disconnect_timer);
  212. safe_delete(camp_timer);
  213. safe_delete(CLE_keepalive_timer);
  214. safe_delete(connect);
  215. --numclients;
  216. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  217. if (player && !player->GetPendingDeletion())
  218. safe_delete(player);
  219. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  220. safe_delete(search_items);
  221. safe_delete(current_rez.expire_timer);
  222. safe_delete(pending_last_name);
  223. safe_delete_array(incoming_paperdoll.image_bytes);
  224. if (GetTempPlacementSpawn())
  225. {
  226. Spawn* tmp = GetTempPlacementSpawn();
  227. delete tmp;
  228. SetTempPlacementSpawn(nullptr);
  229. }
  230. UpdateWindowTitle(0);
  231. }
  232. void Client::QueuePacket(EQ2Packet* app, bool attemptedCombine) {
  233. if (eqs) {
  234. if (!eqs->CheckActive()) {
  235. client_list.Remove(this);
  236. eqs = 0;
  237. }
  238. }
  239. if (app && eqs && version > 0)
  240. eqs->EQ2QueuePacket(app, attemptedCombine);
  241. else {
  242. safe_delete(app);
  243. }
  244. }
  245. void Client::PopulateSkillMap() {
  246. EQ2Packet* app = master_skill_list.GetPopulateSkillsPacket(GetVersion());
  247. if (app)
  248. QueuePacket(app);
  249. else {
  250. LogWrite(WORLD__ERROR, 0, "World", "Unable to send populate skills packet for version: %i!", GetVersion());
  251. Disconnect(); //the client cant proceed without the skill packet, might as well kick it now
  252. }
  253. }
  254. void Client::SendLoginInfo() {
  255. if (firstlogin) {
  256. LogWrite(WORLD__DEBUG, 0, "World", "Increment Server_Accepted_Connection + 1");
  257. world.UpdateServerStatistic(STAT_SERVER_ACCEPTED_CONNECTION, 1);
  258. LogWrite(CCLIENT__DEBUG, 0, "Client", "Populate Skill Map...");
  259. PopulateSkillMap();
  260. // JA: Check client version and move player to valid zone if current client does not support last saved zone (loading SF client on DoV saved zone) IT CAN HAPPEN!
  261. LogWrite(MISC__TODO, 1, "TODO", "Check client version at login, move char if invalid zone file");
  262. }
  263. LogWrite(CCLIENT__DEBUG, 0, "Client", "Toggle Character Online...");
  264. database.ToggleCharacterOnline(this, 1);
  265. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Skills for player '%s'...", player->GetName());
  266. int32 count = database.LoadCharacterSkills(GetCharacterID(), player);
  267. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Character Spells for player '%s'...", player->GetName());
  268. count = database.LoadCharacterSpells(GetCharacterID(), player);
  269. // get the latest character starting skills / spells, may have been updated after character creation
  270. world.SyncCharacterAbilities(this);
  271. count = database.LoadCharacterTitles(GetCharacterID(), player);
  272. if (count == 0) {
  273. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character titles found!");
  274. LogWrite(CCLIENT__DEBUG, 0, "Client", "Initializing starting values - Titles");
  275. database.UpdateStartingTitles(GetCharacterID(), player->GetAdventureClass(), player->GetRace(), player->GetGender());
  276. }
  277. count = database.LoadCharacterLanguages(GetCharacterID(), player);
  278. if (count == 0)
  279. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character languages loaded!");
  280. count = database.LoadPlayerRecipeBooks(GetCharacterID(), player);
  281. if (count == 0)
  282. LogWrite(CCLIENT__DEBUG, 0, "Client", "No character recipe books found!");
  283. ClientPacketFunctions::SendLoginAccepted(this);
  284. ClientPacketFunctions::SendAbilities ( this );
  285. ClientPacketFunctions::SendCommandNamePacket(this);
  286. ClientPacketFunctions::SendQuickBarInit(this);
  287. // we only need to send the MOTD if it is the first time the person is logging in.
  288. if (firstlogin) {
  289. ClientPacketFunctions::SendMOTD(this);
  290. ClientPacketFunctions::SendCharacterMacros(this);
  291. zone_list.CheckFriendList(this);
  292. }
  293. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  294. if (firstlogin && player->item_list.GetNumberOfItems() == 0 && player->GetEquipmentList()->GetNumberOfItems() == 0) //re-add starting items if missing
  295. {
  296. LogWrite(CCLIENT__WARNING, 0, "Client", "Player has no items - reloading starting items: '%s' (%u)", player->GetName(), GetCharacterID());
  297. database.UpdateStartingItems(GetCharacterID(), player->GetAdventureClass(), player->GetRace());
  298. database.LoadCharacterItemList(GetAccountID(), GetCharacterID(), player, GetVersion());
  299. }
  300. database.LoadPlayerFactions(this);
  301. database.LoadCharacterQuests(this);
  302. database.LoadPlayerMail(this);
  303. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  304. SendQuestJournal(true, 0, false);
  305. if (version > 546) // right version? possibly not!
  306. master_aa_list.DisplayAA(this, 0, 3);
  307. if (version > 283)
  308. SendCollectionList();
  309. SendBiography();
  310. map<int32, Quest*>::iterator itr;
  311. Quest* quest = 0;
  312. for (itr = player->player_quests.begin(); itr != player->player_quests.end(); itr++) {
  313. quest = itr->second;
  314. if (quest->IsTracked()) {
  315. quest->SetTracked(false);
  316. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  317. quest->SetTracked(true);
  318. QueuePacket(itr->second->QuestJournalReply(version, GetNameCRC(), player));
  319. }
  320. }
  321. // SendAchievementsList();
  322. /*Guild* guild = player->GetGuild();
  323. if (guild) {
  324. guild->UpdateGuildMemberInfo(GetPlayer());
  325. if (firstlogin)
  326. guild->SendGuildMOTD(this);
  327. guild->SendGuildUpdate(this);
  328. guild->SendGuildMember(GetPlayer(), firstlogin);
  329. guild->SendGuildEventList(this);
  330. guild->SendGuildBankEventList(this);
  331. guild->SendAllGuildEvents(this);
  332. guild->SendGuildMemberList(this);
  333. }*/
  334. if (version > 283) {
  335. LogWrite(CCLIENT__DEBUG, 0, "Client", "Loading Faction Updates...");
  336. EQ2Packet* outapp = player->GetFactions()->FactionUpdate(GetVersion());
  337. if (outapp) {
  338. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  339. //DumpPacket(outapp);
  340. QueuePacket(outapp);
  341. }
  342. }
  343. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Command List...");
  344. ClientPacketFunctions::SendCommandList(this);
  345. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Language Updates...");
  346. SendLanguagesUpdate(database.GetCharacterCurrentLang(GetCharacterID(), player));
  347. ClientPacketFunctions::SendInstanceList(this);
  348. SendZoneInfo();
  349. /*Spell* spell = 0;
  350. vector<QuickBarItem*>::iterator itr;
  351. for(itr = player->GetQuickbar()->begin(); itr != player->GetQuickbar()->end(); itr++){
  352. if((*itr)->type == 1){
  353. spell = master_spell_list.GetSpell((*itr)->id);
  354. if(spell)
  355. QueuePacket(spell->serialize(this, false, 0x20));
  356. }
  357. }*/
  358. }
  359. void Client::SendPlayerDeathWindow()
  360. {
  361. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendPlayerDeathWindow");
  362. vector<RevivePoint*>* results = GetCurrentZone()->GetRevivePoints(this);
  363. vector<RevivePoint*>::iterator itr;
  364. if (results && results->size() > 0)
  365. {
  366. PacketStruct* packet = configReader.getStruct("WS_DeathWindow", GetVersion());
  367. if (packet)
  368. {
  369. packet->setArrayLengthByName("location_count", results->size());
  370. RevivePoint* point = 0;
  371. int32 i = 0;
  372. for (itr = results->begin(); itr != results->end(); itr++, i++)
  373. {
  374. point = *itr;
  375. if (point)
  376. {
  377. packet->setArrayDataByName("location_id", point->id, i);
  378. //zone_name = database.GetZoneName(point->zone_id);
  379. string zone_name = database.GetZoneDescription(point->zone_id);
  380. if (zone_name.length() > 0)
  381. packet->setArrayDataByName("zone_name", zone_name.c_str(), i);
  382. packet->setArrayDataByName("location_name", point->location_name.c_str(), i);
  383. packet->setArrayDataByName("distance", GetPlayer()->GetDistance(point->x, point->y, point->z), i);
  384. }
  385. if (point->id == 0xFFFFFFFF)//tmp location
  386. safe_delete(point);
  387. }
  388. // done with the revive points so lets free up the pointer
  389. safe_delete(results);
  390. #if EQDEBUG >= 3
  391. LogWrite(CCLIENT__DEBUG, 0, "Client", "WS_DeathWindow Packet:");
  392. packet->PrintPacket();
  393. #endif
  394. EQ2Packet* outapp = packet->serialize();
  395. QueuePacket(outapp);
  396. safe_delete(packet);
  397. }
  398. }
  399. }
  400. void Client::DisplayDeadWindow()
  401. {
  402. LogWrite(ZONE__DEBUG, 0, "Zone", "DisplayDeadWindow()");
  403. player->SetHP(0);
  404. player->SetPower(0);
  405. GetCurrentZone()->TriggerCharSheetTimer();
  406. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  407. if (packet)
  408. {
  409. packet->setDataByName("parameter1", 8);
  410. packet->setDataByName("value", 1);
  411. QueuePacket(packet->serialize());
  412. packet->setDataByName("parameter1", 16);
  413. QueuePacket(packet->serialize());
  414. safe_delete(packet);
  415. }
  416. packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  417. if (packet)
  418. {
  419. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  420. QueuePacket(packet->serialize());
  421. safe_delete(packet);
  422. }
  423. SendPlayerDeathWindow();
  424. }
  425. void Client::HandlePlayerRevive(int32 point_id)
  426. {
  427. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  428. if (packet)
  429. {
  430. packet->setDataByName("parameter1", 8);
  431. QueuePacket(packet->serialize());
  432. packet->setDataByName("parameter1", 16);
  433. QueuePacket(packet->serialize());
  434. safe_delete(packet);
  435. }
  436. SimpleMessage(CHANNEL_NARRATIVE, "You regain consciousness!");
  437. packet = configReader.getStruct("WS_Resurrected", GetVersion());
  438. if (packet)
  439. {
  440. QueuePacket(packet->serialize());
  441. safe_delete(packet);
  442. }
  443. float x, y, z, heading;
  444. RevivePoint* revive_point = 0;
  445. if (point_id != 0xFFFFFFFF)
  446. revive_point = GetCurrentZone()->GetRevivePoint(point_id);
  447. string zone_desc;
  448. const char* location_name = "Unknown";
  449. //revive at zone safe coords
  450. if (!revive_point)
  451. {
  452. LogWrite(CCLIENT__WARNING, 0, "Client", "No Revive Point! Spawning player at safe coordinates!");
  453. x = GetCurrentZone()->GetSafeX();
  454. y = GetCurrentZone()->GetSafeY();
  455. z = GetCurrentZone()->GetSafeZ();
  456. heading = GetCurrentZone()->GetSafeHeading();
  457. zone_desc = GetCurrentZone()->GetZoneDescription();
  458. location_name = "Zone Safe Point";
  459. Zone(GetCurrentZone()->GetZoneName(), false);
  460. }
  461. else
  462. {
  463. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to chosen Revive Point.");
  464. x = revive_point->x;
  465. y = revive_point->y;
  466. z = revive_point->z;
  467. heading = revive_point->heading;
  468. zone_desc = database.GetZoneDescription(revive_point->zone_id);
  469. location_name = revive_point->location_name.c_str();
  470. Zone(GetCurrentZone()->GetZoneName(), false);
  471. }
  472. player->SetResurrecting(true);
  473. player->SetX(x);
  474. player->SetY(y);
  475. player->SetZ(z);
  476. player->SetHeading(heading);
  477. player->SetHP(player->GetTotalHP());
  478. player->SetPower(player->GetTotalPower());
  479. LogWrite(CCLIENT__DEBUG, 0, "Client", "Attempt Revive @ %s, %.2f, %.2f, %.2f, %.2f, HP: %i, Pow: %i, %s",
  480. zone_desc.c_str(),
  481. player->GetX(),
  482. player->GetY(),
  483. player->GetZ(),
  484. player->GetHeading(),
  485. player->GetHP(),
  486. player->GetPower(),
  487. location_name);
  488. //player->ClearEverything();
  489. Save();
  490. if (revive_point && revive_point->zone_id != GetCurrentZone()->GetZoneID() && revive_point->zone_id != 0)
  491. {
  492. string zone_name = database.GetZoneName(revive_point->zone_id);
  493. if (zone_name.length() == 0)
  494. {
  495. LogWrite(CCLIENT__WARNING, 0, "Client", "Unable to zone player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  496. x = GetCurrentZone()->GetSafeX();
  497. y = GetCurrentZone()->GetSafeY();
  498. z = GetCurrentZone()->GetSafeZ();
  499. heading = GetCurrentZone()->GetSafeHeading();
  500. location_name = "Zone Safe Point";
  501. }
  502. else
  503. {
  504. LogWrite(CCLIENT__DEBUG, 0, "Client", "Sending player to revive zone ID '%u', using current zone's safe coords.", revive_point->zone_id);
  505. location_name = revive_point->location_name.c_str();
  506. player->ClearEverything();
  507. Zone(zone_name.c_str(), false);
  508. }
  509. }
  510. zone_desc = GetCurrentZone()->GetZoneDescription();
  511. Message(CHANNEL_NARRATIVE, "Reviving in %s at %s.", zone_desc.c_str(), location_name);
  512. player->SetSpawnType(4);
  513. if (version > 283) {
  514. packet = configReader.getStruct("WS_CancelMoveObjectMode", GetVersion());
  515. if (packet)
  516. {
  517. QueuePacket(packet->serialize());
  518. safe_delete(packet);
  519. }
  520. }
  521. packet = configReader.getStruct("WS_TeleportWithinZone", GetVersion());
  522. if (packet)
  523. {
  524. packet->setDataByName("x", x);
  525. packet->setDataByName("y", y);
  526. packet->setDataByName("z", z);
  527. QueuePacket(packet->serialize());
  528. safe_delete(packet);
  529. }
  530. packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  531. if (packet)
  532. {
  533. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  534. packet->setDataByName("speed", 32);
  535. packet->setDataByName("unknown2", 0);
  536. //DoF Merge: old value and speed wasn't included
  537. //packet->setDataByName("unknown2", 255);
  538. QueuePacket(packet->serialize());
  539. safe_delete(packet);
  540. }
  541. packet = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  542. if (packet)
  543. {
  544. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  545. QueuePacket(packet->serialize());
  546. safe_delete(packet);
  547. }
  548. GetCurrentZone()->RemoveSpawn(false, player, false);
  549. m_resurrect.writelock(__FUNCTION__, __LINE__);
  550. if (current_rez.active)
  551. current_rez.should_delete = true;
  552. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  553. }
  554. void Client::SendCharInfo() {
  555. EQ2Packet* app;
  556. player->SetEquippedItemAppearances();
  557. ClientPacketFunctions::SendCharacterData(this);
  558. SendCharPOVGhost();
  559. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", GetVersion());
  560. if (packet) {
  561. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  562. packet->setDataByName("size", .56);
  563. packet->setDataByName("unknown2", 255);
  564. packet->setDataByName("speed", player->GetSpeed());
  565. packet->setDataByName("air_speed", player->GetAirSpeed());
  566. EQ2Packet* app = packet->serialize();
  567. QueuePacket(app);
  568. safe_delete(packet);
  569. }
  570. if (version <= 283) {
  571. //le: hack to allow client time to zone in, it gets stuck on Loading UI Resources if we go too fast, need to figure it out. Probably something it doesnt like with ExamineInfo packets
  572. Sleep(2000);
  573. }
  574. //sending bad spawn packet?
  575. //SendAchievementsList();
  576. ClientPacketFunctions::SendCharacterSheet(this);
  577. ClientPacketFunctions::SendTraitList(this);// moved from below
  578. ClientPacketFunctions::SendAbilities(this);
  579. ClientPacketFunctions::SendSkillBook(this);
  580. if (!player->IsResurrecting()) {
  581. if(GetVersion() > 546) //we will send this later on for 546 and below
  582. ClientPacketFunctions::SendUpdateSpellBook(this);
  583. }
  584. else {
  585. player->SetResurrecting(false);
  586. }
  587. ClientPacketFunctions::SendLoginCommandMessages(this);
  588. GetCurrentZone()->AddSpawn(player);
  589. //SendCollectionList();
  590. Guild* guild = player->GetGuild();
  591. if (guild)
  592. guild->GuildMemberLogin(this, firstlogin);
  593. app = player->item_list.serialize(GetPlayer(), GetVersion());
  594. if (app) {
  595. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  596. //DumpPacket(app);
  597. QueuePacket(app);
  598. }
  599. app = player->GetEquipmentList()->serialize(GetVersion());
  600. if (app) {
  601. QueuePacket(app);
  602. }
  603. vector<Item*>* items = player->item_list.GetItemsFromBagID(-3); // bank items
  604. if (items && items->size() > 0) {
  605. for (int32 i = 0; i < items->size(); i++) {
  606. EQ2Packet* outapp = items->at(i)->serialize(GetVersion(), false, GetPlayer());
  607. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  608. //DumpPacket(outapp);
  609. QueuePacket(outapp);
  610. }
  611. }
  612. if (firstlogin && (app = chat.GetWorldChannelList(this)) != NULL)
  613. QueuePacket(app);
  614. safe_delete(items);
  615. items = player->item_list.GetItemsFromBagID(-4); //shared bank items
  616. if (items && items->size() > 0) {
  617. for (int32 i = 0; i < items->size(); i++)
  618. QueuePacket(items->at(i)->serialize(GetVersion(), false, GetPlayer()));
  619. }
  620. safe_delete(items);
  621. if (version > 283) {
  622. SendTitleUpdate();
  623. }
  624. GetPlayer()->ChangePrimaryWeapon();
  625. GetPlayer()->ChangeSecondaryWeapon();
  626. GetPlayer()->ChangeRangedWeapon();
  627. database.LoadBuyBacks(this);
  628. if (version > 546)
  629. master_aa_list.DisplayAA(this, 0, 0);
  630. string zone_motd = GetCurrentZone()->GetZoneMOTD();
  631. if (zone_motd.length() > 0 && zone_motd[0] != ' ') {
  632. string zone_motd_send = "Zone MOTD: " + zone_motd;
  633. SimpleMessage(CHANNEL_NARRATIVE, zone_motd_send.c_str());
  634. }
  635. const char* zone_script = world.GetZoneScript(GetCurrentZone()->GetZoneID());
  636. if (zone_script && lua_interface)
  637. lua_interface->RunZoneScript(zone_script, "player_entry", GetCurrentZone(), GetPlayer());
  638. this->client_zoning = false;
  639. if (player->GetHP() < player->GetTotalHP() || player->GetPower() < player->GetTotalPower())
  640. GetCurrentZone()->AddDamagedSpawn(player);
  641. if (firstlogin && rule_manager.GetGlobalRule(R_World, IRCGlobalEnabled)->GetBool())
  642. Message(CHANNEL_BROADCAST, "This server has a global IRC channel, join the world channel %s to use", rule_manager.GetGlobalRule(R_World, IRCChan)->GetString());
  643. if (firstlogin)
  644. firstlogin = false;
  645. player->ClearProcs();
  646. items = player->GetEquippedItemList();
  647. if (items && items->size() > 0) {
  648. for (int32 i = 0; i < items->size(); i++) {
  649. Item* item = items->at(i);
  650. if (item && item->GetItemScript() && lua_interface)
  651. lua_interface->RunItemScript(item->GetItemScript(), "equipped", item, player);
  652. }
  653. }
  654. //Allow this player to change their last name if they meet the level requirement
  655. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && player->GetLevel() >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  656. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  657. safe_delete(items);
  658. if (!player->Alive())
  659. DisplayDeadWindow();
  660. ClientPacketFunctions::SendLocalizedTextMessage(this);
  661. if (GetCurrentZone()->GetInstanceID())
  662. {
  663. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(GetCurrentZone()->GetInstanceID());
  664. if (ph) {
  665. //HouseZone* hz = world.GetHouseZone(ph->house_id);
  666. string name = string(GetPlayer()->GetName());
  667. if (name.compare(ph->player_name) == 0)
  668. SetHasOwnerOrEditAccess(true);
  669. }
  670. }
  671. if (version > 546)
  672. ClientPacketFunctions::SendHousingList(this);
  673. }
  674. void Client::SendZoneSpawns() {
  675. //Allows us to place spawns almost anywhere
  676. if (version > 283) {
  677. uchar blah[] = { 0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46,0x00,0x3C,0x1C,0x46 };
  678. EQ2Packet* app = new EQ2Packet(OP_MoveableObjectPlacementCriteri, blah, sizeof(blah));
  679. QueuePacket(app);
  680. }
  681. ClientPacketFunctions::SendSkillSlotMappings(this);
  682. ClientPacketFunctions::SendGameWorldTime(this);
  683. GetCurrentZone()->StartZoneInitialSpawnThread(this);
  684. }
  685. void Client::SendCharPOVGhost() {
  686. PacketStruct* set_pov = configReader.getStruct("WS_SetPOVGhostCmd", GetVersion());
  687. if (set_pov) {
  688. set_pov->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  689. EQ2Packet* app_pov = set_pov->serialize();
  690. QueuePacket(app_pov);
  691. safe_delete(set_pov);
  692. }
  693. }
  694. void Client::SendZoneInfo() {
  695. ZoneServer* zone = GetCurrentZone();
  696. if (zone) {
  697. EQ2Packet* packet = zone->GetZoneInfoPacket(this);
  698. QueuePacket(packet);
  699. if (version > 283) {
  700. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  701. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  702. #if EQDEBUG >= 9
  703. fog_packet->PrintPacket();
  704. #endif
  705. if (fog_packet) {
  706. database.LoadFogInit(zone->GetZoneFile(), fog_packet);
  707. QueuePacket(fog_packet->serialize());
  708. safe_delete(fog_packet);
  709. }
  710. zone->SendFlightPathsPackets(this);
  711. }
  712. }
  713. /*
  714. uchar blah[] ={0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0x00,0x01,0x00,0x00,0x00,0x00
  715. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  716. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF
  717. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
  718. ,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x00,0x00,0x00
  719. ,0x00,0x00,0x00,0x00,0x10,0x49,0x2B,0x62,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  720. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  721. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  722. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  723. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  724. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  725. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  726. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  727. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  728. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  729. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  730. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  731. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  732. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  733. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  734. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  735. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  736. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  737. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  738. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  739. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  740. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  741. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  742. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  743. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  744. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  745. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  746. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  747. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  748. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  749. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xFF,0x00};
  750. EQ2Packet* appA = new EQ2Packet(OP_GuildUpdateMsg, blah, sizeof(blah));
  751. QueuePacket(appA);
  752. uchar blahA[] ={0x45,0x00,0x00,0x00,0x06,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00
  753. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  754. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00
  755. ,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00
  756. ,0x00,0x10,0xE2,0x10,0x6C,0x00,0x00,0x00,0x00};
  757. EQ2Packet* appB = new EQ2Packet(OP_KeymapDataMsg, blahA, sizeof(blahA));
  758. QueuePacket(appB);
  759. */
  760. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendFriendList");
  761. SendFriendList();
  762. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendIgnoreList");
  763. SendIgnoreList();
  764. }
  765. void Client::SendDefaultGroupOptions() {
  766. /*
  767. 0 - loot method
  768. 1 - loot items rarity
  769. 2 - Auto split coin
  770. 4 - default yell method
  771. 6 - group autolock
  772. 7 - solo autolock
  773. */
  774. PacketStruct* default_options = configReader.getStruct("WS_DefaultGroupOptions", GetVersion());
  775. if (default_options) {
  776. default_options->setDataByName("loot_method", 1);
  777. default_options->setDataByName("loot_items_rarity", 1);
  778. default_options->setDataByName("auto_split_coin", 1);
  779. default_options->setDataByName("default_yell_method", 1);
  780. EQ2Packet* app7 = default_options->serialize();
  781. QueuePacket(app7);
  782. safe_delete(default_options);
  783. }
  784. }
  785. bool Client::HandlePacket(EQApplicationPacket* app) {
  786. bool ret = true;
  787. //cout << "INCOMING PACKET!!!!!!!: " << app->GetOpcodeName() << endl;
  788. //DumpPacket(app);
  789. #if EQDEBUG >= 9
  790. LogWrite(PACKET__DEBUG, 9, "Packet", "[EQDEBUG] Received Packet:");
  791. DumpPacket(app, true);
  792. #endif
  793. EmuOpcode opcode = app->GetOpcode();
  794. #if EQDEBUG >= 9
  795. const char* name = app->GetOpcodeName();
  796. if (name)
  797. cout << name;
  798. else
  799. cout << "Unknown";
  800. cout << " Packet: OPCode: 0x" << hex << setw(2) << setfill('0') << app->GetOpcode() << dec << ", size: " << setw(5) << setfill(' ') << app->Size() << endl;
  801. DumpPacket(app);
  802. #endif
  803. //if (opcode != OP_UpdatePositionMsg) {
  804. // LogWrite(PACKET__DEBUG, 0, "opcode %s received", app->GetOpcodeName());
  805. //}
  806. if (!connected_to_zone && opcode != OP_LoginByNumRequestMsg)
  807. {
  808. opcode = _maxEmuOpcode; // skip since this is not a valid packet, sent before we allowed the login
  809. }
  810. switch (opcode) {
  811. case _maxEmuOpcode:
  812. break;
  813. case OP_LoginByNumRequestMsg: {
  814. LogWrite(OPCODE__DEBUG, 0, "Opcode", "Opcode 0x%X (%i): OP_LoginByNumRequestMsg", opcode, opcode);
  815. PacketStruct* request;
  816. request = configReader.getStruct("LoginByNumRequest", 1);
  817. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  818. // test the original location of Version for clients older than 1212
  819. version = request->getType_int16_ByName("version");
  820. if (version == 0 || version >= 1208 || EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  821. // must be new client data version method, re-fetch the packet
  822. safe_delete(request);
  823. request = configReader.getStruct("LoginByNumRequest", 1208);
  824. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  825. // Xinux suggests using an INT16 here. Our first new version = 57000
  826. version = request->getType_int16_ByName("version");
  827. }
  828. else {
  829. LogWrite(LOGIN__ERROR, 0, "Login", "Nasty Horrible things happening. Tell a dev asap! Version: %i", version);
  830. break;
  831. }
  832. }
  833. if (EQOpcodeManager.count(GetOpcodeVersion(version)) == 0) {
  834. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  835. ClientPacketFunctions::SendLoginDenied(this);
  836. return false;
  837. }
  838. int32 account_id = request->getType_int32_ByName("account_id");
  839. int32 access_code = request->getType_int32_ByName("access_code");
  840. if (!HandleNewLogin(account_id, access_code))
  841. return false;
  842. }
  843. safe_delete(request);
  844. break;
  845. }
  846. case OP_SysClient: {
  847. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SysClient", opcode, opcode);
  848. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client '%s' (%u) is ready for spawn updates.", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  849. SetReadyForUpdates();
  850. break;
  851. }
  852. case OP_MapRequest: {
  853. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapRequest", opcode, opcode);
  854. PacketStruct* packet = configReader.getStruct("WS_MapRequest", GetVersion());
  855. if (packet && app->size > 2 && GetCurrentZone()) {
  856. packet->LoadPacketData(app->pBuffer, app->size);
  857. PacketStruct* fog_packet = configReader.getStruct("WS_FogInit", GetVersion());
  858. if (fog_packet) {
  859. LogWrite(PACKET__DEBUG, 0, "Packet", "In OP_MapRequest: Fog Packet");
  860. database.LoadFogInit(packet->getType_EQ2_16BitString_ByName("zone").data, fog_packet);
  861. fog_packet->setDataByName("unknown1", 1);
  862. fog_packet->setDataByName("unknown3", 1);
  863. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  864. //fog_packet->PrintPacket();
  865. QueuePacket(fog_packet->serialize());
  866. safe_delete(fog_packet);
  867. }
  868. safe_delete(packet);
  869. }
  870. break;
  871. }
  872. case OP_RequestCampMsg: {
  873. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RequestCampMsg", opcode, opcode);
  874. PacketStruct* request = configReader.getStruct("WS_RequestCamp", GetVersion());
  875. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  876. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client '%s' (%u) is camping...", GetPlayer()->GetName(), GetPlayer()->GetCharacterID());
  877. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_RequestCamp - quit: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  878. request->getType_int8_ByName("quit"),
  879. request->getType_int8_ByName("camp_desktop"),
  880. request->getType_int16_ByName("camp_char_select"),
  881. (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? request->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  882. //DumpPacket(app->pBuffer, app->size);
  883. //request->PrintPacket();
  884. if (!camp_timer) {
  885. int16 camp_time = 20; // default if rule cannot be found
  886. if (GetAdminStatus() >= 100)
  887. camp_time = rule_manager.GetGlobalRule(R_World, GMCampTimer)->GetInt16();
  888. else
  889. camp_time = rule_manager.GetGlobalRule(R_World, PlayerCampTimer)->GetInt16();
  890. PacketStruct* response = configReader.getStruct("WS_Camp", GetVersion());
  891. if (response) {
  892. bool disconnect = false;
  893. if (request->getType_int8_ByName("camp_desktop") == 1 && request->getType_int8_ByName("quit") == 1) {
  894. // Command: /camp desktop
  895. // Command: /quit
  896. response->setDataByName("camp_desktop", 1);
  897. disconnect = true;
  898. }
  899. else {
  900. // Command: /camp
  901. response->setDataByName("camp_desktop", request->getType_int8_ByName("camp_desktop"));
  902. response->setDataByName("camp_char_select", request->getType_int16_ByName("camp_char_select"));
  903. response->setDataByName("seconds", camp_time);
  904. }
  905. camp_timer = new Timer(camp_time * 1000);
  906. camp_timer->Enable();
  907. if (request->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) {
  908. // /camp {char_name}
  909. response->setDataByName("char_name", request->getType_EQ2_16BitString_ByName("char_name").data.c_str());
  910. }
  911. else if (request->getType_int8_ByName("camp_desktop") == 0 && request->getType_int16_ByName("camp_char_select") == 0) {
  912. // /camp (go back to char selection screen)
  913. response->setDataByName("char_name", " ");
  914. response->setDataByName("camp_char_select", 1);
  915. }
  916. LogWrite(CCLIENT__DEBUG, 0, "CClient", "WS_Camp - seconds: %i, camp_desktop: %i, camp_char_select: %i, (to) char_name: %s",
  917. response->getType_int8_ByName("seconds"),
  918. response->getType_int8_ByName("camp_desktop"),
  919. response->getType_int8_ByName("camp_char_select"),
  920. (response->getType_EQ2_16BitString_ByName("char_name").data.length() > 0) ? response->getType_EQ2_16BitString_ByName("char_name").data.c_str() : "");
  921. // JA: trying to recognize /camp vs LD (see ZoneServer::ClientProcess())
  922. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) == 0)
  923. player->SetActivityStatus(player->GetActivityStatus() + ACTIVITY_STATUS_CAMPING);
  924. //response->PrintPacket();
  925. QueuePacket(response->serialize());
  926. safe_delete(response);
  927. if (disconnect)
  928. Disconnect();
  929. }
  930. }
  931. }
  932. safe_delete(request);
  933. break;
  934. }
  935. case OP_StoodMsg: {
  936. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StoodMsg", opcode, opcode);
  937. if (camp_timer)
  938. {
  939. // JA: clear camping flag
  940. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  941. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  942. safe_delete(camp_timer);
  943. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  944. QueuePacket(outapp);
  945. }
  946. player->SetTempVisualState(0);
  947. break;
  948. }
  949. case OP_StandMsg: {
  950. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StandMsg", opcode, opcode);
  951. if (camp_timer)
  952. {
  953. // JA: clear camping flag
  954. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  955. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  956. safe_delete(camp_timer);
  957. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  958. QueuePacket(outapp);
  959. }
  960. player->SetTempVisualState(539);
  961. break;
  962. }
  963. case OP_SitMsg: {
  964. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SitMsg", opcode, opcode);
  965. player->SetTempVisualState(538);
  966. break;
  967. }
  968. case OP_SatMsg: {
  969. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SatMsg", opcode, opcode);
  970. player->SetTempVisualState(540);
  971. break;
  972. }
  973. case OP_QuestJournalOpenMsg:
  974. case OP_QuestJournalInspectMsg: {
  975. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalOpenMsg, OP_QuestJournalInspectMsg", opcode, opcode);
  976. if (app->size < sizeof(int32))
  977. break;
  978. int32 quest_id = 0;
  979. memcpy(&quest_id, app->pBuffer, sizeof(int32));
  980. Quest* quest = GetActiveQuest(quest_id);
  981. if (quest)
  982. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  983. else {
  984. quest = player->GetCompletedQuest(quest_id);
  985. if (quest)
  986. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, 0, 1, true));
  987. }
  988. break;
  989. }
  990. case OP_QuestJournalSetVisibleMsg: {
  991. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalSetVisibleMsg", opcode, opcode);
  992. PacketStruct* packet = configReader.getStruct("WS_QuestJournalVisible", GetVersion());
  993. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  994. int32 quest_id = packet->getType_int32_ByName("quest_id");
  995. bool hidden = packet->getType_int8_ByName("visible") == 1 ? false : true;
  996. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  997. if (player_quests) {
  998. if (player_quests->count(quest_id) > 0)
  999. player_quests->at(quest_id)->SetHidden(hidden);
  1000. else
  1001. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Player does not have quest with id of %u", quest_id);
  1002. }
  1003. else
  1004. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_QuestJournalSetVisibleMsg error: Unable to get player(%s) quests", player->GetName());
  1005. safe_delete(packet);
  1006. }
  1007. break;
  1008. }
  1009. case OP_MacroUpdateMsg: {
  1010. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MacroUpdateMsg", opcode, opcode);
  1011. PacketStruct* macro_update = configReader.getStruct("WS_MacroUpdate", GetVersion());
  1012. if (macro_update && macro_update->LoadPacketData(app->pBuffer, app->size)) {
  1013. vector<string>* update = new vector<string>;
  1014. int8 number = macro_update->getType_int8_ByName("number");
  1015. int16 icon = macro_update->getType_int16_ByName("icon");
  1016. string name = macro_update->getType_EQ2_8BitString_ByName("name").data;
  1017. int8 count = macro_update->getType_int8_ByName("macro_count");
  1018. if (GetVersion() <= 283) {
  1019. update->push_back(macro_update->getType_EQ2_8BitString_ByName("command").data);
  1020. }
  1021. else {
  1022. for (int8 i = 0; i < count; i++) {
  1023. char tmp_command[15] = { 0 };
  1024. sprintf(tmp_command, "command_%i", i);
  1025. update->push_back(macro_update->getType_EQ2_16BitString_ByName(tmp_command).data);
  1026. }
  1027. }
  1028. if (name.length() == 0)
  1029. database.UpdateCharacterMacro(GetCharacterID(), number, 0, icon, update);
  1030. else
  1031. database.UpdateCharacterMacro(GetCharacterID(), number, name.c_str(), icon, update);
  1032. safe_delete(update);
  1033. safe_delete(macro_update);
  1034. }
  1035. break;
  1036. }
  1037. case OP_DialogSelectMsg: {
  1038. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DialogSelectMsg", opcode, opcode);
  1039. PacketStruct* packet = configReader.getStruct("WS_DialogSelect", GetVersion());
  1040. if (packet) {
  1041. packet->LoadPacketData(app->pBuffer, app->size);
  1042. int32 conversation_id = packet->getType_int32_ByName("conversation_id");
  1043. int32 response_index = packet->getType_int32_ByName("response");
  1044. if (GetCurrentZone()) {
  1045. Spawn* spawn = conversation_spawns[conversation_id];
  1046. Item* item = conversation_items[conversation_id];
  1047. if (conversation_map.count(conversation_id) > 0 && conversation_map[conversation_id].count(response_index) > 0) {
  1048. if (spawn)
  1049. GetCurrentZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_CONVERSATION, player, conversation_map[conversation_id][response_index].c_str());
  1050. else if (item && lua_interface && item->GetItemScript())
  1051. lua_interface->RunItemScript(item->GetItemScript(), conversation_map[conversation_id][response_index].c_str(), item, player);
  1052. }
  1053. else
  1054. CloseDialog(conversation_id);
  1055. }
  1056. safe_delete(packet);
  1057. }
  1058. break;
  1059. }
  1060. case OP_CancelMoveObjectModeMsg: {
  1061. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1062. if (GetTempPlacementSpawn())
  1063. {
  1064. Spawn* tmp = GetTempPlacementSpawn();
  1065. GetCurrentZone()->RemoveSpawn(false, tmp);
  1066. delete tmp;
  1067. SetTempPlacementSpawn(nullptr);
  1068. SetPlacementUniqueItemID(0);
  1069. break; // break out early if we are tied to a temp spawn
  1070. }
  1071. // if we are moving some other object? other use-cases not covered
  1072. break;
  1073. }
  1074. case OP_PositionMoveableObject: {
  1075. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PositionMoveableObject", opcode, opcode);
  1076. PacketStruct* place_object = configReader.getStruct("WS_PlaceMoveableObject", GetVersion());
  1077. if (place_object && place_object->LoadPacketData(app->pBuffer, app->size)) {
  1078. Spawn* spawn = 0;
  1079. if (GetTempPlacementSpawn())
  1080. spawn = GetTempPlacementSpawn();
  1081. else
  1082. spawn = GetPlayer()->GetSpawnWithPlayerID(place_object->getType_int32_ByName("spawn_id"));
  1083. if (!spawn) {
  1084. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn.");
  1085. break;
  1086. }
  1087. else if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE && !HasOwnerOrEditAccess())
  1088. {
  1089. SimpleMessage(CHANNEL_COLOR_RED, "This is not your home!");
  1090. break;
  1091. }
  1092. // handles instantiation logic + adding to zone of a new house object
  1093. PopulateHouseSpawn(place_object);
  1094. float newHeading = place_object->getType_float_ByName("heading") + 180;
  1095. char query[256];
  1096. switch (GetSpawnPlacementMode())
  1097. {
  1098. case ServerSpawnPlacementMode::OPEN_HEADING:
  1099. {
  1100. if (spawn && spawn->IsWidget())
  1101. {
  1102. Widget* widget = (Widget*)spawn;
  1103. widget->SetOpenHeading(newHeading);
  1104. widget->SetIncludeHeading(true);
  1105. spawn->position_changed = true;
  1106. _snprintf(query, 256, "open_heading=%f,include_heading=1", newHeading);
  1107. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1108. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget open heading information.");
  1109. }
  1110. else
  1111. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1112. break;
  1113. }
  1114. case ServerSpawnPlacementMode::CLOSE_HEADING:
  1115. {
  1116. if (spawn && spawn->IsWidget())
  1117. {
  1118. Widget* widget = (Widget*)spawn;
  1119. widget->SetClosedHeading(newHeading);
  1120. widget->SetIncludeHeading(true);
  1121. spawn->position_changed = true;
  1122. _snprintf(query, 256, "closed_heading=%f,include_heading=1", newHeading);
  1123. if (database.UpdateSpawnWidget(widget->GetWidgetID(), query))
  1124. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved widget close heading information.");
  1125. if (spawn->GetSpawnLocationID())
  1126. {
  1127. Query query;
  1128. query.RunQuery2(Q_INSERT, "update spawn_location_placement set heading = %f where id = %u", newHeading, spawn->GetSpawnLocationID());
  1129. }
  1130. }
  1131. else
  1132. SimpleMessage(CHANNEL_COLOR_YELLOW, "Spawn is not widget, unable to set close heading information.");
  1133. break;
  1134. }
  1135. default:
  1136. {
  1137. spawn->SetX(place_object->getType_float_ByName("x"));
  1138. spawn->SetY(place_object->getType_float_ByName("y"));
  1139. spawn->SetZ(place_object->getType_float_ByName("z"));
  1140. spawn->SetHeading(newHeading);
  1141. spawn->SetSpawnOrigX(spawn->GetX());
  1142. spawn->SetSpawnOrigY(spawn->GetY());
  1143. spawn->SetSpawnOrigZ(spawn->GetZ());
  1144. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1145. if (spawn->GetSpawnLocationID() > 0 && database.UpdateSpawnLocationSpawns(spawn))
  1146. SimpleMessage(CHANNEL_COLOR_YELLOW, "Successfully saved spawn information.");
  1147. else if (spawn->GetSpawnLocationID() > 0)
  1148. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn information, see console window for details.");
  1149. }
  1150. }
  1151. PopulateHouseSpawnFinalize();
  1152. SetSpawnPlacementMode(Client::ServerSpawnPlacementMode::DEFAULT);
  1153. safe_delete(place_object);
  1154. }
  1155. break;
  1156. }
  1157. case OP_CampAbortedMsg: {
  1158. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CampAbortedMsg", opcode, opcode);
  1159. if (camp_timer)
  1160. {
  1161. // JA: clear camping flag
  1162. if ((player->GetActivityStatus() & ACTIVITY_STATUS_CAMPING) > 0)
  1163. player->SetActivityStatus(player->GetActivityStatus() - ACTIVITY_STATUS_CAMPING);
  1164. safe_delete(camp_timer);
  1165. EQ2Packet* outapp = new EQ2Packet(OP_CampAbortedMsg, 0, 0);
  1166. QueuePacket(outapp);
  1167. }
  1168. break;
  1169. }
  1170. case OP_DoneLoadingUIResourcesMsg: {
  1171. ClientPacketFunctions::SendUpdateSpellBook(this);
  1172. EQ2Packet* app = new EQ2Packet(OP_DoneLoadingUIResourcesMsg, 0, 0);
  1173. QueuePacket(app);
  1174. break;
  1175. }
  1176. case OP_DoneLoadingZoneResourcesMsg: {
  1177. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingZoneResourcesMsg", opcode, opcode);
  1178. SendZoneSpawns();
  1179. break;
  1180. }
  1181. case OP_DefaultGroupOptionsRequestMsg: {
  1182. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DefaultGroupOptionsRequestMsg", opcode, opcode);
  1183. SendDefaultGroupOptions();
  1184. break;
  1185. }
  1186. case OP_DoneLoadingEntityResourcesMsg: {
  1187. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_DoneLoadingEntityResourcesMsg", opcode, opcode);
  1188. if (!IsReadyForSpawns())
  1189. SetReadyForSpawns(true);
  1190. SendCharInfo();
  1191. world.RejoinGroup(this, rejoin_group_id);
  1192. pos_update.Start();
  1193. quest_pos_timer.Start();
  1194. break;
  1195. }
  1196. case OP_LootItemsRequestMsg: {
  1197. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_LootItemsRequestMsg", opcode, opcode);
  1198. HandleLoot(app);
  1199. break;
  1200. }
  1201. case OP_KnowledgeWindowSlotMappingMsg: {
  1202. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_KnowledgeWindowSlotMappingMsg", opcode, opcode);
  1203. PacketStruct* packet = configReader.getStruct("WS_SpellSlotMapping", GetVersion());
  1204. if (packet) {
  1205. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  1206. int num_updates = packet->getType_int16_ByName("spell_count");
  1207. int32 spell_id = 0;
  1208. int16 slot_id = 0;
  1209. char tmp_spell_id[15];
  1210. char tmp_slot[15];
  1211. for (int i = 0; i < num_updates; i++) {
  1212. memset(tmp_spell_id, 0, 15);
  1213. memset(tmp_slot, 0, 15);
  1214. sprintf(tmp_spell_id, "spell_id_%i", i);
  1215. sprintf(tmp_slot, "slot_id_%i", i);
  1216. spell_id = packet->getType_int32_ByName(tmp_spell_id);
  1217. if (spell_id > 0) {
  1218. slot_id = packet->getType_int16_ByName(tmp_slot);
  1219. SpellBookEntry* spell = player->GetSpellBookSpell(spell_id);
  1220. if (spell && spell->slot != slot_id) {
  1221. spell->slot = slot_id;
  1222. spell->save_needed = true;
  1223. }
  1224. }
  1225. }
  1226. }
  1227. safe_delete(packet);
  1228. }
  1229. //SendKnowledgeWindowSlot();
  1230. break;
  1231. }
  1232. case OP_ReadyToZoneMsg: {
  1233. if (!IsReadyForSpawns())
  1234. {
  1235. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s is logging into zone, skipping disconnect.");
  1236. }
  1237. else
  1238. {
  1239. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyToZoneMsg", opcode, opcode);
  1240. if (client_zoning)
  1241. LogWrite(WORLD__INFO, 0, "World", "OP_ReadyToZone: Player %s zoning to %s", player->GetName(), GetCurrentZone()->GetZoneName());
  1242. else
  1243. LogWrite(WORLD__ERROR, 0, "World", "OP_ReadyToZone: Player %s attempting to zone without server authorization.", player->GetName());
  1244. Disconnect();
  1245. }
  1246. break;
  1247. }
  1248. case OP_ClientFellMsg: {
  1249. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ClientFellMsg (ouch!)", opcode, opcode);
  1250. PacketStruct* request = configReader.getStruct("WS_ClientFell", GetVersion());
  1251. if (request && request->LoadPacketData(app->pBuffer, app->size)) {
  1252. float height = request->getType_float_ByName("height");
  1253. /*int32 spawn_id = request->getType_int32_ByName("spawn_id");
  1254. if(GetPlayer()->GetSpawnWithPlayerID(spawn_id) != GetPlayer()){
  1255. cout << "Error: " << GetPlayer()->GetName() << " called ClientFell with an invalid ID of: " << spawn_id << endl;
  1256. break;
  1257. }*/
  1258. float safe_height = 13.0f;
  1259. Skill* skill = GetPlayer()->GetSkillByName("Safe Fall", true);
  1260. if (skill)
  1261. safe_height += (skill->current_val + 1) / 5;
  1262. if (height > safe_height) {
  1263. int16 damage = (int16)ceil((height - safe_height) * 125);
  1264. if (height >= 80)
  1265. damage = 30000;
  1266. //cout << "Detected fall height:" << height << " damage:" << damage << endl;
  1267. if (damage > 0) {
  1268. GetPlayer()->TakeDamage(damage);
  1269. if (GetPlayer()->GetPlayerStatisticValue(STAT_PLAYER_HIGHEST_FALLING_HIT) < damage)
  1270. GetPlayer()->UpdatePlayerStatistic(STAT_PLAYER_HIGHEST_FALLING_HIT, damage, true);
  1271. if (!GetPlayer()->GetInvulnerable())
  1272. GetPlayer()->SetCharSheetChanged(true);
  1273. GetCurrentZone()->SendDamagePacket(0, GetPlayer(), DAMAGE_PACKET_TYPE_SIMPLE_DAMAGE, GetPlayer()->GetInvulnerable() ? DAMAGE_PACKET_RESULT_INVULNERABLE : DAMAGE_PACKET_RESULT_SUCCESSFUL, DAMAGE_PACKET_DAMAGE_TYPE_FALLING, damage, 0);
  1274. if (GetPlayer()->GetHP() == 0) {
  1275. GetCurrentZone()->KillSpawn(false, GetPlayer(), 0);
  1276. }
  1277. }
  1278. }
  1279. safe_delete(request);
  1280. }
  1281. break;
  1282. }
  1283. case OP_MapFogDataUpdateMsg: {
  1284. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MapFogDataUpdateMsg", opcode, opcode);
  1285. LogWrite(MISC__TODO, 3, "TODO", "Handle (OP_MapFogDataUpdateMsg), ignoring it for now\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  1286. break;
  1287. }
  1288. case OP_SelectZoneTeleporterDestinatio: {
  1289. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SelectZoneTeleporterDestinatio", opcode, opcode);
  1290. ProcessTeleportLocation(app);
  1291. break;
  1292. }
  1293. case OP_SendLatestRequestMsg: {
  1294. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SendLatestRequestMsg", opcode, opcode);
  1295. uchar blah25[] = { 0x01 };
  1296. EQ2Packet* app25 = new EQ2Packet(OP_ClearDataMsg, blah25, sizeof(blah25));
  1297. QueuePacket(app25);
  1298. break;
  1299. }
  1300. case OP_ShowCreateFromRecipeUIMsg: {
  1301. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ShowCreateFromRecipeUIMsg", opcode, opcode);
  1302. break;
  1303. /*uchar blah[] ={0x09,0x0e,0x00,0x51,0x75,0x65,0x65,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e
  1304. ,0x79,0x00,0x00,0x00,0x00,0x40,0x40,0xff,0xff,0xff};
  1305. EQ2Packet* app = new EQ2Packet(OP_EncounterBrokenMsg, blah, sizeof(blah));
  1306. QueuePacket(app);
  1307. uchar blah2[] = {0x00,0x00,0xff,0xff,0xff,0xff};
  1308. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah2, sizeof(blah2));
  1309. QueuePacket(app);
  1310. uchar blah3[] ={0x09,0x17,0x00,0x5c,0x23,0x46,0x46,0x45,0x34,0x30,0x30,0x20,0x51,0x75,0x65,0x65
  1311. ,0x6e,0x27,0x73,0x20,0x43,0x6f,0x6c,0x6f,0x6e,0x79,0x00,0x00,0x00,0x00,0xa0,0x40
  1312. ,0xff,0xff,0xff};
  1313. app = new EQ2Packet(OP_CreateCharFromCBBRequestMsg, blah3, sizeof(blah3));
  1314. QueuePacket(app);
  1315. uchar blah4[] ={0x0b,0x00,0x21,0x00,0x00,0x00,0x1d,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17
  1316. ,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81,0x42,0x17,0x81
  1317. ,0x42,0x17,0x81,0x42,0x17,0x81,0x42};
  1318. app = new EQ2Packet(OP_UpdateSpellBookMsg, blah4, sizeof(blah4));
  1319. QueuePacket(app);
  1320. uchar blah5[] ={0x00,0x00};
  1321. app = new EQ2Packet(OP_RecipeDetailsMsg, blah5, sizeof(blah5));
  1322. QueuePacket(app);
  1323. break;*/
  1324. //player->GetPlayerInfo()->GetInfo()->cur_power = 100;
  1325. //EQ2Packet* app = player->GetPlayerInfo()->serialize(1);
  1326. //QueuePacket(app);
  1327. }
  1328. case OP_BeginItemCreationMsg: {
  1329. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginItemCreationMsg", opcode, opcode);
  1330. //DumpPacket(app->pBuffer, app->size);
  1331. PacketStruct* packet = configReader.getStruct("WS_BeginItemCreation", GetVersion());
  1332. if (packet) {
  1333. packet->LoadPacketData(app->pBuffer, app->size);
  1334. int32 item = 0;
  1335. vector<int32> items;
  1336. char tmp_item_id[20];
  1337. item = packet->getType_int32_ByName("primary_component_id");
  1338. if (item > 0)
  1339. items.push_back(item);
  1340. item = 0;
  1341. int8 build_components = packet->getType_int8_ByName("num_build_components");
  1342. for (int8 i = 0; i < build_components; i++) {
  1343. memset(tmp_item_id, 0, 20);
  1344. sprintf(tmp_item_id, "component_id_%i", i);
  1345. item = packet->getType_int32_ByName(tmp_item_id);
  1346. if (item > 0)
  1347. items.push_back(item);
  1348. item = 0;
  1349. }
  1350. item = packet->getType_int32_ByName("fuel_id");
  1351. if (item > 0)
  1352. items.push_back(item);
  1353. GetCurrentZone()->GetTradeskillMgr()->BeginCrafting(this, items);
  1354. safe_delete(packet);
  1355. }
  1356. break;
  1357. }
  1358. case OP_StopItemCreationMsg: {
  1359. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopItemCreationMsg", opcode, opcode);
  1360. //DumpPacket(app->pBuffer, app->size);
  1361. GetCurrentZone()->GetTradeskillMgr()->StopCrafting(this);
  1362. break;
  1363. }
  1364. case OP_SignalMsg: {
  1365. PacketStruct* packet = configReader.getStruct("WS_Signal", GetVersion());
  1366. if (packet) {
  1367. packet->LoadPacketData(app->pBuffer, app->size);
  1368. EQ2_16BitString str = packet->getType_EQ2_16BitString_ByName("signal");
  1369. if (str.size > 0) {
  1370. if (strcmp(str.data.c_str(), "sys_client_avatar_ready") == 0) {
  1371. SetReadyForUpdates();
  1372. GetPlayer()->SendSpawnChanges(true);
  1373. }
  1374. const char* zone_script = world.GetZoneScript(player->GetZone()->GetZoneID());
  1375. if (zone_script && lua_interface)
  1376. {
  1377. lua_interface->RunZoneScript(zone_script, "signal_changed", player->GetZone(), player, 0, str.data.c_str());
  1378. }
  1379. }
  1380. }
  1381. break;
  1382. }
  1383. case OP_EntityVerbsRequestMsg: {
  1384. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsRequestMsg", opcode, opcode);
  1385. HandleVerbRequest(app);
  1386. break;
  1387. }
  1388. case OP_EntityVerbsVerbMsg: {
  1389. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EntityVerbsVerbMsg", opcode, opcode);
  1390. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsVerb", GetVersion());
  1391. if (packet) {
  1392. packet->LoadPacketData(app->pBuffer, app->size);
  1393. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1394. player->SetTarget(player->GetSpawnWithPlayerID(spawn_id));
  1395. Spawn* spawn = player->GetTarget();
  1396. if (spawn && !spawn->IsNPC() && !spawn->IsPlayer()) {
  1397. string command = packet->getType_EQ2_16BitString_ByName("command").data;
  1398. if (!HandleHouseEntityCommands(spawn, spawn_id, command))
  1399. {
  1400. if (EntityCommandPrecheck(spawn, command.c_str())) {
  1401. if (spawn->IsGroundSpawn())
  1402. ((GroundSpawn*)spawn)->HandleUse(this, command);
  1403. else if (spawn->IsObject())
  1404. ((Object*)spawn)->HandleUse(this, command);
  1405. else if (spawn->IsWidget())
  1406. ((Widget*)spawn)->HandleUse(this, command);
  1407. else if (spawn->IsSign())
  1408. ((Sign*)spawn)->HandleUse(this, command);
  1409. }
  1410. }
  1411. }
  1412. else {
  1413. EQ2_16BitString command = packet->getType_EQ2_16BitString_ByName("command");
  1414. if (command.size > 0) {
  1415. string command_name = command.data;
  1416. if (command_name.find(" ") < 0xFFFFFFFF)
  1417. command_name = command_name.substr(0, command_name.find(" "));
  1418. int32 handler = commands.GetCommandHandler(command_name.c_str());
  1419. if (handler != 0xFFFFFFFF) {
  1420. if (command.data == command_name) {
  1421. command.data = "";
  1422. command.size = 0;
  1423. }
  1424. else {
  1425. command.data = command.data.substr(command.data.find(" ") + 1);
  1426. command.size = command.data.length();
  1427. }
  1428. commands.Process(handler, &command, this);
  1429. }
  1430. else {
  1431. if (spawn && spawn->IsNPC()) {
  1432. if (EntityCommandPrecheck(spawn, command.data.c_str())) {
  1433. if (!((NPC*)spawn)->HandleUse(this, command.data)) {
  1434. LogWrite(WORLD__ERROR, 0, "World", "Unhandled command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1435. }
  1436. }
  1437. }
  1438. else
  1439. LogWrite(WORLD__ERROR, 0, "World", "Unknown command in OP_EntityVerbsVerbMsg: %s", command.data.c_str());
  1440. }
  1441. }
  1442. }
  1443. safe_delete(packet);
  1444. }
  1445. break;
  1446. }
  1447. case OP_SkillInfoRequest: {
  1448. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SkillInfoRequest", opcode, opcode);
  1449. HandleSkillInfoRequest(app);
  1450. break;
  1451. }
  1452. case OP_UpdateTargetMsg: {
  1453. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_UpdateTargetMsg", opcode, opcode);
  1454. int16 index = 0;
  1455. memcpy(&index, app->pBuffer, sizeof(int16));
  1456. if (index == 0xFFFF)
  1457. GetPlayer()->SetTarget(0);
  1458. else
  1459. GetPlayer()->SetTarget(GetPlayer()->GetSpawnByIndex(index));
  1460. if (GetPlayer()->GetTarget())
  1461. GetCurrentZone()->CallSpawnScript(GetPlayer()->GetTarget(), SPAWN_SCRIPT_TARGETED, GetPlayer());
  1462. //player->SetTarget((int16*)app->pBuffer);
  1463. break;
  1464. }
  1465. case OP_ExamineInfoRequestMsg: {
  1466. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExamineInfoRequestMsg", opcode, opcode);
  1467. HandleExamineInfoRequest(app);
  1468. break;
  1469. }
  1470. case OP_QuickbarUpdateMsg:
  1471. //case OP_QuickbarAddMsg:
  1472. {
  1473. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuickbarUpdateMsg, OP_QuickbarAddMsg", opcode, opcode);
  1474. HandleQuickbarUpdateRequest(app);
  1475. break;
  1476. }
  1477. case OP_PredictionUpdateMsg: {
  1478. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PredictionUpdateMsg", opcode, opcode);
  1479. if (version <= 546) {
  1480. int8 offset = 9;
  1481. if (app->pBuffer[0] == 0xFF)
  1482. offset += 2;
  1483. if (app->size > offset) {
  1484. if (player->IsCasting()) {
  1485. float distance = 0;
  1486. float x = player->GetX();
  1487. float y = player->GetY();
  1488. float z = player->GetZ();
  1489. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1490. distance = player->GetDistance(x, y, z, false);
  1491. if (distance > .5)
  1492. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1493. }
  1494. else
  1495. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1496. player_pos_changed = true;
  1497. //DumpPacket(app);
  1498. }
  1499. }
  1500. else {
  1501. EQ2Packet* app = new EQ2Packet(OP_PredictionUpdateMsg, 0, 0);
  1502. QueuePacket(app);
  1503. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1504. }
  1505. break;
  1506. }
  1507. case OP_RemoteCmdMsg: {
  1508. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RemoteCmdMsg", opcode, opcode);
  1509. if (app->size > 0) {
  1510. EQ2_CommandString remote(app->pBuffer, app->size);
  1511. LogWrite(PACKET__DEBUG, 1, "Packet", "RemoteCmdMsg Packet dump:");
  1512. #if EQDEBUG >= 9
  1513. DumpPacket(app);
  1514. #endif
  1515. commands.Process(remote.handler, &remote.command, this);
  1516. }
  1517. else //bad client, disconnect
  1518. Disconnect();
  1519. break;
  1520. }
  1521. case OP_CancelSpellCast: {
  1522. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_CancelSpellCast", opcode, opcode);
  1523. current_zone->Interrupted(player, 0, 0, true);
  1524. SimpleMessage(CHANNEL_SPELLS_OTHER, "You stop casting.");
  1525. break;
  1526. }
  1527. case OP_UpdatePositionMsg: {
  1528. LogWrite(OPCODE__DEBUG, 7, "Opcode", "Opcode 0x%X (%i): OP_UpdatePositionMsg", opcode, opcode);
  1529. int8 offset = 13;
  1530. if (app->pBuffer[0] == 0xFF)
  1531. offset += 2;
  1532. if (app->size > offset) {
  1533. if (player->IsCasting()) {
  1534. float distance = 0;
  1535. float x = player->GetX();
  1536. float y = player->GetY();
  1537. float z = player->GetZ();
  1538. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1539. distance = player->GetDistance(x, y, z, false);
  1540. if (distance > .5)
  1541. current_zone->Interrupted(player, 0, SPELL_ERROR_INTERRUPTED, false, true);
  1542. }
  1543. else
  1544. player->PrepareIncomingMovementPacket(app->size - offset, app->pBuffer + offset, version);
  1545. player_pos_changed = true;
  1546. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  1547. //DumpPacket(app);
  1548. }
  1549. break;
  1550. }
  1551. case OP_MailSendMessageMsg: {
  1552. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_MailSendMessageMsg", opcode, opcode);
  1553. HandleSentMail(app);
  1554. break;
  1555. }
  1556. case OP_StopTrackingMsg: {
  1557. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_StopTrackingMsg", opcode, opcode);
  1558. player->GetZone()->RemovePlayerTracking(player, TRACKING_STOP);
  1559. break;
  1560. }
  1561. case OP_BeginTrackingMsg: {
  1562. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BeginTrackingMsg", opcode, opcode);
  1563. PacketStruct* packet = configReader.getStruct("WS_BeginTracking", GetVersion());
  1564. if (packet) {
  1565. packet->LoadPacketData(app->pBuffer, app->size);
  1566. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  1567. Spawn* spawn = player->GetSpawnWithPlayerID(spawn_id);
  1568. if (spawn) {
  1569. AddWaypoint(spawn->GetName(), WAYPOINT_CATEGORY_TRACKING, spawn_id);
  1570. BeginWaypoint(spawn->GetName(), spawn->GetX(), spawn->GetY(), spawn->GetZ());
  1571. player->GetZone()->RemovePlayerTracking(player, TRACKING_CLOSE_WINDOW);
  1572. }
  1573. safe_delete(packet);
  1574. }
  1575. break;
  1576. }
  1577. case OP_BioUpdateMsg: {
  1578. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BioUpdateMsg", opcode, opcode);
  1579. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  1580. if (packet) {
  1581. packet->LoadPacketData(app->pBuffer, app->size);
  1582. player->SetBiography(packet->getType_EQ2_16BitString_ByName("biography").data);
  1583. safe_delete(packet);
  1584. }
  1585. break;
  1586. }
  1587. case OP_RewardPackMsg: {
  1588. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RewardPackMsg", opcode, opcode);
  1589. /* This logging is still here because I remember another system using this packet and just want to make sure we can figure out that it's being sent
  1590. when we come across it (scatman) */
  1591. const char* name = app->GetOpcodeName();
  1592. if (name)
  1593. LogWrite(WORLD__DEBUG, 0, "World", "%s Received OP_RewardPackMsg %04i", name, app->GetRawOpcode());
  1594. else
  1595. LogWrite(WORLD__DEBUG, 0, "World", "Received OP_RewardPackMsg %04i", app->GetRawOpcode());
  1596. //DumpPacket(app);
  1597. PacketStruct* packet = configReader.getStruct("WS_RewardPackMsg", GetVersion());
  1598. if (packet) {
  1599. packet->LoadPacketData(app->pBuffer, app->size);
  1600. string recruiter_name = packet->getType_EQ2_16BitString_ByName("recruiter_name").data;
  1601. /* Player has contacted a guild recruiter */
  1602. if (recruiter_name.length() > 0) {
  1603. Guild* guild = guild_list.GetGuild(packet->getType_int32_ByName("guild_id"));
  1604. Client* recruiter = zone_list.GetClientByCharName(recruiter_name);
  1605. if (recruiter && guild) {
  1606. Message(CHANNEL_GUILD_EVENT, "Contact request sent to %s of %s.", recruiter->GetPlayer()->GetName(), guild->GetName());
  1607. recruiter->Message(CHANNEL_GUILD_EVENT, "%s [%u %s], [0 Unskilled] (%s) is requesting to speak to YOU about joining the guild.", player->GetName(), player->GetLevel(), classes.GetClassNameCase(player->GetAdventureClass()).c_str(), races.GetRaceNameCase(player->GetRace()));
  1608. recruiter->PlaySound("ui_guild_page");
  1609. }
  1610. }
  1611. /* New picture taken for guild recruiting */
  1612. else {
  1613. //DumpPacket(app->pBuffer, app->size);
  1614. int32 guild_id = 0;
  1615. int16 picture_data_size = 0;
  1616. unsigned char* recruiter_picture_data = 0;
  1617. memcpy(&guild_id, app->pBuffer + 4, sizeof(int32));
  1618. memcpy(&picture_data_size, app->pBuffer + 15, sizeof(int16));
  1619. Guild* guild = guild_list.GetGuild(guild_id);
  1620. if (guild) {
  1621. GuildMember* gm = guild->GetGuildMember(player);
  1622. if (gm) {
  1623. safe_delete_array(gm->recruiter_picture_data);
  1624. recruiter_picture_data = new unsigned char[picture_data_size];
  1625. for (int16 i = 0; i < picture_data_size; i++)
  1626. memcpy(recruiter_picture_data + i, app->pBuffer + 17 + i, 2);
  1627. gm->recruiter_picture_data = recruiter_picture_data;
  1628. gm->recruiter_picture_data_size = picture_data_size;
  1629. guild->SetMemberSaveNeeded(true);
  1630. }
  1631. }
  1632. }
  1633. safe_delete(packet);
  1634. }
  1635. break;
  1636. }
  1637. case OP_PetOptions: {
  1638. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PetOptions", opcode, opcode);
  1639. Spawn* target = player->GetTarget();
  1640. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  1641. if (packet && target && (target == player->GetPet() || target == player->GetCharmedPet() || target == player->GetDeityPet() || target == player->GetCosmeticPet())) {
  1642. bool change = false;
  1643. packet->LoadPacketData(app->pBuffer, app->size);
  1644. string name = packet->getType_EQ2_16BitString_ByName("pet_name").data;
  1645. if (strlen(name.c_str()) != 0) {
  1646. target->SetName(name.c_str());
  1647. strcpy(player->GetInfoStruct()->pet_name, name.c_str());
  1648. GetCurrentZone()->SendUpdateTitles(target);
  1649. change = true;
  1650. }
  1651. // Check protect self setting and update if needed
  1652. if (packet->getType_int8_ByName("protect_self") == 1) {
  1653. if ((player->GetInfoStruct()->pet_behavior & 2) == 0) {
  1654. player->GetInfoStruct()->pet_behavior += 2;
  1655. change = true;
  1656. }
  1657. }
  1658. else {
  1659. if ((player->GetInfoStruct()->pet_behavior & 2) != 0) {
  1660. player->GetInfoStruct()->pet_behavior -= 2;
  1661. change = true;
  1662. }
  1663. }
  1664. // Check protect master setting and update if needed
  1665. if (packet->getType_int8_ByName("protect_master") == 1) {
  1666. if ((player->GetInfoStruct()->pet_behavior & 1) == 0) {
  1667. player->GetInfoStruct()->pet_behavior += 1;
  1668. change = true;
  1669. }
  1670. }
  1671. else {
  1672. if ((player->GetInfoStruct()->pet_behavior & 1) != 0) {
  1673. player->GetInfoStruct()->pet_behavior -= 1;
  1674. change = true;
  1675. }
  1676. }
  1677. // Check stay/follow setting and update if needed
  1678. if (packet->getType_int8_ByName("stay_follow_toggle") == 1) {
  1679. if (player->GetInfoStruct()->pet_movement != 2) {
  1680. player->GetInfoStruct()->pet_movement = 2;
  1681. change = true;
  1682. }
  1683. }
  1684. else {
  1685. if (player->GetInfoStruct()->pet_movement != 1) {
  1686. player->GetInfoStruct()->pet_movement = 1;
  1687. change = true;
  1688. }
  1689. }
  1690. // Ranged/Melee settings are not implemented yet
  1691. if (change)
  1692. player->SetCharSheetChanged(true);
  1693. safe_delete(packet);
  1694. }
  1695. break;
  1696. }
  1697. case OP_RecipeBook: {
  1698. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_RecipeBook", opcode, opcode);
  1699. SendRecipeList();
  1700. break;
  1701. }
  1702. case OP_BuyPlayerHouseMsg: {
  1703. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_BuyPlayerHouseMsg", opcode, opcode);
  1704. DumpPacket(app);
  1705. PacketStruct* packet = configReader.getStruct("WS_BuyHouse", GetVersion());
  1706. if (packet) {
  1707. packet->LoadPacketData(app->pBuffer, app->size);
  1708. HouseZone* hz = world.GetHouseZone(packet->getType_int64_ByName("house_id"));
  1709. if (hz) {
  1710. std::vector<PlayerHouse*> houses = world.GetAllPlayerHouses(GetCharacterID());
  1711. if (houses.size() > 24)
  1712. {
  1713. SimpleMessage(CHANNEL_COLOR_YELLOW, "You already own 25 houses and may not own another.");
  1714. safe_delete(packet);
  1715. break;
  1716. }
  1717. if ((!hz->upkeep_coin && !hz->cost_coin) || player->RemoveCoins(hz->cost_coin+hz->upkeep_coin)) // TODO: Need option to take from bank if player does not have enough coin on them
  1718. {
  1719. ZoneServer* instance_zone = zone_list.GetByInstanceID(0, hz->zone_id);
  1720. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800; // 604800 = 7 days
  1721. int64 unique_id = database.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, instance_zone->GetInstanceID(), upkeep_due);
  1722. world.AddPlayerHouse(GetPlayer()->GetCharacterID(), hz->id, unique_id, instance_zone->GetInstanceID(), upkeep_due, 0, 0, GetPlayer()->GetName());
  1723. //ClientPacketFunctions::SendHousingList(this);
  1724. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(unique_id);
  1725. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1726. PlaySound("coin_cha_ching");
  1727. }
  1728. else
  1729. {
  1730. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to purchase the house.");
  1731. PlaySound("buy_failed");
  1732. }
  1733. }
  1734. }
  1735. safe_delete(packet);
  1736. break;
  1737. }
  1738. case OP_EnterHouseMsg: {
  1739. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EnterHouseMsg", opcode, opcode);
  1740. DumpPacket(app);
  1741. PacketStruct* packet = configReader.getStruct("WS_EnterHouse", GetVersion());
  1742. if (packet) {
  1743. packet->LoadPacketData(app->pBuffer, app->size);
  1744. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(packet->getType_int64_ByName("house_id"));
  1745. if (ph) {
  1746. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1747. if (hz) {
  1748. ZoneServer* house = zone_list.GetByInstanceID(ph->instance_id, hz->zone_id);
  1749. if (house) {
  1750. Zone(house, true);
  1751. }
  1752. }
  1753. }
  1754. }
  1755. safe_delete(packet);
  1756. break;
  1757. }
  1758. case OP_PayHouseUpkeepMsg: {
  1759. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_PayHouseUpkeepMsg", opcode, opcode);
  1760. DumpPacket(app);
  1761. PacketStruct* packet = configReader.getStruct("WS_PayUpkeep", GetVersion());
  1762. if (packet) {
  1763. packet->LoadPacketData(app->pBuffer, app->size);
  1764. int64 houseID = packet->getType_int64_ByName("house_id");
  1765. PlayerHouse* ph = world.GetPlayerHouseByUniqueID(houseID);
  1766. if (ph)
  1767. {
  1768. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1769. if (!hz)
  1770. {
  1771. Message(CHANNEL_COLOR_YELLOW, "HouseZone ID %u does NOT exist!", ph->house_id);
  1772. safe_delete(packet);
  1773. break;
  1774. }
  1775. int32 upkeep_due = Timer::GetUnixTimeStamp() + 604800;
  1776. if (((sint64)ph->upkeep_due - (sint64)Timer::GetUnixTimeStamp()) > 0)
  1777. {
  1778. upkeep_due = ph->upkeep_due + 604800; // 604800 = 7 days
  1779. if (upkeep_due > (Timer::GetUnixTimeStamp() + 7257600)) // 84 days max upkeep to pay https://eq2.zam.com/wiki/Housing_%28EQ2%29#Upkeep
  1780. {
  1781. Message(CHANNEL_COLOR_YELLOW, "You cannot pay more than 3 months of upkeep.");
  1782. PlaySound("buy_failed");
  1783. safe_delete(packet);
  1784. break;
  1785. }
  1786. }
  1787. int64 coinReq = hz->upkeep_coin;
  1788. int64 tmpRecoverCoins = 0;
  1789. bool escrowChange = false;
  1790. if (ph->escrow_coins && coinReq >= ph->escrow_coins) // more required to upkeep than in escrow, subtract what we have left
  1791. {
  1792. escrowChange = true;
  1793. tmpRecoverCoins = ph->escrow_coins;
  1794. coinReq -= ph->escrow_coins;
  1795. ph->escrow_coins = 0;
  1796. }
  1797. else if (ph->escrow_coins && coinReq && coinReq <= ph->escrow_coins)
  1798. {
  1799. escrowChange = true;
  1800. // more than enough in escrow, subtract and make our cost 0!
  1801. ph->escrow_coins -= coinReq;
  1802. coinReq = 0;
  1803. }
  1804. // TODO: Need support for upkeep_status, but alas status_points are not implemented!
  1805. if (!coinReq || coinReq && player->RemoveCoins(coinReq)) // TODO: Need option to take from bank if player does not have enough coin on them
  1806. {
  1807. database.AddHistory(ph, GetPlayer()->GetName(), "Paid Upkeep", Timer::GetUnixTimeStamp(), hz->upkeep_coin, 0, 0);
  1808. if (escrowChange)
  1809. database.UpdateHouseEscrow(ph->house_id, ph->instance_id, ph->escrow_coins);
  1810. ph->upkeep_due = upkeep_due;
  1811. database.SetHouseUpkeepDue(GetCharacterID(), ph->house_id, ph->instance_id, ph->upkeep_due);
  1812. //ClientPacketFunctions::SendHousingList(this);
  1813. ClientPacketFunctions::SendBaseHouseWindow(this, hz, ph, this->GetPlayer()->GetID());
  1814. PlaySound("coin_cha_ching");
  1815. }
  1816. else
  1817. {
  1818. // recover the escrow we were going to use but could not spend due to lack of funds
  1819. if (tmpRecoverCoins)
  1820. ph->escrow_coins += tmpRecoverCoins;
  1821. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have enough money to pay for upkeep.");
  1822. PlaySound("buy_failed");
  1823. }
  1824. }
  1825. else
  1826. Message(CHANNEL_COLOR_YELLOW, "PlayerHouse ID %u does NOT exist!", houseID);
  1827. }
  1828. safe_delete(packet);
  1829. break;
  1830. }
  1831. case OP_ExitHouseMsg: {
  1832. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ExitHouseMsg", opcode, opcode);
  1833. int32 instance_id = GetCurrentZone()->GetInstanceID();
  1834. if (instance_id > 0) {
  1835. PlayerHouse* ph = world.GetPlayerHouseByInstanceID(instance_id);
  1836. if (ph) {
  1837. HouseZone* hz = world.GetHouseZone(ph->house_id);
  1838. if (hz) {
  1839. ZoneServer* new_zone = zone_list.Get(hz->exit_zone_id);
  1840. // determine if this is an instanced zone that already exists
  1841. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(hz->exit_zone_id);
  1842. if (instance_zone || new_zone) {
  1843. GetPlayer()->SetX(hz->exit_x);
  1844. GetPlayer()->SetY(hz->exit_y);
  1845. GetPlayer()->SetZ(hz->exit_z);
  1846. GetPlayer()->SetHeading(hz->exit_heading);
  1847. if (instance_zone)
  1848. Zone(instance_zone->GetInstanceID(), false, true);
  1849. else
  1850. Zone(new_zone, false);
  1851. }
  1852. }
  1853. }
  1854. }
  1855. DumpPacket(app);
  1856. break;
  1857. }
  1858. case OP_QuestJournalWaypointMsg: {
  1859. //DumpPacket(app);
  1860. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_QuestJournalWaypointMsg", opcode, opcode);
  1861. PacketStruct* packet = configReader.getStruct("WS_QuestJournalWaypoint", GetVersion());
  1862. if (packet) {
  1863. packet->LoadPacketData(app->pBuffer, app->size);
  1864. int32 quests = packet->getType_int32_ByName("num_quests");
  1865. if (quests > 100) // just picking a number higher than max allowed
  1866. {
  1867. LogWrite(CCLIENT__ERROR, 0, "Client", "num_quests = %u - quantity too high, aborting load.", quests);
  1868. break;
  1869. }
  1870. LogWrite(CCLIENT__DEBUG, 0, "Client", "num_quests = %u", quests);
  1871. for (int32 i = 0; i < quests; i++) {
  1872. int32 id = packet->getType_int32_ByName("quest_id_0", i);
  1873. if (id == 0)
  1874. continue;
  1875. LogWrite(CCLIENT__DEBUG, 5, "Client", "quest_id = %u", id);
  1876. bool tracked = packet->getType_int8_ByName("quest_tracked_0", i) == 1 ? true : false;
  1877. if (player->player_quests.count(id) > 0) {
  1878. player->player_quests[id]->SetTracked(tracked);
  1879. player->player_quests[id]->SetSaveNeeded(true);
  1880. }
  1881. }
  1882. safe_delete(packet);
  1883. }
  1884. break;
  1885. }
  1886. case OP_PaperdollImage: {
  1887. PacketStruct* packet = configReader.getStruct("WS_PaperdollImage", version);
  1888. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1889. //First check if this is a new image... delete an existing partial image if one exists
  1890. int8 packet_index = packet->getType_int8_ByName("packetIndex");
  1891. if (packet_index == 0) {
  1892. safe_delete_array(incoming_paperdoll.image_bytes);
  1893. incoming_paperdoll.last_received_packet_index = 0;
  1894. incoming_paperdoll.current_size_bytes = 0;
  1895. }
  1896. //return if this packet is not the one we are expecting...
  1897. else if (packet_index != incoming_paperdoll.last_received_packet_index + 1) {
  1898. safe_delete(packet);
  1899. break;
  1900. }
  1901. //Check how many packets we're supposed to be receiving for this/these images
  1902. incoming_paperdoll.image_num_packets = packet->getType_int8_ByName("totalNumPackets");
  1903. //Check the image type, if this is a new type in the same series of packets we have a new image
  1904. int8 img_type = packet->getType_int8_ByName("image_type");
  1905. if (packet_index != 0 && img_type != incoming_paperdoll.image_type) {
  1906. //We have a new image. Save the old data and clear before continuing
  1907. SavePlayerImages();
  1908. }
  1909. incoming_paperdoll.image_type = img_type;
  1910. //Get the size of the image data in this packet
  1911. sint64 image_size = packet->getType_int32_ByName("imageSize");
  1912. if (image_size <= 0 || image_size > 1048576) {
  1913. //If this packet is saying that the array is size <= 0 or > 1 MiB return out... it shouldn't be those sizes ever
  1914. safe_delete(packet);
  1915. break;
  1916. }
  1917. //Create a new array
  1918. int32 new_image_size = image_size;
  1919. uchar* new_image = new uchar[incoming_paperdoll.current_size_bytes + new_image_size];
  1920. if (incoming_paperdoll.image_bytes) {
  1921. memcpy(new_image, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  1922. safe_delete_array(incoming_paperdoll.image_bytes);
  1923. }
  1924. //variable i should be the index in the packet of the first PNG file byte
  1925. vector<DataStruct*>* d_structs = packet->getStructs();
  1926. vector<DataStruct*>::iterator itr;
  1927. int32 i = 0;
  1928. for (itr = d_structs->begin(); itr != d_structs->end(); itr++) {
  1929. DataStruct* ds = (*itr);
  1930. if (strcmp(ds->GetName(), "pngData_0") != 0)
  1931. i += ds->GetDataSizeInBytes();
  1932. else
  1933. break;
  1934. }
  1935. //Return if this packet is bad and we would read out of bounds
  1936. if (app->size - i < new_image_size) {
  1937. safe_delete(packet);
  1938. safe_delete_array(new_image);
  1939. break;
  1940. }
  1941. uchar* tmp = new_image + incoming_paperdoll.current_size_bytes;
  1942. memcpy(tmp, app->pBuffer + i, new_image_size);
  1943. incoming_paperdoll.current_size_bytes += new_image_size;
  1944. incoming_paperdoll.image_bytes = new_image;
  1945. //Check if this is the last packet we're expecting for this image. Create a final image if so
  1946. if (incoming_paperdoll.image_num_packets == 1 ||
  1947. incoming_paperdoll.last_received_packet_index + 2 == incoming_paperdoll.image_num_packets) {
  1948. SavePlayerImages();
  1949. }
  1950. incoming_paperdoll.last_received_packet_index = packet_index;
  1951. }
  1952. safe_delete(packet);
  1953. break;
  1954. }
  1955. case OP_ReadyForTakeOffMsg:
  1956. {
  1957. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_ReadyForTakeOffMsg", opcode, opcode);
  1958. int32 index = GetCurrentZone()->GetFlightPathIndex(GetPendingFlightPath());
  1959. if (GetPendingFlightPath() > 0) {
  1960. if (index != -1) {
  1961. PacketStruct* packet = configReader.getStruct("WS_ClearForTakeOff", GetVersion());
  1962. if (packet) {
  1963. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  1964. packet->setDataByName("path_id", index);
  1965. packet->setDataByName("speed", GetCurrentZone()->GetFlightPathSpeed(GetPendingFlightPath()));
  1966. QueuePacket(packet->serialize());
  1967. safe_delete(packet);
  1968. on_auto_mount = true;
  1969. }
  1970. }
  1971. else {
  1972. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but unable to get an index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1973. Message(CHANNEL_ERROR, "Unable to get index for path (%u) in zone (%u)", GetPendingFlightPath(), GetCurrentZone()->GetZoneID());
  1974. EndAutoMount();
  1975. }
  1976. SetPendingFlightPath(0);
  1977. }
  1978. else
  1979. LogWrite(CCLIENT__ERROR, 0, "Client", "OP_ReadyForTakeOffMsg recieved but there is no pending flight path...");
  1980. break;
  1981. }
  1982. case OP_EarlyLandingRequestMsg:
  1983. {
  1984. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_EarlyLandingRequestMsg", opcode, opcode);
  1985. EndAutoMount();
  1986. break;
  1987. }
  1988. case OP_SubmitCharCust:
  1989. {
  1990. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): OP_SubmitCharCust", opcode, opcode);
  1991. PacketStruct* packet = configReader.getStruct("WS_SubmitCharCust", version);
  1992. if (packet && packet->LoadPacketData(app->pBuffer, app->size)) {
  1993. int8 type = packet->getType_int8_ByName("type");
  1994. if (type == 0) {
  1995. if (player->custNPC) {
  1996. player->custNPCTarget->CustomizeAppearance(packet);
  1997. current_zone->SendSpawnChanges(player->custNPCTarget);
  1998. }
  1999. else {
  2000. player->CustomizeAppearance(packet);
  2001. current_zone->SendSpawnChanges(player);
  2002. }
  2003. }
  2004. }
  2005. if (player->custNPC) {
  2006. memcpy(&player->appearance, &player->SavedApp, sizeof(AppearanceData));
  2007. memcpy(&player->features, &player->SavedFeatures, sizeof(CharFeatures));
  2008. if (player->custNPCTarget->IsBot())
  2009. database.SaveBotAppearance((Bot*)player->custNPCTarget);
  2010. player->custNPC = false;
  2011. player->custNPCTarget = 0;
  2012. player->changed = true;
  2013. player->info_changed = true;
  2014. current_zone->SendSpawnChanges(player, this);
  2015. }
  2016. break;
  2017. }
  2018. default: {
  2019. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Opcode 0x%X (%i): Unknown in %s", opcode, opcode, __FILE__);
  2020. const char* name = app->GetOpcodeName();
  2021. if (name)
  2022. LogWrite(OPCODE__DEBUG, 1, "Opcode", "%s Received %04X (%i)", name, app->GetRawOpcode(), app->GetRawOpcode());
  2023. else
  2024. LogWrite(OPCODE__DEBUG, 1, "Opcode", "Received %04X (%i)", app->GetRawOpcode(), app->GetRawOpcode());
  2025. //DumpPacket(app);
  2026. }
  2027. }
  2028. if (!eqs || !eqs->CheckActive()) {
  2029. return false;
  2030. }
  2031. return ret;
  2032. }
  2033. bool Client::HandleLootItem(Spawn* entity, Item* item) {
  2034. if (!item) {
  2035. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find item to loot!");
  2036. return false;
  2037. }
  2038. if (player->item_list.HasFreeSlot() || player->item_list.CanStack(item)) {
  2039. if (player->item_list.AssignItemToFreeSlot(item)) {
  2040. int8 type = CHANNEL_LOOT;
  2041. if (entity) {
  2042. Message(type, "You loot %s from the corpse of %s", item->CreateItemLink(GetVersion()).c_str(), entity->GetName());
  2043. }
  2044. else {
  2045. Message(type, "You found a %s.", item->CreateItemLink(GetVersion()).c_str());
  2046. }
  2047. Guild* guild = player->GetGuild();
  2048. if (guild && item->details.tier >= ITEM_TAG_LEGENDARY) {
  2049. char adjective[32];
  2050. int8 type;
  2051. memset(adjective, 0, sizeof(adjective));
  2052. if (item->details.tier >= ITEM_TAG_MYTHICAL) {
  2053. strncpy(adjective, "Mythical", sizeof(adjective) - 1);
  2054. type = GUILD_EVENT_LOOTS_MYTHICAL_ITEM;
  2055. }
  2056. else if (item->details.tier >= ITEM_TAG_FABLED) {
  2057. strncpy(adjective, "Fabled", sizeof(adjective) - 1);
  2058. type = GUILD_EVENT_LOOTS_FABELED_ITEM;
  2059. }
  2060. else {
  2061. strncpy(adjective, "Legendary", sizeof(adjective) - 1);
  2062. type = GUILD_EVENT_LOOTS_LEGENDARY_ITEM;
  2063. }
  2064. guild->AddNewGuildEvent(type, "%s has looted the %s %s", Timer::GetUnixTimeStamp(), true, player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2065. guild->SendMessageToGuild(type, "%s has looted the %s %s", player->GetName(), adjective, item->CreateItemLink(GetVersion()).c_str());
  2066. }
  2067. CheckPlayerQuestsItemUpdate(item);
  2068. return true;
  2069. }
  2070. else
  2071. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  2072. }
  2073. else
  2074. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to loot item: Inventory is FULL.");
  2075. return false;
  2076. }
  2077. bool Client::HandleLootItem(Spawn* entity, int32 item_id) {
  2078. if (!entity) {
  2079. return false;
  2080. }
  2081. return HandleLootItem(entity, entity->LootItem(item_id));
  2082. }
  2083. void Client::HandleLoot(EQApplicationPacket* app) {
  2084. PacketStruct* packet = configReader.getStruct("WS_LootType", GetVersion());
  2085. if (packet) {
  2086. packet->LoadPacketData(app->pBuffer, app->size);
  2087. int32 loot_id = packet->getType_int32_ByName("loot_id");
  2088. bool loot_all = (packet->getType_int8_ByName("loot_all") == 1);
  2089. safe_delete(packet);
  2090. int32 item_id = 0;
  2091. Item* item = 0;
  2092. Spawn* spawn = GetCurrentZone()->GetSpawnByID(loot_id);
  2093. if (player->HasPendingLootItems(loot_id)) {
  2094. Item* master_item = 0;
  2095. if (loot_all) {
  2096. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2097. if (items) {
  2098. for (int32 i = 0; loot_all && i < items->size(); i++) {
  2099. master_item = items->at(i);
  2100. if (master_item) {
  2101. item = new Item(master_item);
  2102. if (item) {
  2103. loot_all = HandleLootItem(0, item);
  2104. if (loot_all)
  2105. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2106. }
  2107. }
  2108. }
  2109. safe_delete(items);
  2110. }
  2111. }
  2112. else {
  2113. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2114. if (packet) {
  2115. packet->LoadPacketData(app->pBuffer, app->size);
  2116. item_id = packet->getType_int32_ByName("item_id");
  2117. vector<Item*>* items = player->GetPendingLootItems(loot_id);
  2118. if (items) {
  2119. for (int32 i = 0; i < items->size(); i++) {
  2120. master_item = items->at(i);
  2121. if (master_item && master_item->details.item_id == item_id) {
  2122. item = new Item(master_item);
  2123. if (item && HandleLootItem(0, item))
  2124. player->RemovePendingLootItem(loot_id, item->details.item_id);
  2125. break;
  2126. }
  2127. }
  2128. safe_delete(items);
  2129. }
  2130. safe_delete(packet);
  2131. }
  2132. }
  2133. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2134. if (outapp)
  2135. QueuePacket(outapp);
  2136. Loot(0, player->GetPendingLootItems(loot_id), spawn);
  2137. }
  2138. else {
  2139. if (spawn && !spawn->Alive() && spawn->IsNPC() && ((NPC*)spawn)->Brain()->CheckLootAllowed(player)) {
  2140. if (loot_all) {
  2141. while (loot_all && ((item_id = spawn->GetLootItemID()) > 0)) {
  2142. loot_all = HandleLootItem(spawn, item_id);
  2143. }
  2144. }
  2145. else {
  2146. packet = configReader.getStruct("WS_LootItem", GetVersion());
  2147. if (packet) {
  2148. packet->LoadPacketData(app->pBuffer, app->size);
  2149. item_id = packet->getType_int32_ByName("item_id");
  2150. HandleLootItem(spawn, item_id);
  2151. safe_delete(packet);
  2152. }
  2153. }
  2154. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  2155. if (outapp)
  2156. QueuePacket(outapp);
  2157. Loot(spawn);
  2158. if (!spawn->HasLoot()) {
  2159. CloseLoot(loot_id);
  2160. if (spawn->IsNPC())
  2161. GetCurrentZone()->RemoveDeadSpawn(spawn);
  2162. }
  2163. }
  2164. else {
  2165. if (!spawn) {
  2166. LogWrite(WORLD__ERROR, 0, "World", "Unknown id of %u when looting!", loot_id);
  2167. SimpleMessage(CHANNEL_COLOR_YELLOW, "Unable to find spawn to loot!");
  2168. }
  2169. else
  2170. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not unable to loot that at this time.");
  2171. }
  2172. }
  2173. }
  2174. }
  2175. void Client::HandleSkillInfoRequest(EQApplicationPacket* app) {
  2176. PacketStruct* request = 0;
  2177. // cout << "Request: \n";
  2178. // DumpPacket(app);
  2179. switch (app->pBuffer[0]) {
  2180. case 0: { //items
  2181. request = configReader.getStruct("WS_SkillInfoItemRequest", GetVersion());
  2182. if (request) {
  2183. request->LoadPacketData(app->pBuffer, app->size);
  2184. Item* item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(request->getType_int32_ByName("unique_id"));
  2185. if (!item)
  2186. item = GetPlayer()->item_list.GetItemFromUniqueID(request->getType_int32_ByName("unique_id"), true);
  2187. if (item) {
  2188. PacketStruct* response = configReader.getStruct("WS_SkillInfoItemResponse", GetVersion());
  2189. if (response) {
  2190. response->setDataByName("request_type", request->getType_int32_ByName("request_type"));
  2191. response->setDataByName("unique_id", request->getType_int32_ByName("unique_id"));
  2192. response->setSmallStringByName("name", item->name.c_str());
  2193. EQ2Packet* app2 = response->serialize();
  2194. //DumpPacket(app2);
  2195. QueuePacket(app2);
  2196. safe_delete(response);
  2197. }
  2198. }
  2199. }
  2200. break;
  2201. }
  2202. case 2: {//spells
  2203. request = configReader.getStruct("WS_SkillInfoSpellRequest", GetVersion());
  2204. if (request) {
  2205. request->LoadPacketData(app->pBuffer, app->size);
  2206. int32 id = request->getType_int32_ByName("id");
  2207. int8 tier = request->getType_int32_ByName("unique_id"); //on live this is really unique_id, but I'm going to make it tier instead :)
  2208. Spell* spell = master_spell_list.GetSpell(id, tier);
  2209. PacketStruct* response = configReader.getStruct("WS_SkillInfoResponse", GetVersion());
  2210. if (response) {
  2211. response->setDataByName("request_type", 2);
  2212. response->setDataByName("unique_id", tier);
  2213. response->setDataByName("id", id);
  2214. if (spell)
  2215. response->setSmallStringByName("name", spell->GetName());
  2216. else
  2217. response->setSmallStringByName("name", "Unknown Spell");
  2218. EQ2Packet* app2 = response->serialize();
  2219. // DumpPacket(app2);
  2220. QueuePacket(app2);
  2221. safe_delete(response);
  2222. }
  2223. }
  2224. break;
  2225. }
  2226. default: {
  2227. LogWrite(WORLD__ERROR, 0, "World", "Unknown SkillInfoRequest type of %i", (int)app->pBuffer[0]);
  2228. }
  2229. }
  2230. safe_delete(request);
  2231. }
  2232. void Client::HandleExamineInfoRequest(EQApplicationPacket* app) {
  2233. PacketStruct* request = 0;
  2234. //LogWrite(CCLIENT__DEBUG, 0, "Client", "Request2:");
  2235. //DumpPacket(app);
  2236. int8 type = app->pBuffer[0];
  2237. //283: item: 0, effect: 1, recipe: 2, spell: 3
  2238. if (version <= 283) {
  2239. if (type == 1)
  2240. type = 4;
  2241. else if (type == 2)
  2242. type = 5;
  2243. }
  2244. if (type == 3) {
  2245. Spell* spell = 0;
  2246. bool trait_display;
  2247. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2248. if (!request) {
  2249. return;
  2250. }
  2251. request->LoadPacketData(app->pBuffer, app->size);
  2252. int32 id = request->getType_int32_ByName("id");
  2253. int32 tier = request->getType_int32_ByName("tier");
  2254. int32 trait_tier = request->getType_int32_ByName("unknown_id");
  2255. bool display = true;
  2256. if (version <= 283 && request->getType_int8_ByName("display") == 1) // this is really requesting a partial packet
  2257. display = false;
  2258. else if (version <= 546)
  2259. display = request->getType_int8_ByName("display");
  2260. else if (version > 546)
  2261. display = false; // clients default is false otherwise it pops up a window when hovering over the knowledge book abilities
  2262. //printf("Type: (%i) Tier: (%u) Unknown ID: (%u) Item ID: (%u)\n",type,tier,trait_tier,id);
  2263. if (trait_tier != 0xFFFFFFFF) {
  2264. spell = master_spell_list.GetSpell(id, trait_tier);
  2265. if (!spell) {
  2266. spell = master_spell_list.GetSpell(id, trait_tier + 1);
  2267. }
  2268. trait_display = true;
  2269. }
  2270. else {
  2271. spell = master_spell_list.GetSpell(id, tier);
  2272. trait_display = false;
  2273. }
  2274. // if we can't find it on the master spell list, see if it is a custom spell
  2275. if (!spell)
  2276. {
  2277. lua_interface->FindCustomSpellLock();
  2278. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2279. if (tmpSpell)
  2280. spell = tmpSpell->spell;
  2281. lua_interface->FindCustomSpellUnlock();
  2282. }
  2283. if (spell && sent_spell_details.count(id) == 0) {
  2284. if (!spell->IsCopiedSpell())
  2285. sent_spell_details[id] = true;
  2286. EQ2Packet* app = spell->SerializeSpell(this, display, trait_display);
  2287. //DumpPacket(app);
  2288. QueuePacket(app);
  2289. }
  2290. }
  2291. else if (type == 0) {
  2292. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2293. if (!request) {
  2294. return;
  2295. }
  2296. request->LoadPacketData(app->pBuffer, app->size);
  2297. int32 id = request->getType_int32_ByName("id");
  2298. Item* item = 0;
  2299. // translate from unique id to spawn id for houses
  2300. Spawn* spawn = this->GetCurrentZone()->GetSpawnFromUniqueItemID(id);
  2301. bool wasSpawn = false;
  2302. if (spawn)
  2303. {
  2304. item = master_item_list.GetItem(spawn->GetPickupItemID());
  2305. if (item)
  2306. {
  2307. wasSpawn = true;
  2308. item = new Item(item);
  2309. item->details.unique_id = spawn->GetPickupUniqueItemID();
  2310. }
  2311. }
  2312. if (!item)
  2313. item = GetPlayer()->item_list.GetItemFromUniqueID(id, true);
  2314. if (!item)
  2315. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(id);
  2316. if (!item)
  2317. item = master_item_list.GetItem(id);
  2318. if (item) {// && sent_item_details.count(id) == 0){
  2319. sent_item_details[id] = true;
  2320. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2321. //DumpPacket(app);
  2322. QueuePacket(app);
  2323. if (wasSpawn)
  2324. delete item;
  2325. }
  2326. else {
  2327. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2328. DumpPacket(app);
  2329. }
  2330. }
  2331. else if (type == 1) {
  2332. request = configReader.getStruct("WS_ExamineInfoItemRequest", GetVersion());
  2333. if (!request) {
  2334. return;
  2335. }
  2336. request->LoadPacketData(app->pBuffer, app->size);
  2337. int32 id = request->getType_int32_ByName("id");
  2338. int32 unique_id = request->getType_int32_ByName("unique_id");
  2339. Item* item = GetPlayer()->item_list.GetItemFromUniqueID(unique_id, true);
  2340. if (!item)
  2341. item = GetPlayer()->GetEquipmentList()->GetItemFromUniqueID(unique_id);
  2342. if (!item)
  2343. item = master_item_list.GetItem(id);
  2344. if (item) {
  2345. sent_item_details[id] = true;
  2346. EQ2Packet* app = item->serialize(GetVersion(), false, GetPlayer());
  2347. //DumpPacket(app);
  2348. QueuePacket(app);
  2349. }
  2350. else {
  2351. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2352. DumpPacket(app);
  2353. }
  2354. }
  2355. else if (type == 2) {
  2356. request = configReader.getStruct("WS_ExamineInfoItemLinkRequest", GetVersion());
  2357. if (!request) {
  2358. return;
  2359. }
  2360. request->LoadPacketData(app->pBuffer, app->size);
  2361. int32 id = request->getType_int32_ByName("item_id");
  2362. //int32 unknown_0 = request->getType_int32_ByName("unknown",0);
  2363. //int32 unknown_1 = request->getType_int32_ByName("unknown",1);
  2364. //int8 unknown2 = request->getType_int8_ByName("unknown2");
  2365. //int32 unique_id = request->getType_int32_ByName("unique_id");
  2366. //int16 unknown5 = request->getType_sint16_ByName("unknown5");
  2367. //printf("Type: (%i) Unknown_0: (%u) Unknown_1: (%u) Unknown2: (%i) Unique ID: (%u) Unknown5: (%i) Item ID: (%u)\n",type,unknown_0,unknown_1,unknown2,unique_id,unknown5,id);
  2368. Item* item = master_item_list.GetItem(id);
  2369. if (item) {
  2370. //only display popup for non merchant links
  2371. EQ2Packet* app = item->serialize(GetVersion(), (request->getType_int8_ByName("show_popup") != 0), GetPlayer(), true, 0, 0, true);
  2372. //DumpPacket(app);
  2373. QueuePacket(app);
  2374. }
  2375. else {
  2376. LogWrite(WORLD__ERROR, 0, "World", "HandleExamineInfoRequest: Unknown Item ID = %u", id);
  2377. DumpPacket(app);
  2378. }
  2379. }
  2380. else if (type == 4) { //spell effect
  2381. request = configReader.getStruct("WS_ExamineSpellEffectRequest", GetVersion());
  2382. if (!request) {
  2383. return;
  2384. }
  2385. request->LoadPacketData(app->pBuffer, app->size);
  2386. int32 id = request->getType_int32_ByName("id");
  2387. int16 display = request->getType_int8_ByName("partial_info");
  2388. SpellEffects* effect = player->GetSpellEffect(id);
  2389. //printf("Type: (%i) Unknown5: (%i) Item ID: (%u)\n",type,unknown5,id);
  2390. if (effect) {
  2391. int8 tier = effect->tier;
  2392. Spell* spell = master_spell_list.GetSpell(id, tier);
  2393. // if we can't find it on the master spell list, see if it is a custom spell
  2394. if (!spell)
  2395. {
  2396. lua_interface->FindCustomSpellLock();
  2397. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2398. EQ2Packet* pack = 0;
  2399. if (tmpSpell)
  2400. spell = tmpSpell->spell;
  2401. lua_interface->FindCustomSpellUnlock();
  2402. }
  2403. if (spell && sent_spell_details.count(id) == 0) {
  2404. if (!spell->IsCopiedSpell())
  2405. sent_spell_details[id] = true;
  2406. int8 type = 0;
  2407. if (version <= 283)
  2408. type = 1;
  2409. EQ2Packet* app = spell->SerializeSpecialSpell(this, false, type, 0x81);
  2410. //DumpPacket(app);
  2411. QueuePacket(app);
  2412. }
  2413. }
  2414. }
  2415. else if (type == 5) { // recipe info
  2416. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2417. if (!request)
  2418. return;
  2419. request->LoadPacketData(app->pBuffer, app->size);
  2420. int32 id = request->getType_int32_ByName("unknown_id");
  2421. Recipe* recipe = master_recipe_list.GetRecipe(id);
  2422. if (recipe) {
  2423. EQ2Packet* app = recipe->SerializeRecipe(this, recipe, false, GetItemPacketType(GetVersion()), 0x02);
  2424. //DumpPacket(app);
  2425. QueuePacket(app);
  2426. }
  2427. }
  2428. else if (type == 6) { // AA spell info
  2429. Spell* spell = 0;
  2430. //Spell* spell2 = 0;
  2431. //AltAdvanceData* data = 0;
  2432. request = configReader.getStruct("WS_ExamineInfoRequest", GetVersion());
  2433. if (!request)
  2434. return;
  2435. request->LoadPacketData(app->pBuffer, app->size);
  2436. int32 id = request->getType_int32_ByName("id");
  2437. int32 tier = GetPlayer()->GetSpellTier(id);
  2438. LogWrite(WORLD__INFO, 0, "World", "Examine Info Request->Unique ID: %u Tier: %u ", id, tier);
  2439. //data = master_aa_list.GetAltAdvancement(id);
  2440. //LogWrite(WORLD__INFO, 0, "World", "SOE Spell CRC: %u", data->spell_crc);
  2441. //spell = master_spell_list.GetSpellByCRC(data->spell_crc);
  2442. spell = master_spell_list.GetSpell(id, tier);
  2443. if (!spell)
  2444. spell = master_spell_list.GetSpell(id, 1);
  2445. if (!spell)
  2446. {
  2447. lua_interface->FindCustomSpellLock();
  2448. LuaSpell* tmpSpell = lua_interface->FindCustomSpell(id);
  2449. if (tmpSpell)
  2450. spell = tmpSpell->spell;
  2451. lua_interface->FindCustomSpellUnlock();
  2452. }
  2453. if (!spell)
  2454. {
  2455. LogWrite(WORLD__ERROR, 0, "WORLD", "FAILED Examine Info Request-> Spell ID: %u, tier: %i", id, tier);
  2456. return;
  2457. }
  2458. //if (spell && sent_spell_details.count(spell->GetSpellID()) == 0) {
  2459. if (!spell->IsCopiedSpell())
  2460. sent_spell_details[spell->GetSpellID()] = true;
  2461. // EQ2Packet* app = spell->SerializeAASpell(this,tier, data, false, GetItemPacketType(GetVersion()), 0x04);
  2462. EQ2Packet* app = master_spell_list.GetAASpellPacket(id, tier, this, false, 0x4F);//0x45 change version to match client
  2463. /////////////////////////////////////////GetAASpellPacket(int32 id, int8 tier, Client* client, bool display, int8 packet_type) {
  2464. //DumpPacket(app);
  2465. LogWrite(WORLD__INFO, 0, "WORLD", "Examine Info Request-> Spell ID: %u", spell->GetSpellID());
  2466. QueuePacket(app);
  2467. //}
  2468. }
  2469. else {
  2470. LogWrite(WORLD__ERROR, 0, "World", "Unknown examine request: %i", (int)type);
  2471. DumpPacket(app);
  2472. }
  2473. safe_delete(request);
  2474. }
  2475. void Client::HandleQuickbarUpdateRequest(EQApplicationPacket* app) {
  2476. PacketStruct* request = configReader.getStruct("WS_QuickBarUpdateRequest", GetVersion());
  2477. if (request) {
  2478. request->LoadPacketData(app->pBuffer, app->size);
  2479. int32 id = request->getType_int32_ByName("id");
  2480. int32 bar = request->getType_int32_ByName("hotbar_number");
  2481. int32 slot = request->getType_int32_ByName("hotkey_slot");
  2482. int32 type = request->getType_int32_ByName("type");
  2483. int8 tier = request->getType_int32_ByName("unique_id");
  2484. EQ2_16BitString text = request->getType_EQ2_16BitString_ByName("text");
  2485. Spell* spell = 0;
  2486. if (type == 0xFFFFFFFF)
  2487. GetPlayer()->RemoveQuickbarItem(bar, slot);
  2488. else {
  2489. if (type == QUICKBAR_NORMAL)
  2490. spell = master_spell_list.GetSpell(id, tier);
  2491. if (spell)
  2492. GetPlayer()->AddQuickbarItem(bar, slot, type, spell->GetSpellIcon(), spell->GetSpellIconBackdrop(), id, tier, 0, text.data.c_str());
  2493. else
  2494. GetPlayer()->AddQuickbarItem(bar, slot, type, 0, 0, id, 0, 0, text.data.c_str());
  2495. }
  2496. safe_delete(request);
  2497. }
  2498. }
  2499. bool Client::Process(bool zone_process) {
  2500. if (!eqs) {
  2501. return false;
  2502. }
  2503. if ((connected_to_zone && !zone_process) || (!connected_to_zone && zone_process)) {
  2504. return true;
  2505. }
  2506. if (new_client_login) {
  2507. LogWrite(CCLIENT__DEBUG, 0, "Client", "SendLoginInfo to new client...");
  2508. SendLoginInfo();
  2509. new_client_login = false;
  2510. }
  2511. bool ret = true;
  2512. sockaddr_in to;
  2513. memset((char*)&to, 0, sizeof(to));
  2514. to.sin_family = AF_INET;
  2515. to.sin_port = port;
  2516. to.sin_addr.s_addr = ip;
  2517. /************ Get all packets from packet manager out queue and process them ************/
  2518. EQApplicationPacket* app = 0;
  2519. if (eqs && !eqs->CheckActive()) {
  2520. num_active_failures++;
  2521. LogWrite(CCLIENT__DEBUG, 7, "Client", "%s, num_active_failures = %i", __FUNCTION__, num_active_failures);
  2522. if (num_active_failures > 100) {
  2523. return false;
  2524. }
  2525. return true;
  2526. }
  2527. while (ret && eqs && (app = eqs->PopPacket())) {
  2528. ret = HandlePacket(app);
  2529. LogWrite(CCLIENT__DEBUG, 5, "Client", "Func: %s, Line: %i, Opcode: '%s'", __FUNCTION__, __LINE__, app->GetOpcodeName());
  2530. delete app;
  2531. }
  2532. if (GetCurrentZone() && GetCurrentZone()->GetSpawnByID(GetPlayer()->GetID()) && should_load_spells) {
  2533. player->ApplyPassiveSpells();
  2534. //database.LoadCharacterActiveSpells(player);
  2535. player->UnlockAllSpells(true);
  2536. should_load_spells = false;
  2537. }
  2538. if (delayedLogin && delayTimer.Enabled() && delayTimer.Check())
  2539. {
  2540. if (!HandleNewLogin(delayedAccountID, delayedAccessKey))
  2541. return false;
  2542. }
  2543. if (quest_updates) {
  2544. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, ProcessQuestUpdates", __FUNCTION__, __LINE__);
  2545. ProcessQuestUpdates();
  2546. }
  2547. if (last_update_time > 0 && last_update_time < (Timer::GetCurrentTime2() - 300)) {
  2548. LogWrite(CCLIENT__DEBUG, 1, "Client", "%s, CheckQuestQueue", __FUNCTION__, __LINE__);
  2549. CheckQuestQueue();
  2550. }
  2551. if (pos_update.Check() && player_pos_changed && IsReadyForUpdates() && ( !disconnect_timer || !disconnect_timer->Enabled())) {
  2552. //GetPlayer()->CalculateLocation();
  2553. client_list.CheckPlayersInvisStatus(this);
  2554. GetCurrentZone()->SendPlayerPositionChanges(GetPlayer());
  2555. player_pos_changed = false;
  2556. GetCurrentZone()->CheckTransporters(this);
  2557. }
  2558. if (lua_interface && lua_debug && lua_debug_timer.Check())
  2559. lua_interface->UpdateDebugClients(this);
  2560. if (quest_pos_timer.Check())
  2561. CheckPlayerQuestsLocationUpdate();
  2562. if (camp_timer && camp_timer->Check() && getConnection()) {
  2563. getConnection()->SendDisconnect(false);
  2564. safe_delete(camp_timer);
  2565. disconnect_timer = new Timer(2000);
  2566. disconnect_timer->Start();
  2567. }
  2568. if (player->GetSkills()->HasSkillUpdates()) {
  2569. vector<Skill*>* skills = player->GetSkills()->GetSkillUpdates();
  2570. if (skills) {
  2571. Skill* skill = 0;
  2572. vector<Skill*>::iterator itr;
  2573. for (itr = skills->begin(); itr != skills->end(); itr++) {
  2574. skill = *itr;
  2575. SkillChanged(skill, skill->previous_val, skill->current_val);
  2576. }
  2577. EQ2Packet* app = GetPlayer()->skill_list.GetSkillPacket(GetVersion());
  2578. if (app) QueuePacket(app);
  2579. safe_delete(skills);
  2580. }
  2581. }
  2582. if (disconnect_timer && disconnect_timer->Check()) {
  2583. safe_delete(disconnect_timer);
  2584. ret = false;
  2585. }
  2586. m_resurrect.writelock(__FUNCTION__, __LINE__);
  2587. if (current_rez.should_delete || (current_rez.expire_timer && current_rez.expire_timer->Check(false))) {
  2588. safe_delete(current_rez.expire_timer);
  2589. current_rez.expire_timer = 0;
  2590. current_rez.active = false;
  2591. current_rez.caster = 0;
  2592. current_rez.crit = false;
  2593. current_rez.crit_mod = 0;
  2594. current_rez.expire_timer = 0;
  2595. current_rez.heal_name = "";
  2596. current_rez.hp_perc = 0;
  2597. current_rez.mp_perc = 0;
  2598. current_rez.no_calcs = false;
  2599. current_rez.range = 0;
  2600. current_rez.should_delete = false;
  2601. current_rez.spell_name = "";
  2602. current_rez.spell_visual = 0;
  2603. current_rez.subspell = 0;
  2604. }
  2605. m_resurrect.releasewritelock(__FUNCTION__, __LINE__);
  2606. // Quest timers
  2607. Quest* failed_step = 0;
  2608. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  2609. if (quest_timers.size() > 0) {
  2610. vector<int32>::iterator itr;
  2611. map<int32, Quest*>* player_quests = player->GetPlayerQuests();
  2612. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  2613. if (player_quests->count(*itr) > 0 && player_quests->at(*itr)->GetStepTimer() != 0) {
  2614. Quest* quest = player_quests->at(*itr);
  2615. if (Timer::GetUnixTimeStamp() >= quest->GetStepTimer()) {
  2616. failed_step = quest;
  2617. break;
  2618. }
  2619. }
  2620. else {
  2621. quest_timers.erase(itr);
  2622. break;
  2623. }
  2624. }
  2625. }
  2626. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  2627. if (failed_step)
  2628. failed_step->StepFailed(failed_step->GetTimerStep());
  2629. if (player->ControlFlagsChanged())
  2630. player->SendControlFlagUpdates(this);
  2631. if (!eqs || (eqs && !eqs->CheckActive()))
  2632. ret = false;
  2633. // redundant to client disconnect
  2634. // if(!ret)
  2635. // Save();
  2636. return ret;
  2637. }
  2638. ClientList::ClientList() {
  2639. MClients.SetName("ClientList::MClients");
  2640. }
  2641. ClientList::~ClientList() {
  2642. }
  2643. void ClientList::ReloadQuests() {
  2644. list<Client*>::iterator client_iter;
  2645. Client* client = 0;
  2646. MClients.readlock(__FUNCTION__, __LINE__);
  2647. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2648. client = *client_iter;
  2649. if (client)
  2650. client->ReloadQuests();
  2651. }
  2652. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2653. }
  2654. void ClientList::CheckPlayersInvisStatus(Client* owner) {
  2655. if (!owner->GetPlayer() || (!owner->GetPlayer()->IsInvis() && !owner->GetPlayer()->IsStealthed()))
  2656. return;
  2657. list<Client*>::iterator client_iter;
  2658. Client* client = 0;
  2659. MClients.readlock(__FUNCTION__, __LINE__);
  2660. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2661. client = *client_iter;
  2662. if (client == owner || client->GetPlayer() == NULL)
  2663. continue;
  2664. if (client->GetPlayer()->CheckChangeInvisHistory((Entity*)owner->GetPlayer()))
  2665. client->GetPlayer()->GetZone()->SendSpawnChanges(owner->GetPlayer(), client, true, true);
  2666. }
  2667. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2668. }
  2669. void ClientList::RemovePlayerFromInvisHistory(int32 spawnID) {
  2670. list<Client*>::iterator client_iter;
  2671. Client* client = 0;
  2672. MClients.readlock(__FUNCTION__, __LINE__);
  2673. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2674. client = *client_iter;
  2675. if (!client->GetPlayer())
  2676. continue;
  2677. client->GetPlayer()->RemoveTargetInvisHistory(spawnID);
  2678. }
  2679. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2680. }
  2681. int32 ClientList::Count() {
  2682. return client_list.size();
  2683. }
  2684. void ClientList::Add(Client* client) {
  2685. MClients.writelock(__FUNCTION__, __LINE__);
  2686. client_list.push_back(client);
  2687. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2688. }
  2689. Client* ClientList::FindByAccountID(int32 account_id) {
  2690. list<Client*>::iterator client_iter;
  2691. Client* client = 0;
  2692. Client* ret = 0;
  2693. MClients.readlock(__FUNCTION__, __LINE__);
  2694. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2695. client = *client_iter;
  2696. if (client->GetAccountID() == account_id) {
  2697. ret = client;
  2698. break;
  2699. }
  2700. }
  2701. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2702. return ret;
  2703. }
  2704. Client* ClientList::FindByName(char* charName) {
  2705. list<Client*>::iterator client_iter;
  2706. Client* client = 0;
  2707. Client* ret = 0;
  2708. MClients.readlock(__FUNCTION__, __LINE__);
  2709. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2710. client = *client_iter;
  2711. if (!client || !client->GetPlayer())
  2712. continue;
  2713. if (!strncmp(client->GetPlayer()->GetName(), charName, strlen(charName))) {
  2714. ret = client;
  2715. break;
  2716. }
  2717. }
  2718. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2719. return ret;
  2720. }
  2721. Client* ClientList::Get(int32 ip, int16 port) {
  2722. list<Client*>::iterator client_iter;
  2723. Client* client = 0;
  2724. Client* ret = 0;
  2725. MClients.readlock(__FUNCTION__, __LINE__);
  2726. for (client_iter = client_list.begin(); client_list.size() > 0 && client_iter != client_list.end(); client_iter++) {
  2727. client = *client_iter;
  2728. if (client->GetIP() == ip && client->GetPort() == port) {
  2729. ret = client;
  2730. break;
  2731. }
  2732. }
  2733. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2734. return ret;
  2735. }
  2736. void ClientList::Process() {
  2737. list<Client*>::iterator client_iter;
  2738. list<Client*>::iterator erase_iter;
  2739. Client* client = 0;
  2740. MClients.readlock(__FUNCTION__, __LINE__);
  2741. erase_iter = client_list.end();
  2742. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2743. client = *client_iter;
  2744. // have a sanity check because the client list can sometimes obtain null client pointers
  2745. if (!client || client->remove_from_list || (!client->Process())) { // if we should be removing from list, don't process any further
  2746. erase_iter = client_iter;
  2747. break;
  2748. }
  2749. }
  2750. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2751. if (erase_iter != client_list.end()) {
  2752. client = *erase_iter;
  2753. MClients.writelock(__FUNCTION__, __LINE__);
  2754. client_list.erase(erase_iter);
  2755. MClients.releasewritelock(__FUNCTION__, __LINE__);
  2756. if (client && !client->remove_from_list) {
  2757. struct in_addr in;
  2758. in.s_addr = client->GetIP();
  2759. LogWrite(WORLD__INFO, 0, "World", "Removing client from ip: %s port: %i", inet_ntoa(in), client->GetPort());
  2760. safe_delete(client);
  2761. }
  2762. }
  2763. }
  2764. void ClientList::RemoveConnection(EQStream* eqs) {
  2765. Client* client;
  2766. if (eqs) {
  2767. list<Client*>::iterator client_iter;
  2768. MClients.readlock(__FUNCTION__, __LINE__);
  2769. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2770. client = *client_iter;
  2771. if (client->getConnection() == eqs)
  2772. client->Disconnect(false);
  2773. }
  2774. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2775. }
  2776. }
  2777. bool ClientList::ContainsStream(EQStream* eqs) {
  2778. if (!eqs) {
  2779. return false;
  2780. }
  2781. list<Client*>::iterator client_iter;
  2782. bool ret = false;
  2783. MClients.readlock(__FUNCTION__, __LINE__);
  2784. for (client_iter = client_list.begin(); client_iter != client_list.end(); client_iter++) {
  2785. if ((*client_iter)->getConnection() && (*client_iter)->getConnection()->GetRemotePort() == eqs->GetRemotePort() && (*client_iter)->getConnection()->GetRemoteIP() == eqs->GetRemoteIP()) {
  2786. ret = true;
  2787. break;
  2788. }
  2789. }
  2790. MClients.releasereadlock(__FUNCTION__, __LINE__);
  2791. return ret;
  2792. }
  2793. void ClientList::Remove(Client* client, bool remove_data) {
  2794. client->remove_from_list = true;
  2795. if (remove_data) {
  2796. safe_delete(client);
  2797. }
  2798. }
  2799. void Client::SetCurrentZone(int32 id) {
  2800. if (current_zone) {
  2801. //current_zone->GetCombat()->RemoveHate(player);
  2802. current_zone->RemoveSpawn(false, player, false);
  2803. }
  2804. SetCurrentZone(zone_list.Get(id));
  2805. }
  2806. void Client::SetCurrentZoneByInstanceID(int32 id, int32 zoneid) {
  2807. if (current_zone) {
  2808. //current_zone->GetCombat()->RemoveHate(player);
  2809. current_zone->RemoveSpawn(false, player, false);
  2810. }
  2811. SetCurrentZone(zone_list.GetByInstanceID(id, zoneid));
  2812. }
  2813. ZoneServer* Client::GetCurrentZone() {
  2814. return current_zone;
  2815. }
  2816. int8 Client::GetMessageChannelColor(int8 channel_type) {
  2817. if (GetVersion() >= 973 && GetVersion() <= 1000) {
  2818. if (channel_type == CHANNEL_LOOT)
  2819. return CHANNEL_COLOR_NEW_LOOT;
  2820. }
  2821. else if (GetVersion() >= 973) {
  2822. if (channel_type == CHANNEL_LOOT)
  2823. return CHANNEL_COLOR_NEWEST_LOOT;
  2824. }
  2825. if (GetVersion() <= 283) {
  2826. if (channel_type <=12)
  2827. return channel_type;
  2828. switch (channel_type) {
  2829. case CHANNEL_GROUP_CHAT:
  2830. case CHANNEL_GROUP_SAY:
  2831. case CHANNEL_RAID_SAY:
  2832. case CHANNEL_GUILD_CHAT:
  2833. case CHANNEL_GUILD_SAY:
  2834. case CHANNEL_OFFICER_SAY:
  2835. case CHANNEL_GUILD_MOTD:
  2836. return channel_type - 1;
  2837. case CHANNEL_PRIVATE_CHAT:
  2838. case CHANNEL_NONPLAYER_TELL:
  2839. return channel_type - 5;
  2840. case CHANNEL_PRIVATE_TELL:
  2841. case CHANNEL_TELL_FROM_CS:
  2842. return channel_type - 6;
  2843. case CHANNEL_CHAT_CHANNEL_TEXT:
  2844. case CHANNEL_OUT_OF_CHARACTER:
  2845. case CHANNEL_AUCTION:
  2846. case CHANNEL_CUSTOM_CHANNEL:
  2847. case CHANNEL_CHARACTER_TEXT:
  2848. case CHANNEL_REWARD:
  2849. case CHANNEL_DEATH:
  2850. case CHANNEL_PET_CHAT:
  2851. case CHANNEL_SKILL:
  2852. return channel_type - 7;
  2853. case CHANNEL_SPELLS:
  2854. case CHANNEL_YOU_CAST:
  2855. case CHANNEL_YOU_FAIL:
  2856. return channel_type - 8;
  2857. case CHANNEL_FRIENDLY_CAST:
  2858. case CHANNEL_FRIENDLY_FAIL:
  2859. case CHANNEL_OTHER_CAST:
  2860. case CHANNEL_OTHER_FAIL:
  2861. case CHANNEL_HOSTILE_CAST:
  2862. case CHANNEL_HOSTILE_FAIL:
  2863. case CHANNEL_WORN_OFF:
  2864. case CHANNEL_SPELLS_OTHER:
  2865. return channel_type - 9;
  2866. case CHANNEL_COMBAT:
  2867. return channel_type - 15;
  2868. case CHANNEL_HEROIC_OPPORTUNITY:
  2869. case CHANNEL_NON_MELEE_DAMAGE:
  2870. case CHANNEL_DAMAGE_SHIELD:
  2871. return channel_type - 16;
  2872. case CHANNEL_MELEE_COMBAT:
  2873. case CHANNEL_WARNINGS:
  2874. case CHANNEL_YOU_HIT:
  2875. case CHANNEL_YOU_MISS:
  2876. case CHANNEL_ATTACKER_HITS:
  2877. case CHANNEL_ATTACKER_MISSES:
  2878. return channel_type - 18;
  2879. case CHANNEL_OTHER_HIT:
  2880. case CHANNEL_OTHER_MISSES:
  2881. case CHANNEL_CRITICAL_HIT:
  2882. return channel_type - 22;
  2883. case CHANNEL_OTHER:
  2884. case CHANNEL_MONEY_SPLIT:
  2885. case CHANNEL_LOOT:
  2886. return channel_type - 30;
  2887. case CHANNEL_COMMAND_TEXT:
  2888. case CHANNEL_BROADCAST:
  2889. case CHANNEL_WHO:
  2890. case CHANNEL_COMMANDS:
  2891. case CHANNEL_MERCHANT:
  2892. case CHANNEL_MERCHANT_BUY_SELL:
  2893. case CHANNEL_CONSIDER_MESSAGE:
  2894. case CHANNEL_CON_MINUS_2:
  2895. case CHANNEL_CON_MINUS_1:
  2896. case CHANNEL_CON_0:
  2897. case CHANNEL_CON_1:
  2898. case CHANNEL_CON_2:
  2899. return channel_type - 31;
  2900. default: {
  2901. return CHANNEL_DEFAULT;
  2902. }
  2903. }
  2904. }
  2905. else if (GetVersion() <= 546) {
  2906. if (channel_type < 20)
  2907. return channel_type;
  2908. switch (channel_type) {
  2909. case CHANNEL_GUILD_MOTD:
  2910. case CHANNEL_GUILD_MEMBER_ONLINE:
  2911. case CHANNEL_GUILD_EVENT:
  2912. return channel_type + 1;
  2913. case CHANNEL_PRIVATE_CHAT:
  2914. case CHANNEL_NONPLAYER_TELL:
  2915. return channel_type - 1;
  2916. case CHANNEL_PRIVATE_TELL:
  2917. case CHANNEL_TELL_FROM_CS:
  2918. case CHANNEL_ARENA:
  2919. case CHANNEL_CHAT_CHANNEL_TEXT:
  2920. case CHANNEL_OUT_OF_CHARACTER:
  2921. case CHANNEL_AUCTION:
  2922. case CHANNEL_CUSTOM_CHANNEL:
  2923. case CHANNEL_CHARACTER_TEXT:
  2924. case CHANNEL_REWARD:
  2925. case CHANNEL_DEATH:
  2926. case CHANNEL_PET_CHAT:
  2927. case CHANNEL_SKILL:
  2928. case CHANNEL_FACTION:
  2929. case CHANNEL_SPELLS:
  2930. case CHANNEL_YOU_CAST:
  2931. case CHANNEL_YOU_FAIL:
  2932. return channel_type - 2;
  2933. case CHANNEL_FRIENDLY_CAST:
  2934. case CHANNEL_FRIENDLY_FAIL:
  2935. case CHANNEL_OTHER_CAST:
  2936. case CHANNEL_OTHER_FAIL:
  2937. case CHANNEL_HOSTILE_CAST:
  2938. case CHANNEL_HOSTILE_FAIL:
  2939. case CHANNEL_WORN_OFF:
  2940. case CHANNEL_SPELLS_OTHER:
  2941. case CHANNEL_HEAL_SPELLS:
  2942. case CHANNEL_HEALS:
  2943. case CHANNEL_FRIENDLY_HEALS:
  2944. case CHANNEL_OTHER_HEALS:
  2945. case CHANNEL_HOSTILE_HEALS:
  2946. return channel_type - 3;
  2947. case CHANNEL_COMBAT:
  2948. case CHANNEL_GENERAL_COMBAT:
  2949. case CHANNEL_HEROIC_OPPORTUNITY:
  2950. case CHANNEL_NON_MELEE_DAMAGE:
  2951. case CHANNEL_DAMAGE_SHIELD:
  2952. case CHANNEL_WARD:
  2953. return channel_type - 4;
  2954. case CHANNEL_MELEE_COMBAT:
  2955. case CHANNEL_WARNINGS:
  2956. case CHANNEL_YOU_HIT:
  2957. case CHANNEL_YOU_MISS:
  2958. case CHANNEL_ATTACKER_HITS:
  2959. case CHANNEL_ATTACKER_MISSES:
  2960. case CHANNEL_YOUR_PET_HITS:
  2961. case CHANNEL_YOUR_PET_MISSES:
  2962. case CHANNEL_ATTACKER_HITS_PET:
  2963. case CHANNEL_ATTACKER_MISSES_PET:
  2964. case CHANNEL_OTHER_HIT:
  2965. case CHANNEL_OTHER_MISSES:
  2966. return channel_type - 5;
  2967. case CHANNEL_OTHER:
  2968. case CHANNEL_MONEY_SPLIT:
  2969. case CHANNEL_LOOT:
  2970. return channel_type - 14;
  2971. case CHANNEL_COMMAND_TEXT:
  2972. case CHANNEL_BROADCAST:
  2973. case CHANNEL_WHO:
  2974. case CHANNEL_COMMANDS:
  2975. case CHANNEL_MERCHANT:
  2976. case CHANNEL_MERCHANT_BUY_SELL:
  2977. case CHANNEL_CONSIDER_MESSAGE:
  2978. case CHANNEL_CON_MINUS_2:
  2979. case CHANNEL_CON_MINUS_1:
  2980. case CHANNEL_CON_0:
  2981. case CHANNEL_CON_1:
  2982. case CHANNEL_CON_2:
  2983. case CHANNEL_TRADESKILLS:
  2984. case CHANNEL_HARVESTING:
  2985. case CHANNEL_HARVESTING_WARNINGS:
  2986. return channel_type - 15;
  2987. default: {
  2988. return CHANNEL_DEFAULT;
  2989. }
  2990. }
  2991. }
  2992. else {
  2993. switch (channel_type) {
  2994. default: {
  2995. return channel_type;
  2996. }
  2997. }
  2998. }
  2999. return channel_type;
  3000. }
  3001. void Client::HandleTellMessage(Client* from, const char* message) {
  3002. if (!from || GetPlayer()->IsIgnored(from->GetPlayer()->GetName()))
  3003. return;
  3004. PacketStruct* packet = configReader.getStruct("WS_HearChat", GetVersion());
  3005. if (packet) {
  3006. packet->setDataByName("from", from->GetPlayer()->GetName());
  3007. packet->setDataByName("to", GetPlayer()->GetName());
  3008. packet->setDataByName("channel", GetMessageChannelColor(CHANNEL_PRIVATE_TELL));
  3009. packet->setDataByName("from_spawn_id", 0xFFFFFFFF);
  3010. packet->setDataByName("to_spawn_id", 0xFFFFFFFF);
  3011. packet->setDataByName("unknown2", 1, 1);
  3012. packet->setDataByName("show_bubble", 1);
  3013. packet->setDataByName("understood", 1);
  3014. packet->setDataByName("time", 2);
  3015. packet->setMediumStringByName("message", message);
  3016. EQ2Packet* outpacket = packet->serialize();
  3017. QueuePacket(outpacket);
  3018. safe_delete(packet);
  3019. }
  3020. }
  3021. void Client::SimpleMessage(int8 color, const char* message) {
  3022. PacketStruct* command_packet = configReader.getStruct("WS_DisplayText", GetVersion());
  3023. if (command_packet) {
  3024. command_packet->setDataByName("color", GetMessageChannelColor(color));//convert this to the correct client type (different clients have different chat numbers)
  3025. command_packet->setMediumStringByName("text", message);
  3026. command_packet->setDataByName("unknown02", 0x00ff);
  3027. EQ2Packet* outapp = command_packet->serialize();
  3028. QueuePacket(outapp);
  3029. safe_delete(command_packet);
  3030. }
  3031. }
  3032. void Client::SendSpellUpdate(Spell* spell) {
  3033. PacketStruct* packet = configReader.getStruct("WS_SpellGainedMsg", GetVersion());
  3034. if (packet) {
  3035. int8 xxx = spell->GetSpellData()->is_aa;
  3036. packet->setDataByName("spell_type", spell->GetSpellData()->type);
  3037. packet->setDataByName("spell_id", spell->GetSpellID());
  3038. packet->setDataByName("unique_id", spell->GetSpellData()->spell_name_crc);
  3039. packet->setDataByName("spell_name", spell->GetName());
  3040. packet->setDataByName("unknown", xxx);
  3041. packet->setDataByName("display_spell_tier", 1);
  3042. packet->setDataByName("unknown3", 1);
  3043. packet->setDataByName("tier", spell->GetSpellTier());
  3044. packet->setDataByName("icon", spell->GetSpellIcon());
  3045. packet->setDataByName("icon_type", spell->GetSpellIconBackdrop());
  3046. packet->setDataByName("unknown5", 0xFFFFFFFF);
  3047. //packet->PrintPacket();
  3048. EQ2Packet* outapp = packet->serialize();
  3049. //DumpPacket(outapp);
  3050. QueuePacket(outapp);
  3051. safe_delete(packet);
  3052. }
  3053. }
  3054. void Client::Message(int8 type, const char* message, ...) {
  3055. va_list argptr;
  3056. char buffer[4096];
  3057. va_start(argptr, message);
  3058. vsnprintf(buffer, sizeof(buffer), message, argptr);
  3059. va_end(argptr);
  3060. SimpleMessage(type, buffer);
  3061. }
  3062. void Client::Disconnect(bool send_disconnect)
  3063. {
  3064. LogWrite(CCLIENT__DEBUG, 0, "CClient", "Client Disconnect...");
  3065. SetConnected(false);
  3066. if (send_disconnect && getConnection())
  3067. getConnection()->SendDisconnect(true);
  3068. this->Save();
  3069. this->GetPlayer()->WritePlayerStatistics();
  3070. eqs = 0;
  3071. }
  3072. bool Client::Summon(const char* search_name) {
  3073. Spawn* target = 0;
  3074. if (search_name || GetPlayer()->GetTarget()) {
  3075. Client* search_client = 0;
  3076. if (search_name) {
  3077. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3078. if (target && target->IsPlayer())
  3079. search_client = GetCurrentZone()->GetClientBySpawn(target);
  3080. if (!target) {
  3081. search_client = zone_list.GetClientByCharName(string(search_name));
  3082. if (search_client)
  3083. target = search_client->GetPlayer();
  3084. }
  3085. }
  3086. else
  3087. target = GetPlayer()->GetTarget();
  3088. if (target && target != GetPlayer()) {
  3089. target->SetX(GetPlayer()->GetX());
  3090. target->SetY(GetPlayer()->GetY());
  3091. target->SetZ(GetPlayer()->GetZ());
  3092. target->SetHeading(GetPlayer()->GetHeading());
  3093. if (!target->IsPlayer()) {
  3094. target->SetSpawnOrigX(target->GetX());
  3095. target->SetSpawnOrigY(target->GetY());
  3096. target->SetSpawnOrigZ(target->GetZ());
  3097. target->SetSpawnOrigHeading(target->GetHeading());
  3098. }
  3099. target->SetLocation(GetPlayer()->GetLocation());
  3100. }
  3101. else if (target)
  3102. Message(CHANNEL_COLOR_RED, "Error: You cannot summon yourself!");
  3103. if (search_client && search_client != this) {
  3104. search_client->Message(CHANNEL_COLOR_YELLOW, "You have been summoned by '%s'!", GetPlayer()->GetName());
  3105. Message(CHANNEL_COLOR_YELLOW, "Summoning '%s'...", search_client->GetPlayer()->GetName());
  3106. if (search_client->GetCurrentZone() != GetCurrentZone())
  3107. search_client->Zone(GetCurrentZone()->GetZoneName(), false);
  3108. else {
  3109. EQ2Packet* app = search_client->GetPlayer()->Move(GetPlayer()->GetX(), GetPlayer()->GetY(), GetPlayer()->GetZ(), search_client->GetVersion());
  3110. if (app)
  3111. search_client->QueuePacket(app);
  3112. }
  3113. }
  3114. }
  3115. if (!target)
  3116. return false;
  3117. else
  3118. return true;
  3119. }
  3120. bool Client::TryZoneInstance(int32 zoneID, bool zone_coords_valid) {
  3121. ZoneServer* instance_zone = NULL;
  3122. int8 instanceType = 0;
  3123. // determine if this is a group instanced zone that already exists
  3124. instance_zone = GetPlayer()->GetGroupMemberInZone(zoneID);
  3125. if (instance_zone != NULL)
  3126. Zone(instance_zone->GetInstanceID(), zone_coords_valid, true);
  3127. else if ((instanceType = database.GetInstanceTypeByZoneID(zoneID)) > 0)
  3128. {
  3129. // best to check if we already have our own instance!
  3130. InstanceData* data = GetPlayer()->GetCharacterInstances()->FindInstanceByZoneID(zoneID);
  3131. if (data) {
  3132. // If lockout instances check to see if we are locked out
  3133. if (instanceType == SOLO_LOCKOUT_INSTANCE || instanceType == GROUP_LOCKOUT_INSTANCE || instanceType == RAID_LOCKOUT_INSTANCE) {
  3134. int32 time = 0;
  3135. // Check success timer
  3136. if (data->last_success_timestamp > 0) {
  3137. if (Timer::GetUnixTimeStamp() < data->last_success_timestamp + data->success_lockout_time) {
  3138. // Timer has not expired yet can't re enter
  3139. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Success lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3140. time = (data->last_success_timestamp + data->success_lockout_time) - Timer::GetUnixTimeStamp();
  3141. }
  3142. }
  3143. // Check failure timer
  3144. if (data->last_failure_timestamp > 0) {
  3145. if (Timer::GetUnixTimeStamp() < data->last_failure_timestamp + data->failure_lockout_time) {
  3146. // Timer has not expired yet
  3147. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Failure lockout not expired for character %s in zone %u", GetPlayer()->GetName(), zoneID);
  3148. time = (data->last_failure_timestamp + data->failure_lockout_time) - Timer::GetUnixTimeStamp();
  3149. }
  3150. }
  3151. // Time > 0 then we are locked out, make the message and send it and return true
  3152. if (time > 0) {
  3153. string time_msg = "";
  3154. int16 hour;
  3155. int8 min;
  3156. int8 sec;
  3157. hour = time / 3600;
  3158. time = time % 3600;
  3159. min = time / 60;
  3160. time = time % 60;
  3161. sec = time;
  3162. if (hour > 0) {
  3163. char temp[10];
  3164. sprintf(temp, " %i", hour);
  3165. time_msg.append(temp);
  3166. time_msg.append(" hour");
  3167. time_msg.append((hour > 1) ? "s" : "");
  3168. }
  3169. if (min > 0) {
  3170. char temp[5];
  3171. sprintf(temp, " %i", min);
  3172. time_msg.append(temp);
  3173. time_msg.append(" minute");
  3174. time_msg.append((min > 1) ? "s" : "");
  3175. }
  3176. // Only add seconds if minutes and hours are 0
  3177. if (hour == 0 && min == 0 && sec > 0) {
  3178. char temp[5];
  3179. sprintf(temp, " %i", sec);
  3180. time_msg.append(temp);
  3181. time_msg.append(" second");
  3182. time_msg.append((sec > 1) ? "s" : "");
  3183. }
  3184. Message(CHANNEL_COLOR_YELLOW, "You may not enter again for%s.", time_msg.c_str());
  3185. return true;
  3186. }
  3187. }
  3188. // Need to update `character_instances` table with new timestamps (for persistent) and instance id's
  3189. instance_zone = zone_list.GetByInstanceID(data->instance_id, zoneID);
  3190. // if we got an instance_zone and the instance_id from the data is 0 or data instance id is not the same as the zone instance id then update values
  3191. if (instance_zone && (data->instance_id == 0 || data->instance_id != instance_zone->GetInstanceID())) {
  3192. if (instanceType == SOLO_PERSIST_INSTANCE || instanceType == GROUP_PERSIST_INSTANCE || instanceType == RAID_PERSIST_INSTANCE) {
  3193. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  3194. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  3195. }
  3196. else
  3197. database.UpdateCharacterInstance(GetCharacterID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceID());
  3198. data->instance_id = instance_zone->GetInstanceID();
  3199. }
  3200. }
  3201. else {
  3202. switch (instanceType)
  3203. {
  3204. case SOLO_LOCKOUT_INSTANCE:
  3205. case GROUP_LOCKOUT_INSTANCE:
  3206. case RAID_LOCKOUT_INSTANCE:
  3207. {
  3208. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3209. if (instance_zone) {
  3210. // once lockout instance zone shuts down you can't renenter if you have a lockout or if you don't you get a new zone
  3211. // so delete `instances` entry for the zone when it shuts down.
  3212. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  3213. if (db_id > 0)
  3214. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), 0, 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3215. }
  3216. break;
  3217. }
  3218. case SOLO_PERSIST_INSTANCE:
  3219. case GROUP_PERSIST_INSTANCE:
  3220. case RAID_PERSIST_INSTANCE:
  3221. {
  3222. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3223. if (instance_zone) {
  3224. int32 db_id = database.AddCharacterInstance(GetPlayer()->GetCharacterID(), instance_zone->GetInstanceID(), string(instance_zone->GetZoneName()), instance_zone->GetInstanceType(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime());
  3225. if (db_id > 0)
  3226. GetPlayer()->GetCharacterInstances()->AddInstance(db_id, instance_zone->GetInstanceID(), Timer::GetUnixTimeStamp(), 0, instance_zone->GetDefaultLockoutTime(), instance_zone->GetDefaultReenterTime(), zoneID, instance_zone->GetInstanceType(), string(instance_zone->GetZoneName()));
  3227. }
  3228. break;
  3229. }
  3230. case PUBLIC_INSTANCE:
  3231. case TRADESKILL_INSTANCE:
  3232. {
  3233. // if its public/tradeskill, look for a public already setup
  3234. instance_zone = zone_list.GetByLowestPopulation(zoneID);
  3235. if (instance_zone) {
  3236. // Check the current population against the max population, if greater or equal start a new version
  3237. if (instance_zone->GetClientCount() >= rule_manager.GetGlobalRule(R_Zone, MaxPlayers)->GetInt32())
  3238. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3239. }
  3240. else
  3241. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3242. break;
  3243. }
  3244. case PERSONAL_HOUSE_INSTANCE:
  3245. case GUILD_HOUSE_INSTANCE:
  3246. {
  3247. // Because of the way housing works (need to load a specific instance id supplied in a packet) we can't
  3248. // use this function without some rework, so it will all be handled in Client::HandlePacket()
  3249. // with the OP_EnterHouseMsg opcode
  3250. break;
  3251. }
  3252. case QUEST_INSTANCE:
  3253. {
  3254. instance_zone = zone_list.GetByInstanceID(0, zoneID);
  3255. break;
  3256. /*
  3257. ALTER TABLE `zones` CHANGE COLUMN `instance_type` `instance_type` ENUM('NONE','GROUP_LOCKOUT_INSTANCE','GROUP_PERSIST_INSTANCE','RAID_LOCKOUT_INSTANCE','RAID_PERSIST_INSTANCE','SOLO_LOCKOUT_INSTANCE','SOLO_PERSIST_INSTANCE','TRADESKILL_INSTANCE','PUBLIC_INSTANCE','PERSONAL_HOUSE_INSTANCE','GUILD_HOUSE_INSTANCE','QUEST_INSTANCE') NOT NULL DEFAULT 'NONE' COLLATE 'latin1_general_ci' AFTER `start_zone`;
  3258. */
  3259. }
  3260. default:
  3261. {
  3262. // NONE
  3263. }
  3264. }
  3265. }
  3266. if (instance_zone != NULL)
  3267. Zone(instance_zone, zone_coords_valid);
  3268. }
  3269. if (instance_zone != NULL)
  3270. return true;
  3271. else
  3272. return false;
  3273. }
  3274. bool Client::GotoSpawn(const char* search_name, bool forceTarget) {
  3275. Spawn* target = 0;
  3276. if (search_name || GetPlayer()->GetTarget()) {
  3277. Client* search_client = 0;
  3278. if (search_name) {
  3279. target = GetCurrentZone()->FindSpawn(GetPlayer(), search_name);
  3280. if (!target) {
  3281. search_client = zone_list.GetClientByCharName(search_name);
  3282. if (search_client)
  3283. target = search_client->GetPlayer();
  3284. }
  3285. if (target)
  3286. GetPlayer()->SetTarget(target);
  3287. }
  3288. else
  3289. target = GetPlayer()->GetTarget();
  3290. if (target && target != GetPlayer()) {
  3291. GetPlayer()->SetX(target->GetX());
  3292. GetPlayer()->SetY(target->GetY());
  3293. GetPlayer()->SetZ(target->GetZ());
  3294. GetPlayer()->SetHeading(target->GetHeading());
  3295. GetPlayer()->SetLocation(target->GetLocation());
  3296. Message(CHANNEL_COLOR_YELLOW, "Warping to '%s'", target->GetName());
  3297. }
  3298. else if (target)
  3299. Message(CHANNEL_COLOR_RED, "Error: You cannot goto yourself!");
  3300. if (search_client && search_client->GetCurrentZone() != GetCurrentZone())
  3301. Zone(search_client->GetCurrentZone()->GetZoneName(), false);
  3302. else if (target) {
  3303. EQ2Packet* app = GetPlayer()->Move(target->GetX(), target->GetY(), target->GetZ(), GetVersion());
  3304. if (app)
  3305. QueuePacket(app);
  3306. }
  3307. }
  3308. if (!target)
  3309. return false;
  3310. else
  3311. return true;
  3312. }
  3313. bool Client::CheckZoneAccess(const char* zoneName) {
  3314. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone access check for %s (%u), client: %u", zoneName, database.GetZoneID(zoneName), GetVersion());
  3315. ZoneServer* zone = zone_list.Get(zoneName, false);
  3316. // JA: implemented /zone lock|unlock commands (2012.07.28)
  3317. if (zone && zone->GetZoneLockState())
  3318. {
  3319. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone currently LOCKED: '%s' (%ul)", zoneName, zone->GetZoneID());
  3320. Message(CHANNEL_COLOR_RED, "This zone is locked, and you don't have the key! (%s).", zoneName);
  3321. return false;
  3322. }
  3323. sint16 zoneMinStatus = 0;
  3324. int16 zoneMinLevel = 0;
  3325. int16 zoneMaxLevel = 0;
  3326. int16 zoneMinVersion = 0;
  3327. if (!zone)
  3328. {
  3329. LogWrite(CCLIENT__DEBUG, 0, "Client", "Grabbing zone requirements for %s", zoneName);
  3330. bool success = database.GetZoneRequirements(zoneName, &zoneMinStatus, &zoneMinLevel, &zoneMaxLevel, &zoneMinVersion);
  3331. if (!success) { // couldn't even find the zone, this shouldn't happen though..
  3332. return true;
  3333. }
  3334. }
  3335. else
  3336. {
  3337. zoneMinStatus = zone->GetMinimumStatus();
  3338. zoneMinLevel = zone->GetMinimumLevel();
  3339. zoneMaxLevel = zone->GetMaximumLevel();
  3340. zoneMinVersion = zone->GetMinimumVersion();
  3341. }
  3342. LogWrite(CCLIENT__DEBUG, 0, "Client", "Access Requirements: status %i, level %i - %i, req >= %i version", zoneMinStatus, zoneMinLevel, zoneMaxLevel, zoneMinVersion);
  3343. // use ZoneLevelOverrideStatus in both min_level and max_level checks
  3344. sint16 ZoneLevelOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneLevelOverrideStatus)->GetSInt16();
  3345. if ((zoneMinVersion > 0) && (GetVersion() < zoneMinVersion))
  3346. {
  3347. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinVersion of %i challenge...", zoneMinVersion);
  3348. Message(CHANNEL_COLOR_RED, "You do not have the required expansion pack to enter here (%s).", database.GetExpansionIDByVersion(zoneMinVersion).c_str());
  3349. LogWrite(CCLIENT__DEBUG, 0, "Client", "Client denied access to zone '%s' (version req: %i)", zoneName, zoneMinVersion);
  3350. return false;
  3351. }
  3352. if ((zoneMinLevel > 1) && (player->GetLevel() < zoneMinLevel))
  3353. {
  3354. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3355. {
  3356. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3357. Message(CHANNEL_COLOR_RED, "Your level is too low to enter here (%s)", zoneMinLevel);
  3358. return false;
  3359. }
  3360. }
  3361. if ((zoneMaxLevel > 1) && (player->GetLevel() > zoneMaxLevel))
  3362. {
  3363. if (ZoneLevelOverrideStatus && ZoneLevelOverrideStatus > GetAdminStatus())
  3364. {
  3365. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (level req: %i)", zoneName, player->GetLevel());
  3366. Message(CHANNEL_COLOR_RED, "Your level is too high to enter here (%s)", zoneMaxLevel);
  3367. return false;
  3368. }
  3369. }
  3370. if ((zoneMinStatus > 0) && (GetAdminStatus() < zoneMinStatus))
  3371. {
  3372. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone MinStatus of %i challenge...", zoneMinStatus);
  3373. sint16 ZoneAccessOverrideStatus = rule_manager.GetGlobalRule(R_Zone, MinZoneAccessOverrideStatus)->GetSInt16();
  3374. if (ZoneAccessOverrideStatus && ZoneAccessOverrideStatus > GetAdminStatus())
  3375. {
  3376. LogWrite(CCLIENT__DEBUG, 0, "Client", "Player denied access to zone '%s' (status req: %i)", zoneName, GetAdminStatus());
  3377. Message(CHANNEL_COLOR_RED, "You do not have permission to enter here (%i).", zoneMinStatus);
  3378. return false;
  3379. }
  3380. }
  3381. return true;
  3382. }
  3383. void Client::Zone(int32 instanceid, bool set_coords, bool byInstanceID) {
  3384. Zone(zone_list.GetByInstanceID(instanceid), set_coords);
  3385. }
  3386. void Client::Zone(ZoneServer* new_zone, bool set_coords) {
  3387. if (!new_zone) {
  3388. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request Denied! No 'new_zone' value");
  3389. return;
  3390. }
  3391. client_zoning = true;
  3392. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting player Resurrecting to 'true'", __FUNCTION__);
  3393. player->SetResurrecting(true);
  3394. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from fighting...", __FUNCTION__);
  3395. //GetCurrentZone()->GetCombat()->RemoveHate(player);
  3396. // Remove players pet from zone if there is one
  3397. player->DismissPet((NPC*)player->GetPet());
  3398. player->DismissPet((NPC*)player->GetCharmedPet());
  3399. player->DismissPet((NPC*)player->GetDeityPet());
  3400. player->DismissPet((NPC*)player->GetCosmeticPet());
  3401. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Removing player from current zone...", __FUNCTION__);
  3402. GetCurrentZone()->RemoveSpawn(false, player, false);
  3403. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Setting zone to '%s'...", __FUNCTION__, new_zone->GetZoneName());
  3404. SetCurrentZone(new_zone);
  3405. if (player->GetGroupMemberInfo())
  3406. {
  3407. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Player in group, updating group info...", __FUNCTION__);
  3408. player->UpdateGroupMemberInfo();
  3409. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id, this);
  3410. }
  3411. // block out the member info for the group
  3412. TempRemoveGroup();
  3413. UpdateTimeStampFlag(ZONE_UPDATE_FLAG);
  3414. if (set_coords)
  3415. {
  3416. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Zoning player to coordinates x: %2f, y: %2f, z: %2f, heading: %2f in zone '%s'...",
  3417. __FUNCTION__,
  3418. GetCurrentZone()->GetSafeX(),
  3419. GetCurrentZone()->GetSafeY(),
  3420. GetCurrentZone()->GetSafeZ(),
  3421. GetCurrentZone()->GetSafeHeading(),
  3422. new_zone->GetZoneName()
  3423. );
  3424. player->SetX(GetCurrentZone()->GetSafeX());
  3425. player->SetY(GetCurrentZone()->GetSafeY());
  3426. player->SetZ(GetCurrentZone()->GetSafeZ());
  3427. player->SetHeading(GetCurrentZone()->GetSafeHeading());
  3428. }
  3429. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Saving Player info...", __FUNCTION__);
  3430. Save();
  3431. char* new_zone_ip = 0;
  3432. struct in_addr in;
  3433. in.s_addr = this->GetIP();
  3434. if (strncmp(inet_ntoa(in), "192.168", 7) == 0 && strlen(net.GetInternalWorldAddress()) > 0)
  3435. new_zone_ip = net.GetInternalWorldAddress();
  3436. else
  3437. new_zone_ip = net.GetWorldAddress();
  3438. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: New Zone IP '%s'...", __FUNCTION__, new_zone_ip);
  3439. int32 key = Timer::GetUnixTimeStamp();
  3440. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending ZoneChangeMsg...", __FUNCTION__);
  3441. ClientPacketFunctions::SendZoneChange(this, new_zone_ip, net.GetWorldPort(), key);
  3442. LogWrite(CCLIENT__DEBUG, 0, "Client", "%s: Sending to zone_auth.AddAuth...", __FUNCTION__);
  3443. zone_auth.AddAuth(new ZoneAuthRequest(GetAccountID(), player->GetName(), key));
  3444. if (version > 283) {
  3445. PacketStruct* packet = configReader.getStruct("WS_CancelMoveObjectMode", version);
  3446. if (packet)
  3447. {
  3448. QueuePacket(packet->serialize());
  3449. safe_delete(packet);
  3450. }
  3451. }
  3452. }
  3453. void Client::Zone(const char* new_zone, bool set_coords)
  3454. {
  3455. LogWrite(CCLIENT__DEBUG, 0, "Client", "Zone Request to '%s'", new_zone);
  3456. Zone(zone_list.Get(new_zone), set_coords);
  3457. }
  3458. float Client::DistanceFrom(Client* client) {
  3459. float ret = 0;
  3460. if (client && client != this) {
  3461. ret = pow(player->GetX() - client->player->GetX(), 2) + pow(player->GetY() - client->player->GetY(), 2) + pow(player->GetZ() - client->player->GetZ(), 2);
  3462. ret = sqrt(ret);
  3463. }
  3464. return ret;
  3465. }
  3466. void Client::DetermineCharacterUpdates() {
  3467. ServerPacket* outpack = new ServerPacket(ServerOP_BasicCharUpdate, sizeof(CharDataUpdate_Struct));
  3468. CharDataUpdate_Struct* cdu = (CharDataUpdate_Struct*)outpack->pBuffer;
  3469. cdu->account_id = GetAccountID();
  3470. cdu->char_id = GetCharacterID();
  3471. int32 timestamp = Timer::GetUnixTimeStamp();
  3472. int8 flag = GetTimeStampFlag();
  3473. if (flag & LEVEL_UPDATE_FLAG)
  3474. {
  3475. cdu->update_field = LEVEL_UPDATE_FLAG;
  3476. cdu->update_data = player->GetLevel();
  3477. loginserver.SendPacket(outpack);
  3478. }
  3479. //if(flag&CLASS_UPDATE_FLAG && player->GetLevel() >= 20)// Perseverance only
  3480. if (flag & CLASS_UPDATE_FLAG)
  3481. {
  3482. cdu->update_field = CLASS_UPDATE_FLAG;
  3483. cdu->update_data = player->GetAdventureClass();
  3484. loginserver.SendPacket(outpack);
  3485. }
  3486. if (flag & GENDER_UPDATE_FLAG)
  3487. {
  3488. cdu->update_field = GENDER_UPDATE_FLAG;
  3489. cdu->update_data = player->GetGender();
  3490. loginserver.SendPacket(outpack);
  3491. }
  3492. if (flag & DELETE_UPDATE_FLAG) {
  3493. LogWrite(MISC__TODO, 1, "TODO", "Delete update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3494. }
  3495. safe_delete(outpack); // Zone, armor and name use a different structure
  3496. if (flag & RACE_UPDATE_FLAG)
  3497. {
  3498. outpack = new ServerPacket(ServerOP_RaceUpdate, sizeof(RaceUpdate_Struct));
  3499. RaceUpdate_Struct* ru = (RaceUpdate_Struct*)outpack->pBuffer;
  3500. ru->account_id = GetAccountID();
  3501. ru->char_id = GetCharacterID();
  3502. ru->race = player->GetRace();
  3503. ru->model_type = player->GetModelType();
  3504. loginserver.SendPacket(outpack);
  3505. safe_delete(outpack);
  3506. }
  3507. if (flag & ZONE_UPDATE_FLAG) {
  3508. ServerPacket* outpack = new ServerPacket(ServerOP_ZoneUpdate, CHARZONESTRUCT_MAXSIZE);
  3509. memset(outpack->pBuffer, 0, CHARZONESTRUCT_MAXSIZE);
  3510. CharZoneUpdate_Struct* czu = (CharZoneUpdate_Struct*)outpack->pBuffer;
  3511. czu->account_id = GetAccountID();
  3512. czu->char_id = GetCharacterID();
  3513. czu->zone_id = GetCurrentZone()->GetZoneID();
  3514. const char* zone_file = GetCurrentZone()->GetZoneFile();
  3515. czu->zone_length = strlen(zone_file);
  3516. if (czu->zone_length > 64)
  3517. czu->zone_length = 64;
  3518. strncpy(czu->new_zone, zone_file, czu->zone_length);
  3519. loginserver.SendPacket(outpack);
  3520. safe_delete(outpack);
  3521. }
  3522. if (flag & ARMOR_UPDATE_FLAG) {
  3523. LogWrite(MISC__TODO, 1, "TODO", "Armor update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3524. }
  3525. if (flag & NAME_UPDATE_FLAG) {
  3526. LogWrite(MISC__TODO, 1, "TODO", "Name update req in func: %s, line: %i", __FUNCTION__, __LINE__);
  3527. }
  3528. database.UpdateCharacterTimeStamp(GetAccountID(), GetCharacterID(), timestamp);
  3529. }
  3530. void Client::Save() {
  3531. if (GetCharacterID() == 0)
  3532. return;
  3533. if (current_zone) {
  3534. DetermineCharacterUpdates();
  3535. UpdateCharacterInstances();
  3536. database.Save(this);
  3537. if (GetPlayer()->UpdateQuickbarNeeded()) {
  3538. database.SaveQuickBar(GetCharacterID(), GetPlayer()->GetQuickbar());
  3539. GetPlayer()->ResetQuickbarNeeded();
  3540. }
  3541. database.SaveItems(this);
  3542. database.SaveBuyBacks(this);
  3543. GetPlayer()->SaveHistory();
  3544. GetPlayer()->SaveLUAHistory();
  3545. }
  3546. }
  3547. void Client::UpdateCharacterInstances() {
  3548. if (GetPlayer() != NULL)
  3549. GetPlayer()->GetCharacterInstances()->ProcessInstanceTimers(GetPlayer());
  3550. /*if ( GetPlayer() != NULL )
  3551. {
  3552. // determine the last timestamp then get a new one, determine the difference in the timestamp
  3553. // to use for applying the update to each instances timer
  3554. int32 lastSaveTS = GetLastSavedTimeStamp();
  3555. int32 newSaveTS = Timer::GetUnixTimeStamp();
  3556. int32 diffTS = newSaveTS - lastSaveTS;
  3557. // update instance timers
  3558. GetPlayer()->GetCharacterInstances().ProcessInstanceTimers(GetPlayer(),diffTS);
  3559. // update with the new timestamp and save the db
  3560. this->SetLastSavedTimeStamp(newSaveTS);
  3561. }*/
  3562. }
  3563. void Client::HandleVerbRequest(EQApplicationPacket* app) {
  3564. PacketStruct* packet = configReader.getStruct("WS_EntityVerbsRequest", GetVersion());
  3565. if (packet) {
  3566. packet->LoadPacketData(app->pBuffer, app->size);
  3567. int32 spawn_id = packet->getType_int32_ByName("spawn_id");
  3568. PacketStruct* out = configReader.getStruct("WS_EntityVerbsResponse", GetVersion());
  3569. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(spawn_id);
  3570. vector<EntityCommand*> commands;
  3571. vector<EntityCommand*> delete_commands;
  3572. if (out && spawn) {
  3573. for (int32 i = 0; i < spawn->primary_command_list.size(); i++)
  3574. {
  3575. // default is a deny list not allow, only allow if on the iterator list and itr second is not false (deny)
  3576. if (!spawn->primary_command_list[i]->default_allow_list)
  3577. {
  3578. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3579. if (itr == spawn->primary_command_list[i]->allow_or_deny.end() || !itr->second)
  3580. continue;
  3581. }
  3582. else
  3583. {
  3584. // default is allow list, only deny if added to the list as deny (false itr second)
  3585. map<int32, bool>::iterator itr = spawn->primary_command_list[i]->allow_or_deny.find(GetPlayer()->GetCharacterID());
  3586. if (itr != spawn->primary_command_list[i]->allow_or_deny.end() && !itr->second)
  3587. continue;
  3588. }
  3589. commands.push_back(spawn->primary_command_list[i]);
  3590. }
  3591. for (int32 i = 0; i < spawn->secondary_command_list.size(); i++)
  3592. commands.push_back(spawn->secondary_command_list[i]);
  3593. if (spawn->IsPlayer()) {
  3594. if (player->IsFriend(spawn->GetName()))
  3595. delete_commands.push_back(player->CreateEntityCommand("remove from friends list", 10000, "friend_remove", "", 0, 0));
  3596. else
  3597. delete_commands.push_back(player->CreateEntityCommand("add to friends list", 10000, "friend_add", "", 0, 0));
  3598. if (player->IsIgnored(spawn->GetName()))
  3599. delete_commands.push_back(player->CreateEntityCommand("remove from ignore list", 10000, "ignore_remove", "", 0, 0));
  3600. else
  3601. {
  3602. delete_commands.push_back(player->CreateEntityCommand("add to ignore list", 10000, "ignore_add", "", 0, 0));
  3603. delete_commands.push_back(player->CreateEntityCommand("Trade", 10, "start_trade", "", 0, 0));
  3604. }
  3605. if (((Player*)spawn)->GetGroupMemberInfo()) {
  3606. if (player->IsGroupMember((Player*)spawn) && player->GetGroupMemberInfo()->leader) { //group leader
  3607. delete_commands.push_back(player->CreateEntityCommand("kick from group", 10000, "kickfromgroup", "", 0, 0));
  3608. delete_commands.push_back(player->CreateEntityCommand("make group leader", 10000, "makeleader", "", 0, 0));
  3609. }
  3610. }
  3611. else if (!player->GetGroupMemberInfo() || (player->GetGroupMemberInfo()->leader && world.GetGroupManager()->GetGroupSize(player->GetGroupMemberInfo()->group_id) < 6))
  3612. delete_commands.push_back(player->CreateEntityCommand("invite to group", 10000, "invite", "", 0, 0));
  3613. commands.insert(commands.end(), delete_commands.begin(), delete_commands.end());
  3614. }
  3615. out->setDataByName("spawn_id", spawn_id);
  3616. out->setArrayLengthByName("num_verbs", commands.size());
  3617. for (int32 i = 0; i < commands.size(); i++) {
  3618. out->setArrayDataByName("command", commands[i]->command.c_str(), i);
  3619. out->setArrayDataByName("distance", commands[i]->distance, i);
  3620. if (commands[i]->error_text.length() == 0)
  3621. out->setArrayAddToPacketByName("error", false, i);
  3622. else {
  3623. out->setArrayDataByName("display_error", 1, i);
  3624. out->setArrayDataByName("error", commands[i]->error_text.c_str(), i);
  3625. }
  3626. out->setArrayDataByName("display_text", commands[i]->name.c_str(), i);
  3627. }
  3628. EQ2Packet* outapp = out->serialize();
  3629. //DumpPacket(outapp);
  3630. QueuePacket(outapp);
  3631. safe_delete(out);
  3632. for (int32 i = 0; i < delete_commands.size(); i++) {
  3633. safe_delete(delete_commands[i]);
  3634. }
  3635. }
  3636. safe_delete(packet);
  3637. }
  3638. }
  3639. void Client::SkillChanged(Skill* skill, int16 previous_value, int16 new_value) {
  3640. if (previous_value != new_value) {
  3641. Message(CHANNEL_SKILL, "You get %s at %s (%i/%i).", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3642. char tmp[200] = { 0 };
  3643. sprintf(tmp, "\\#6EFF6EYou get %s at \12\\#C8FFC8%s\\#6EFF6E! (%i/%i)", new_value > previous_value ? "better" : "worse", skill->name.data.c_str(), new_value, skill->max_val);
  3644. SendPopupMessage(6, tmp, new_value > previous_value ? "skill_up" : "skill_down", 2.75f, 0xFF, 0xFF, 0xFF);
  3645. }
  3646. }
  3647. void Client::SendPopupMessage(int8 unknown, const char* text, const char* type, float size, int8 red, int8 green, int8 blue)
  3648. {
  3649. /* JA notes on the unknown:
  3650. 2 = ding glimmer
  3651. 16 = Achievement Unlocked
  3652. 6 no longer does anything
  3653. */
  3654. PacketStruct* packet = configReader.getStruct("WS_OnScreenMsg", GetVersion());
  3655. if (packet) {
  3656. packet->setDataByName("unknown", unknown);
  3657. packet->setMediumStringByName("text", text);
  3658. if (type && strlen(type) > 0)
  3659. packet->setMediumStringByName("message_type", type);
  3660. packet->setDataByName("size", size);
  3661. packet->setDataByName("red", red);
  3662. packet->setDataByName("green", green);
  3663. packet->setDataByName("blue", blue);
  3664. QueuePacket(packet->serialize());
  3665. safe_delete(packet);
  3666. }
  3667. }
  3668. void Client::ChangeLevel(int16 old_level, int16 new_level) {
  3669. if (new_level < 1) {
  3670. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3671. return;
  3672. }
  3673. if (player->GetLevel() != new_level) {
  3674. player->SetLevel(new_level);
  3675. if (player->GetGroupMemberInfo()) {
  3676. player->UpdateGroupMemberInfo();
  3677. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3678. }
  3679. }
  3680. if (new_level > old_level)
  3681. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_ADVENTURE, new_level, player->GetAdventureClass());
  3682. if (player->GetPet()) {
  3683. NPC* pet = (NPC*)player->GetPet();
  3684. if (pet->GetMaxPetLevel() == 0 || new_level <= pet->GetMaxPetLevel()) {
  3685. pet->SetLevel(new_level);
  3686. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3687. if (command_packet) {
  3688. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(pet));
  3689. command_packet->setDataByName("anim_type", 1753);
  3690. QueuePacket(command_packet->serialize());
  3691. safe_delete(command_packet);
  3692. }
  3693. }
  3694. }
  3695. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3696. if (level_update) {
  3697. level_update->setDataByName("old_level", old_level);
  3698. level_update->setDataByName("new_level", new_level);
  3699. QueuePacket(level_update->serialize());
  3700. safe_delete(level_update);
  3701. GetCurrentZone()->StartZoneSpawnsForLevelThread(this);
  3702. GetCurrentZone()->SendCastSpellPacket(322, player, player); //send level up spell effect
  3703. //GetCurrentZone()->SendAllSpawnsForLevelChange(this);
  3704. }
  3705. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3706. if (command_packet) {
  3707. command_packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(player));
  3708. command_packet->setDataByName("anim_type", 1753);
  3709. QueuePacket(command_packet->serialize());
  3710. safe_delete(command_packet);
  3711. }
  3712. if (!player->get_character_flag(CF_ENABLE_CHANGE_LASTNAME) && new_level >= rule_manager.GetGlobalRule(R_Player, MinLastNameLevel)->GetInt8())
  3713. player->set_character_flag(CF_ENABLE_CHANGE_LASTNAME);
  3714. SendNewSpells(player->GetAdventureClass());
  3715. SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3716. SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3717. GetPlayer()->ChangePrimaryWeapon();
  3718. GetPlayer()->ChangeSecondaryWeapon();
  3719. GetPlayer()->ChangeRangedWeapon();
  3720. GetPlayer()->GetInfoStruct()->level = new_level;
  3721. // GetPlayer()->SetLevel(new_level);
  3722. LogWrite(MISC__TODO, 1, "TODO", "Get new HP/POWER/stat based on default values from DB\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  3723. GetPlayer()->SetTotalHPBase(new_level * new_level * 2 + 40);
  3724. GetPlayer()->SetTotalPowerBase((sint32)(new_level * new_level * 2.1 + 45));
  3725. GetPlayer()->CalculateBonuses();
  3726. GetPlayer()->SetHP(GetPlayer()->GetTotalHP());
  3727. GetPlayer()->SetPower(GetPlayer()->GetTotalPower());
  3728. InfoStruct* info = player->GetInfoStruct();
  3729. info->agi_base = new_level * 2 + 15;
  3730. info->intel_base = new_level * 2 + 15;
  3731. info->wis_base = new_level * 2 + 15;
  3732. info->str_base = new_level * 2 + 15;
  3733. info->sta_base = new_level * 2 + 15;
  3734. info->cold_base = (int16)(new_level * 1.5 + 10);
  3735. info->heat_base = (int16)(new_level * 1.5 + 10);
  3736. info->disease_base = (int16)(new_level * 1.5 + 10);
  3737. info->mental_base = (int16)(new_level * 1.5 + 10);
  3738. info->magic_base = (int16)(new_level * 1.5 + 10);
  3739. info->divine_base = (int16)(new_level * 1.5 + 10);
  3740. info->poison_base = (int16)(new_level * 1.5 + 10);
  3741. GetPlayer()->SetHPRegen((int)(new_level * .75) + (int)(new_level / 10) + 3);
  3742. GetPlayer()->SetPowerRegen(new_level + (int)(new_level / 10) + 4);
  3743. GetPlayer()->GetInfoStruct()->poison_base = (int16)(new_level * 1.5 + 10);
  3744. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3745. GetPlayer()->SetCharSheetChanged(true);
  3746. Message(CHANNEL_REWARD, "You are now level %i!", new_level);
  3747. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3748. int16 new_skill_cap = 5 * new_level;
  3749. PlayerSkillList* player_skills = player->GetSkills();
  3750. player_skills->SetSkillCapsByType(SKILL_TYPE_COMBAT, new_skill_cap);
  3751. player_skills->SetSkillCapsByType(SKILL_TYPE_SPELLCASTING, new_skill_cap);
  3752. player_skills->SetSkillCapsByType(SKILL_TYPE_AVOIDANCE, new_skill_cap);
  3753. player_skills->SetSkillCapsByType(SKILL_TYPE_GENERAL, new_skill_cap);
  3754. if (new_level > player->GetTSLevel())
  3755. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, new_skill_cap);
  3756. Guild* guild = GetPlayer()->GetGuild();
  3757. if (guild) {
  3758. int8 event_type = 0;
  3759. if (new_level < 10)
  3760. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_1_10;
  3761. else if (new_level == 10)
  3762. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_10;
  3763. else if (new_level >= 11 && new_level < 20)
  3764. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_11_20;
  3765. else if (new_level == 20)
  3766. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_20;
  3767. else if (new_level >= 21 && new_level < 30)
  3768. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_21_30;
  3769. else if (new_level == 30)
  3770. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_30;
  3771. else if (new_level >= 31 && new_level < 40)
  3772. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_31_40;
  3773. else if (new_level == 40)
  3774. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_40;
  3775. else if (new_level >= 41 && new_level < 50)
  3776. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_41_50;
  3777. else if (new_level == 50)
  3778. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_50;
  3779. else if (new_level >= 51 && new_level < 60)
  3780. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_51_60;
  3781. else if (new_level == 60)
  3782. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_60;
  3783. else if (new_level >= 61 && new_level < 70)
  3784. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_61_70;
  3785. else if (new_level == 70)
  3786. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_70;
  3787. else if (new_level >= 71 && new_level < 80)
  3788. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_71_80;
  3789. else if (new_level == 80)
  3790. event_type = GUILD_EVENT_GAINS_ADV_LEVEL_80;
  3791. guild->AddNewGuildEvent(event_type, "%s has gained an adventure level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  3792. guild->SendMessageToGuild(event_type, "%s has gained an adventure level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetAdventureClass()).c_str());
  3793. guild->UpdateGuildMemberInfo(GetPlayer());
  3794. guild->SendGuildMember(GetPlayer());
  3795. guild->SendGuildMemberList();
  3796. }
  3797. // Need to send the trait list every time the players level changes
  3798. // Also need to force the char sheet update or else there can be a large delay from when you level
  3799. // to when you are actually able to select traits.
  3800. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3801. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3802. if (version > 546)
  3803. master_aa_list.DisplayAA(this, 0, 0);
  3804. if (GetPlayer()->SpawnedBots.size() > 0) {
  3805. map<int32, int32>::iterator itr;
  3806. for (itr = GetPlayer()->SpawnedBots.begin(); itr != GetPlayer()->SpawnedBots.end(); itr++) {
  3807. Spawn* bot = GetCurrentZone()->GetSpawnByID(itr->second);
  3808. if (bot && bot->IsBot())
  3809. ((Bot*)bot)->ChangeLevel(old_level, new_level);
  3810. }
  3811. }
  3812. }
  3813. void Client::ChangeTSLevel(int16 old_level, int16 new_level) {
  3814. if (new_level < 1) {
  3815. SimpleMessage(CHANNEL_COLOR_RED, "You cannot be lower than level 1!");
  3816. return;
  3817. }
  3818. if ((player->GetTSLevel() >= 9 && player->GetTradeskillClass() == 1) || (player->GetTSLevel() >= 19 && (player->GetTradeskillClass() == 1 || player->GetTradeskillClass() == 2 || player->GetTradeskillClass() == 6 || player->GetTradeskillClass() == 10))) {
  3819. SimpleMessage(CHANNEL_COLOR_YELLOW, "You can not gain levels until you select your next class!");
  3820. return;
  3821. }
  3822. if (new_level > old_level)
  3823. player->UpdatePlayerHistory(HISTORY_TYPE_XP, HISTORY_SUBTYPE_TRADESKILL, new_level, player->GetTradeskillClass());
  3824. if (player->GetTSLevel() != new_level) {
  3825. player->SetTSLevel(new_level);
  3826. if (player->GetGroupMemberInfo()) {
  3827. player->UpdateGroupMemberInfo();
  3828. world.GetGroupManager()->SendGroupUpdate(player->GetGroupMemberInfo()->group_id);
  3829. }
  3830. }
  3831. // Only tradeskill skills should increace, and then only those related to your class
  3832. PacketStruct* level_update = configReader.getStruct("WS_LevelChanged", GetVersion());
  3833. if (level_update) {
  3834. level_update->setDataByName("old_level", old_level);
  3835. level_update->setDataByName("new_level", new_level);
  3836. level_update->setDataByName("type", 1);
  3837. QueuePacket(level_update->serialize());
  3838. safe_delete(level_update);
  3839. }
  3840. // Need to make tradeskill versions of the following
  3841. //SendNewSpells(player->GetAdventureClass());
  3842. //SendNewSpells(classes.GetBaseClass(player->GetAdventureClass()));
  3843. //SendNewSpells(classes.GetSecondaryBaseClass(player->GetAdventureClass()));
  3844. PacketStruct* command_packet = configReader.getStruct("WS_CannedEmote", GetVersion());
  3845. if (command_packet) {
  3846. command_packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  3847. command_packet->setDataByName("anim_type", 1753);
  3848. QueuePacket(command_packet->serialize());
  3849. safe_delete(command_packet);
  3850. }
  3851. GetPlayer()->GetInfoStruct()->tradeskill_level = new_level;
  3852. GetPlayer()->SetTSLevel(new_level);
  3853. UpdateTimeStampFlag(LEVEL_UPDATE_FLAG);
  3854. GetPlayer()->SetCharSheetChanged(true);
  3855. Message(CHANNEL_NARRATIVE, "Your tradeskill level is now %i!", new_level);
  3856. LogWrite(WORLD__DEBUG, 0, "World", "Player: %s leveled from %u to %u", GetPlayer()->GetName(), old_level, new_level);
  3857. PlayerSkillList* player_skills = player->GetSkills();
  3858. int16 specialize_skill_cap = new_level * 5;
  3859. int16 artisan_skill_cap = std::max<int16>(specialize_skill_cap, 49);
  3860. int16 specialize_10_skill_cap = std::max<int16>(specialize_skill_cap, 99);
  3861. int8 ts_class = player->GetTradeskillClass();
  3862. int8 base_ts_class = classes.GetSecondaryTSBaseClass(ts_class);
  3863. int32 skill_id_1, skill_id_2, skill_id_3;
  3864. switch (base_ts_class) {
  3865. case ARTISAN:
  3866. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3867. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3868. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3869. break;
  3870. case OUTFITTER:
  3871. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3872. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3873. skill_id_1 = SKILL_ID_TAILORING;
  3874. skill_id_2 = SKILL_ID_METALSHAPING;
  3875. skill_id_3 = SKILL_ID_METALWORKING;
  3876. if (ts_class == TAILOR) {
  3877. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3878. skill_id_1 = 0;
  3879. }
  3880. else if (ts_class == ARMORER) {
  3881. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3882. skill_id_2 = 0;
  3883. }
  3884. else if (ts_class == WEAPONSMITH) {
  3885. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3886. skill_id_3 = 0;
  3887. }
  3888. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3889. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3890. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3891. break;
  3892. case SCHOLAR:
  3893. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3894. player_skills->SetSkillCapsByType(SKILL_TYPE_CRAFTSMAN, artisan_skill_cap);
  3895. skill_id_1 = SKILL_ID_SCRIBING;
  3896. skill_id_2 = SKILL_ID_CHEMISTRY;
  3897. skill_id_3 = SKILL_ID_ARTIFICING;
  3898. if (ts_class == SAGE) {
  3899. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3900. skill_id_1 = 0;
  3901. }
  3902. else if (ts_class == ALCHEMIST) {
  3903. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3904. skill_id_2 = 0;
  3905. }
  3906. else if (ts_class == JEWELER) {
  3907. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3908. skill_id_3 = 0;
  3909. }
  3910. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3911. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3912. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3913. break;
  3914. case CRAFTSMAN:
  3915. player_skills->SetSkillCapsByType(SKILL_TYPE_OUTFITTER, artisan_skill_cap);
  3916. player_skills->SetSkillCapsByType(SKILL_TYPE_SCHOLAR, artisan_skill_cap);
  3917. skill_id_1 = SKILL_ID_ARTISTRY;
  3918. skill_id_2 = SKILL_ID_FLETCHING;
  3919. skill_id_3 = SKILL_ID_SCULPTING;
  3920. if (ts_class == PROVISIONER) {
  3921. player_skills->SetSkillCap(skill_id_1, specialize_skill_cap);
  3922. skill_id_1 = 0;
  3923. }
  3924. else if (ts_class == WOODWORKER) {
  3925. player_skills->SetSkillCap(skill_id_2, specialize_skill_cap);
  3926. skill_id_2 = 0;
  3927. }
  3928. else if (ts_class == CARPENTER) {
  3929. player_skills->SetSkillCap(skill_id_3, specialize_skill_cap);
  3930. skill_id_3 = 0;
  3931. }
  3932. if (skill_id_1) player_skills->SetSkillCap(skill_id_1, specialize_10_skill_cap);
  3933. if (skill_id_2) player_skills->SetSkillCap(skill_id_2, specialize_10_skill_cap);
  3934. if (skill_id_3) player_skills->SetSkillCap(skill_id_3, specialize_10_skill_cap);
  3935. break;
  3936. default:
  3937. break;
  3938. }
  3939. if (new_level > player->GetAdventureClass())
  3940. player_skills->SetSkillCapsByType(SKILL_TYPE_HARVESTING, specialize_skill_cap);
  3941. Guild* guild = GetPlayer()->GetGuild();
  3942. if (guild) {
  3943. int8 event_type = 0;
  3944. if (new_level < 10)
  3945. event_type = GUILD_EVENT_GAINS_TS_LEVEL_1_10;
  3946. else if (new_level == 10)
  3947. event_type = GUILD_EVENT_GAINS_TS_LEVEL_10;
  3948. else if (new_level >= 11 && new_level < 20)
  3949. event_type = GUILD_EVENT_GAINS_TS_LEVEL_11_20;
  3950. else if (new_level == 20)
  3951. event_type = GUILD_EVENT_GAINS_TS_LEVEL_20;
  3952. else if (new_level >= 21 && new_level < 30)
  3953. event_type = GUILD_EVENT_GAINS_TS_LEVEL_21_30;
  3954. else if (new_level == 30)
  3955. event_type = GUILD_EVENT_GAINS_TS_LEVEL_30;
  3956. else if (new_level >= 31 && new_level < 40)
  3957. event_type = GUILD_EVENT_GAINS_TS_LEVEL_31_40;
  3958. else if (new_level == 40)
  3959. event_type = GUILD_EVENT_GAINS_TS_LEVEL_40;
  3960. else if (new_level >= 41 && new_level < 50)
  3961. event_type = GUILD_EVENT_GAINS_TS_LEVEL_41_50;
  3962. else if (new_level == 50)
  3963. event_type = GUILD_EVENT_GAINS_TS_LEVEL_50;
  3964. else if (new_level >= 51 && new_level < 60)
  3965. event_type = GUILD_EVENT_GAINS_TS_LEVEL_51_60;
  3966. else if (new_level == 60)
  3967. event_type = GUILD_EVENT_GAINS_TS_LEVEL_60;
  3968. else if (new_level >= 61 && new_level < 70)
  3969. event_type = GUILD_EVENT_GAINS_TS_LEVEL_61_70;
  3970. else if (new_level == 70)
  3971. event_type = GUILD_EVENT_GAINS_TS_LEVEL_70;
  3972. else if (new_level >= 71 && new_level < 80)
  3973. event_type = GUILD_EVENT_GAINS_TS_LEVEL_71_80;
  3974. else if (new_level == 80)
  3975. event_type = GUILD_EVENT_GAINS_TS_LEVEL_80;
  3976. guild->AddNewGuildEvent(event_type, "%s has gained a tradeskill level and is now a level %u %s.", Timer::GetUnixTimeStamp(), true, GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  3977. guild->SendMessageToGuild(event_type, "%s has gained a tradeskill level and is now a level %u %s.", GetPlayer()->GetName(), new_level, classes.GetClassNameCase(GetPlayer()->GetTradeskillClass() + 42).c_str());
  3978. guild->UpdateGuildMemberInfo(GetPlayer());
  3979. guild->SendGuildMember(GetPlayer());
  3980. guild->SendGuildMemberList();
  3981. }
  3982. // Need to send the trait list every time the players level changes
  3983. // Also need to force the char sheet update or else there can be a large delay from when you level
  3984. // to when you are actually able to select traits.
  3985. QueuePacket(GetPlayer()->GetPlayerInfo()->serialize(GetVersion()));
  3986. QueuePacket(master_trait_list.GetTraitListPacket(this));
  3987. }
  3988. void Client::SendPendingLoot(int32 total_coins, Spawn* entity) {
  3989. if (entity)
  3990. Loot(total_coins, player->GetPendingLootItems(entity->GetID()), entity);
  3991. }
  3992. void Client::CloseLoot(int32 spawn_id) {
  3993. if (GetVersion() > 546) {
  3994. PacketStruct* packet = configReader.getStruct("WS_CloseWindow", GetVersion());
  3995. if (packet) {
  3996. packet->setDataByName("window_id", 4);
  3997. EQ2Packet* outapp = packet->serialize();
  3998. if (outapp) {
  3999. //DumpPacket(outapp);
  4000. QueuePacket(outapp);
  4001. }
  4002. safe_delete(packet);
  4003. }
  4004. }
  4005. else if(spawn_id > 0){
  4006. PacketStruct* packet = configReader.getStruct("WS_StoppedLooting", GetVersion());
  4007. if (packet) {
  4008. packet->setDataByName("spawn_id", spawn_id);
  4009. EQ2Packet* outapp = packet->serialize();
  4010. if (outapp)
  4011. QueuePacket(outapp);
  4012. safe_delete(packet);
  4013. }
  4014. }
  4015. }
  4016. string Client::GetCoinMessage(int32 total_coins) {
  4017. if (total_coins == 0) {
  4018. return " 0 Copper";
  4019. }
  4020. char tmp[64] = { 0 };
  4021. string message = "";
  4022. int32 val = 0;
  4023. if (total_coins >= 1000000) {
  4024. val = total_coins / 1000000;
  4025. total_coins -= 1000000 * val;
  4026. sprintf(tmp, " %u Platinum", val);
  4027. message.append(tmp);
  4028. memset(tmp, 0, 64);
  4029. }
  4030. if (total_coins >= 10000) {
  4031. val = total_coins / 10000;
  4032. total_coins -= 10000 * val;
  4033. sprintf(tmp, " %u Gold", val);
  4034. message.append(tmp);
  4035. memset(tmp, 0, 64);
  4036. }
  4037. if (total_coins >= 100) {
  4038. val = total_coins / 100;
  4039. total_coins -= 100 * val;
  4040. sprintf(tmp, " %u Silver", val);
  4041. message.append(tmp);
  4042. memset(tmp, 0, 64);
  4043. }
  4044. if (total_coins > 0) {
  4045. sprintf(tmp, " %u Copper", (int32)total_coins);
  4046. message.append(tmp);
  4047. }
  4048. return message;
  4049. }
  4050. void Client::Loot(int32 total_coins, vector<Item*>* items, Spawn* entity) {
  4051. if (!entity) {
  4052. CloseLoot(0);
  4053. return;
  4054. }
  4055. if (total_coins > 0) {
  4056. player->AddCoins(total_coins);
  4057. //PlaySound("coin_cha_ching");
  4058. string message = "";
  4059. if (entity->GetHP() == 0) {
  4060. message = "You loot ";
  4061. entity->SetLootCoins(0);
  4062. }
  4063. else
  4064. message = "You receive ";
  4065. message.append(GetCoinMessage(total_coins));
  4066. if (entity->GetHP() == 0)
  4067. message.append(" from the corpse of ").append(entity->GetName());
  4068. int8 type = CHANNEL_LOOT;
  4069. SimpleMessage(type, message.c_str());
  4070. }
  4071. if (!items || items->size() == 0)
  4072. CloseLoot(entity->GetID());
  4073. PacketStruct* packet = configReader.getStruct("WS_UpdateLoot", GetVersion());
  4074. if (packet) {
  4075. vector<Item*>::iterator itr;
  4076. int32 packet_size = 0;
  4077. EQ2Packet* outapp = 0;
  4078. uchar* data = 0;
  4079. if (GetVersion() >= 284) {
  4080. if (GetVersion() > 546) {
  4081. if (items && items->size() > 0) {
  4082. packet->setDataByName("loot_count", items->size());
  4083. packet->setDataByName("display", 1);
  4084. }
  4085. packet->setDataByName("loot_type", 1);
  4086. if (version >= 1096)
  4087. packet->setDataByName("lotto_timeout", 0x78);
  4088. else
  4089. packet->setDataByName("lotto_timeout", 0x3C);
  4090. packet->setDataByName("loot_id", entity->GetID());
  4091. EQ2Packet* tmpPacket = packet->serialize();
  4092. packet_size += tmpPacket->size;
  4093. if (items && items->size() > 0) {
  4094. data = new uchar[items->size() * 1000 + packet_size];
  4095. memset(data, 0, items->size() * 1000 + packet_size);
  4096. }
  4097. else {
  4098. data = new uchar[packet_size];
  4099. memset(data, 0, packet_size);
  4100. }
  4101. uchar* ptr = data;
  4102. memcpy(ptr, tmpPacket->pBuffer, tmpPacket->size);
  4103. ptr += tmpPacket->size;
  4104. safe_delete(tmpPacket);
  4105. Item* item = 0;
  4106. if (items && items->size() > 0) {
  4107. for (itr = items->begin(); itr != items->end(); itr++) {
  4108. item = *itr;
  4109. memcpy(ptr, &item->details.item_id, sizeof(int32));
  4110. ptr += sizeof(int32);
  4111. packet_size += sizeof(int32);
  4112. tmpPacket = item->serialize(GetVersion(), true, GetPlayer(), false, 1, 0, false, true);
  4113. int8 offset = 0;
  4114. if (GetVersion() >= 1188) {
  4115. offset = 13;
  4116. }
  4117. else if (GetVersion() >= 860) {
  4118. offset = 11;
  4119. }
  4120. else if (GetVersion() <= 546) {
  4121. offset = 19;
  4122. }
  4123. else {
  4124. offset = 10;
  4125. }
  4126. memcpy(ptr, tmpPacket->pBuffer + offset, tmpPacket->size - offset);
  4127. ptr += tmpPacket->size - offset;
  4128. packet_size += tmpPacket->size - offset;
  4129. safe_delete(tmpPacket);
  4130. }
  4131. }
  4132. packet_size -= sizeof(int32);
  4133. memcpy(data, &packet_size, sizeof(int32));
  4134. packet_size += sizeof(int32);
  4135. outapp = new EQ2Packet(OP_ClientCmdMsg, data, packet_size);
  4136. }
  4137. else {
  4138. if (items && items->size() > 0) {
  4139. packet->setArrayLengthByName("loot_count", items->size());
  4140. Item* item = 0;
  4141. if (items && items->size() > 0) {
  4142. int i = 0;
  4143. for (itr = items->begin(); itr != items->end(); itr++) {
  4144. item = *itr;
  4145. packet->setArrayDataByName("loot_id", item->details.item_id, i);
  4146. packet->setItemArrayDataByName("item", item, GetPlayer(), i, 0, 2, true);
  4147. i++;
  4148. }
  4149. }
  4150. packet->setDataByName("display", 1);
  4151. }
  4152. packet->setDataByName("loot_type", 1); // normal
  4153. packet->setDataByName("lotto_timeout", 0x3c); // 60 seconds
  4154. packet->setDataByName("spawn_id", entity->GetID());
  4155. outapp = packet->serialize();
  4156. }
  4157. }
  4158. else {
  4159. if (items && items->size() > 0) {
  4160. packet->setArrayLengthByName("loot_count", items->size());
  4161. for (int i = 0; i < items->size(); i++) {
  4162. Item* item = (*items)[i];
  4163. packet->setArrayDataByName("name", item->name.c_str(), i);
  4164. packet->setArrayDataByName("item_id", item->details.item_id, i);
  4165. packet->setArrayDataByName("count", item->details.count, i);
  4166. packet->setArrayDataByName("icon", item->details.icon, i);
  4167. if (item->generic_info.skill_req1 > 0 && item->generic_info.skill_req1 < 0xFFFFFFFF)
  4168. packet->setArrayDataByName("ability_id", item->generic_info.skill_req1, i);
  4169. else if (item->generic_info.skill_req2 > 0 && item->generic_info.skill_req2 < 0xFFFFFFFF)
  4170. packet->setArrayDataByName("ability_id", item->generic_info.skill_req2, i);
  4171. else
  4172. packet->setArrayDataByName("ability_id", 0xFFFFFFFF, i);
  4173. }
  4174. }
  4175. packet->setDataByName("object_id", entity->GetID());
  4176. packet->setDataByName("unknown3", 1);
  4177. packet->setDataByName("unknown4", 1);
  4178. packet->setDataByName("unknown5", 60);
  4179. outapp = packet->serialize();
  4180. }
  4181. if (outapp) {
  4182. DumpPacket(outapp);
  4183. QueuePacket(outapp);
  4184. }
  4185. safe_delete_array(data);
  4186. safe_delete(packet);
  4187. }
  4188. }
  4189. void Client::Loot(Spawn* entity, bool attemptDisarm) {
  4190. if (entity->IsNPC() && ((NPC*)entity)->Brain()->CheckLootAllowed(GetPlayer())) {
  4191. int32 total_coins = entity->GetLootCoins();
  4192. entity->LockLoot();
  4193. Loot(total_coins, entity->GetLootItems(), entity);
  4194. entity->UnlockLoot();
  4195. OpenChest(entity, attemptDisarm);
  4196. }
  4197. else
  4198. SimpleMessage(CHANNEL_COLOR_YELLOW, "You are not allowed to loot at this time.");
  4199. }
  4200. void Client::OpenChest(Spawn* entity, bool attemptDisarm)
  4201. {
  4202. if (!entity)
  4203. return;
  4204. int8 chest_difficulty = 0;
  4205. int32 state = 0;
  4206. // Check for the chest and set the action state
  4207. /*4034 = small chest | 5864 = treasure chest | 5865 = ornate treasure chest | 4015 = exquisite chest*/
  4208. string modelName;
  4209. if (entity->GetModelType() == 4034) {
  4210. // small chest, open with copper coins
  4211. // does not include traps, however can be disarmed
  4212. chest_difficulty = 1;
  4213. state = 11899;
  4214. modelName.append("Small Chest");
  4215. }
  4216. else if (entity->GetModelType() == 5864) {
  4217. // treasure chest, open with silver coins
  4218. chest_difficulty = 2;
  4219. state = 11901;
  4220. modelName.append("Treasure Chest");
  4221. }
  4222. else if (entity->GetModelType() == 5865) {
  4223. // ornate chest, open with gold coins
  4224. chest_difficulty = 3;
  4225. state = 11900;
  4226. modelName.append("Ornate Chest");
  4227. }
  4228. else if (entity->GetModelType() == 4015) {
  4229. // exquisite chest, open with gold coins and jewels as well as a glow effect
  4230. chest_difficulty = 5;
  4231. state = 11898;
  4232. modelName.append("Exquisite Chest");
  4233. }
  4234. bool firstChestOpen = false;
  4235. if (chest_difficulty > 0 && !entity->HasTrapTriggered())
  4236. {
  4237. ChestTrap::ChestTrapInfo nextTrap;
  4238. bool ret = chest_trap_list.GetNextTrap(GetCurrentZone()->GetZoneID(), chest_difficulty, &nextTrap);
  4239. Skill* disarmSkill = GetPlayer()->GetSkillByName("Disarm Trap", false);
  4240. firstChestOpen = true;
  4241. entity->SetTrapTriggered(true);
  4242. if (ret)
  4243. {
  4244. if (disarmSkill && attemptDisarm)
  4245. {
  4246. if (disarmSkill->CheckDisarmSkill(entity->GetLevel(), chest_difficulty) < 1)
  4247. {
  4248. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4249. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4250. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4251. }
  4252. else
  4253. {
  4254. Message(CHANNEL_NARRATIVE, "You disarm the trap on %s", modelName.c_str());
  4255. }
  4256. // despite fail/succeed we should always try to increase skill if disarm is available
  4257. GetPlayer()->GetSkillByName("Disarm Trap", true);
  4258. }
  4259. else // no disarm skill, always fail
  4260. {
  4261. CastGroupOrSelf(entity && entity->IsEntity() ? (Entity*)entity : 0, nextTrap.spell_id, nextTrap.spell_tier,
  4262. rule_manager.GetGlobalRule(R_Loot, ChestTriggerRadiusGroup)->GetFloat());
  4263. Message(CHANNEL_NARRATIVE, "You trigger the trap on %s!", modelName.c_str());
  4264. }
  4265. }
  4266. }
  4267. else if (!entity->HasTrapTriggered())
  4268. {
  4269. firstChestOpen = true;
  4270. entity->SetTrapTriggered(true);
  4271. }
  4272. // We set the visual state with out updating so those not in range will see it opened when it is finally sent to them,
  4273. // for those in range the SendStateCommand will cause it to animate open.
  4274. // TODO: when player enters radius that does not have visual state, update visual state
  4275. if (firstChestOpen)
  4276. entity->SetVisualState(state, false);
  4277. GetCurrentZone()->SendStateCommand(entity, state);
  4278. }
  4279. void Client::CastGroupOrSelf(Entity* source, uint32 spellID, uint32 spellTier, float restrictiveRadius)
  4280. {
  4281. Spell* spell = master_spell_list.GetSpell(spellID, spellTier);
  4282. SpellProcess* spellProcess = GetCurrentZone()->GetSpellProcess();
  4283. if (source == NULL)
  4284. source = (Entity*)GetPlayer();
  4285. if (spell)
  4286. {
  4287. GroupMemberInfo* gmi = GetPlayer()->GetGroupMemberInfo();
  4288. if (gmi && gmi->group_id)
  4289. {
  4290. PlayerGroup* group = world.GetGroupManager()->GetGroup(gmi->group_id);
  4291. if (group)
  4292. {
  4293. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4294. deque<GroupMemberInfo*>* members = group->GetMembers();
  4295. for (int8 i = 0; i < members->size(); i++) {
  4296. Entity* member = members->at(i)->member;
  4297. if (!member->Alive() || (member->GetZone() != source->GetZone()))
  4298. continue;
  4299. // if we have a radius provided then check if the group member is outside the radius or not
  4300. if (restrictiveRadius > 0.0f && member->GetDistance(source) > restrictiveRadius)
  4301. continue;
  4302. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4303. }
  4304. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4305. }
  4306. }
  4307. else
  4308. spellProcess->CastInstant(spell, source, (Entity*)GetPlayer());
  4309. }
  4310. }
  4311. Spawn* Client::GetBanker() {
  4312. return banker;
  4313. }
  4314. void Client::SetBanker(Spawn* in_banker) {
  4315. banker = in_banker;
  4316. }
  4317. void Client::Bank(Spawn* banker, bool cancel) {
  4318. if (banker && banker->primary_command_list.size() > 0 && banker->primary_command_list[0]->command == "bank") {
  4319. if (!cancel)
  4320. SetBanker(banker);
  4321. else
  4322. SetBanker(0);
  4323. PacketStruct* packet = configReader.getStruct("WS_UpdateBank", GetVersion());
  4324. if (packet) {
  4325. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(banker));
  4326. int64 coins = GetPlayer()->GetInfoStruct()->bank_coin_copper + GetPlayer()->GetInfoStruct()->bank_coin_silver * 100 +
  4327. GetPlayer()->GetInfoStruct()->bank_coin_gold * 10000 + (int64)GetPlayer()->GetInfoStruct()->bank_coin_plat * 1000000;
  4328. int32 coins1, coins2;
  4329. coins1 = ((int32*)&coins)[0];
  4330. coins2 = ((int32*)&coins)[1];
  4331. packet->setDataByName("bank_coins", coins1);
  4332. packet->setDataByName("bank_coins2", coins2);
  4333. packet->setDataByName("copper", GetPlayer()->GetInfoStruct()->coin_copper);
  4334. packet->setDataByName("silver", GetPlayer()->GetInfoStruct()->coin_silver);
  4335. packet->setDataByName("gold", GetPlayer()->GetInfoStruct()->coin_gold);
  4336. packet->setDataByName("plat", GetPlayer()->GetInfoStruct()->coin_plat);
  4337. if (!cancel)
  4338. packet->setDataByName("display", 1);
  4339. QueuePacket(packet->serialize());
  4340. safe_delete(packet);
  4341. }
  4342. }
  4343. }
  4344. void Client::BankWithdrawal(int64 amount) {
  4345. bool cheater = false;
  4346. if (GetBanker() && amount > 0) {
  4347. string withdrawal = "";
  4348. char withdrawal_data[512] = { 0 };
  4349. int32 tmp = 0;
  4350. if (amount >= 1000000) {
  4351. tmp = amount / 1000000;
  4352. if (tmp > GetPlayer()->GetBankCoinsPlat())
  4353. cheater = true;
  4354. else {
  4355. GetPlayer()->GetInfoStruct()->bank_coin_plat -= tmp;
  4356. GetPlayer()->GetInfoStruct()->coin_plat += tmp;
  4357. amount -= (int64)tmp * 1000000;
  4358. sprintf(withdrawal_data, "%u Platinum ", tmp);
  4359. withdrawal.append(withdrawal_data);
  4360. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4361. }
  4362. }
  4363. if (!cheater && amount >= 10000) {
  4364. tmp = amount / 10000;
  4365. if (tmp > GetPlayer()->GetBankCoinsGold())
  4366. cheater = true;
  4367. else {
  4368. GetPlayer()->GetInfoStruct()->bank_coin_gold -= tmp;
  4369. if ((GetPlayer()->GetInfoStruct()->coin_gold + tmp) > 100) {
  4370. GetPlayer()->GetInfoStruct()->coin_gold = (GetPlayer()->GetInfoStruct()->coin_gold + tmp) - 100;
  4371. GetPlayer()->GetInfoStruct()->coin_plat += 1;
  4372. }
  4373. else
  4374. GetPlayer()->GetInfoStruct()->coin_gold += tmp;
  4375. amount -= tmp * 10000;
  4376. sprintf(withdrawal_data, "%u Gold ", tmp);
  4377. withdrawal.append(withdrawal_data);
  4378. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4379. }
  4380. }
  4381. if (!cheater && amount >= 100) {
  4382. tmp = amount / 100;
  4383. if (tmp > GetPlayer()->GetBankCoinsSilver())
  4384. cheater = true;
  4385. else {
  4386. GetPlayer()->GetInfoStruct()->bank_coin_silver -= tmp;
  4387. if ((GetPlayer()->GetInfoStruct()->coin_silver + tmp) > 100) {
  4388. GetPlayer()->GetInfoStruct()->coin_silver = (GetPlayer()->GetInfoStruct()->coin_silver + tmp) - 100;
  4389. GetPlayer()->GetInfoStruct()->coin_gold += 1;
  4390. }
  4391. else
  4392. GetPlayer()->GetInfoStruct()->coin_silver += tmp;
  4393. amount -= tmp * 100;
  4394. sprintf(withdrawal_data, "%u Silver ", tmp);
  4395. withdrawal.append(withdrawal_data);
  4396. memset(withdrawal_data, 0, sizeof(withdrawal_data));
  4397. }
  4398. }
  4399. if (!cheater) {
  4400. if (amount > 0) {
  4401. sprintf(withdrawal_data, "%u Copper ", (int32)amount);
  4402. withdrawal.append(withdrawal_data);
  4403. GetPlayer()->GetInfoStruct()->bank_coin_copper -= amount;
  4404. if ((GetPlayer()->GetInfoStruct()->coin_copper + amount) > 100) {
  4405. GetPlayer()->GetInfoStruct()->coin_copper = (GetPlayer()->GetInfoStruct()->coin_copper + amount) - 100;
  4406. GetPlayer()->GetInfoStruct()->coin_silver += 1;
  4407. }
  4408. else
  4409. GetPlayer()->GetInfoStruct()->coin_copper += amount;
  4410. }
  4411. if (withdrawal.length() > 0) {
  4412. withdrawal.append("withdrawn ");
  4413. sprintf(withdrawal_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4414. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4415. withdrawal.append(withdrawal_data);
  4416. SimpleMessage(CHANNEL_NARRATIVE, withdrawal.c_str());
  4417. }
  4418. }
  4419. else
  4420. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4421. player->SetCharSheetChanged(true);
  4422. Bank(banker);
  4423. }
  4424. }
  4425. void Client::BankDeposit(int64 amount) {
  4426. bool cheater = false;
  4427. if (GetBanker() && amount > 0) {
  4428. int32 tmp = 0;
  4429. char deposit_data[512] = { 0 };
  4430. string deposit = "";
  4431. if (amount >= 1000000) {
  4432. tmp = amount / 1000000;
  4433. if (tmp > GetPlayer()->GetCoinsPlat())
  4434. cheater = true;
  4435. else {
  4436. GetPlayer()->GetInfoStruct()->bank_coin_plat += tmp;
  4437. GetPlayer()->GetInfoStruct()->coin_plat -= tmp;
  4438. amount -= (int64)tmp * 1000000;
  4439. sprintf(deposit_data, "%u Platinum ", tmp);
  4440. deposit.append(deposit_data);
  4441. memset(deposit_data, 0, sizeof(deposit_data));
  4442. }
  4443. }
  4444. if (!cheater && amount >= 10000) {
  4445. tmp = amount / 10000;
  4446. if (tmp > GetPlayer()->GetCoinsGold())
  4447. cheater = true;
  4448. else {
  4449. if ((GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) > 100) {
  4450. GetPlayer()->GetInfoStruct()->bank_coin_gold = (GetPlayer()->GetInfoStruct()->bank_coin_gold + tmp) - 100;
  4451. GetPlayer()->GetInfoStruct()->bank_coin_plat += 1;
  4452. }
  4453. else
  4454. GetPlayer()->GetInfoStruct()->bank_coin_gold += tmp;
  4455. GetPlayer()->GetInfoStruct()->coin_gold -= tmp;
  4456. amount -= tmp * 10000;
  4457. sprintf(deposit_data, "%u Gold ", tmp);
  4458. deposit.append(deposit_data);
  4459. memset(deposit_data, 0, sizeof(deposit_data));
  4460. }
  4461. }
  4462. if (!cheater && amount >= 100) {
  4463. tmp = amount / 100;
  4464. if (tmp > GetPlayer()->GetCoinsSilver())
  4465. cheater = true;
  4466. else {
  4467. if ((GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) > 100) {
  4468. GetPlayer()->GetInfoStruct()->bank_coin_silver = (GetPlayer()->GetInfoStruct()->bank_coin_silver + tmp) - 100;
  4469. GetPlayer()->GetInfoStruct()->bank_coin_gold += 1;
  4470. }
  4471. else
  4472. GetPlayer()->GetInfoStruct()->bank_coin_silver += tmp;
  4473. GetPlayer()->GetInfoStruct()->coin_silver -= tmp;
  4474. amount -= tmp * 100;
  4475. sprintf(deposit_data, "%u Silver ", tmp);
  4476. deposit.append(deposit_data);
  4477. memset(deposit_data, 0, sizeof(deposit_data));
  4478. }
  4479. }
  4480. if (!cheater) {
  4481. if (amount > 0) {
  4482. sprintf(deposit_data, "%u Copper ", (int32)amount);
  4483. deposit.append(deposit_data);
  4484. if ((GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) > 100) {
  4485. GetPlayer()->GetInfoStruct()->bank_coin_copper = (GetPlayer()->GetInfoStruct()->bank_coin_copper + amount) - 100;
  4486. GetPlayer()->GetInfoStruct()->bank_coin_silver += 1;
  4487. }
  4488. else
  4489. GetPlayer()->GetInfoStruct()->bank_coin_copper += amount;
  4490. GetPlayer()->GetInfoStruct()->coin_copper -= amount;
  4491. }
  4492. if (deposit.length() > 0) {
  4493. deposit.append("deposited ");
  4494. sprintf(deposit_data, "(%u Plat %u Gold %u Silver %u Copper in the bank now.)", GetPlayer()->GetInfoStruct()->bank_coin_plat,
  4495. GetPlayer()->GetInfoStruct()->bank_coin_gold, GetPlayer()->GetInfoStruct()->bank_coin_silver, GetPlayer()->GetInfoStruct()->bank_coin_copper);
  4496. deposit.append(deposit_data);
  4497. SimpleMessage(CHANNEL_NARRATIVE, deposit.c_str());
  4498. }
  4499. }
  4500. else
  4501. Message(CHANNEL_COLOR_RED, "Stop trying to cheat!");
  4502. player->SetCharSheetChanged(true);
  4503. Bank(banker);
  4504. }
  4505. }
  4506. void Client::AddPendingQuestReward(Quest* quest) {
  4507. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4508. quest_pending_reward.push_back(quest);
  4509. quest_updates = true;
  4510. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4511. }
  4512. void Client::AddPendingQuestUpdate(int32 quest_id, int32 step_id, int32 progress) {
  4513. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4514. quest_pending_updates[quest_id][step_id] = progress;
  4515. quest_updates = true;
  4516. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4517. }
  4518. void Client::ProcessQuestUpdates() {
  4519. if (quest_pending_updates.size() > 0) {
  4520. map<int32, map<int32, int32> > tmp_quest_updates;
  4521. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4522. tmp_quest_updates.insert(quest_pending_updates.begin(), quest_pending_updates.end());
  4523. quest_pending_updates.clear();
  4524. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4525. map<int32, map<int32, int32> >::iterator quest_itr;
  4526. map<int32, int32>::iterator step_itr;
  4527. for (quest_itr = tmp_quest_updates.begin(); quest_itr != tmp_quest_updates.end(); quest_itr++) {
  4528. for (step_itr = quest_itr->second.begin(); step_itr != quest_itr->second.end(); step_itr++) {
  4529. if (step_itr->second == 0xFFFFFFFF) {
  4530. SetStepComplete(quest_itr->first, step_itr->first);
  4531. player->SendQuestRequiredSpawns(quest_itr->first);
  4532. }
  4533. else
  4534. AddStepProgress(quest_itr->first, step_itr->first, step_itr->second);
  4535. }
  4536. }
  4537. }
  4538. if (quest_pending_reward.size() > 0) {
  4539. vector<Quest*>::iterator itr;
  4540. vector<Quest*> tmp_quest_rewards;
  4541. MQuestPendingUpdates.writelock(__FUNCTION__, __LINE__);
  4542. tmp_quest_rewards.insert(tmp_quest_rewards.begin(), quest_pending_reward.begin(), quest_pending_reward.end());
  4543. quest_pending_reward.clear();
  4544. MQuestPendingUpdates.releasewritelock(__FUNCTION__, __LINE__);
  4545. for (itr = tmp_quest_rewards.begin(); itr != tmp_quest_rewards.end(); itr++) {
  4546. GiveQuestReward(*itr);
  4547. }
  4548. }
  4549. quest_updates = false;
  4550. }
  4551. void Client::CheckQuestQueue() {
  4552. MQuestQueue.writelock();
  4553. last_update_time = 0;
  4554. vector<QueuedQuest*>::iterator itr;
  4555. QueuedQuest* queued_quest = 0;
  4556. for (itr = quest_queue.begin(); itr != quest_queue.end(); itr++) {
  4557. queued_quest = *itr;
  4558. SendQuestUpdateStepImmediately(queued_quest->quest, queued_quest->step, queued_quest->display_quest_helper);
  4559. //if(queued_quest->quest && queued_quest->quest->GetTurnedIn()) //update the journal so the old quest isn't the one displayed in the client's quest helper
  4560. // SendQuestJournal();
  4561. safe_delete(queued_quest);
  4562. }
  4563. quest_queue.clear();
  4564. MQuestQueue.releasewritelock();
  4565. }
  4566. void Client::SetStepComplete(int32 quest_id, int32 step) {
  4567. Quest* quest = player->SetStepComplete(quest_id, step);
  4568. if (quest) {
  4569. SendQuestUpdate(quest);
  4570. GetCurrentZone()->SendQuestUpdates(this);
  4571. }
  4572. }
  4573. void Client::AddStepProgress(int32 quest_id, int32 step, int32 progress) {
  4574. Quest* quest = player->AddStepProgress(quest_id, step, progress);
  4575. if (quest) {
  4576. SendQuestUpdate(quest);
  4577. GetCurrentZone()->SendQuestUpdates(this);
  4578. }
  4579. }
  4580. void Client::CheckPlayerQuestsKillUpdate(Spawn* spawn) {
  4581. bool hadUpdates = false;
  4582. vector<Quest*>* quest_updates = player->CheckQuestsKillUpdate(spawn);
  4583. if (quest_updates) {
  4584. for (int32 i = 0; i < quest_updates->size(); i++)
  4585. {
  4586. SendQuestUpdate(quest_updates->at(i));
  4587. hadUpdates = true;
  4588. }
  4589. }
  4590. safe_delete(quest_updates);
  4591. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4592. if (quest_failures) {
  4593. for (int32 i = 0; i < quest_failures->size(); i++)
  4594. {
  4595. SendQuestFailure(quest_failures->at(i));
  4596. hadUpdates = true;
  4597. }
  4598. }
  4599. safe_delete(quest_failures);
  4600. if (hadUpdates)
  4601. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4602. }
  4603. void Client::CheckPlayerQuestsChatUpdate(Spawn* spawn) {
  4604. vector<Quest*>* quest_updates = player->CheckQuestsChatUpdate(spawn);
  4605. if (quest_updates) {
  4606. for (int32 i = 0; i < quest_updates->size(); i++)
  4607. SendQuestUpdate(quest_updates->at(i));
  4608. GetCurrentZone()->SendQuestUpdates(this);
  4609. }
  4610. safe_delete(quest_updates);
  4611. }
  4612. void Client::CheckPlayerQuestsItemUpdate(Item* item) {
  4613. vector<Quest*>* quest_updates = player->CheckQuestsItemUpdate(item);
  4614. if (quest_updates) {
  4615. for (int32 i = 0; i < quest_updates->size(); i++)
  4616. SendQuestUpdate(quest_updates->at(i));
  4617. }
  4618. safe_delete(quest_updates);
  4619. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4620. if (quest_failures) {
  4621. for (int32 i = 0; i < quest_failures->size(); i++)
  4622. SendQuestFailure(quest_failures->at(i));
  4623. }
  4624. safe_delete(quest_failures);
  4625. }
  4626. void Client::CheckPlayerQuestsLocationUpdate() {
  4627. vector<Quest*>* quest_updates = player->CheckQuestsLocationUpdate();
  4628. if (quest_updates) {
  4629. for (int32 i = 0; i < quest_updates->size(); i++)
  4630. SendQuestUpdate(quest_updates->at(i));
  4631. }
  4632. safe_delete(quest_updates);
  4633. }
  4634. void Client::CheckPlayerQuestsSpellUpdate(Spell* spell) {
  4635. vector<Quest*>* quest_updates = player->CheckQuestsSpellUpdate(spell);
  4636. if (quest_updates) {
  4637. for (int32 i = 0; i < quest_updates->size(); i++)
  4638. SendQuestUpdate(quest_updates->at(i));
  4639. }
  4640. safe_delete(quest_updates);
  4641. vector<Quest*>* quest_failures = player->CheckQuestsFailures();
  4642. if (quest_failures) {
  4643. for (int32 i = 0; i < quest_failures->size(); i++)
  4644. SendQuestFailure(quest_failures->at(i));
  4645. }
  4646. safe_delete(quest_failures);
  4647. }
  4648. void Client::AddPendingQuest(Quest* quest, bool forced) {
  4649. if (version <= 283 || forced) { //this client doesn't ask if you want the quest, so auto accept
  4650. player->pending_quests[quest->GetQuestID()] = quest;
  4651. AcceptQuest(quest->GetQuestID());
  4652. }
  4653. else {
  4654. player->pending_quests[quest->GetQuestID()] = quest;
  4655. EQ2Packet* outapp = quest->OfferQuest(GetVersion(), player);
  4656. //DumpPacket(outapp);
  4657. QueuePacket(outapp);
  4658. }
  4659. }
  4660. Quest* Client::GetActiveQuest(int32 quest_id) {
  4661. if (player->player_quests.count(quest_id) > 0) {
  4662. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u active quests for char_id: %u", player->player_quests.count(quest_id), player->GetCharacterID());
  4663. return player->player_quests[quest_id];
  4664. }
  4665. return 0;
  4666. }
  4667. void Client::AcceptQuest(int32 id) {
  4668. Quest* quest = GetPendingQuest(id);
  4669. if (quest) {
  4670. RemovePendingQuest(quest);
  4671. AddPlayerQuest(quest);
  4672. GetCurrentZone()->SendQuestUpdates(this);
  4673. // If character has already completed this quest once update the given date in the database
  4674. if (GetPlayer()->GetCompletedPlayerQuests()->count(id) > 0) {
  4675. Quest* quest2 = GetPlayer()->GetCompletedQuest(id);
  4676. if (quest2)
  4677. quest->SetCompleteCount(quest2->GetCompleteCount());
  4678. database.SaveCharRepeatableQuest(this, id, quest->GetCompleteCount());
  4679. }
  4680. }
  4681. }
  4682. Quest* Client::GetPendingQuest(int32 id) {
  4683. if (player->pending_quests.count(id) > 0) {
  4684. LogWrite(CCLIENT__DEBUG, 0, "Client", "Found %u pending quests for char_id: %u", player->pending_quests.count(id), player->GetCharacterID());
  4685. return player->pending_quests[id];
  4686. }
  4687. return 0;
  4688. }
  4689. void Client::RemovePendingQuest(Quest* quest) {
  4690. player->pending_quests.erase(quest->GetQuestID());
  4691. }
  4692. void Client::SetPlayerQuest(Quest* quest, map<int32, int32>* progress) {
  4693. if (!quest || !progress) {
  4694. return;
  4695. }
  4696. map<int32, int32>::iterator itr;
  4697. QuestStep* step = 0;
  4698. player->SetZone(GetCurrentZone());
  4699. for (itr = progress->begin(); itr != progress->end(); itr++) {
  4700. step = quest->GetQuestStep(itr->first);
  4701. if (step && itr->second > 0) {
  4702. step->SetStepProgress(itr->second);
  4703. if (lua_interface && step->GetQuestCurrentQuantity() >= step->GetQuestNeededQuantity())
  4704. lua_interface->CallQuestFunction(quest, "Reload", player, step->GetStepID());
  4705. }
  4706. }
  4707. if (lua_interface)
  4708. lua_interface->CallQuestFunction(quest, "CurrentStep", player, step->GetStepID());
  4709. }
  4710. void Client::AddPlayerQuest(Quest* quest, bool call_accepted, bool send_packets) {
  4711. if (player->player_quests.count(quest->GetQuestID()) > 0) {
  4712. if (player->player_quests[quest->GetQuestID()]->GetQuestFlags() > 0)
  4713. quest->SetQuestFlags(player->player_quests[quest->GetQuestID()]->GetQuestFlags());
  4714. RemovePlayerQuest(quest->GetQuestID(), false, false);
  4715. }
  4716. player->player_quests[quest->GetQuestID()] = quest;
  4717. quest->SetPlayer(player);
  4718. current_quest_id = quest->GetQuestID();
  4719. if (send_packets && quest->GetQuestGiver() > 0)
  4720. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  4721. if (lua_interface && call_accepted)
  4722. lua_interface->CallQuestFunction(quest, "Accepted", player);
  4723. if (send_packets) {
  4724. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4725. //SendQuestJournal();
  4726. SendQuestJournalUpdate(quest);
  4727. // sent twice to match live
  4728. quest->SetTracked(false);
  4729. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4730. quest->SetTracked(true);
  4731. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player));
  4732. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4733. }
  4734. //This isn't during a load screen, so update spawns with required quests
  4735. if (call_accepted)
  4736. player->SendQuestRequiredSpawns(quest->GetQuestID());
  4737. }
  4738. void Client::RemovePlayerQuest(int32 id, bool send_update, bool delete_quest) {
  4739. if (current_quest_id == id)
  4740. current_quest_id = 0;
  4741. if (player->player_quests.count(id) > 0) {
  4742. if (delete_quest) {
  4743. player->player_quests[id]->SetDeleted(true);
  4744. database.DeleteCharacterQuest(id, GetCharacterID(), player->GetCompletedPlayerQuests()->count(id) > 0);
  4745. }
  4746. if (send_update && player->player_quests[id]->GetQuestGiver() > 0)
  4747. GetCurrentZone()->SendSpawnChangesByDBID(player->player_quests[id]->GetQuestGiver(), this, false, true);
  4748. if (send_update) {
  4749. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4750. SendQuestJournal(false, 0, true);
  4751. }
  4752. player->RemoveQuest(id, delete_quest);
  4753. if (send_update) {
  4754. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4755. SendQuestJournal(false, 0, true);
  4756. GetCurrentZone()->SendAllSpawnsForVisChange(this);
  4757. }
  4758. }
  4759. }
  4760. void Client::SendQuestUpdateStepImmediately(Quest* quest, int32 step, bool display_quest_helper) {
  4761. if (quest) {
  4762. QuestStep* quest_step = quest->GetQuestStep(step);
  4763. if (quest_step) {
  4764. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, quest_step, 1, false, false, display_quest_helper));
  4765. quest_step->WasUpdated(false);
  4766. }
  4767. }
  4768. }
  4769. void Client::SendQuestUpdateStep(Quest* quest, int32 step, bool display_quest_helper) {
  4770. QueuedQuest* item = new QueuedQuest;
  4771. item->quest = quest;
  4772. item->step = step;
  4773. item->display_quest_helper = display_quest_helper;
  4774. MQuestQueue.writelock();
  4775. quest_queue.push_back(item);
  4776. last_update_time = Timer::GetCurrentTime2();
  4777. MQuestQueue.releasewritelock();
  4778. }
  4779. void Client::SendQuestFailure(Quest* quest) {
  4780. vector<QuestStep*>* failures = quest->GetQuestFailures();
  4781. if (failures) {
  4782. QuestStep* step = 0;
  4783. for (int32 i = 0; i < failures->size(); i++) {
  4784. step = failures->at(i);
  4785. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step, 1, false, true));
  4786. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4787. SendQuestJournal(false, 0, true);
  4788. }
  4789. failures->clear();
  4790. }
  4791. }
  4792. void Client::SendQuestUpdate(Quest* quest) {
  4793. vector<QuestStep*>* updates = quest->GetQuestUpdates();
  4794. if (updates) {
  4795. QuestStep* step = 0;
  4796. bool updated = false;
  4797. for (int32 i = 0; i < updates->size(); i++) {
  4798. step = updates->at(i);
  4799. if (lua_interface && step->Complete() && quest->GetCompleteAction(step->GetStepID()))
  4800. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(step->GetStepID()), player);
  4801. if (step->WasUpdated()) {
  4802. SendQuestJournal(false, 0, true);
  4803. QueuePacket(quest->QuestJournalReply(GetVersion(), GetNameCRC(), player, step));
  4804. }
  4805. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  4806. }
  4807. if (lua_interface && quest->GetCompleted() && quest->GetCompleteAction()) {
  4808. lua_interface->CallQuestFunction(quest, quest->GetCompleteAction(), player);
  4809. SendQuestJournalUpdate(quest, false);
  4810. }
  4811. if (quest->GetCompleted()) {
  4812. if (quest->GetQuestReturnNPC() > 0)
  4813. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestReturnNPC(), this, false, true);
  4814. if (quest->GetCompletedFlag())
  4815. quest->SetCompletedFlag(false);
  4816. }
  4817. updates->clear();
  4818. }
  4819. }
  4820. void Client::SendQuestJournal(bool all_quests, Client* client, bool updated) {
  4821. if (!client)
  4822. client = this;
  4823. PacketStruct* packet = player->GetQuestJournalPacket(all_quests, GetVersion(), GetNameCRC(), current_quest_id, updated);
  4824. if (packet) {
  4825. EQ2Packet* outapp = packet->serialize();
  4826. //DumpPacket(outapp);
  4827. client->QueuePacket(outapp);
  4828. safe_delete(packet);
  4829. }
  4830. }
  4831. void Client::SendQuestJournalUpdate(Quest* quest, bool updated) {
  4832. PacketStruct* packet = player->GetQuestJournalPacket(quest, GetVersion(), GetNameCRC(), updated);
  4833. if (packet) {
  4834. QueuePacket(packet->serialize());
  4835. safe_delete(packet);
  4836. }
  4837. }
  4838. void Client::ReloadQuests() {
  4839. vector<int32> ids = player->GetQuestIDs();
  4840. Quest* quest = 0;
  4841. for (int32 i = 0; i < ids.size(); i++) {
  4842. quest = master_quest_list.GetQuest(ids[i]);
  4843. if (quest)
  4844. AddPlayerQuest(quest, false);
  4845. else
  4846. RemovePlayerQuest(ids[i]);
  4847. }
  4848. }
  4849. Quest* Client::GetPendingQuestAcceptance(int32 item_id) {
  4850. bool found_quest = false;
  4851. vector<Quest*>::iterator itr;
  4852. vector<Item*>* items = 0;
  4853. Quest* quest = 0;
  4854. MPendingQuestAccept.lock();
  4855. for (itr = pending_quest_accept.begin(); itr != pending_quest_accept.end(); itr++) {
  4856. quest = *itr;
  4857. items = quest->GetSelectableRewardItems();
  4858. if (items && items->size() > 0) {
  4859. for (int32 i = 0; i < items->size(); i++) {
  4860. if (items->at(i)->details.item_id == item_id) {
  4861. found_quest = true;
  4862. break;
  4863. }
  4864. }
  4865. }
  4866. else if (item_id == 0)
  4867. found_quest = true;
  4868. if (found_quest) {
  4869. pending_quest_accept.erase(itr);
  4870. break;
  4871. }
  4872. }
  4873. MPendingQuestAccept.unlock();
  4874. if (found_quest)
  4875. return quest;
  4876. return 0;
  4877. }
  4878. void Client::AcceptQuestReward(Quest* quest, int32 item_id) {
  4879. int8 num_slots_needed = 0;
  4880. int16 free_slots = player->item_list.GetNumberOfFreeSlots();
  4881. Item* master_item = 0;
  4882. if (item_id > 0) {
  4883. num_slots_needed++;
  4884. master_item = master_item_list.GetItem(item_id);
  4885. }
  4886. vector<Item*>* items = quest->GetRewardItems();
  4887. if (items && items->size() > 0)
  4888. num_slots_needed += items->size();
  4889. if (free_slots >= num_slots_needed || (player->item_list.HasFreeBagSlot() && master_item && master_item->IsBag() && master_item->bag_info->num_slots >= items->size())) {
  4890. if (master_item)
  4891. AddItem(item_id);
  4892. if (items && items->size() > 0) {
  4893. for (int32 i = 0; i < items->size(); i++)
  4894. AddItem(new Item(items->at(i)));
  4895. }
  4896. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  4897. if (outapp)
  4898. QueuePacket(outapp);
  4899. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  4900. map<int32, sint32>::iterator itr;
  4901. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  4902. int32 faction_id = itr->first;
  4903. sint32 amount = itr->second;
  4904. if (amount > 0)
  4905. player->GetFactions()->IncreaseFaction(faction_id, amount);
  4906. else
  4907. player->GetFactions()->DecreaseFaction(faction_id, (amount * -1));
  4908. }
  4909. if (player->GetGuild()) {
  4910. player->GetInfoStruct()->status_points += quest->GetStatusPoints();
  4911. player->SetCharSheetChanged(true);
  4912. }
  4913. }
  4914. else {
  4915. MPendingQuestAccept.lock();
  4916. pending_quest_accept.push_back(quest);
  4917. MPendingQuestAccept.unlock();
  4918. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots! Free some slots and try again.");
  4919. DisplayQuestComplete(quest);
  4920. }
  4921. }
  4922. void Client::DisplayQuestRewards(Quest* quest, int64 coin, vector<Item*>* rewards, vector<Item*>* selectable_rewards, map<int32, sint32>* factions, const char* header, int32 status_points, const char* text) {
  4923. if (coin == 0 && (!rewards || rewards->size() == 0) && (!selectable_rewards || selectable_rewards->size() == 0) && (!factions || factions->size() == 0) && status_points == 0 && text == 0 && (!quest || (quest->GetCoinsReward() == 0 && quest->GetCoinsRewardMax() == 0))) {
  4924. if (quest)
  4925. text = quest->GetName();
  4926. else
  4927. return;//nothing to give
  4928. }
  4929. PacketStruct* packet2 = configReader.getStruct("WS_QuestRewardPackMsg", GetVersion());
  4930. if (packet2) {
  4931. int32 source_id = 0;
  4932. if (quest)
  4933. source_id = quest->GetQuestID();
  4934. int64 rewarded_coin = 0;
  4935. if (quest) {
  4936. if (quest->GetCoinsReward() > 0) {
  4937. if (quest->GetCoinsRewardMax() > 0)
  4938. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  4939. else
  4940. rewarded_coin = quest->GetCoinsReward();
  4941. }
  4942. quest->SetGeneratedCoin(rewarded_coin);
  4943. }
  4944. if (rewarded_coin > coin)
  4945. coin = rewarded_coin;
  4946. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  4947. player->AddCoins(coin);
  4948. PlaySound("coin_cha_ching");
  4949. }
  4950. packet2->setSubstructDataByName("reward_data", "unknown1", 255);
  4951. packet2->setSubstructDataByName("reward_data", "reward", header);
  4952. packet2->setSubstructDataByName("reward_data", "coin", coin);
  4953. if (player->GetGuild()) {
  4954. if (!quest) { //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  4955. player->GetInfoStruct()->status_points += status_points;
  4956. player->SetCharSheetChanged(true);
  4957. }
  4958. packet2->setSubstructDataByName("reward_data", "status_points", status_points);
  4959. }
  4960. if(text)
  4961. packet2->setSubstructDataByName("reward_data", "text", text);
  4962. if(rewards){
  4963. packet2->setSubstructArrayLengthByName("reward_data", "num_rewards", rewards->size());
  4964. for (int i = 0; i < rewards->size(); i++) {
  4965. Item* item = rewards->at(i);
  4966. if (item) {
  4967. packet2->setArrayDataByName("reward_id", item->details.item_id, i);
  4968. packet2->setItemArrayDataByName("item", item, player, i, 0, -1);
  4969. }
  4970. if(!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  4971. player->AddPendingItemReward(item); //item reference will be deleted after the player accepts it
  4972. }
  4973. }
  4974. if (selectable_rewards) {
  4975. packet2->setSubstructArrayLengthByName("reward_data", "num_select_rewards", selectable_rewards->size());
  4976. for (int i = 0; i < selectable_rewards->size(); i++) {
  4977. Item* item = selectable_rewards->at(i);
  4978. if (item) {
  4979. packet2->setArrayDataByName("select_reward_id", item->details.item_id, i);
  4980. packet2->setItemArrayDataByName("select_item", item, player, i, 0, -1);
  4981. if (!quest) //this entire function is either for version <=546 or for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  4982. player->AddPendingSelectableItemReward(source_id, item); //item reference will be deleted after the player selects one
  4983. }
  4984. }
  4985. }
  4986. if (factions) {
  4987. map<int32, sint32>::iterator itr;
  4988. map<Faction*, signed int> factions_map;
  4989. for (itr = factions->begin(); itr != factions->end(); itr++) {
  4990. Faction* faction = master_faction_list.GetFaction(itr->first);
  4991. if (faction)
  4992. factions_map[faction] = itr->second;
  4993. }
  4994. packet2->setSubstructArrayLengthByName("reward_data", "num_factions", factions_map.size());
  4995. map<Faction*, signed int>::iterator faction_itr;
  4996. int8 i = 0;
  4997. for (faction_itr = factions_map.begin(); faction_itr != factions_map.end(); faction_itr++) {
  4998. packet2->setArrayDataByName("faction_name", faction_itr->first->name.c_str(), i);
  4999. sint32 amount = faction_itr->second;
  5000. packet2->setArrayDataByName("amount", amount, i);
  5001. if (!quest) { //this entire function is for quest rewards in middle of quest, so quest should be 0, otherwise quest will handle the rewards
  5002. if (amount > 0)
  5003. player->GetFactions()->IncreaseFaction(faction_itr->first->id, amount);
  5004. else
  5005. player->GetFactions()->DecreaseFaction(faction_itr->first->id, (amount * -1));
  5006. }
  5007. i++;
  5008. }
  5009. }
  5010. QueuePacket(packet2->serialize());
  5011. safe_delete(packet2);
  5012. }
  5013. }
  5014. void Client::DisplayQuestComplete(Quest* quest) {
  5015. if (!quest)
  5016. return;
  5017. if (GetVersion() <= 546) {
  5018. DisplayQuestRewards(quest, 0, quest->GetRewardItems(), quest->GetSelectableRewardItems(), quest->GetRewardFactions(), "Quest Complete!", quest->GetStatusPoints());
  5019. return;
  5020. }
  5021. PacketStruct* packet = configReader.getStruct("WS_QuestComplete", GetVersion());
  5022. if (packet) {
  5023. packet->setDataByName("title", "Quest Reward!");
  5024. packet->setDataByName("name", quest->GetName());
  5025. packet->setDataByName("description", quest->GetDescription());
  5026. packet->setDataByName("level", quest->GetLevel());
  5027. packet->setDataByName("encounter_level", quest->GetEncounterLevel());
  5028. int8 difficulty = 0;
  5029. if ((string)quest->GetType() == "Tradeskill")
  5030. difficulty = player->GetTSArrowColor(quest->GetLevel());
  5031. else
  5032. difficulty = player->GetArrowColor(quest->GetLevel());
  5033. packet->setDataByName("difficulty", difficulty);
  5034. int64 rewarded_coin = 0;
  5035. if (quest->GetCoinsReward() > 0) {
  5036. if (quest->GetCoinsRewardMax() > 0)
  5037. rewarded_coin = MakeRandomInt(quest->GetCoinsReward(), quest->GetCoinsRewardMax());
  5038. else
  5039. rewarded_coin = quest->GetCoinsReward();
  5040. }
  5041. quest->SetGeneratedCoin(rewarded_coin);
  5042. packet->setDataByName("max_coin", rewarded_coin);
  5043. packet->setDataByName("min_coin", rewarded_coin);
  5044. packet->setDataByName("status_points", quest->GetStatusPoints());
  5045. vector<Item*>* items2 = quest->GetSelectableRewardItems();
  5046. vector<Item*>* items = quest->GetRewardItems();
  5047. if (items) {
  5048. packet->setArrayLengthByName("num_rewards", items->size());
  5049. for (int32 i = 0; i < items->size(); i++) {
  5050. packet->setArrayDataByName("reward_id", items->at(i)->details.item_id, i);
  5051. if (version < 860)
  5052. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, -1);
  5053. else if (version < 1193)
  5054. packet->setItemArrayDataByName("item", items->at(i), player, i);
  5055. else
  5056. packet->setItemArrayDataByName("item", items->at(i), player, i, 0, 2);
  5057. }
  5058. }
  5059. if (items2 && items2->size() > 0) {
  5060. packet->setArrayLengthByName("num_select_rewards", items2->size());
  5061. for (int32 i = 0; i < items2->size(); i++) {
  5062. packet->setArrayDataByName("select_reward_id", items2->at(i)->details.item_id, i);
  5063. if (version < 860)
  5064. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, -1);
  5065. else if (version < 1193)
  5066. packet->setItemArrayDataByName("select_item", items2->at(i), player, i);
  5067. else
  5068. packet->setItemArrayDataByName("select_item", items2->at(i), player, i, 0, 2);
  5069. }
  5070. }
  5071. map<int32, sint32>* reward_factions = quest->GetRewardFactions();
  5072. if (reward_factions && reward_factions->size() > 0) {
  5073. packet->setArrayLengthByName("num_factions", reward_factions->size());
  5074. map<int32, sint32>::iterator itr;
  5075. int16 index = 0;
  5076. for (itr = reward_factions->begin(); itr != reward_factions->end(); itr++) {
  5077. int32 faction_id = itr->first;
  5078. sint32 amount = itr->second;
  5079. const char* faction_name = master_faction_list.GetFactionNameByID(faction_id);
  5080. if (faction_name) {
  5081. packet->setArrayDataByName("faction_name", const_cast<char*>(faction_name), index);
  5082. packet->setArrayDataByName("amount", amount, index);
  5083. }
  5084. index++;
  5085. }
  5086. }
  5087. EQ2Packet* outapp = packet->serialize();
  5088. // DumpPacket(outapp);
  5089. QueuePacket(outapp);
  5090. safe_delete(packet);
  5091. }
  5092. }
  5093. void Client::DisplayRandomizeFeatures(int32 flags) {
  5094. SimpleMessage(CHANNEL_NARRATIVE, "Showing Active Randomize Features:");
  5095. if (flags > 0) {
  5096. if (flags & RANDOMIZE_GENDER)
  5097. SimpleMessage(CHANNEL_NARRATIVE, "- Gender");
  5098. if (flags & RANDOMIZE_RACE)
  5099. SimpleMessage(CHANNEL_NARRATIVE, "- Race");
  5100. if (flags & RANDOMIZE_MODEL_TYPE)
  5101. SimpleMessage(CHANNEL_NARRATIVE, "- Model");
  5102. if (flags & RANDOMIZE_FACIAL_HAIR_TYPE)
  5103. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair");
  5104. if (flags & RANDOMIZE_HAIR_TYPE)
  5105. SimpleMessage(CHANNEL_NARRATIVE, "- Hair");
  5106. if (flags & RANDOMIZE_WING_TYPE)
  5107. SimpleMessage(CHANNEL_NARRATIVE, "- Wing");
  5108. if (flags & RANDOMIZE_CHEEK_TYPE)
  5109. SimpleMessage(CHANNEL_NARRATIVE, "- Cheek");
  5110. if (flags & RANDOMIZE_CHIN_TYPE)
  5111. SimpleMessage(CHANNEL_NARRATIVE, "- Chin");
  5112. if (flags & RANDOMIZE_EAR_TYPE)
  5113. SimpleMessage(CHANNEL_NARRATIVE, "- Ear");
  5114. if (flags & RANDOMIZE_EYE_BROW_TYPE)
  5115. SimpleMessage(CHANNEL_NARRATIVE, "- Eyebrow");
  5116. if (flags & RANDOMIZE_EYE_TYPE)
  5117. SimpleMessage(CHANNEL_NARRATIVE, "- Eye");
  5118. if (flags & RANDOMIZE_LIP_TYPE)
  5119. SimpleMessage(CHANNEL_NARRATIVE, "- Lip");
  5120. if (flags & RANDOMIZE_NOSE_TYPE)
  5121. SimpleMessage(CHANNEL_NARRATIVE, "- Nose");
  5122. if (flags & RANDOMIZE_EYE_COLOR)
  5123. SimpleMessage(CHANNEL_NARRATIVE, "- Eye Color");
  5124. if (flags & RANDOMIZE_HAIR_COLOR1)
  5125. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color1");
  5126. if (flags & RANDOMIZE_HAIR_COLOR2)
  5127. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color2");
  5128. if (flags & RANDOMIZE_HAIR_HIGHLIGHT)
  5129. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Color Highlights");
  5130. if (flags & RANDOMIZE_HAIR_FACE_COLOR)
  5131. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color");
  5132. if (flags & RANDOMIZE_HAIR_FACE_HIGHLIGHT_COLOR)
  5133. SimpleMessage(CHANNEL_NARRATIVE, "- Facial Hair Color Highlights");
  5134. if (flags & RANDOMIZE_HAIR_TYPE_COLOR)
  5135. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Color");
  5136. if (flags & RANDOMIZE_HAIR_TYPE_HIGHLIGHT_COLOR)
  5137. SimpleMessage(CHANNEL_NARRATIVE, "- Hair Type Highlights");
  5138. if (flags & RANDOMIZE_SKIN_COLOR)
  5139. SimpleMessage(CHANNEL_NARRATIVE, "- Skin Color");
  5140. if (flags & RANDOMIZE_WING_COLOR1)
  5141. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color1");
  5142. if (flags & RANDOMIZE_WING_COLOR2)
  5143. SimpleMessage(CHANNEL_NARRATIVE, "- Wing Color2");
  5144. }
  5145. else
  5146. {
  5147. SimpleMessage(CHANNEL_NARRATIVE, "- No Randomization Set.");
  5148. }
  5149. }
  5150. void Client::GiveQuestReward(Quest* quest) {
  5151. current_quest_id = 0;
  5152. MPendingQuestAccept.lock();
  5153. pending_quest_accept.push_back(quest);
  5154. MPendingQuestAccept.unlock();
  5155. quest->IncrementCompleteCount();
  5156. player->AddCompletedQuest(quest);
  5157. LogWrite(CCLIENT__DEBUG, 0, "Client", "Send Quest Journal...");
  5158. SendQuestJournal();
  5159. player->RemoveQuest(quest->GetQuestID(), false);
  5160. DisplayQuestComplete(quest);
  5161. if (quest->GetExpReward() > 0) {
  5162. int16 level = player->GetLevel();
  5163. int32 xp = quest->GetExpReward();
  5164. if (player->AddXP(xp)) {
  5165. Message(CHANNEL_REWARD, "You gain %u experience!", (int32)xp);
  5166. if (player->GetLevel() != level)
  5167. ChangeLevel(level, player->GetLevel());
  5168. player->SetCharSheetChanged(true);
  5169. }
  5170. }
  5171. if (quest->GetTSExpReward() > 0) {
  5172. int8 ts_level = player->GetTSLevel();
  5173. int32 xp = quest->GetTSExpReward();
  5174. if (player->AddTSXP(xp)) {
  5175. Message(CHANNEL_REWARD, "You gain %u tradeskill experience!", (int32)xp);
  5176. if (player->GetTSLevel() != ts_level)
  5177. ChangeTSLevel(ts_level, player->GetTSLevel());
  5178. player->SetCharSheetChanged(true);
  5179. }
  5180. }
  5181. int64 total_coins = quest->GetGeneratedCoin();
  5182. if (total_coins > 0) {
  5183. player->AddCoins(total_coins);
  5184. PlaySound("coin_cha_ching");
  5185. char tmp[64] = { 0 };
  5186. string message = "You receive ";
  5187. int32 val = 0;
  5188. if (total_coins >= 1000000) {
  5189. val = total_coins / 1000000;
  5190. total_coins -= 1000000 * val;
  5191. sprintf(tmp, "%u Platinum ", val);
  5192. message.append(tmp);
  5193. memset(tmp, 0, 64);
  5194. }
  5195. if (total_coins >= 10000) {
  5196. val = total_coins / 10000;
  5197. total_coins -= 10000 * val;
  5198. sprintf(tmp, "%u Gold ", val);
  5199. message.append(tmp);
  5200. memset(tmp, 0, 64);
  5201. }
  5202. if (total_coins >= 100) {
  5203. val = total_coins / 100;
  5204. total_coins -= 100 * val;
  5205. sprintf(tmp, "%u Silver ", val);
  5206. message.append(tmp);
  5207. memset(tmp, 0, 64);
  5208. }
  5209. if (total_coins > 0) {
  5210. sprintf(tmp, "%u Copper ", (int32)total_coins);
  5211. message.append(tmp);
  5212. }
  5213. message.append("for completing ").append(quest->GetName());
  5214. int8 type = CHANNEL_LOOT;
  5215. SimpleMessage(type, message.c_str());
  5216. }
  5217. if (quest->GetQuestGiver() > 0)
  5218. GetCurrentZone()->SendSpawnChangesByDBID(quest->GetQuestGiver(), this, false, true);
  5219. RemovePlayerQuest(quest->GetQuestID(), true, false);
  5220. }
  5221. void Client::DisplayConversation(int32 conversation_id, int32 spawn_id, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5222. PacketStruct* packet = configReader.getStruct("WS_DialogOpen", GetVersion());
  5223. if (packet) {
  5224. packet->setDataByName("conversation_id", conversation_id);
  5225. packet->setDataByName("text", text);
  5226. packet->setDataByName("unknown2", 1);
  5227. conversation_map[conversation_id].clear();
  5228. if (conversations) {
  5229. packet->setArrayLengthByName("num_responses", conversations->size());
  5230. for (int32 i = 0; i < conversations->size(); i++) {
  5231. packet->setArrayDataByName("response", conversations->at(i).option.c_str(), i);
  5232. if (conversations->at(i).function.length() > 0)
  5233. conversation_map[conversation_id][i] = conversations->at(i).function;
  5234. }
  5235. }
  5236. packet->setDataByName("spawn_id", spawn_id);
  5237. if (mp3) {
  5238. packet->setDataByName("voice", mp3);
  5239. packet->setDataByName("key1", key1);
  5240. packet->setDataByName("key2", key2);
  5241. }
  5242. QueuePacket(packet->serialize());
  5243. safe_delete(packet);
  5244. }
  5245. }
  5246. void Client::DisplayConversation(Item* item, vector<ConversationOption>* conversations, const char* text, int8 type, const char* mp3, int32 key1, int32 key2) {
  5247. if (!item || !text || !conversations || conversations->size() == 0) {
  5248. return;
  5249. }
  5250. int32 conversation_id = GetConversationID(0, item);
  5251. if (conversation_id == 0) {
  5252. next_conversation_id++;
  5253. conversation_id = next_conversation_id;
  5254. }
  5255. conversation_items[conversation_id] = item;
  5256. if (type == 4)
  5257. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5258. else
  5259. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5260. }
  5261. void Client::DisplayConversation(Entity* npc, int8 type, vector<ConversationOption>* conversations, const char* text, const char* mp3, int32 key1, int32 key2) {
  5262. if (!npc || !(type == 1 || type == 2 || type == 3) || !text /*|| !conversations || conversations->size() == 0*/) {
  5263. return;
  5264. }
  5265. int32 conversation_id = GetConversationID(npc, 0);
  5266. if (conversation_id == 0) {
  5267. next_conversation_id++;
  5268. conversation_id = next_conversation_id;
  5269. }
  5270. conversation_spawns[conversation_id] = npc;
  5271. /* NPCs can start two different types of conversations.
  5272. * Type 1: The chat type with bubbles.
  5273. * Type 2: The dialog type with the blue box. */
  5274. if (type == 1)
  5275. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(npc), conversations, text, mp3, key1, key2);
  5276. else if (type == 2)
  5277. DisplayConversation(conversation_id, 0xFFFFFFFF, conversations, text, mp3, key1, key2);
  5278. else //if (type == 3)
  5279. DisplayConversation(conversation_id, player->GetIDWithPlayerSpawn(player), conversations, text, mp3, key1, key2);
  5280. }
  5281. void Client::CloseDialog(int32 conversation_id) {
  5282. PacketStruct* packet = configReader.getStruct("WS_ServerDialogClose", GetVersion());
  5283. if (packet) {
  5284. packet->setDataByName("conversation_id", conversation_id);
  5285. QueuePacket(packet->serialize());
  5286. safe_delete(packet);
  5287. }
  5288. conversation_items.erase(conversation_id);
  5289. conversation_spawns.erase(conversation_id);
  5290. }
  5291. int32 Client::GetConversationID(Spawn* spawn, Item* item) {
  5292. int32 conversation_id = 0;
  5293. if (spawn) {
  5294. map<int32, Spawn*>::iterator itr;
  5295. for (itr = conversation_spawns.begin(); itr != conversation_spawns.end(); itr++) {
  5296. if (itr->second == spawn) {
  5297. conversation_id = itr->first;
  5298. break;
  5299. }
  5300. }
  5301. }
  5302. else if (item) {
  5303. map<int32, Item*>::iterator itr;
  5304. for (itr = conversation_items.begin(); itr != conversation_items.end(); itr++) {
  5305. if (itr->second == item) {
  5306. conversation_id = itr->first;
  5307. break;
  5308. }
  5309. }
  5310. }
  5311. return conversation_id;
  5312. }
  5313. Spawn* Client::GetCombineSpawn() {
  5314. return combine_spawn;
  5315. }
  5316. bool Client::ShouldTarget() {
  5317. return should_target;
  5318. }
  5319. void Client::TargetSpawn(Spawn* spawn) {
  5320. should_target = false;
  5321. PacketStruct* packet = configReader.getStruct("WS_ServerUpdateTarget", GetVersion());
  5322. if (packet) {
  5323. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  5324. QueuePacket(packet->serialize());
  5325. safe_delete(packet);
  5326. }
  5327. }
  5328. void Client::CombineSpawns(float radius, Spawn* spawn) {
  5329. combine_spawn = spawn;
  5330. spawn->RemoveSpawnFromGroup(true);
  5331. if (!GetCurrentZone()->AddCloseSpawnsToSpawnGroup(combine_spawn, radius))
  5332. SimpleMessage(CHANNEL_COLOR_YELLOW, "One or more spawns are in a spawn group and cannot be combined until they are removed from their group.");
  5333. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5334. should_target = true;
  5335. }
  5336. void Client::AddCombineSpawn(Spawn* spawn) {
  5337. if (combine_spawn && combine_spawn != spawn && spawn) {
  5338. combine_spawn->AddSpawnToGroup(spawn);
  5339. spawn->AddSpawnToGroup(combine_spawn);
  5340. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5341. }
  5342. else if (spawn)
  5343. combine_spawn = spawn;
  5344. should_target = true;
  5345. }
  5346. void Client::RemoveCombineSpawn(Spawn* spawn) {
  5347. if (combine_spawn && spawn)
  5348. spawn->RemoveSpawnFromGroup();
  5349. if (combine_spawn == spawn)
  5350. combine_spawn->RemoveSpawnFromGroup(true);
  5351. GetCurrentZone()->RepopSpawns(this, combine_spawn);
  5352. if (combine_spawn == spawn)
  5353. combine_spawn = 0;
  5354. }
  5355. void Client::SaveCombineSpawns(const char* name) {
  5356. if (!combine_spawn) {
  5357. return;
  5358. }
  5359. vector<Spawn*>* spawns = combine_spawn->GetSpawnGroup();
  5360. if (!spawns) {
  5361. return;
  5362. }
  5363. int32 count = spawns->size();
  5364. int32 spawnLocationID = 0;
  5365. if (count == 1)
  5366. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error: You only have a single Spawn in the group!");
  5367. else if ((spawnLocationID = database.SaveCombinedSpawnLocation(GetCurrentZone(), combine_spawn, name)) > 0) {
  5368. Message(CHANNEL_COLOR_YELLOW, "Successfully combined %u spawns into spawn location: %u", count, spawnLocationID);
  5369. // we remove the spawn inside SaveCombinedSpawnLocation
  5370. //GetCurrentZone()->RemoveSpawn(false, combine_spawn);
  5371. }
  5372. else
  5373. SimpleMessage(CHANNEL_COLOR_YELLOW, "Error saving spawn group, check console for details.");
  5374. safe_delete(spawns);
  5375. combine_spawn = 0;
  5376. }
  5377. bool Client::AddItem(int32 item_id, int16 quantity) {
  5378. Item* master_item = master_item_list.GetItem(item_id);
  5379. Item* item = 0;
  5380. if (master_item)
  5381. item = new Item(master_item);
  5382. if (item) {
  5383. if (quantity > 0)
  5384. item->details.count = quantity;
  5385. return AddItem(item);
  5386. }
  5387. else
  5388. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5389. return false;
  5390. }
  5391. bool Client::AddItem(Item* item) {
  5392. if (!item) {
  5393. return false;
  5394. }
  5395. if (item->IsBag()) {
  5396. if (GetVersion() <= 283 && item->details.num_slots > CLASSIC_EQ_MAX_BAG_SLOTS)
  5397. item->details.num_slots = CLASSIC_EQ_MAX_BAG_SLOTS;
  5398. }
  5399. if (player->AddItem(item)) {
  5400. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5401. if (outapp) {
  5402. //DumpPacket(outapp);
  5403. QueuePacket(outapp);
  5404. //resend bag desc with new item name added
  5405. outapp = player->SendBagUpdate(item->details.unique_id, GetVersion());
  5406. if (outapp) {
  5407. //DumpPacket(outapp);
  5408. QueuePacket(outapp);
  5409. }
  5410. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5411. DumpPacket(app);
  5412. client->QueuePacket(app);
  5413. */
  5414. }
  5415. CheckPlayerQuestsItemUpdate(item);
  5416. if (item->GetItemScript() && lua_interface)
  5417. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5418. }
  5419. else {
  5420. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5421. safe_delete(item);
  5422. return false;
  5423. }
  5424. return true;
  5425. }
  5426. bool Client::AddItemToBank(int32 item_id, int16 quantity) {
  5427. Item* master_item = master_item_list.GetItem(item_id);
  5428. Item* item = 0;
  5429. if (master_item)
  5430. item = new Item(master_item);
  5431. if (item) {
  5432. if (quantity > 0)
  5433. item->details.count = quantity;
  5434. return AddItemToBank(item);
  5435. }
  5436. else
  5437. Message(CHANNEL_COLOR_RED, "Could not find item with id of: %i", item_id);
  5438. return false;
  5439. }
  5440. bool Client::AddItemToBank(Item* item) {
  5441. if (!item) {
  5442. return false;
  5443. }
  5444. if (player->AddItemToBank(item)) {
  5445. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5446. if (outapp) {
  5447. QueuePacket(outapp);
  5448. //resend bag desc with new item name added
  5449. outapp = player->SendBagUpdate(item->details.inv_slot_id, GetVersion());
  5450. if (outapp)
  5451. QueuePacket(outapp);
  5452. /*EQ2Packet* app = item->serialize(client->GetVersion(), false);
  5453. DumpPacket(app);
  5454. client->QueuePacket(app);
  5455. */
  5456. }
  5457. CheckPlayerQuestsItemUpdate(item);
  5458. if (item->GetItemScript() && lua_interface)
  5459. lua_interface->RunItemScript(item->GetItemScript(), "obtained", item, player);
  5460. }
  5461. else {
  5462. SimpleMessage(CHANNEL_COLOR_RED, "Could not find free slot to place item.");
  5463. safe_delete(item);
  5464. return false;
  5465. }
  5466. return true;
  5467. }
  5468. bool Client::RemoveItem(Item* item, int16 quantity) {
  5469. EQ2Packet* outapp;
  5470. bool delete_item = false;
  5471. assert(item);
  5472. if (quantity > 0 && !item->IsBag() && item->details.count > quantity) {
  5473. item->details.count -= quantity;
  5474. item->save_needed = true;
  5475. }
  5476. else {
  5477. database.DeleteItem(character_id, item, 0);
  5478. player->GetPlayerItemList()->RemoveItem(item, false);
  5479. delete_item = true;
  5480. }
  5481. if ((outapp = player->SendInventoryUpdate(version))) {
  5482. QueuePacket(outapp);
  5483. if (item->GetItemScript() && lua_interface)
  5484. lua_interface->RunItemScript(item->GetItemScript(), "removed", item, player);
  5485. if (delete_item)
  5486. safe_delete(item);
  5487. return true;
  5488. }
  5489. return false;
  5490. }
  5491. void Client::SetLuaDebugClient(bool val) {
  5492. if (val)
  5493. lua_debug_timer.Start();
  5494. lua_debug = val;
  5495. if (lua_interface && !val) {
  5496. lua_interface->RemoveDebugClients(this);
  5497. lua_debug_timer.Disable();
  5498. }
  5499. }
  5500. void Client::SetMerchantTransaction(Spawn* spawn) {
  5501. merchant_transaction = spawn;
  5502. }
  5503. Spawn* Client::GetMerchantTransaction() {
  5504. return merchant_transaction;
  5505. }
  5506. void Client::SetMailTransaction(Spawn* spawn) {
  5507. mail_transaction = spawn;
  5508. mail_window.coin_copper = 0;
  5509. mail_window.coin_silver = 0;
  5510. mail_window.coin_gold = 0;
  5511. mail_window.coin_plat = 0;
  5512. mail_window.char_item_id = 0;
  5513. }
  5514. Spawn* Client::GetMailTransaction() {
  5515. return mail_transaction;
  5516. }
  5517. void Client::PlaySound(const char* name) {
  5518. if (name) {
  5519. PacketStruct* packet = configReader.getStruct("WS_PlaySound", GetVersion());
  5520. if (packet) {
  5521. packet->setMediumStringByName("name", name);
  5522. QueuePacket(packet->serialize());
  5523. safe_delete(packet);
  5524. }
  5525. }
  5526. }
  5527. float Client::CalculateBuyMultiplier(int32 merchant_id) {
  5528. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5529. if(multiplier){
  5530. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5531. float diff_low = faction_val - multiplier->faction_min;
  5532. if(diff_low < 0)
  5533. diff_low*=-1;
  5534. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5535. if(total_diff < 0)
  5536. total_diff*=-1;
  5537. float buy_multiplier = multiplier->high_buy_multiplier - multiplier->low_buy_multiplier;
  5538. float total1 = (diff_low/total_diff);
  5539. float final_buy_multiplier = total1*buy_multiplier + total1*multiplier->low_buy_multiplier;
  5540. return final_buy_multiplier;
  5541. }*/
  5542. return 1;
  5543. }
  5544. float Client::CalculateSellMultiplier(int32 merchant_id) {
  5545. /*MerchantFactionMultiplier* multiplier = world.GetMerchantMultiplier(merchant_id);
  5546. if(multiplier){
  5547. sint32 faction_val = player->GetFactions()->GetFactionValue(multiplier->faction_id);
  5548. float diff_low = faction_val - multiplier->faction_min;
  5549. if(diff_low < 0)
  5550. diff_low*=-1;
  5551. float total_diff = multiplier->faction_max - multiplier->faction_min;
  5552. if(total_diff < 0)
  5553. total_diff*=-1;
  5554. float sell_multiplier = multiplier->high_sell_multiplier - multiplier->low_sell_multiplier;
  5555. float total1 = (diff_low/total_diff);
  5556. float final_sell_multiplier = total1*sell_multiplier + total1*multiplier->low_sell_multiplier;
  5557. return final_sell_multiplier;
  5558. }*/
  5559. return 1;
  5560. }
  5561. void Client::SellItem(int32 item_id, int16 quantity, int32 unique_id) {
  5562. Spawn* spawn = GetMerchantTransaction();
  5563. Guild* guild = GetPlayer()->GetGuild();
  5564. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5565. int32 total_sell_price = 0;
  5566. int32 total_status_sell_price = 0; //for status
  5567. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5568. int32 sell_price = 0;
  5569. int32 status_sell_price = 0; //for status
  5570. Item* master_item = master_item_list.GetItem(item_id);
  5571. Item* item = 0;
  5572. if (unique_id == 0)
  5573. item = player->item_list.GetItemFromID(item_id, quantity);
  5574. else
  5575. item = player->item_list.GetItemFromUniqueID(unique_id);
  5576. if (!item)
  5577. player->item_list.GetItemFromID(item_id);
  5578. if (item && master_item) {
  5579. int32 sell_price = (int32)(master_item->sell_price * multiplier);
  5580. if (sell_price > item->sell_price)
  5581. sell_price = item->sell_price;
  5582. if (quantity > item->details.count)
  5583. quantity = item->details.count;
  5584. total_sell_price = sell_price * quantity;
  5585. //------------------------------For Selling Status Items
  5586. status_sell_price = (int32)(master_item->sell_status * multiplier);
  5587. if (status_sell_price > item->sell_status)
  5588. status_sell_price = item->sell_status;
  5589. if (quantity > item->details.count)
  5590. quantity = item->details.count;
  5591. if (player->GetGuild()) {
  5592. total_status_sell_price = status_sell_price * quantity;
  5593. player->GetInfoStruct()->status_points += total_status_sell_price;
  5594. guild->UpdateGuildStatus(GetPlayer(), total_status_sell_price / 10);
  5595. guild->SendGuildMemberList();
  5596. guild->AddEXPCurrent((total_status_sell_price / 10), true);
  5597. }
  5598. if (quantity > 1)
  5599. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %i %s to %s for %s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5600. else
  5601. Message(CHANNEL_MERCHANT_BUY_SELL, "You sell %s to %s for %s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_sell_price).c_str());
  5602. player->AddCoins(total_sell_price);
  5603. AddBuyBack(unique_id, item_id, quantity, sell_price);
  5604. if (quantity >= item->details.count) {
  5605. database.DeleteItem(GetCharacterID(), item, 0);
  5606. player->item_list.DestroyItem(item->details.index);
  5607. }
  5608. else {
  5609. item->details.count -= quantity;
  5610. item->save_needed = true;
  5611. }
  5612. EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5613. if (outapp)
  5614. QueuePacket(outapp);
  5615. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5616. SendSellMerchantList();
  5617. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5618. SendBuyBackList();
  5619. }
  5620. }
  5621. }
  5622. void Client::BuyBack(int32 item_id, int16 quantity) {
  5623. Spawn* spawn = GetMerchantTransaction();
  5624. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5625. deque<BuyBackItem*>::iterator itr;
  5626. BuyBackItem* buyback = 0;
  5627. BuyBackItem* closest = 0;
  5628. MBuyBack.readlock(__FUNCTION__, __LINE__);
  5629. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5630. buyback = *itr;
  5631. if (buyback->unique_id == item_id) {
  5632. closest = buyback;
  5633. quantity = buyback->quantity;
  5634. break;
  5635. }
  5636. }
  5637. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  5638. if (closest) {
  5639. Item* item = 0;
  5640. Item* master_item = master_item_list.GetItem(closest->item_id);
  5641. if (master_item) {
  5642. item = new Item(master_item);
  5643. if (closest->quantity >= quantity)
  5644. item->details.count = quantity;
  5645. else
  5646. item->details.count = closest->quantity;
  5647. }
  5648. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item))
  5649. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5650. else if (player->RemoveCoins(closest->quantity * closest->price)) {
  5651. bool removed = false;
  5652. if (closest->quantity == quantity) {
  5653. MBuyBack.writelock(__FUNCTION__, __LINE__);
  5654. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++) {
  5655. if (*itr == closest) {
  5656. buy_back_items.erase(itr);
  5657. removed = true;
  5658. break;
  5659. }
  5660. }
  5661. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  5662. }
  5663. else {
  5664. closest->quantity -= quantity;
  5665. closest->save_needed = true;
  5666. }
  5667. AddItem(item);
  5668. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5669. //if(outapp)
  5670. //QueuePacket(outapp);
  5671. if (removed) {
  5672. database.DeleteBuyBack(GetCharacterID(), closest->item_id, closest->quantity, closest->price);
  5673. safe_delete(closest);
  5674. }
  5675. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY))
  5676. SendSellMerchantList();
  5677. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY_BACK))
  5678. SendBuyBackList();
  5679. }
  5680. else
  5681. SimpleMessage(CHANNEL_COLOR_RED, "You cannot afford this item.");
  5682. }
  5683. }
  5684. }
  5685. void Client::BuyItem(int32 item_id, int16 quantity) {
  5686. // Get the merchant we are buying from
  5687. Spawn* spawn = GetMerchantTransaction();
  5688. // Make sure the spawn has a merchant list
  5689. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  5690. int32 total_buy_price = 0;
  5691. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  5692. int32 sell_price = 0;
  5693. Item* master_item = master_item_list.GetItem(item_id);
  5694. Item* item = 0;
  5695. int16 total_available = 0;
  5696. vector<MerchantItemInfo>* temp;
  5697. vector<MerchantItemInfo>::iterator itr;
  5698. MerchantItemInfo* ItemInfo = 0;
  5699. temp = world.GetMerchantList(spawn->GetMerchantID());
  5700. for (itr = temp->begin(); itr != temp->end(); itr++) {
  5701. if ((*itr).item_id == item_id) {
  5702. ItemInfo = &(*itr);
  5703. break;
  5704. }
  5705. }
  5706. if (master_item && ItemInfo) {
  5707. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO) {
  5708. quantity = 1;
  5709. total_available = 0xFFFF;
  5710. sell_price = master_item->sell_price;
  5711. }
  5712. else {
  5713. total_available = world.GetMerchantItemQuantity(spawn->GetMerchantID(), item_id);
  5714. sell_price = (int32)(master_item->sell_price * multiplier);
  5715. if (quantity > total_available)
  5716. quantity = total_available;
  5717. }
  5718. total_buy_price = sell_price * quantity;
  5719. item = new Item(master_item);
  5720. item->details.count = quantity;
  5721. if (!player->item_list.HasFreeSlot() && !player->item_list.CanStack(item)) {
  5722. SimpleMessage(CHANNEL_COLOR_RED, "You do not have any slots available for this item.");
  5723. safe_delete(item);
  5724. }
  5725. else {
  5726. // Price not set in the merchant_inventory table, use the old method
  5727. if (ItemInfo->price_item_id == 0 && ItemInfo->price_item2_id == 0 && ItemInfo->price_status == 0 && ItemInfo->price_stationcash == 0 && ItemInfo->price_coins == 0) {
  5728. if (player->RemoveCoins(total_buy_price)) {
  5729. item->SetMaxSellValue(sell_price);
  5730. if (quantity > 1)
  5731. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5732. else
  5733. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(total_buy_price).c_str());
  5734. AddItem(item);
  5735. CheckPlayerQuestsItemUpdate(item);
  5736. if (item && total_available < 0xFFFF) {
  5737. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5738. SendBuyMerchantList();
  5739. }
  5740. //EQ2Packet* outapp = player->SendInventoryUpdate(GetVersion());
  5741. //if(outapp)
  5742. // QueuePacket(outapp);
  5743. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5744. SendSellMerchantList();
  5745. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5746. PlayLotto(total_buy_price, item->details.item_id);
  5747. }
  5748. else {
  5749. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5750. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5751. PlaySound("buy_failed");
  5752. }
  5753. }
  5754. else {
  5755. // Price set in merchant_inventory table
  5756. // Check if the player has enough status, coins and staion cash to buy the item before checking the items
  5757. // TODO: need to add support for station cash
  5758. if (player->GetInfoStruct()->status_points >= ItemInfo->price_status && player->HasCoins(ItemInfo->price_coins * quantity)) {
  5759. // Check items
  5760. int16 item_quantity = 0;
  5761. // Default these to true in case price_item_id or price_item2_id was never set
  5762. bool hasItem1 = true;
  5763. bool hasItem2 = true;
  5764. Item* tempItem1 = 0;
  5765. Item* tempItem2 = 0;
  5766. if (ItemInfo->price_item_id != 0) {
  5767. // Same item for whatever reason lets add the quantities together
  5768. if (ItemInfo->price_item_id == ItemInfo->price_item2_id)
  5769. item_quantity = ItemInfo->price_item_qty + ItemInfo->price_item2_qty;
  5770. else
  5771. item_quantity = ItemInfo->price_item_qty;
  5772. tempItem1 = player->item_list.GetItemFromID(ItemInfo->price_item_id);
  5773. if (tempItem1) {
  5774. if (tempItem1->details.count < item_quantity)
  5775. hasItem1 = false;
  5776. }
  5777. else {
  5778. hasItem1 = false;
  5779. }
  5780. }
  5781. // Check item2, if item_quantity is greater then item1 quantity then item2 is the same item
  5782. // as item1 and we already checked for it so we can skip this check
  5783. if (ItemInfo->price_item2_id != 0 && item_quantity <= ItemInfo->price_item_qty) {
  5784. tempItem2 = player->item_list.GetItemFromID(ItemInfo->price_item2_id);
  5785. if (tempItem2) {
  5786. if (tempItem2->details.count < ItemInfo->price_item2_qty)
  5787. hasItem2 = false;
  5788. }
  5789. else {
  5790. hasItem2 = false;
  5791. }
  5792. }
  5793. // if we have every thing then remove the price and give the item
  5794. if (hasItem1 && hasItem2) {
  5795. player->GetInfoStruct()->status_points -= ItemInfo->price_status;
  5796. // TODO: station cash
  5797. // The update that would normally be sent after modifing the players inventory is automatically sent in AddItem wich is called later
  5798. // so there is no need to send it more then that one time
  5799. if (tempItem1) {
  5800. if (tempItem1->details.count > item_quantity) {
  5801. tempItem1->details.count -= item_quantity;
  5802. tempItem1->save_needed = true;
  5803. }
  5804. else {
  5805. database.DeleteItem(GetCharacterID(), tempItem1, 0);
  5806. player->item_list.DestroyItem(tempItem1->details.index);
  5807. }
  5808. }
  5809. if (tempItem2) {
  5810. if (tempItem2->details.count > ItemInfo->price_item2_qty) {
  5811. tempItem2->details.count -= ItemInfo->price_item2_qty;
  5812. tempItem2->save_needed = true;
  5813. }
  5814. else {
  5815. database.DeleteItem(GetCharacterID(), tempItem2, 0);
  5816. player->item_list.DestroyItem(tempItem2->details.index);
  5817. }
  5818. }
  5819. // Checked to see if we had enough coins already so don't need to check the return type on RemoveCoins as it will always be true
  5820. player->RemoveCoins(ItemInfo->price_coins * quantity);
  5821. item->SetMaxSellValue(sell_price);
  5822. if (quantity > 1)
  5823. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %i %s from %s for%s.", quantity, master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5824. else
  5825. Message(CHANNEL_MERCHANT_BUY_SELL, "You buy %s from %s for%s.", master_item->CreateItemLink(GetVersion()).c_str(), spawn->GetName(), GetCoinMessage(ItemInfo->price_coins * quantity).c_str());
  5826. AddItem(item);
  5827. CheckPlayerQuestsItemUpdate(item);
  5828. if (item && total_available < 0xFFFF) {
  5829. world.DecreaseMerchantQuantity(spawn->GetMerchantID(), item_id, quantity);
  5830. SendBuyMerchantList();
  5831. }
  5832. if (!(spawn->GetMerchantType() & MERCHANT_TYPE_NO_BUY) && !(spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO))
  5833. SendSellMerchantList();
  5834. if (spawn->GetMerchantType() & MERCHANT_TYPE_LOTTO)
  5835. PlayLotto(total_buy_price, item->details.item_id);
  5836. }
  5837. else {
  5838. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5839. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5840. PlaySound("buy_failed");
  5841. }
  5842. }
  5843. else {
  5844. Message(CHANNEL_COLOR_RED, "You do not have enough coin to purchase %s.", master_item->CreateItemLink(GetVersion()).c_str());
  5845. GetCurrentZone()->SendSpellFailedPacket(this, SPELL_ERROR_NOT_ENOUGH_COIN);
  5846. PlaySound("buy_failed");
  5847. }
  5848. }
  5849. }
  5850. }
  5851. }
  5852. }
  5853. void Client::RepairItem(int32 item_id) {
  5854. Spawn* spawn = GetMerchantTransaction();
  5855. if (spawn) {
  5856. Item* item = player->item_list.GetItemFromID(item_id);
  5857. if (!item)
  5858. item = player->GetEquipmentList()->GetItemFromItemID(item_id);
  5859. if (item) {
  5860. int32 repair_cost = item->CalculateRepairCost();
  5861. if (player->RemoveCoins((int32)repair_cost)) {
  5862. item->generic_info.condition = 100;
  5863. item->save_needed = true;
  5864. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5865. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5866. QueuePacket(item->serialize(version, false, player));
  5867. Message(CHANNEL_MERCHANT, "You give %s %s to repair your %s.", spawn->GetName(), GetCoinMessage(repair_cost).c_str(), item->CreateItemLink(GetVersion()).c_str());
  5868. PlaySound("coin_cha_ching");
  5869. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5870. SendRepairList();
  5871. }
  5872. else {
  5873. LogWrite(MISC__TODO, 1, "TODO", " Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5874. Message(CHANNEL_MERCHANT, "You do not have enough coin to repair %s.", item->CreateItemLink(GetVersion()).c_str());
  5875. PlaySound("buy_failed");
  5876. }
  5877. }
  5878. }
  5879. }
  5880. void Client::RepairAllItems() {
  5881. Spawn* spawn = GetMerchantTransaction();
  5882. if (spawn) {
  5883. vector<Item*>* repairable_items = GetRepairableItems();
  5884. if (repairable_items && repairable_items->size() > 0) {
  5885. vector<Item*>::iterator itr;
  5886. int64 total_cost = 0;
  5887. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++)
  5888. total_cost += (*itr)->CalculateRepairCost();
  5889. if (player->RemoveCoins((int32)total_cost)) {
  5890. Message(CHANNEL_MERCHANT, "You give %s to repair all of your items.", GetCoinMessage((int32)total_cost).c_str());
  5891. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++) {
  5892. Item* item = *itr;
  5893. if (item) {
  5894. item->generic_info.condition = 100;
  5895. item->save_needed = true;
  5896. QueuePacket(item->serialize(version, false, player));
  5897. Message(CHANNEL_COLOR_YELLOW, "Repaired: %s.", item->CreateItemLink(GetVersion()).c_str());
  5898. }
  5899. }
  5900. QueuePacket(player->GetEquipmentList()->serialize(GetVersion()));
  5901. QueuePacket(player->SendInventoryUpdate(GetVersion()));
  5902. PlaySound("coin_cha_ching");
  5903. if (spawn->GetMerchantType() & MERCHANT_TYPE_REPAIR)
  5904. SendRepairList();
  5905. }
  5906. else {
  5907. LogWrite(MISC__TODO, 1, "TODO", "Send pop up that says 'Not enough coin.'\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  5908. SimpleMessage(CHANNEL_MERCHANT, "You do not have enough coin to repair all of your items.");
  5909. PlaySound("buy_failed");
  5910. }
  5911. }
  5912. safe_delete(repairable_items);
  5913. }
  5914. }
  5915. void Client::SendAchievementsList()
  5916. {
  5917. /*map<int32, Achievement *> *achievements = player->GetAchievementList()->GetAchievements();
  5918. map<int32, Achievement *>::iterator itr;
  5919. Achievement *achievement;
  5920. vector<AchievementRequirements *> *requirements = 0;
  5921. vector<AchievementRequirements *>::iterator itr2;
  5922. AchievementRequirements *requirement;
  5923. vector<AchievementRewards *> *rewards = 0;
  5924. vector<AchievementRewards *>::iterator itr3;
  5925. AchievementRewards *reward;
  5926. PacketStruct *packet;
  5927. int16 i = 0;
  5928. int16 j = 0;
  5929. int16 k = 0;
  5930. if (!(packet = configReader.getStruct("WS_CharacterAchievements", version))) {
  5931. return;
  5932. }
  5933. packet->setArrayLengthByName("num_achievements" , achievements->size());
  5934. for (itr = achievements->begin(); itr != achievements->end(); itr++) {
  5935. achievement = itr->second;
  5936. packet->setArrayDataByName("achievement_id", achievement->GetID(), i);
  5937. packet->setArrayDataByName("title", achievement->GetTitle(), i);
  5938. packet->setArrayDataByName("uncompleted_text", achievement->GetUncompletedText(), i);
  5939. packet->setArrayDataByName("completed_text", achievement->GetCompletedText(), i);
  5940. packet->setArrayDataByName("category", achievement->GetCategory(), i);
  5941. packet->setArrayDataByName("expansion", achievement->GetExpansion(), i);
  5942. packet->setArrayDataByName("icon", achievement->GetIcon(), i);
  5943. packet->setArrayDataByName("point_value", achievement->GetPointValue(), i);
  5944. packet->setArrayDataByName("qty_req", achievement->GetQtyReq(), i);
  5945. packet->setArrayDataByName("hide_achievement", achievement->GetHide(), i);
  5946. packet->setArrayDataByName("unknown3", achievement->GetUnknown3a(), i);
  5947. packet->setArrayDataByName("unknown3", achievement->GetUnknown3b(), i);
  5948. requirements = achievement->GetRequirements();
  5949. rewards = achievement->GetRewards();
  5950. j = 0;
  5951. k = 0;
  5952. packet->setSubArrayLengthByName("num_items", requirements->size(), i, j);
  5953. for (itr2 = requirements->begin(); itr2 != requirements->end(); itr2++) {
  5954. requirement = *itr2;
  5955. packet->setSubArrayDataByName("item_name", requirement->name.c_str(), i, j);
  5956. packet->setSubArrayDataByName("item_qty_req", requirement->qty_req, i, j);
  5957. j++;
  5958. }
  5959. packet->setSubArrayLengthByName("num_rewards", achievement->GetRewards()->size(), i, k);
  5960. for (itr3 = rewards->begin(); itr3 != rewards->end(); itr3++) {
  5961. reward = *itr3;
  5962. packet->setSubArrayDataByName("reward_item", reward->reward.c_str(), i, k);
  5963. k++;
  5964. }
  5965. i++;
  5966. }
  5967. //packet->PrintPacket();
  5968. EQ2Packet* data = packet->serialize();
  5969. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  5970. safe_delete(packet);
  5971. safe_delete(data);
  5972. //DumpPacket(app);
  5973. QueuePacket(app);*/
  5974. QueuePacket(master_achievement_list.GetAchievementPacket()->Copy());
  5975. SendAchievementUpdate(true);
  5976. }
  5977. void Client::SendAchievementUpdate(bool first_login) {
  5978. map<int32, AchievementUpdate*>* updates = player->GetAchievementUpdateList()->GetAchievementUpdates();
  5979. map<int32, AchievementUpdate*>::iterator itr;
  5980. AchievementUpdate* update;
  5981. vector<AchievementUpdateItems*>* update_items = 0;
  5982. vector<AchievementUpdateItems*>::iterator itr2;
  5983. AchievementUpdateItems* update_item;
  5984. int16 i = 0;
  5985. int16 j = 0;
  5986. PacketStruct* packet;
  5987. if (!(packet = configReader.getStruct("WS_AchievementUpdate", version))) {
  5988. return;
  5989. }
  5990. packet->setDataByName("unknown1", first_login ? 1 : 0);
  5991. packet->setArrayLengthByName("num_achievements", updates->size());
  5992. for (itr = updates->begin(); itr != updates->end(); itr++) {
  5993. update = itr->second;
  5994. packet->setArrayDataByName("achievement_id", update->GetID(), i);
  5995. packet->setArrayDataByName("completed_date", update->GetCompletedDate(), i);
  5996. update_items = update->GetUpdateItems();
  5997. j = 0;
  5998. packet->setSubArrayLengthByName("num_items", update_items->size(), i);
  5999. for (itr2 = update_items->begin(); itr2 != update_items->end(); itr2++) {
  6000. update_item = *itr2;
  6001. packet->setSubArrayDataByName("item_update", update_item->item_update, i, j);
  6002. j++;
  6003. }
  6004. i++;
  6005. }
  6006. //packet->PrintPacket();
  6007. EQ2Packet* data = packet->serialize();
  6008. EQ2Packet* app = new EQ2Packet(OP_ClientCmdMsg, data->pBuffer, data->size);
  6009. safe_delete(packet);
  6010. safe_delete(data);
  6011. //DumpPacket(app);
  6012. QueuePacket(app);
  6013. }
  6014. void Client::SendBuyMerchantList(bool sell) {
  6015. Spawn* spawn = GetMerchantTransaction();
  6016. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6017. vector<MerchantItemInfo>* items = world.GetMerchantItemList(spawn->GetMerchantID(), spawn->GetMerchantType(), player);
  6018. if (items) {
  6019. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6020. if (packet) {
  6021. float multiplier = CalculateBuyMultiplier(spawn->GetMerchantID());
  6022. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6023. packet->setArrayLengthByName("num_items", items->size());
  6024. vector<MerchantItemInfo>::iterator itr;
  6025. sint8 item_difficulty = 0;
  6026. int32 sell_price = 0;
  6027. int i = 0;
  6028. int tmp_level = 0;
  6029. for (itr = items->begin(); itr != items->end(); itr++, i++) {
  6030. MerchantItemInfo ItemInfo = *itr;
  6031. Item* item = master_item_list.GetItem(ItemInfo.item_id);
  6032. if (!item)
  6033. continue;
  6034. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6035. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6036. packet->setArrayDataByName("stack_size", item->stack_count, i);
  6037. packet->setArrayDataByName("icon", item->details.icon, i);
  6038. if (item->generic_info.adventure_default_level > 0)
  6039. tmp_level = item->generic_info.adventure_default_level;
  6040. else
  6041. tmp_level = item->generic_info.tradeskill_default_level;
  6042. packet->setArrayDataByName("level", tmp_level, i);
  6043. packet->setArrayDataByName("tier", item->details.tier, i);
  6044. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6045. item_difficulty = player->GetArrowColor(tmp_level);
  6046. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6047. item_difficulty = ARROW_COLOR_WHITE;
  6048. item_difficulty -= 6;
  6049. if (item_difficulty < 0)
  6050. item_difficulty *= -1;
  6051. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6052. packet->setArrayDataByName("quantity", ItemInfo.quantity, i);
  6053. packet->setArrayDataByName("unknown5", 255, i);
  6054. packet->setArrayDataByName("stack_size2", item->stack_count, i);
  6055. if (GetVersion() <= 1096)
  6056. packet->setArrayDataByName("description", item->description.c_str(), i);
  6057. // If no price set in the merchant_inventory table then use the old method
  6058. if (ItemInfo.price_item_id == 0 && ItemInfo.price_item2_id == 0 && ItemInfo.price_coins == 0 && ItemInfo.price_status == 0 && ItemInfo.price_stationcash == 0) {
  6059. sell_price = (int32)(item->sell_price * multiplier);
  6060. packet->setArrayDataByName("price", sell_price, i);
  6061. }
  6062. else {
  6063. int8 count = 0;
  6064. if (ItemInfo.price_item_id != 0 && ItemInfo.price_item_qty != 0)
  6065. count++;
  6066. if (ItemInfo.price_item2_id != 0 && ItemInfo.price_item2_qty != 0)
  6067. count++;
  6068. if (count != 0) {
  6069. packet->setSubArrayLengthByName("num_tokens", count, i);
  6070. int8 index = 0;
  6071. Item* token = 0;
  6072. if (ItemInfo.price_item_id != 0) {
  6073. token = master_item_list.GetItem(ItemInfo.price_item_id);
  6074. if (item) {
  6075. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6076. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item_qty, i, index);
  6077. packet->setSubArrayDataByName("token_id", ItemInfo.price_item_id, i, index);
  6078. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6079. }
  6080. token = 0;
  6081. index++;
  6082. }
  6083. if (ItemInfo.price_item2_id != 0) {
  6084. token = master_item_list.GetItem(ItemInfo.price_item2_id);
  6085. if (item) {
  6086. packet->setSubArrayDataByName("token_icon", token->details.icon, i, index);
  6087. packet->setSubArrayDataByName("token_qty", ItemInfo.price_item2_qty, i, index);
  6088. packet->setSubArrayDataByName("token_id", ItemInfo.price_item2_id, i, index);
  6089. packet->setSubArrayDataByName("token_name", token->name.c_str(), i, index);
  6090. }
  6091. }
  6092. }
  6093. packet->setArrayDataByName("price", ItemInfo.price_coins, i);
  6094. packet->setArrayDataByName("status", ItemInfo.price_status, i);
  6095. packet->setArrayDataByName("station_cash", ItemInfo.price_stationcash, i);
  6096. }
  6097. }
  6098. if (GetVersion() <= 546) {
  6099. //buy is 0 so dont need to set it
  6100. if (sell)
  6101. packet->setDataByName("type", 1);
  6102. }
  6103. else {
  6104. if (sell)
  6105. packet->setDataByName("type", 130);
  6106. else
  6107. packet->setDataByName("type", 2);
  6108. }
  6109. EQ2Packet* outapp = packet->serialize();
  6110. // DumpPacket(outapp);
  6111. QueuePacket(outapp);
  6112. safe_delete(packet);
  6113. }
  6114. safe_delete(items);
  6115. }
  6116. else {
  6117. // Need to send an empty packet in the event there is no item list, otherwise the
  6118. // last item list sent to the player will show for this merchant
  6119. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6120. if (packet) {
  6121. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6122. if (GetVersion() <= 546) {
  6123. //buy is 0 so dont need to set it
  6124. if (sell)
  6125. packet->setDataByName("type", 1);
  6126. }
  6127. else {
  6128. if (sell)
  6129. packet->setDataByName("type", 130);
  6130. else
  6131. packet->setDataByName("type", 2);
  6132. }
  6133. EQ2Packet* outapp = packet->serialize();
  6134. QueuePacket(outapp);
  6135. safe_delete(packet);
  6136. }
  6137. }
  6138. }
  6139. }
  6140. void Client::SendSellMerchantList(bool sell) {
  6141. Spawn* spawn = GetMerchantTransaction();
  6142. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6143. map<int32, Item*>* items = player->GetItemList();
  6144. if (items) {
  6145. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6146. if (packet) {
  6147. vector<Item*> sellable_items;
  6148. map<int32, Item*>::iterator test_itr;
  6149. for (test_itr = items->begin(); test_itr != items->end(); test_itr++) {
  6150. if (test_itr->second && !test_itr->second->CheckFlag(NO_VALUE))
  6151. sellable_items.push_back(test_itr->second);
  6152. }
  6153. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6154. packet->setArrayLengthByName("num_items", sellable_items.size());
  6155. vector<Item*>::iterator itr;
  6156. Item* item = 0;
  6157. sint8 item_difficulty = 0;
  6158. float multiplier = CalculateSellMultiplier(spawn->GetMerchantID());
  6159. int32 sell_price = 0;
  6160. Item* master_item = 0;
  6161. int i = 0;
  6162. int tmp_level = 0;
  6163. for (itr = sellable_items.begin(); itr != sellable_items.end(); itr++, i++) {
  6164. item = *itr;
  6165. master_item = master_item_list.GetItem(item->details.item_id);
  6166. if (master_item)
  6167. sell_price = (int32)(master_item->sell_price * multiplier);
  6168. else
  6169. sell_price = 0;
  6170. if (sell_price > item->sell_price)
  6171. sell_price = item->sell_price;
  6172. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6173. string thename = item->name;
  6174. packet->setArrayDataByName("price", sell_price, i);
  6175. if (player->GetGuild()) {
  6176. packet->setArrayDataByName("status", 0, i);//additive to status 2 maybe for server bonus etc
  6177. packet->setArrayDataByName("status2", item->sell_status, i); //this one is the main status
  6178. }
  6179. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6180. packet->setArrayDataByName("unique_item_id", item->details.unique_id, i);
  6181. packet->setArrayDataByName("stack_size", item->details.count, i);
  6182. packet->setArrayDataByName("icon", item->details.icon, i);
  6183. if (item->generic_info.adventure_default_level > 0)
  6184. tmp_level = item->generic_info.adventure_default_level;
  6185. else
  6186. tmp_level = item->generic_info.tradeskill_default_level;
  6187. packet->setArrayDataByName("level", item->details.recommended_level, i);
  6188. packet->setArrayDataByName("tier", item->details.tier, i);
  6189. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6190. item_difficulty = player->GetArrowColor(tmp_level);
  6191. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6192. item_difficulty = ARROW_COLOR_WHITE;
  6193. item_difficulty -= 6;
  6194. if (item_difficulty < 0)
  6195. item_difficulty *= -1;
  6196. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6197. if (item->details.count == 1)
  6198. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6199. else
  6200. packet->setArrayDataByName("quantity", item->details.count, i);
  6201. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6202. if (GetVersion() <= 1096)
  6203. packet->setArrayDataByName("description", item->description.c_str(), i);
  6204. }
  6205. if (GetVersion() <= 546) {
  6206. packet->setDataByName("type", 1);
  6207. }
  6208. else {
  6209. if (sell)
  6210. packet->setDataByName("type", 129);
  6211. else
  6212. packet->setDataByName("type", 1);
  6213. }
  6214. packet->setDataByName("unknown8a", 16256, 6);
  6215. packet->setDataByName("unknown8a", 16256, 10);
  6216. //packet->PrintPacket();
  6217. EQ2Packet* outapp = packet->serialize();
  6218. //DumpPacket(outapp);
  6219. QueuePacket(outapp);
  6220. safe_delete(packet);
  6221. }
  6222. safe_delete(items);
  6223. }
  6224. }
  6225. }
  6226. void Client::SendBuyBackList(bool sell) {
  6227. if (GetVersion() <= 546) //this wasn't added until LU37 on July 31st 2007, well after the DoF client
  6228. return;
  6229. Spawn* spawn = GetMerchantTransaction();
  6230. if (spawn && spawn->GetMerchantID() > 0 && spawn->IsClientInMerchantLevelRange(this)) {
  6231. deque<BuyBackItem*>::iterator itr;
  6232. int i = 0;
  6233. Item* master_item = 0;
  6234. BuyBackItem* buyback = 0;
  6235. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6236. if (packet) {
  6237. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6238. packet->setArrayLengthByName("num_items", buy_back_items.size());
  6239. sint8 item_difficulty = 0;
  6240. MBuyBack.readlock(__FUNCTION__, __LINE__);
  6241. int tmp_level = 0;
  6242. for (itr = buy_back_items.begin(); itr != buy_back_items.end(); itr++, i++) {
  6243. buyback = *itr;
  6244. master_item = master_item_list.GetItem(buyback->item_id);
  6245. if (master_item) {
  6246. packet->setArrayDataByName("item_name", master_item->name.c_str(), i);
  6247. packet->setArrayDataByName("price", buyback->price, i);
  6248. packet->setArrayDataByName("item_id", master_item->details.item_id, i);
  6249. packet->setArrayDataByName("unique_item_id", buyback->unique_id, i);
  6250. packet->setArrayDataByName("stack_size", buyback->quantity, i);
  6251. packet->setArrayDataByName("icon", master_item->details.icon, i);
  6252. if (master_item->generic_info.adventure_default_level > 0)
  6253. tmp_level = master_item->generic_info.adventure_default_level;
  6254. else
  6255. tmp_level = master_item->generic_info.tradeskill_default_level;
  6256. packet->setArrayDataByName("level", tmp_level, i);
  6257. packet->setArrayDataByName("tier", master_item->details.tier, i);
  6258. packet->setArrayDataByName("item_id2", master_item->details.item_id, i);
  6259. item_difficulty = player->GetArrowColor(tmp_level);
  6260. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6261. item_difficulty = ARROW_COLOR_WHITE;
  6262. item_difficulty -= 6;
  6263. if (item_difficulty < 0)
  6264. item_difficulty *= -1;
  6265. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6266. if (buyback->quantity == 1)
  6267. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6268. else
  6269. packet->setArrayDataByName("quantity", buyback->quantity, i);
  6270. packet->setArrayDataByName("stack_size2", buyback->quantity, i);
  6271. if (GetVersion() <= 1096)
  6272. packet->setArrayDataByName("description", master_item->description.c_str(), i);
  6273. }
  6274. }
  6275. MBuyBack.releasereadlock(__FUNCTION__, __LINE__);
  6276. if (sell)
  6277. packet->setDataByName("type", 640);
  6278. else
  6279. packet->setDataByName("type", 512);
  6280. EQ2Packet* outapp = packet->serialize();
  6281. // DumpPacket(outapp);
  6282. QueuePacket(outapp);
  6283. safe_delete(packet);
  6284. }
  6285. }
  6286. }
  6287. void Client::SendRepairList() {
  6288. Spawn* spawn = GetMerchantTransaction();
  6289. if (spawn) {
  6290. vector<Item*>* repairable_items = GetRepairableItems();
  6291. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6292. if (packet) {
  6293. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6294. packet->setArrayLengthByName("num_items", repairable_items->size());
  6295. Item* item = 0;
  6296. sint8 item_difficulty = 0;
  6297. int32 i = 0;
  6298. vector<Item*>::iterator itr;
  6299. for (itr = repairable_items->begin(); itr != repairable_items->end(); itr++, i++) {
  6300. item = *itr;
  6301. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  6302. packet->setArrayDataByName("price", item->CalculateRepairCost(), i);
  6303. packet->setArrayDataByName("item_id", item->details.item_id, i);
  6304. packet->setArrayDataByName("stack_size", item->details.count, i);
  6305. packet->setArrayDataByName("icon", item->details.icon, i);
  6306. /*if (item->generic_info.adventure_default_level > 0)
  6307. tmp_level = item->generic_info.adventure_default_level;
  6308. else
  6309. tmp_level = item->generic_info.tradeskill_default_level;
  6310. packet->setArrayDataByName("level", tmp_level, i);*/
  6311. packet->setArrayDataByName("level", item->generic_info.adventure_default_level, i);
  6312. packet->setArrayDataByName("tier", item->details.tier, i);
  6313. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  6314. item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6315. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6316. item_difficulty = ARROW_COLOR_WHITE;
  6317. item_difficulty -= 6;
  6318. if (item_difficulty < 0)
  6319. item_difficulty *= -1;
  6320. packet->setArrayDataByName("item_difficulty", item_difficulty, i);
  6321. if (item->details.count == 1)
  6322. packet->setArrayDataByName("quantity", 0xFFFF, i);
  6323. else
  6324. packet->setArrayDataByName("quantity", item->details.count, i);
  6325. packet->setArrayDataByName("stack_size2", item->details.count, i);
  6326. if (GetVersion() <= 1096)
  6327. packet->setArrayDataByName("description", item->description.c_str(), i);
  6328. }
  6329. if (GetVersion() <= 546) {
  6330. packet->setDataByName("type", 16);
  6331. }
  6332. else {
  6333. packet->setDataByName("type", 96);
  6334. }
  6335. EQ2Packet* outapp = packet->serialize();
  6336. QueuePacket(outapp);
  6337. safe_delete(packet);
  6338. }
  6339. safe_delete(repairable_items);
  6340. }
  6341. }
  6342. void Client::ShowLottoWindow() {
  6343. Spawn* spawn = GetMerchantTransaction();
  6344. if (spawn) {
  6345. int32 item_id = rule_manager.GetGlobalRule(R_World, GamblingTokenItemID)->GetInt32();
  6346. if (!item_id)
  6347. {
  6348. LogWrite(WORLD__ERROR, 0, "World", "No GamblingTokenItemID rule set!");
  6349. SimpleMessage(CHANNEL_COLOR_RED, "The server admin has not setup a lotto item ticket.");
  6350. return;
  6351. }
  6352. else if (item_id == 0)
  6353. {
  6354. LogWrite(WORLD__ERROR, 0, "World", "Error! Invalid GamblingTokenItemID value!");
  6355. return;
  6356. }
  6357. Item* item = master_item_list.GetItem(item_id);
  6358. if (!item) {
  6359. LogWrite(WORLD__ERROR, 0, "World", "The 'GamblingTokenItemID' rule value %u is not a valid item id.", item_id);
  6360. return;
  6361. }
  6362. LogWrite(WORLD__DEBUG, 0, "World", "GamblingTokenItemID = '%s' (%u)", item->name.c_str(), item_id);
  6363. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6364. if (packet) {
  6365. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6366. packet->setArrayLengthByName("num_items", 1);
  6367. packet->setArrayDataByName("item_name", item->name.c_str());
  6368. packet->setArrayDataByName("price", item->sell_price);
  6369. packet->setArrayDataByName("item_id", item->details.item_id);
  6370. packet->setArrayDataByName("stack_size", item->details.count);
  6371. packet->setArrayDataByName("icon", item->details.icon);
  6372. packet->setArrayDataByName("level", item->generic_info.adventure_default_level);
  6373. packet->setArrayDataByName("tier", item->details.tier);
  6374. packet->setArrayDataByName("item_id2", item->details.item_id);
  6375. int8 item_difficulty = player->GetArrowColor(item->generic_info.adventure_default_level);
  6376. if (item_difficulty != ARROW_COLOR_WHITE && item_difficulty != ARROW_COLOR_RED && item_difficulty != ARROW_COLOR_GRAY)
  6377. item_difficulty = ARROW_COLOR_WHITE;
  6378. item_difficulty -= 6;
  6379. if (item_difficulty < 0)
  6380. item_difficulty *= -1;
  6381. packet->setArrayDataByName("item_difficulty", item_difficulty);
  6382. //if(item->details.count == 1)
  6383. packet->setArrayDataByName("quantity", 0xFFFF);
  6384. //else
  6385. // packet->setArrayDataByName("quantity", item->details.count);
  6386. packet->setArrayDataByName("stack_size2", item->details.count);
  6387. packet->setArrayDataByName("description", item->description.c_str());
  6388. if (GetVersion() <= 546) {
  6389. packet->setDataByName("type", 128);
  6390. }
  6391. else {
  6392. packet->setDataByName("type", 0x00000102);
  6393. }
  6394. QueuePacket(packet->serialize());
  6395. safe_delete(packet);
  6396. }
  6397. }
  6398. }
  6399. void Client::PlayLotto(int32 price, int32 ticket_item_id) {
  6400. PacketStruct* packet = configReader.getStruct("WS_Lottery", GetVersion());
  6401. if (packet) {
  6402. world.AddLottoPlayer(GetCharacterID(), Timer::GetCurrentTime2() + 4500);
  6403. int32 rolls[6] = { 0 };
  6404. int32 lottery_digits[6] = { 0 };
  6405. int8 num_matches = 0;
  6406. int64 jackpot = 0;
  6407. Item* item = GetPlayer()->item_list.GetItemFromID(ticket_item_id);
  6408. if (!item) {
  6409. return;
  6410. }
  6411. database.DeleteItem(GetCharacterID(), item, 0);
  6412. GetPlayer()->item_list.RemoveItem(item, true);
  6413. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  6414. Variable* winning_numbers = variables.FindVariable("gambling_winning_numbers");
  6415. if (!winning_numbers) {
  6416. winning_numbers = new Variable("gambling_winning_numbers", "231205182236", "Current Gigglegibber Gambling Game winning numbers");
  6417. variables.AddVariable(winning_numbers);
  6418. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6419. }
  6420. if (strlen(winning_numbers->GetValue()) != 12) {
  6421. winning_numbers->SetValue("231205182236");
  6422. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6423. }
  6424. try {
  6425. for (int32 i = 0; i < 12; i += 2) {
  6426. char num[4];
  6427. strncpy(num, winning_numbers->GetValue() + i, 2);
  6428. lottery_digits[i / 2] = atoi(num);
  6429. }
  6430. }
  6431. catch (...) {
  6432. LogWrite(WORLD__ERROR, 0, "World", "Error parsing 'gambling_winning_numbers' variable");
  6433. return;
  6434. }
  6435. Variable* jackpot_var = variables.FindVariable("gambling_current_jackpot");
  6436. if (!jackpot_var) {
  6437. jackpot_var = new Variable("gambling_current_jackpot", "10000", "Current Gigglegibber Gambling Game Jackpot");
  6438. variables.AddVariable(jackpot_var);
  6439. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6440. }
  6441. try {
  6442. jackpot = atoul(jackpot_var->GetValue());
  6443. if (jackpot < 10000)
  6444. jackpot = 10000;
  6445. }
  6446. catch (...) {
  6447. jackpot = 10000;
  6448. }
  6449. char new_jackpot[128] = { 0 };
  6450. sprintf(new_jackpot, "%llu", jackpot + price);
  6451. jackpot_var->SetValue(new_jackpot);
  6452. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6453. world.PickRandomLottoDigits(rolls);
  6454. packet->setDataByName("roll_digit1", rolls[0]);
  6455. packet->setDataByName("roll_digit2", rolls[1]);
  6456. packet->setDataByName("roll_digit3", rolls[2]);
  6457. packet->setDataByName("roll_digit4", rolls[3]);
  6458. packet->setDataByName("roll_digit5", rolls[4]);
  6459. packet->setDataByName("roll_digit6", rolls[5]);
  6460. packet->setDataByName("lottery_digit1", lottery_digits[0]);
  6461. packet->setDataByName("lottery_digit2", lottery_digits[1]);
  6462. packet->setDataByName("lottery_digit3", lottery_digits[2]);
  6463. packet->setDataByName("lottery_digit4", lottery_digits[3]);
  6464. packet->setDataByName("lottery_digit5", lottery_digits[4]);
  6465. packet->setDataByName("lottery_digit6", lottery_digits[5]);
  6466. QueuePacket(packet->serialize());
  6467. safe_delete(packet);
  6468. for (int32 i = 0; i < 6; i++) {
  6469. for (int32 j = 0; j < 6; j++) {
  6470. if (rolls[i] == lottery_digits[j]) {
  6471. num_matches++;
  6472. break;
  6473. }
  6474. }
  6475. }
  6476. char new_jackpot_str[16];
  6477. memset(new_jackpot_str, 0, sizeof(new_jackpot_str));
  6478. world.SetLottoPlayerNumMatches(GetCharacterID(), num_matches);
  6479. if (num_matches == 6) {
  6480. world.PickRandomLottoDigits(lottery_digits);
  6481. for (int32 i = 0; i < 12; i += 2)
  6482. sprintf(new_jackpot_str + i, "%02d", lottery_digits[i / 2]);
  6483. winning_numbers->SetValue(new_jackpot_str);
  6484. jackpot_var->SetValue("10000");
  6485. database.SaveVariable(winning_numbers->GetName(), winning_numbers->GetValue(), winning_numbers->GetComment());
  6486. database.SaveVariable(jackpot_var->GetName(), jackpot_var->GetValue(), jackpot_var->GetComment());
  6487. }
  6488. }
  6489. }
  6490. void Client::SendGuildCreateWindow() {
  6491. if (GetVersion() <= 546) {
  6492. SimpleMessage(0, "Not implemented on this client...yet?");
  6493. }
  6494. else {
  6495. Spawn* spawn = GetPlayer()->GetTarget();
  6496. if (spawn) {
  6497. PacketStruct* packet = configReader.getStruct("WS_UpdateMerchant", GetVersion());
  6498. if (packet) {
  6499. packet->setDataByName("spawn_id", player->GetIDWithPlayerSpawn(spawn));
  6500. packet->setArrayLengthByName("num_items", 0);
  6501. packet->setDataByName("type", 0x00008000);
  6502. QueuePacket(packet->serialize());
  6503. safe_delete(packet);
  6504. }
  6505. }
  6506. }
  6507. }
  6508. void Client::AddBuyBack(int32 unique_id, int32 item_id, int16 quantity, int32 price, bool save_needed) {
  6509. BuyBackItem* item = new BuyBackItem;
  6510. item->item_id = item_id;
  6511. item->unique_id = unique_id;
  6512. item->price = price;
  6513. item->quantity = quantity;
  6514. item->save_needed = save_needed;
  6515. MBuyBack.writelock(__FUNCTION__, __LINE__);
  6516. buy_back_items.push_back(item);
  6517. if (buy_back_items.size() > 10) {
  6518. safe_delete(buy_back_items.front());
  6519. buy_back_items.pop_front();
  6520. }
  6521. MBuyBack.releasewritelock(__FUNCTION__, __LINE__);
  6522. }
  6523. deque<BuyBackItem*>* Client::GetBuyBacks() {
  6524. return &buy_back_items;
  6525. }
  6526. vector<Item*>* Client::GetRepairableItems() {
  6527. vector<Item*>* repairable_items = new vector<Item*>;
  6528. vector<Item*>* equipped_items = player->GetEquipmentList()->GetAllEquippedItems();
  6529. map<int32, Item*>* items = player->GetItemList();
  6530. if (equipped_items && equipped_items->size() > 0) {
  6531. for (int32 i = 0; i < equipped_items->size(); i++) {
  6532. Item* item = equipped_items->at(i);
  6533. if (item && item->generic_info.condition < 100)
  6534. repairable_items->push_back(item);
  6535. }
  6536. }
  6537. if (items && items->size() > 0) {
  6538. map<int32, Item*>::iterator itr;
  6539. for (itr = items->begin(); itr != items->end(); itr++) {
  6540. Item* item = itr->second;
  6541. if (item && item->generic_info.condition < 100)
  6542. repairable_items->push_back(item);
  6543. }
  6544. }
  6545. safe_delete(equipped_items);
  6546. safe_delete(items);
  6547. return repairable_items;
  6548. }
  6549. void Client::SendMailList() {
  6550. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6551. if (kiosk_id > 0) {
  6552. PacketStruct* p = configReader.getStruct("WS_GetMailHeader", GetVersion());
  6553. if (p) {
  6554. MutexMap<int32, Mail*>* mail_list = player->GetMail();
  6555. MutexMap<int32, Mail*>::iterator itr = mail_list->begin();
  6556. int16 i = 0;
  6557. p->setDataByName("kiosk_id", kiosk_id);
  6558. p->setArrayLengthByName("num_messages", (int16)mail_list->size());
  6559. while (itr.Next()) {
  6560. Mail* mail = itr->second;
  6561. p->setArrayDataByName("mail_id", mail->mail_id, i);
  6562. p->setArrayDataByName("player_to_id", mail->player_to_id, i);
  6563. p->setArrayDataByName("player_from", mail->player_from.c_str(), i);
  6564. p->setArrayDataByName("subject", mail->subject.c_str(), i);
  6565. p->setArrayDataByName("unknown1", 0x0000, i);
  6566. p->setArrayDataByName("already_read", mail->already_read, i);
  6567. p->setArrayDataByName("mail_deletion", mail->expire_time - mail->time_sent, i);
  6568. p->setArrayDataByName("mail_type", mail->mail_type, i);
  6569. p->setArrayDataByName("mail_expire", 0xFFFFFFFF, i);
  6570. p->setArrayDataByName("unknown1a", 0xFFFFFFFF, i);
  6571. p->setArrayDataByName("coin_copper", mail->coin_copper, i);
  6572. p->setArrayDataByName("coin_silver", mail->coin_silver, i);
  6573. p->setArrayDataByName("coin_gold", mail->coin_gold, i);
  6574. p->setArrayDataByName("coin_plat", mail->coin_plat, i);
  6575. p->setArrayDataByName("num_items", mail->stack, i);
  6576. p->setArrayDataByName("packettype", GetItemPacketType(GetVersion()));
  6577. p->setArrayDataByName("packetsubtype", 0xFF, i);
  6578. p->setArrayDataByName("unknown2", 0, i);
  6579. //p->setArrayDataByName("item_id", 5, i, 0);
  6580. //Item* item = master_item_list.GetItem(5);
  6581. //if (item)
  6582. // printf("%s\n", item->name.c_str());
  6583. //else
  6584. // printf("no item\n");
  6585. //p->setItemArrayDataByName("item", master_item_list.GetItem(5), i, 0);
  6586. i++;
  6587. }
  6588. // GMs send mail for free!
  6589. if (GetAdminStatus() > 0)
  6590. {
  6591. p->setDataByName("postage_cost", 0);
  6592. p->setDataByName("attachment_cost", 0);
  6593. }
  6594. else
  6595. {
  6596. p->setDataByName("postage_cost", 10);
  6597. p->setDataByName("attachment_cost", 50);
  6598. }
  6599. p->setDataByName("unknown3", 0x01F4);
  6600. p->setDataByName("unknown4", 0x01000000);
  6601. QueuePacket(p->serialize());
  6602. safe_delete(p);
  6603. }
  6604. }
  6605. else
  6606. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6607. }
  6608. void Client::DisplayMailMessage(int32 mail_id) {
  6609. Mail* mail = player->GetMail(mail_id);
  6610. if (mail) {
  6611. int32 kiosk_id = player->GetIDWithPlayerSpawn(GetMailTransaction());
  6612. if (kiosk_id > 0) {
  6613. PacketStruct* update = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6614. if (update) {
  6615. update->setDataByName("action", 0x03);
  6616. update->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6617. update->setDataByName("packetsubtype", 0xFF);
  6618. QueuePacket(update->serialize());
  6619. safe_delete(update);
  6620. }
  6621. PacketStruct* packet = configReader.getStruct("WS_MailGetMessage", GetVersion());
  6622. if (packet) {
  6623. packet->setDataByName("kiosk_id", kiosk_id);
  6624. packet->setDataByName("mail_id", mail->mail_id);
  6625. packet->setDataByName("player_to_id", mail->player_to_id);
  6626. packet->setDataByName("player_from", mail->player_from.c_str());
  6627. packet->setDataByName("subject", mail->subject.c_str());
  6628. packet->setDataByName("mail_body", mail->mail_body.c_str());
  6629. packet->setDataByName("unknown1", 1);
  6630. packet->setDataByName("unknown2", 0);
  6631. packet->setDataByName("lock_report_button", 1);
  6632. packet->setDataByName("unknown3", 0xFFFFFFFF);
  6633. packet->setDataByName("unknown3a", 0xFFFFFFFF);
  6634. packet->setDataByName("coin_copper", mail->coin_copper);
  6635. packet->setDataByName("coin_silver", mail->coin_silver);
  6636. packet->setDataByName("coin_gold", mail->coin_gold);
  6637. packet->setDataByName("coin_plat", mail->coin_plat);
  6638. packet->setDataByName("stack", mail->stack);
  6639. packet->setDataByName("packettype", GetItemPacketType(GetVersion()));
  6640. packet->setDataByName("packetsubtype", 0xFF);
  6641. packet->setDataByName("unknown4", 0);
  6642. packet->setDataByName("unknown5", 0);
  6643. packet->setDataByName("unknown6", 0);
  6644. packet->setDataByName("unknown7", 0);
  6645. mail->already_read = true;
  6646. mail->save_needed = true;
  6647. QueuePacket(packet->serialize());
  6648. safe_delete(packet);
  6649. //SendMailList();
  6650. }
  6651. }
  6652. else
  6653. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6654. }
  6655. }
  6656. /* This is called when the client sends a mail message. This determines whether or not the mail can be sent and must send the reply
  6657. packet back to the client before the mail actually sent. */
  6658. void Client::HandleSentMail(EQApplicationPacket* app) {
  6659. PacketStruct* packet = configReader.getStruct("WS_MailSendMessage", GetVersion());
  6660. if (packet) {
  6661. packet->LoadPacketData(app->pBuffer, app->size);
  6662. string player_to = packet->getType_EQ2_16BitString_ByName("player_to").data;
  6663. PacketStruct* reply_packet = configReader.getStruct("WS_MailSendMessageReply", GetVersion());
  6664. vector<int32>* ids = 0;
  6665. if (reply_packet) {
  6666. int8 reply_type = MAIL_SEND_RESULT_UNKNOWN_ERROR;
  6667. if (player_to.length() == 0)
  6668. reply_type = MAIL_SEND_RESULT_EMPTY_TO_LIST;
  6669. else if (player_to.compare(string(GetPlayer()->GetName())) == 0)
  6670. reply_type = MAIL_SEND_RESULT_CANNOT_SEND_TO_SELF;
  6671. else if (GetAdminStatus() == 0 && !player->RemoveCoins(10))
  6672. reply_type = MAIL_SEND_RESULT_NOT_ENOUGH_COIN;
  6673. else {
  6674. if (player_to.compare("<all>") == 0) {
  6675. if (mail_window.coin_copper + mail_window.coin_silver + mail_window.coin_gold + mail_window.coin_plat == 0)
  6676. ids = database.GetAllPlayerIDs();
  6677. else
  6678. SimpleMessage(CHANNEL_NARRATIVE, "You may not mail gifts to multiple players.");
  6679. }
  6680. else {
  6681. ids = new vector<int32>;
  6682. ids->push_back(database.GetCharacterID(player_to.c_str()));
  6683. }
  6684. if (ids) {
  6685. for (int32 i = 0; i < ids->size(); i++) {
  6686. int32 player_to_id = ids->at(i);
  6687. if (player_to_id > 0) {
  6688. reply_type = MAIL_SEND_RESULT_SUCCESS;
  6689. Mail* mail = new Mail;
  6690. mail->mail_id = 0;
  6691. mail->player_to_id = player_to_id;
  6692. mail->player_from = string(GetPlayer()->GetName());
  6693. mail->subject = packet->getType_EQ2_16BitString_ByName("subject").data;
  6694. mail->mail_body = packet->getType_EQ2_16BitString_ByName("mail_body").data;
  6695. mail->already_read = 0;
  6696. mail->mail_type = MAIL_TYPE_REGULAR;
  6697. mail->coin_copper = mail_window.coin_copper;
  6698. mail->coin_silver = mail_window.coin_silver;
  6699. mail->coin_gold = mail_window.coin_gold;
  6700. mail->coin_plat = mail_window.coin_plat;
  6701. mail->stack = 0;
  6702. // GM's send mail for free!
  6703. if (GetAdminStatus() > 0)
  6704. {
  6705. mail->postage_cost = 0;
  6706. mail->attachment_cost = 0;
  6707. }
  6708. else
  6709. {
  6710. mail->postage_cost = 10;
  6711. mail->attachment_cost = 50;
  6712. }
  6713. mail->char_item_id = 0;
  6714. mail->time_sent = Timer::GetUnixTimeStamp();
  6715. mail->expire_time = mail->time_sent + 2592000; //30 days in seconds
  6716. //int16 packettype = packet->getType_int16_ByName("packettype");
  6717. //int8 packetsubtype = packet->getType_int8_ByName("packetsubtype");
  6718. /*int32 postage_cost = packet->getType_int32_ByName("postage_cost");
  6719. int32 attachment_cost = packet->getType_int32_ByName("attachment_cost");
  6720. if (postage_cost > 0 || attachment_cost > 0)
  6721. PlaySoundA("coin_cha_ching");*/
  6722. mail->save_needed = false;
  6723. Client* to_client = zone_list.GetClientByCharID(player_to_id);
  6724. if (to_client) {
  6725. to_client->GetPlayer()->AddMail(mail);
  6726. to_client->SimpleMessage(CHANNEL_NARRATIVE, "You've got mail! :)");
  6727. }
  6728. database.SavePlayerMail(mail);
  6729. mail_window.coin_copper = 0;
  6730. mail_window.coin_silver = 0;
  6731. mail_window.coin_gold = 0;
  6732. mail_window.coin_plat = 0;
  6733. }
  6734. else
  6735. reply_type = MAIL_SEND_RESULT_UNKNOWN_PLAYER;
  6736. }
  6737. }
  6738. }
  6739. string players_to = "";
  6740. if (ids) {
  6741. for (int32 i = 0; i < ids->size(); i++) {
  6742. if (ids->at(i) != 0)
  6743. players_to.append(database.GetCharacterName(ids->at(i)));
  6744. if (i < (ids->size() - 1))
  6745. players_to.append(", ");
  6746. }
  6747. }
  6748. reply_packet->setDataByName("player_to", players_to.c_str());
  6749. reply_packet->setDataByName("reply_type", reply_type);
  6750. QueuePacket(reply_packet->serialize());
  6751. safe_delete(reply_packet);
  6752. safe_delete(ids);
  6753. }
  6754. safe_delete(packet);
  6755. }
  6756. }
  6757. void Client::DeleteMail(int32 mail_id, bool from_database) {
  6758. player->DeleteMail(mail_id, from_database);
  6759. }
  6760. bool Client::AddMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6761. bool ret = false;
  6762. if (GetMailTransaction()) {
  6763. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6764. if (packet) {
  6765. if (copper > 0) {
  6766. if (player->RemoveCoins(copper)) {
  6767. mail_window.coin_copper += copper;
  6768. Message(CHANNEL_NARRATIVE, "You add %u copper to the mail window.", copper);
  6769. ret = true;
  6770. }
  6771. }
  6772. else if (silver > 0) {
  6773. if (player->RemoveCoins(silver * 100)) {
  6774. mail_window.coin_silver += silver;
  6775. Message(CHANNEL_NARRATIVE, "You add %u silver to the mail window.", silver);
  6776. ret = true;
  6777. }
  6778. }
  6779. else if (gold > 0) {
  6780. if (player->RemoveCoins(gold * 10000)) {
  6781. mail_window.coin_gold += gold;
  6782. Message(CHANNEL_NARRATIVE, "You add %u gold to the mail window.", gold);
  6783. ret = true;
  6784. }
  6785. }
  6786. else if (plat > 0) {
  6787. if (player->RemoveCoins(plat * 1000000)) {
  6788. mail_window.coin_plat += plat;
  6789. Message(CHANNEL_NARRATIVE, "You add %u platinum to the mail window.", plat);
  6790. ret = true;
  6791. }
  6792. }
  6793. if (ret) {
  6794. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6795. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6796. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6797. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6798. packet->setDataByName("stack", 0);
  6799. packet->setDataByName("packettype", GetItemPacketType(version));
  6800. packet->setDataByName("packetsubtype", 0xFF);
  6801. packet->setDataByName("unknown2", 0);
  6802. //packet->PrintPacket();
  6803. QueuePacket(packet->serialize());
  6804. }
  6805. else
  6806. SimpleMessage(CHANNEL_NARRATIVE, "You don't have that much money.");
  6807. safe_delete(packet);
  6808. }
  6809. }
  6810. else
  6811. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6812. return ret;
  6813. }
  6814. bool Client::RemoveMailCoin(int32 copper, int32 silver, int32 gold, int32 plat) {
  6815. bool ret = false;
  6816. if (GetMailTransaction()) {
  6817. PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6818. if (packet) {
  6819. if (copper > 0) {
  6820. player->AddCoins(copper);
  6821. mail_window.coin_copper -= copper;
  6822. Message(CHANNEL_NARRATIVE, "You remove %u copper from the mail window.", copper);
  6823. ret = true;
  6824. }
  6825. else if (silver > 0) {
  6826. player->AddCoins(silver * 100);
  6827. mail_window.coin_silver -= silver;
  6828. Message(CHANNEL_NARRATIVE, "You remove %u silver from the mail window.", silver);
  6829. ret = true;
  6830. }
  6831. else if (gold > 0) {
  6832. player->AddCoins(gold * 10000);
  6833. mail_window.coin_gold -= gold;
  6834. Message(CHANNEL_NARRATIVE, "You remove %u gold from the mail window.", gold);
  6835. ret = true;
  6836. }
  6837. else if (plat > 0) {
  6838. player->AddCoins(plat * 1000000);
  6839. mail_window.coin_plat -= plat;
  6840. Message(CHANNEL_NARRATIVE, "You remove %u platinum from the mail window.", plat);
  6841. ret = true;
  6842. }
  6843. if (ret) {
  6844. packet->setDataByName("coin_copper", mail_window.coin_copper);
  6845. packet->setDataByName("coin_silver", mail_window.coin_silver);
  6846. packet->setDataByName("coin_gold", mail_window.coin_gold);
  6847. packet->setDataByName("coin_plat", mail_window.coin_plat);
  6848. packet->setDataByName("stack", 0);
  6849. packet->setDataByName("packettype", 0x2BFE);
  6850. packet->setDataByName("packetsubtype", 0xFF);
  6851. packet->setDataByName("unknown2", 0);
  6852. QueuePacket(packet->serialize());
  6853. }
  6854. safe_delete(packet);
  6855. }
  6856. }
  6857. else
  6858. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6859. return ret;
  6860. }
  6861. void Client::TakeMailAttachments(int32 mail_id) {
  6862. if (GetMailTransaction()) {
  6863. Mail* mail = player->GetMail(mail_id);
  6864. if (mail) {
  6865. int64 amount = 0;
  6866. if (mail->coin_copper > 0) {
  6867. amount += mail->coin_copper;
  6868. mail->coin_copper = 0;
  6869. }
  6870. if (mail->coin_silver > 0) {
  6871. amount += mail->coin_silver * 100;
  6872. mail->coin_silver = 0;
  6873. }
  6874. if (mail->coin_gold > 0) {
  6875. amount += mail->coin_gold * 10000;
  6876. mail->coin_gold = 0;
  6877. }
  6878. if (mail->coin_plat > 0) {
  6879. amount += mail->coin_plat * 1000000;
  6880. mail->coin_plat = 0;
  6881. }
  6882. if (mail->char_item_id > 0) {
  6883. LogWrite(MISC__TODO, 1, "TODO", "Items by Mail\n\t(%s, function: %s, line #: %i)", __FILE__, __FUNCTION__, __LINE__);
  6884. }
  6885. /* Can't find the right packet to send to update the player's mail. This packet below updates the mail the player is sending, not
  6886. the mail the player is getting attachments from. There is an opcode OP_MailRemoveAttachFromMailMsg with opcode 328 but i can't
  6887. find it in any packet logs.*/
  6888. /*PacketStruct* packet = configReader.getStruct("WS_UpdatePlayerMail", GetVersion());
  6889. if (packet) {
  6890. packet->setDataByName("unknown", 0x03);
  6891. packet->setDataByName("coin_copper", mail->coin_copper);
  6892. packet->setDataByName("coin_silver", mail->coin_silver);
  6893. packet->setDataByName("coin_gold", mail->coin_gold);
  6894. packet->setDataByName("coin_plat", mail->coin_plat);
  6895. packet->setDataByName("stack", 0);
  6896. packet->setDataByName("packettype", 0x2BFE);
  6897. packet->setDataByName("packetsubtype", 0xFF);
  6898. packet->setDataByName("unknown2", 0);
  6899. packet->setDataByName("unknown3", 0x00000001);//0x00000016
  6900. DumpPacket(packet->serialize());
  6901. QueuePacket(packet->serialize());
  6902. safe_delete(packet);
  6903. }*/
  6904. database.SavePlayerMail(mail);
  6905. if (amount > 0)
  6906. player->AddCoins(amount);
  6907. SendMailList();
  6908. }
  6909. }
  6910. else
  6911. SimpleMessage(CHANNEL_NARRATIVE, "You are currently not in a mail transaction.");
  6912. }
  6913. void Client::CancelSendMail() {
  6914. SimpleMessage(CHANNEL_NARRATIVE, "You cancel sending a letter.");
  6915. player->AddCoins(mail_window.coin_copper + (mail_window.coin_silver * 100) + (mail_window.coin_gold * 10000) + (mail_window.coin_plat * 1000000));
  6916. mail_window.coin_copper = 0;
  6917. mail_window.coin_silver = 0;
  6918. mail_window.coin_gold = 0;
  6919. mail_window.coin_plat = 0;
  6920. mail_window.char_item_id = 0;
  6921. }
  6922. bool Client::GateAllowed() {
  6923. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6924. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to gate from this spot, allow for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6925. if (zone)
  6926. return true;
  6927. return false;
  6928. }
  6929. bool Client::BindAllowed() {
  6930. LogWrite(MISC__TODO, 1, "TODO", "possibly add a check here to see if a player is allowed to bind in this spot, allow anywhere for now\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  6931. return true;
  6932. }
  6933. bool Client::Bind() {
  6934. player->GetPlayerInfo()->SetBindZone(GetCurrentZone()->GetZoneID());
  6935. player->GetPlayerInfo()->SetBindX(player->GetX());
  6936. player->GetPlayerInfo()->SetBindY(player->GetY());
  6937. player->GetPlayerInfo()->SetBindZ(player->GetZ());
  6938. player->GetPlayerInfo()->SetBindHeading(player->GetHeading());
  6939. return true;
  6940. }
  6941. bool Client::Gate() {
  6942. if (player->GetPlayerInfo()->GetBindZoneID() == 0)
  6943. return false;
  6944. ZoneServer* zone = zone_list.Get(player->GetPlayerInfo()->GetBindZoneID());
  6945. if (zone) {
  6946. player->SetX(player->GetPlayerInfo()->GetBindZoneX());
  6947. player->SetY(player->GetPlayerInfo()->GetBindZoneY());
  6948. player->SetZ(player->GetPlayerInfo()->GetBindZoneZ());
  6949. player->SetHeading(player->GetPlayerInfo()->GetBindZoneHeading());
  6950. Zone(zone, false);
  6951. return true;
  6952. }
  6953. return false;
  6954. }
  6955. void Client::ProcessTeleport(Spawn* spawn, vector<TransportDestination*>* destinations, int32 transport_id) {
  6956. if (!destinations || !spawn) {
  6957. return;
  6958. }
  6959. bool has_map = false;
  6960. if (transport_id > 0)
  6961. has_map = GetCurrentZone()->TransportHasMap(transport_id);
  6962. transport_spawn = spawn;
  6963. vector<TransportDestination*> transport_list;
  6964. vector<TransportDestination*>::iterator itr;
  6965. TransportDestination* destination = 0;
  6966. for (itr = destinations->begin(); itr != destinations->end(); itr++) {
  6967. destination = *itr;
  6968. if (has_map || (destination->type == TRANSPORT_TYPE_ZONE && ((destination->destination_zone_id != GetCurrentZone()->GetZoneID()) || GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) > 100)))
  6969. transport_list.push_back(destination);
  6970. }
  6971. if (transport_list.size() == 0 && destination) {
  6972. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  6973. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  6974. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  6975. else
  6976. {
  6977. EQ2Packet* app = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  6978. if (app)
  6979. QueuePacket(app);
  6980. }
  6981. }
  6982. else {
  6983. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  6984. // determine if this is an instanced zone that already exists
  6985. ZoneServer* instance_zone = GetPlayer()->GetGroupMemberInZone(destination->destination_zone_id);
  6986. if (instance_zone || new_zone) {
  6987. GetPlayer()->SetX(destination->destination_x);
  6988. GetPlayer()->SetY(destination->destination_y);
  6989. GetPlayer()->SetZ(destination->destination_z);
  6990. GetPlayer()->SetHeading(destination->destination_heading);
  6991. if (instance_zone)
  6992. Zone(instance_zone->GetInstanceID(), false, true);
  6993. else
  6994. Zone(new_zone, false);
  6995. }
  6996. }
  6997. if (destination->message.length() > 0)
  6998. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  6999. }
  7000. else if (transport_list.size() > 0) {
  7001. if (!spawn->IsSoundsDisabled())
  7002. PlaySound("mariner_bell");
  7003. PacketStruct* packet = configReader.getStruct("WS_TeleportList", GetVersion());
  7004. if (packet) {
  7005. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  7006. // Put all the destinations the player can go in a new vector
  7007. vector<TransportDestination*> destinations;
  7008. for (int32 i = 0; i < transport_list.size(); i++) {
  7009. destination = transport_list.at(i);
  7010. // Check min level
  7011. if (destination->min_level > 0 && GetPlayer()->GetLevel() < destination->min_level)
  7012. continue;
  7013. // Check max level
  7014. if (destination->max_level > 0 && GetPlayer()->GetLevel() > destination->max_level)
  7015. continue;
  7016. // Check quest complete
  7017. if (destination->req_quest_complete > 0 && GetPlayer()->GetCompletedQuest(destination->req_quest_complete) == 0)
  7018. continue;
  7019. // Check req quest and step
  7020. if (destination->req_quest > 0 && destination->req_quest_step > 0 && GetPlayer()->GetQuestStep(destination->req_quest) != destination->req_quest_step)
  7021. continue;
  7022. // If we have a map and our current location is the same as the detination and player is within 20 units from the transport set the "current" elements but don't addt to the destination list
  7023. if (has_map && (destination->destination_zone_id == GetCurrentZone()->GetZoneID() && GetPlayer()->GetDistance(destination->destination_x, destination->destination_y, destination->destination_z) < 20)) {
  7024. packet->setDataByName("current_zone", destination->display_name.c_str());
  7025. packet->setDataByName("current_map_x", destination->map_x);
  7026. packet->setDataByName("current_map_y", destination->map_y);
  7027. }
  7028. else {
  7029. destinations.push_back(destination);
  7030. }
  7031. }
  7032. // Use the new vector to create the packet
  7033. destination = 0;
  7034. packet->setArrayLengthByName("num_destinations", destinations.size());
  7035. for (int32 i = 0; i < destinations.size(); i++) {
  7036. destination = destinations.at(i);
  7037. packet->setArrayDataByName("unique_id", destination->unique_id, i);
  7038. packet->setArrayDataByName("display_name", destination->display_name.c_str(), i);
  7039. packet->setArrayDataByName("zone_name", destination->display_name.c_str(), i);
  7040. packet->setArrayDataByName("zone_file_name", destination->display_name.c_str(), i);
  7041. packet->setArrayDataByName("cost", destination->cost, i);
  7042. if (has_map) {
  7043. packet->setArrayDataByName("map_x", destination->map_x, i);
  7044. packet->setArrayDataByName("map_y", destination->map_y, i);
  7045. }
  7046. }
  7047. if (has_map)
  7048. packet->setDataByName("map_name", GetCurrentZone()->GetTransportMap(transport_id).c_str());
  7049. EQ2Packet* app = packet->serialize();
  7050. //DumpPacket(app);
  7051. if (destinations.size() > 0)
  7052. QueuePacket(app);
  7053. safe_delete(packet);
  7054. }
  7055. }
  7056. }
  7057. void Client::ProcessTeleportLocation(EQApplicationPacket* app) {
  7058. PacketStruct* packet = configReader.getStruct("WS_TeleportDestination", GetVersion());
  7059. if (packet) {
  7060. if (packet->LoadPacketData(app->pBuffer, app->size)) {
  7061. Spawn* spawn = GetPlayer()->GetSpawnWithPlayerID(packet->getType_int32_ByName("spawn_id"));
  7062. int32 unique_id = packet->getType_int32_ByName("unique_id");
  7063. string zone_name = packet->getType_EQ2_16BitString_ByName("zone_name").data;
  7064. int32 cost = packet->getType_int32_ByName("cost");
  7065. vector<TransportDestination*> destinations;
  7066. TransportDestination* destination = 0;
  7067. if (this->GetTemporaryTransportID() || (spawn && spawn == transport_spawn && spawn->GetTransporterID()))
  7068. GetCurrentZone()->GetTransporters(&destinations, this, this->GetTemporaryTransportID() ? this->GetTemporaryTransportID() : spawn->GetTransporterID());
  7069. vector<TransportDestination*>::iterator itr;
  7070. for (itr = destinations.begin(); itr != destinations.end(); itr++) {
  7071. if ((*itr)->unique_id == unique_id && (*itr)->display_name == zone_name && (*itr)->cost == cost) {
  7072. destination = *itr;
  7073. break;
  7074. }
  7075. }
  7076. SetTemporaryTransportID(0);
  7077. if (!destination)
  7078. SimpleMessage(CHANNEL_COLOR_RED, "Error processing transport.");
  7079. else {
  7080. if (cost == 0 || player->RemoveCoins(cost)) {
  7081. if (destination->destination_zone_id == 0 || destination->destination_zone_id == GetCurrentZone()->GetZoneID()) {
  7082. if (destination->type == TRANSPORT_TYPE_FLIGHT)
  7083. SendFlightAutoMount(destination->flight_path_id, destination->mount_id, destination->mount_red_color, destination->mount_green_color, destination->mount_blue_color);
  7084. else
  7085. {
  7086. EQ2Packet* outapp = GetPlayer()->Move(destination->destination_x, destination->destination_y, destination->destination_z, GetVersion());
  7087. if (outapp)
  7088. QueuePacket(outapp);
  7089. }
  7090. }
  7091. else {
  7092. GetPlayer()->SetX(destination->destination_x);
  7093. GetPlayer()->SetY(destination->destination_y);
  7094. GetPlayer()->SetZ(destination->destination_z);
  7095. GetPlayer()->SetHeading(destination->destination_heading);
  7096. // Test if where we're going is an Instanced zone
  7097. if (!TryZoneInstance(destination->destination_zone_id, false)) {
  7098. LogWrite(INSTANCE__DEBUG, 0, "Instance", "Attempting to zone normally");
  7099. ZoneServer* new_zone = zone_list.Get(destination->destination_zone_id);
  7100. Zone(new_zone, false);
  7101. }
  7102. }
  7103. if (destination->message.length() > 0)
  7104. SimpleMessage(CHANNEL_COLOR_YELLOW, destination->message.c_str());
  7105. }
  7106. else
  7107. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough money to use this transport.");
  7108. }
  7109. }
  7110. safe_delete(packet);
  7111. }
  7112. }
  7113. void Client::SendNewSpells(int8 class_id) {
  7114. if (class_id > 0) {
  7115. vector<Spell*>* spells = master_spell_list.GetSpellListByAdventureClass(class_id, player->GetLevel(), 1);
  7116. vector<Spell*>::iterator itr;
  7117. Spell* spell = 0;
  7118. bool send_updates = false;
  7119. for (itr = spells->begin(); itr != spells->end(); itr++) {
  7120. spell = *itr;
  7121. if (spell && !player->HasSpell(spell->GetSpellID(), spell->GetSpellTier(), true) && spell->GetSpellData()->lua_script.length() > 0) {
  7122. send_updates = true;
  7123. SendSpellUpdate(spell);
  7124. player->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), player->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  7125. player->UnlockSpell(spell);
  7126. }
  7127. }
  7128. if (send_updates) {
  7129. EQ2Packet* outapp = player->GetSpellBookUpdatePacket(GetVersion());
  7130. if (outapp)
  7131. QueuePacket(outapp);
  7132. }
  7133. safe_delete(spells);
  7134. }
  7135. }
  7136. void Client::SetItemSearch(vector<Item*>* items) {
  7137. if (items) {
  7138. safe_delete(search_items);
  7139. search_items = items;
  7140. }
  7141. }
  7142. vector<Item*>* Client::GetSearchItems() {
  7143. return search_items;
  7144. }
  7145. void Client::SearchStore(int32 page) {
  7146. if (search_items) {
  7147. PacketStruct* packet = configReader.getStruct("WS_BrokerItems", GetVersion());
  7148. if (packet) {
  7149. int32 x = page * 8;
  7150. if (search_items->size() > 8) {
  7151. if ((search_items->size() - x) > 8)
  7152. packet->setArrayLengthByName("num_items", 8);
  7153. else
  7154. packet->setArrayLengthByName("num_items", search_items->size() - x);
  7155. }
  7156. else
  7157. packet->setArrayLengthByName("num_items", search_items->size());
  7158. if (search_items->size() > 0) {
  7159. packet->setArrayLengthByName("num_sellers", 1);
  7160. packet->setArrayDataByName("seller_seller_id", 1);
  7161. packet->setArrayDataByName("seller_name", "EQ2EmuDevs");
  7162. packet->setDataByName("per_page", 8);
  7163. packet->setDataByName("num_pages", search_items->size() / 8 + 1);
  7164. packet->setDataByName("page", page);
  7165. Item* item = 0;
  7166. int32 limit = search_items->size() > 8 ? 8 : search_items->size();
  7167. for (int32 i = 0; i < limit; i++, x++) {
  7168. if (x >= search_items->size())
  7169. break;
  7170. item = search_items->at(x);
  7171. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7172. packet->setArrayDataByName("item_id2", item->details.item_id, i);
  7173. packet->setArrayDataByName("icon", item->details.icon, i);
  7174. //packet->setArrayDataByName("unknown2b", i, i);
  7175. packet->setArrayDataByName("item_seller_id", 1, i);
  7176. if (item->stack_count == 0)
  7177. packet->setArrayDataByName("quantity", 1, i);
  7178. else
  7179. packet->setArrayDataByName("quantity", item->stack_count, i);
  7180. packet->setArrayDataByName("stack_size", item->stack_count, i);
  7181. std::string tmpStr("");
  7182. tmpStr.append(item->name.c_str());
  7183. tmpStr.append(" (");
  7184. tmpStr.append(std::to_string(item->details.item_id));
  7185. tmpStr.append(")");
  7186. packet->setArrayDataByName("item_name", tmpStr.c_str(), i);
  7187. packet->setArrayDataByName("req_level", item->generic_info.adventure_default_level, i);
  7188. //QueuePacket(item->serialize(GetVersion(), false, GetPlayer()));
  7189. }
  7190. }
  7191. /*EQ2Packet* outapp = packet->serialize();
  7192. DumpPacket(outapp);
  7193. QueuePacket(outapp);*/
  7194. QueuePacket(packet->serialize());
  7195. safe_delete(packet);
  7196. }
  7197. }
  7198. }
  7199. void Client::SetReadyForUpdates() {
  7200. GetPlayer()->SetFullyLoggedIn(true);
  7201. if (!ready_for_updates)
  7202. database.loadCharacterProperties(this);
  7203. ready_for_updates = true;
  7204. }
  7205. void Client::SetReadyForSpawns(bool val) {
  7206. ready_for_spawns = val;
  7207. if (GetPlayer()->GetActivityStatus() > 0) {
  7208. GetPlayer()->SetActivityStatus(0);
  7209. if (GetPlayer()->GetGroupMemberInfo()) {
  7210. world.GetGroupManager()->GroupMessage(GetPlayer()->GetGroupMemberInfo()->group_id, "%s has returned from Linkdead.", GetPlayer()->GetName());
  7211. }
  7212. }
  7213. zone_list.CheckFriendZoned(this);
  7214. }
  7215. void Client::SendChatRelationship(int8 type, const char* name) {
  7216. if (!name) {
  7217. return;
  7218. }
  7219. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7220. if (packet) {
  7221. packet->setDataByName("account_id", GetAccountID());
  7222. packet->setDataByName("type", type);
  7223. packet->setArrayLengthByName("num_names", 1);
  7224. packet->setArrayDataByName("name", name);
  7225. if (type == 0) {
  7226. Client* client = zone_list.GetClientByCharName(name);
  7227. if (client) {
  7228. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName());
  7229. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()));
  7230. }
  7231. }
  7232. QueuePacket(packet->serialize());
  7233. safe_delete(packet);
  7234. }
  7235. }
  7236. void Client::SendFriendList() {
  7237. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7238. if (packet) {
  7239. packet->setDataByName("account_id", GetAccountID());
  7240. map<string, int8>::iterator itr;
  7241. map<string, int8>* friends = player->GetFriends();
  7242. if (friends && friends->size() > 0) {
  7243. Client* client = 0;
  7244. vector<string> names;
  7245. for (itr = friends->begin(); itr != friends->end(); itr++) {
  7246. if (itr->second == 2)
  7247. continue;
  7248. names.push_back(itr->first);
  7249. }
  7250. packet->setArrayLengthByName("num_names", names.size());
  7251. for (int32 i = 0; i < names.size(); i++) {
  7252. client = zone_list.GetClientByCharName(names[i]);
  7253. packet->setArrayDataByName("name", names[i].c_str(), i);
  7254. if (client) {
  7255. packet->setArrayDataByName("location", client->GetCurrentZone()->GetZoneName(), i);
  7256. packet->setArrayDataByName("class_name", classes.GetClassName(client->GetPlayer()->GetAdventureClass()), i);
  7257. }
  7258. }
  7259. }
  7260. QueuePacket(packet->serialize());
  7261. safe_delete(packet);
  7262. }
  7263. }
  7264. void Client::SendIgnoreList() {
  7265. PacketStruct* packet = configReader.getStruct("WS_ChatRelationship", GetVersion());
  7266. if (packet) {
  7267. packet->setDataByName("account_id", GetAccountID());
  7268. packet->setDataByName("type", 2);
  7269. map<string, int8>::iterator itr;
  7270. map<string, int8>* ignored = player->GetIgnoredPlayers();
  7271. if (ignored && ignored->size() > 0) {
  7272. vector<string> names;
  7273. for (itr = ignored->begin(); itr != ignored->end(); itr++) {
  7274. if (itr->second == 2)
  7275. continue;
  7276. names.push_back(itr->first);
  7277. }
  7278. packet->setArrayLengthByName("num_names", names.size());
  7279. for (int32 i = 0; i < names.size(); i++)
  7280. packet->setArrayDataByName("name", names[i].c_str(), i);
  7281. }
  7282. QueuePacket(packet->serialize());
  7283. safe_delete(packet);
  7284. }
  7285. }
  7286. void Client::AddWaypoint(const char* waypoint_name, int8 waypoint_category, int32 spawn_id) {
  7287. if (waypoint_name) {
  7288. PacketStruct* packet = configReader.getStruct("WS_WaypointUpdate", GetVersion());
  7289. if (packet) {
  7290. packet->setArrayLengthByName("num_updates", 1);
  7291. packet->setArrayDataByName("waypoint_name", waypoint_name, 0);
  7292. packet->setArrayDataByName("waypoint_category", waypoint_category, 0);
  7293. packet->setArrayDataByName("spawn_id", spawn_id, 0);
  7294. packet->setArrayDataByName("waypoint_category2", waypoint_category, 0);
  7295. packet->setArrayDataByName("spawn_id2", spawn_id, 0);
  7296. QueuePacket(packet->serialize());
  7297. safe_delete(packet);
  7298. }
  7299. }
  7300. }
  7301. void Client::BeginWaypoint(const char* waypoint_name, float x, float y, float z) {
  7302. if (waypoint_name) {
  7303. PacketStruct* packet = configReader.getStruct("WS_GlowPath", GetVersion());
  7304. if (packet) {
  7305. packet->setArrayLengthByName("num_points", 1);
  7306. packet->setArrayDataByName("x", x, 0);
  7307. packet->setArrayDataByName("y", y, 0);
  7308. packet->setArrayDataByName("z", z, 0);
  7309. packet->setDataByName("waypoint_x", x);
  7310. packet->setDataByName("waypoint_y", y);
  7311. packet->setDataByName("waypoint_z", z);
  7312. packet->setDataByName("waypoint_name", waypoint_name);
  7313. packet->setDataByName("unknown", 0);
  7314. QueuePacket(packet->serialize());
  7315. safe_delete(packet);
  7316. }
  7317. }
  7318. }
  7319. void Client::InspectPlayer(Player* player_to_inspect) {
  7320. if (player_to_inspect) {
  7321. PacketStruct* packet = configReader.getStruct("WS_InspectPlayer", GetVersion());
  7322. if (packet) {
  7323. packet->setDataByName("unknown", 0);
  7324. packet->setSmallStringByName("name", player_to_inspect->GetName());
  7325. packet->setDataByName("race", player_to_inspect->GetRace());
  7326. packet->setDataByName("gender", player_to_inspect->GetGender());
  7327. packet->setDataByName("adventure_level", player_to_inspect->GetLevel());
  7328. LogWrite(MISC__TODO, 1, "TODO", "Put mentored level here (adventure_level_effective)\nfile: %s, func: %s, line: %i", __FILE__, __FUNCTION__, __LINE__);
  7329. packet->setDataByName("adventure_level_effective", player_to_inspect->GetLevel());
  7330. packet->setDataByName("adventure_class", player_to_inspect->GetAdventureClass());
  7331. packet->setDataByName("tradeskill_level", player_to_inspect->GetTSLevel());
  7332. packet->setDataByName("tradeskill_class", player_to_inspect->GetTradeskillClass());
  7333. packet->setDataByName("health", player_to_inspect->GetHP());
  7334. packet->setDataByName("health_max", player_to_inspect->GetTotalHP());
  7335. packet->setDataByName("health_base", player_to_inspect->GetTotalHPBase());
  7336. packet->setDataByName("power", player_to_inspect->GetPower());
  7337. packet->setDataByName("power_max", player_to_inspect->GetTotalPower());
  7338. packet->setDataByName("power_base", player_to_inspect->GetTotalPowerBase());
  7339. packet->setDataByName("mitigation", 0);
  7340. packet->setDataByName("unknown1", 0);
  7341. packet->setDataByName("avoidance", 0);
  7342. packet->setDataByName("unknown2", 0);
  7343. packet->setDataByName("mitigation_percentage", 0);
  7344. packet->setDataByName("strength", player_to_inspect->GetStr());
  7345. packet->setDataByName("strength_base", player_to_inspect->GetStrBase());
  7346. packet->setDataByName("stamina", player_to_inspect->GetSta());
  7347. packet->setDataByName("stamina_base", player_to_inspect->GetStaBase());
  7348. packet->setDataByName("agility", player_to_inspect->GetAgi());
  7349. packet->setDataByName("agility_base", player_to_inspect->GetAgiBase());
  7350. packet->setDataByName("wisdom", player_to_inspect->GetWis());
  7351. packet->setDataByName("wisdom_base", player_to_inspect->GetWisBase());
  7352. packet->setDataByName("intelligence", player_to_inspect->GetInt());
  7353. packet->setDataByName("intelligence_base", player_to_inspect->GetIntBase());
  7354. packet->setDataByName("unknown4", 0);
  7355. packet->setDataByName("unknown5", 0);
  7356. packet->setDataByName("unknown6", 0);
  7357. packet->setDataByName("unknown7", 0);
  7358. packet->setDataByName("unknown8", 0);
  7359. packet->setDataByName("unknown9", 0);
  7360. packet->setDataByName("unknown10", 0);
  7361. packet->setDataByName("unknown11", 0);
  7362. packet->setDataByName("unknown12", 0);
  7363. packet->setDataByName("heat_resist", player_to_inspect->GetHeatResistance());
  7364. packet->setDataByName("heat_resist_base", player_to_inspect->GetHeatResistanceBase());
  7365. packet->setDataByName("heat_resist_percentage", 0);
  7366. packet->setDataByName("cold_resist", player_to_inspect->GetColdResistance());
  7367. packet->setDataByName("cold_resist_base", player_to_inspect->GetColdResistanceBase());
  7368. packet->setDataByName("cold_resist_percentage", 0);
  7369. packet->setDataByName("magic_resist", player_to_inspect->GetMagicResistance());
  7370. packet->setDataByName("magic_resist_base", player_to_inspect->GetMagicResistanceBase());
  7371. packet->setDataByName("magic_resist_percentage", 0);
  7372. packet->setDataByName("mental_resist", player_to_inspect->GetMentalResistance());
  7373. packet->setDataByName("mental_resist_base", player_to_inspect->GetMentalResistanceBase());
  7374. packet->setDataByName("mental_resist_percentage", 0);
  7375. packet->setDataByName("divine_resist", player_to_inspect->GetDivineResistance());
  7376. packet->setDataByName("divine_resist_base", player_to_inspect->GetDivineResistanceBase());
  7377. packet->setDataByName("divine_resist_percentage", 0);
  7378. packet->setDataByName("disease_resist", player_to_inspect->GetDiseaseResistance());
  7379. packet->setDataByName("disease_resist_base", player_to_inspect->GetDiseaseResistanceBase());
  7380. packet->setDataByName("disease_resist_percentage", 0);
  7381. packet->setDataByName("poison_resist", player_to_inspect->GetPoisonResistance());
  7382. packet->setDataByName("poison_resist_base", player_to_inspect->GetPoisonResistanceBase());
  7383. packet->setDataByName("poison_resist_percentage", 0);
  7384. packet->setArrayLengthByName("num_chars", 0x01FF);
  7385. string biography = player_to_inspect->GetBiography();
  7386. for (size_t i = 0; i < biography.length(); i++)
  7387. packet->setArrayDataByName("biography_char", biography[i], i);
  7388. LogWrite(MISC__TODO, 0, "TODO", "Why is inspect player weapons commented out? in func: %s, line: %i", __FUNCTION__, __LINE__);
  7389. /*Item* pw = player_to_inspect->GetEquipmentList()->GetItem(0);
  7390. if (pw)
  7391. packet->setItemByName("primary", pw, player_to_inspect, 0);
  7392. Item* sw = player_to_inspect->GetEquipmentList()->GetItem(1);
  7393. if (sw)
  7394. packet->setItemByName("secondary", sw, player_to_inspect, 0);*/
  7395. //DumpPacket(packet->serialize());
  7396. QueuePacket(packet->serialize());
  7397. safe_delete(packet);
  7398. }
  7399. }
  7400. }
  7401. void Client::SetPendingGuildInvite(Guild* guild, Player* invited_by) {
  7402. pending_guild_invite.guild = guild;
  7403. pending_guild_invite.invited_by = invited_by;
  7404. }
  7405. void Client::ShowClaimWindow() {
  7406. PacketStruct* packet = configReader.getStruct("WS_PromoFlagsDetails", GetVersion());
  7407. if (packet) {
  7408. map<int32, Item*>* items = &master_item_list.items;
  7409. map<int32, Item*>::iterator itr;
  7410. int32 i = 0;
  7411. if (items->size() > 10)
  7412. packet->setArrayLengthByName("num_claim_items", 10);
  7413. else
  7414. packet->setArrayLengthByName("num_claim_items", items->size());
  7415. for (itr = items->begin(); itr != items->end(); itr++) {
  7416. if (i == 10)
  7417. break;
  7418. Item* item = itr->second;
  7419. packet->setArrayDataByName("id", i, i);
  7420. packet->setArrayDataByName("not_yet_claimed", 1, i);
  7421. packet->setArrayDataByName("num_remaining", 5, i);
  7422. packet->setArrayDataByName("one_per_character", 1, i);
  7423. packet->setArrayDataByName("claimed_on_this_char", 0, i);
  7424. packet->setArrayDataByName("item_name", item->name.c_str(), i);
  7425. packet->setArrayDataByName("text", "If you ever see this text, let Scatman know, thanks! :)", i);
  7426. packet->setArrayDataByName("category", "Scott's Shit", i);
  7427. packet->setArrayDataByName("icon", item->details.icon, i);
  7428. packet->setArrayDataByName("item_id", item->details.item_id, i);
  7429. i++;
  7430. }
  7431. packet->setDataByName("unknown3", 1);
  7432. QueuePacket(packet->serialize());
  7433. safe_delete(packet);
  7434. }
  7435. }
  7436. void Client::ShowGuildSearchWindow() {
  7437. PacketStruct* packet = configReader.getStruct("WS_GuildRecruiting", GetVersion());
  7438. if (packet) {
  7439. MutexMap<int32, Guild*>* guilds = guild_list.GetGuilds();
  7440. MutexMap<int32, Guild*>::iterator itr = guilds->begin();
  7441. packet->setArrayLengthByName("num_guilds", guilds->size());
  7442. int32 i = 0;
  7443. while (itr.Next()) {
  7444. Guild* guild = itr.second;
  7445. packet->setArrayDataByName("guild_id", guild->GetID(), i);
  7446. packet->setArrayDataByName("guild_name", guild->GetName(), i);
  7447. packet->setArrayDataByName("recruiting_short_description", guild->GetRecruitingShortDesc().c_str(), i);
  7448. packet->setArrayDataByName("descriptive_tag1", guild->GetRecruitingDescTag(0), i);
  7449. packet->setArrayDataByName("descriptive_tag2", guild->GetRecruitingDescTag(1), i);
  7450. packet->setArrayDataByName("descriptive_tag3", guild->GetRecruitingDescTag(2), i);
  7451. packet->setArrayDataByName("descriptive_tag4", guild->GetRecruitingDescTag(3), i);
  7452. packet->setArrayDataByName("playstyle", guild->GetRecruitingPlayStyle(), i);
  7453. packet->setArrayDataByName("looking_for", guild->GetRecruitingLookingForPacketValue(), i); //tradeskillers, fighters, new
  7454. packet->setArrayDataByName("unknown7", 0x02, i);
  7455. packet->setArrayDataByName("min_level", guild->GetRecruitingMinLevel(), i);
  7456. i++;
  7457. }
  7458. QueuePacket(packet->serialize());
  7459. safe_delete(packet);
  7460. }
  7461. }
  7462. void Client::ShowDressingRoom(Item* item, sint32 crc) {
  7463. PacketStruct* packet;
  7464. vector<int8>* slot_data;
  7465. vector<int8>::iterator itr;
  7466. int32 slots = 0;
  7467. assert(item);
  7468. if (!(packet = configReader.getStruct("WS_DressingRoom", GetVersion()))) {
  7469. return;
  7470. }
  7471. slot_data = &item->slot_data;
  7472. for (itr = slot_data->begin(); itr != slot_data->end(); itr++) {
  7473. if (version >= 1188)
  7474. slots = *itr;
  7475. else
  7476. slots += (int8)pow(2.0, *itr);
  7477. }
  7478. packet->setDataByName("slot", slots);
  7479. packet->setDataByName("appearance_id", item->generic_info.appearance_id);
  7480. if (slots == 2) {
  7481. packet->setDataByName("rgb", item->generic_info.appearance_red, 2);
  7482. packet->setDataByName("rgb", item->generic_info.appearance_blue, 0);
  7483. }
  7484. else {
  7485. packet->setDataByName("rgb", item->generic_info.appearance_red, 0);
  7486. packet->setDataByName("rgb", item->generic_info.appearance_blue, 2);
  7487. }
  7488. packet->setDataByName("rgb", item->generic_info.appearance_green, 1);
  7489. if (slots == 4) {
  7490. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 2);
  7491. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7492. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 0);
  7493. }
  7494. else if (slots == 7) {
  7495. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 1);
  7496. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 0);
  7497. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7498. }
  7499. else {
  7500. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_red, 0);
  7501. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_green, 1);
  7502. packet->setDataByName("highlight_rgb", item->generic_info.appearance_highlight_blue, 2);
  7503. }
  7504. packet->setDataByName("icon", item->details.icon);
  7505. packet->setDataByName("item_id", item->details.item_id);
  7506. packet->setDataByName("item_crc", crc);
  7507. packet->setDataByName("unknown2", 0xFFFFFFFF);
  7508. packet->setDataByName("unknown4", 0xFFFFFFFF);
  7509. packet->setDataByName("unknown5", 0xFF, 9);
  7510. packet->setDataByName("unknown5", 0xFF, 10);
  7511. QueuePacket(packet->serialize());
  7512. safe_delete(packet);
  7513. }
  7514. void Client::SendCollectionList() {
  7515. map<int32, Collection*>* collections = player->GetCollectionList()->GetCollections();
  7516. map<int32, Collection*>::iterator itr;
  7517. vector<struct CollectionItem*>* collection_items;
  7518. Collection* collection;
  7519. struct CollectionItem* collection_item;
  7520. PacketStruct* packet = 0;
  7521. int16 i = 0, j;
  7522. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version)))
  7523. return;
  7524. packet->setArrayLengthByName("num_collections", collections->size());
  7525. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7526. collection = itr->second;
  7527. collection_items = collection->GetCollectionItems();
  7528. packet->setArrayDataByName("unknown", 1, i);
  7529. packet->setArrayDataByName("collection_name", collection->GetName(), i);
  7530. packet->setArrayDataByName("collection_category", collection->GetCategory(), i);
  7531. packet->setArrayDataByName("completed", collection->GetCompleted(), i);
  7532. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7533. packet->setArrayDataByName("level", collection->GetLevel(), i);
  7534. packet->setArrayDataByName("ready_to_turn_in", collection->GetIsReadyToTurnIn(), i);
  7535. packet->setSubArrayLengthByName("num_items", collection_items->size(), i);
  7536. for (j = 0; j < collection_items->size(); j++) {
  7537. collection_item = collection_items->at(j);
  7538. Item* item = master_item_list.GetItem(collection_item->item);
  7539. if (item) {
  7540. packet->setSubArrayDataByName("item_icon", item->details.icon, i, j);
  7541. if (version < 955)
  7542. packet->setSubArrayDataByName("item_name", item->name.c_str(), i, j);
  7543. else
  7544. packet->setSubArrayDataByName("item_id", item->details.item_id, i, j);
  7545. }
  7546. packet->setSubArrayDataByName("item_flag", collection_item->found, i, j);
  7547. }
  7548. i++;
  7549. }
  7550. packet->setDataByName("new_collection_flag", 1);
  7551. QueuePacket(packet->serialize());
  7552. safe_delete(packet);
  7553. }
  7554. bool Client::SendCollectionsForItem(Item* item) {
  7555. map<int32, Collection*> collections_to_send;
  7556. map<int32, Collection*>* collections;
  7557. map<int32, Collection*>::iterator itr;
  7558. vector<struct CollectionItem*>* collection_items;
  7559. Collection* collection;
  7560. struct CollectionItem* collection_item;
  7561. PacketStruct* packet;
  7562. int16 i;
  7563. assert(item);
  7564. /* get any collections required by this item that the player already has */
  7565. collections = player->GetCollectionList()->GetCollections();
  7566. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7567. collection = itr->second;
  7568. if (!collection->GetCompleted() && !collection->GetIsReadyToTurnIn() && collection->NeedsItem(item)) {
  7569. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from player list %u\n", collection->GetID());
  7570. collections_to_send[collection->GetID()] = collection;
  7571. }
  7572. }
  7573. /* get any collections required by this item that the player does not have and send it to the client */
  7574. collections = master_collection_list.GetCollections();
  7575. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7576. collection = itr->second;
  7577. if (collection->NeedsItem(item) && !player->GetCollectionList()->GetCollection(collection->GetID())) {
  7578. if (!(packet = configReader.getStruct("WS_CollectionUpdate", version))) {
  7579. return false;
  7580. }
  7581. packet->setArrayLengthByName("num_collections", 1);
  7582. packet->setArrayDataByName("unknown", 1, 0);
  7583. packet->setArrayDataByName("collection_name", collection->GetName(), 0);
  7584. packet->setArrayDataByName("collection_category", collection->GetCategory(), 0);
  7585. packet->setArrayDataByName("completed", 0, 0);
  7586. packet->setArrayDataByName("collection_id", collection->GetID(), 0);
  7587. packet->setArrayDataByName("level", collection->GetLevel(), 0);
  7588. packet->setArrayDataByName("ready_to_turn_in", 0, 0);
  7589. packet->setArrayDataByName("unknown3", 0x28, 0);
  7590. collection_items = collection->GetCollectionItems();
  7591. packet->setSubArrayLengthByName("num_items", collection_items->size(), 0);
  7592. for (i = 0; i < collection_items->size(); i++) {
  7593. collection_item = collection_items->at(i);
  7594. Item* item2 = master_item_list.GetItem(collection_item->item);
  7595. if (item2) {
  7596. packet->setSubArrayDataByName("item_icon", item2->details.icon, 0, i);
  7597. if (version < 955)
  7598. packet->setSubArrayDataByName("item_name", item2->name.c_str(), 0, i);
  7599. else
  7600. packet->setSubArrayDataByName("item_id", item2->details.item_id, 0, i);
  7601. packet->setSubArrayDataByName("item_flag", collection_item->found, 0, i);
  7602. }
  7603. }
  7604. packet->setDataByName("new_collection_flag", 0);
  7605. QueuePacket(packet->serialize());
  7606. safe_delete(packet);
  7607. LogWrite(COLLECTION__DEBUG, 0, "Collect", "Adding collection from master list %u\n", collection->GetID());
  7608. collections_to_send[collection->GetID()] = collection;
  7609. }
  7610. }
  7611. /* send the client a list of collections that should be filtered for this item */
  7612. if (collections_to_send.size() > 0) {
  7613. if (!(packet = configReader.getStruct("WS_CollectionFilter", version))) {
  7614. return false;
  7615. }
  7616. i = 0;
  7617. packet->setArrayLengthByName("num_filters", collections_to_send.size());
  7618. for (itr = collections_to_send.begin(); itr != collections_to_send.end(); itr++) {
  7619. collection = itr->second;
  7620. packet->setArrayDataByName("collection_id", collection->GetID(), i);
  7621. packet->setArrayDataByName("collection_item_num", collection->GetCollectionItemByItemID(item->details.item_id)->index, i);
  7622. i++;
  7623. }
  7624. packet->setDataByName("item_icon", item->details.icon);
  7625. packet->setDataByName("item_name", item->name.c_str());
  7626. packet->setDataByName("item_id", item->details.item_id);
  7627. packet->setDataByName("unknown3", player->GetCollectionList()->Size());
  7628. QueuePacket(packet->serialize());
  7629. safe_delete(packet);
  7630. }
  7631. return collections_to_send.size() > 0;
  7632. }
  7633. void Client::HandleCollectionAddItem(int32 collection_id, Item* item) {
  7634. Collection* collection;
  7635. struct CollectionItem* collection_item;
  7636. PacketStruct* packet;
  7637. char tmp[200] = { 0 };
  7638. assert(item);
  7639. /* first try to get the collection from the player's collection list. if it's not found, get it from the master list */
  7640. if ((collection = player->GetCollectionList()->GetCollection(collection_id))) {
  7641. /* get the item struct that represents the item for this collection */
  7642. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7643. SendCollectionList();
  7644. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7645. return;
  7646. }
  7647. /* sanity check */
  7648. if (collection_item->found) {
  7649. SendCollectionList();
  7650. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' has already found item '%s' for collection '%s'", player->GetName(), item->name.c_str(), collection->GetName());
  7651. return;
  7652. }
  7653. }
  7654. else if ((collection = master_collection_list.GetCollection(collection_id))) {
  7655. collection = new Collection(collection);
  7656. /* get the item struct that represents the item for this collection */
  7657. if (!(collection_item = collection->GetCollectionItemByItemID(item->details.item_id))) {
  7658. SendCollectionList();
  7659. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find item '%s' required by collection '%s'", item->name.c_str(), collection->GetName());
  7660. safe_delete(collection);
  7661. return;
  7662. }
  7663. /* add the new collection to the player's collection list */
  7664. if (!player->GetCollectionList()->AddCollection(collection)) {
  7665. SendCollectionList();
  7666. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Player '%s' already has collection '%s'", player->GetName(), collection->GetName());
  7667. safe_delete(collection);
  7668. return;
  7669. }
  7670. }
  7671. else {
  7672. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find collection with id %u", collection_id);
  7673. return;
  7674. }
  7675. collection_item->found = 1;
  7676. collection->SetSaveNeeded(true);
  7677. if (!(packet = configReader.getStruct("WS_CollectionItem", version))) {
  7678. SendCollectionList();
  7679. LogWrite(COLLECTION__ERROR, 0, "Collect", "Error in Client::HandleCollectionAddItem. Could not find struct 'WS_CollectionItem'");
  7680. return;
  7681. }
  7682. packet->setDataByName("collection_id", collection_id);
  7683. packet->setDataByName("collection_item_num", collection_item->index);
  7684. packet->setDataByName("add", 1);
  7685. QueuePacket(packet->serialize());
  7686. Item* item2 = master_item_list.GetItem(collection_item->item);
  7687. if (item2) {
  7688. Message(CHANNEL_COLOR_YELLOW, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7689. sprintf(tmp, "You added: %s to %s", item2->name.c_str(), collection->GetName());
  7690. SendPopupMessage(5, tmp, "quest_item", 3.5, 0x64, 0xFF, 0xFF);
  7691. }
  7692. safe_delete(packet);
  7693. RemoveItem(item, 1);
  7694. SendCollectionList();
  7695. }
  7696. void Client::DisplayCollectionComplete(Collection* collection) {
  7697. vector<struct CollectionRewardItem*>* reward_items;
  7698. vector<struct CollectionRewardItem*>* selectable_reward_items;
  7699. struct CollectionRewardItem* reward_item;
  7700. PacketStruct* packet;
  7701. int32 i;
  7702. assert(collection);
  7703. if (!(packet = configReader.getStruct("WS_QuestComplete", version))) {
  7704. return;
  7705. }
  7706. reward_items = collection->GetRewardItems();
  7707. selectable_reward_items = collection->GetSelectableRewardItems();
  7708. packet->setDataByName("title", "Quest Reward!");
  7709. packet->setDataByName("name", collection->GetName());
  7710. packet->setDataByName("description", collection->GetCategory());
  7711. packet->setDataByName("level", collection->GetLevel());
  7712. packet->setDataByName("max_coin", collection->GetRewardCoin());
  7713. packet->setDataByName("min_coin", collection->GetRewardCoin());
  7714. //packet->setDataByName("status_points", quest->GetStatusPoints());
  7715. packet->setArrayLengthByName("num_rewards", reward_items->size());
  7716. for (i = 0; i < reward_items->size(); i++) {
  7717. reward_item = reward_items->at(i);
  7718. packet->setArrayDataByName("reward_id", reward_item->item->details.item_id, i);
  7719. if (version < 860)
  7720. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, -1);
  7721. else if (version < 1193)
  7722. packet->setItemArrayDataByName("item", reward_item->item, player, i);
  7723. else
  7724. packet->setItemArrayDataByName("item", reward_item->item, player, i, 0, 2);
  7725. }
  7726. packet->setArrayLengthByName("num_select_rewards", selectable_reward_items->size());
  7727. for (i = 0; i < selectable_reward_items->size(); i++) {
  7728. reward_item = selectable_reward_items->at(i);
  7729. packet->setArrayDataByName("select_reward_id", reward_item->item->details.item_id, i);
  7730. if (version < 860)
  7731. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, -1);
  7732. else if (version < 1193)
  7733. packet->setItemArrayDataByName("select_item", reward_item->item, player, i);
  7734. else
  7735. packet->setItemArrayDataByName("select_item", reward_item->item, player, i, 0, 2);
  7736. }
  7737. QueuePacket(packet->serialize());
  7738. safe_delete(packet);
  7739. }
  7740. void Client::HandInCollections() {
  7741. map<int32, Collection*>* collections;
  7742. map<int32, Collection*>::iterator itr;
  7743. Collection* collection;
  7744. /* only show 1 collection reward dialog at a time */
  7745. if (player->GetPendingCollectionReward()) {
  7746. return;
  7747. }
  7748. collections = player->GetCollectionList()->GetCollections();
  7749. /* we only want to display 1 collection reward dialog at a time. so once we find one to display, send it and return. once the player accepts the reward
  7750. for this collection, this function gets called again and the process repeats until there are no more collections to hand in */
  7751. for (itr = collections->begin(); itr != collections->end(); itr++) {
  7752. collection = itr->second;
  7753. if (collection->GetIsReadyToTurnIn()) {
  7754. player->SetPendingCollectionReward(collection);
  7755. DisplayCollectionComplete(collection);
  7756. return;
  7757. }
  7758. }
  7759. }
  7760. void Client::AcceptCollectionRewards(Collection* collection, int32 selectable_item_id) {
  7761. vector<struct CollectionRewardItem*>* reward_items;
  7762. vector<struct CollectionRewardItem*>::iterator itr;
  7763. struct CollectionRewardItem* reward_item;
  7764. int16 num_slots_needed;
  7765. int16 num_slots;
  7766. assert(collection);
  7767. reward_items = collection->GetRewardItems();
  7768. num_slots_needed = (int16)reward_items->size();
  7769. if (selectable_item_id > 0)
  7770. num_slots_needed++;
  7771. num_slots = player->GetPlayerItemList()->GetNumberOfFreeSlots();
  7772. if (num_slots < num_slots_needed) {
  7773. SimpleMessage(CHANNEL_COLOR_RED, "You do not have enough free slots. Free up some slots and try again");
  7774. HandInCollections();
  7775. return;
  7776. }
  7777. /* add manditory items */
  7778. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7779. reward_item = *itr;
  7780. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7781. }
  7782. /* find and add the selectable item if there's one */
  7783. if (selectable_item_id > 0) {
  7784. reward_items = collection->GetSelectableRewardItems();
  7785. for (itr = reward_items->begin(); itr != reward_items->end(); itr++) {
  7786. reward_item = *itr;
  7787. if (reward_item->item->details.item_id == selectable_item_id) {
  7788. AddItem(reward_item->item->details.item_id, reward_item->quantity);
  7789. break;
  7790. }
  7791. }
  7792. }
  7793. if (collection->GetRewardXP() > 0) {
  7794. player->AddXP((int32)collection->GetRewardXP());
  7795. SimpleMessage(CHANNEL_COLOR_YELLOW, "You gain experience!");
  7796. }
  7797. if (collection->GetRewardCoin() > 0) {
  7798. player->AddCoins(collection->GetRewardCoin());
  7799. Message(CHANNEL_COLOR_YELLOW, "You receive %s", GetCoinMessage(collection->GetRewardCoin()).c_str());
  7800. }
  7801. collection->SetCompleted(true);
  7802. //update achievements for completeing collection here
  7803. collection->SetSaveNeeded(true);
  7804. SendCollectionList();
  7805. /* reset the pending collection reward and check for my collections that the player needs to hand in */
  7806. player->SetPendingCollectionReward(0);
  7807. HandInCollections();
  7808. }
  7809. void Client::SendRecipeList() {
  7810. PacketStruct* packet = 0;
  7811. if (GetRecipeListSent()) {
  7812. return;
  7813. }
  7814. if (!(packet = configReader.getStruct("WS_RecipeList", version))) {
  7815. return;
  7816. }
  7817. map<int32, Recipe*>* recipes = player->GetRecipeList()->GetRecipes();
  7818. map<int32, Recipe*>::iterator itr;
  7819. Recipe* recipe;
  7820. int16 i = 0;
  7821. packet->setArrayLengthByName("num_recipes", recipes->size());
  7822. for (itr = recipes->begin(); itr != recipes->end(); itr++) {
  7823. recipe = itr->second;
  7824. packet->setArrayDataByName("id", recipe->GetID(), i);
  7825. packet->setArrayDataByName("tier", recipe->GetTier(), i);
  7826. packet->setArrayDataByName("level", recipe->GetLevel(), i);
  7827. packet->setArrayDataByName("icon", recipe->GetIcon(), i);
  7828. packet->setArrayDataByName("classes", recipe->GetClasses(), i);
  7829. packet->setArrayDataByName("skill", recipe->GetSkill(), i);
  7830. packet->setArrayDataByName("technique", recipe->GetTechnique(), i);
  7831. packet->setArrayDataByName("knowledge", recipe->GetKnowledge(), i);
  7832. packet->setArrayDataByName("unknown2", recipe->GetUnknown2(), i);
  7833. packet->setArrayDataByName("recipe_name", recipe->GetName(), i);
  7834. packet->setArrayDataByName("recipe_book", recipe->GetBook(), i);
  7835. packet->setArrayDataByName("unknown3", recipe->GetUnknown3(), i);
  7836. i++;
  7837. }
  7838. //packet->PrintPacket();
  7839. //DumpPacket(packet->serialize());
  7840. QueuePacket(packet->serialize());
  7841. safe_delete(packet);
  7842. SetRecipeListSent(true);
  7843. }
  7844. void Client::ShowRecipeBook() {
  7845. PacketStruct* packet = 0;
  7846. Spawn* target = 0;
  7847. if (!(target = player->GetTarget())) {
  7848. SimpleMessage(CHANNEL_COLOR_YELLOW, "You do not have a tradeskill device targeted");
  7849. return;
  7850. }
  7851. if (!target->IsObject()) {
  7852. return;
  7853. }
  7854. if (!(packet = configReader.getStruct("WS_ShowRecipeBook", version))) {
  7855. return;
  7856. }
  7857. packet->setDataByName("device", target->GetName());
  7858. packet->setDataByName("unknown1", 1);
  7859. if (((Object*)target)->GetDeviceID() > 0) {
  7860. int32 deviceID = (int32)pow(2.0, (double)((Object*)target)->GetDeviceID());
  7861. //LogWrite(TRADESKILL__ERROR, 0, "Tradeskills", "GetDeviceID() = %u, deviceID = %u", ((Object*)target)->GetDeviceID(), deviceID);
  7862. packet->setDataByName("unknown2", 8);
  7863. packet->setDataByName("unknown3", deviceID);
  7864. }
  7865. //packet->PrintPacket();
  7866. QueuePacket(packet->serialize());
  7867. safe_delete(packet);
  7868. }
  7869. void Client::SendTitleUpdate() {
  7870. list<Title*>* titles = player->GetPlayerTitles()->GetAllTitles();
  7871. list<Title*>::iterator itr;
  7872. Title* title;
  7873. int16 i = 0;
  7874. sint16 prefix_index = database.GetCharPrefixIndex(GetCharacterID(), player);
  7875. sint16 suffix_index = database.GetCharSuffixIndex(GetCharacterID(), player);
  7876. PacketStruct* packet = configReader.getStruct("WS_TitleUpdate", GetVersion());
  7877. if (packet) {
  7878. packet->setArrayLengthByName("num_titles", titles->size());
  7879. for (itr = titles->begin(); itr != titles->end(); itr++) {
  7880. title = *itr;
  7881. packet->setArrayDataByName("title", title->GetName(), i);
  7882. packet->setArrayDataByName("prefix", title->GetPrefix(), i);
  7883. i++;
  7884. }
  7885. packet->setDataByName("current_prefix", prefix_index);
  7886. packet->setDataByName("current_suffix", suffix_index);
  7887. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7888. #if EQDEBUG >= 9
  7889. packet->PrintPacket();
  7890. #endif
  7891. QueuePacket(packet->serialize());
  7892. safe_delete(packet);
  7893. SendUpdateTitles(prefix_index, suffix_index);
  7894. }
  7895. }
  7896. void Client::SendUpdateTitles(sint16 prefix, sint16 suffix) {
  7897. Title* suffix_title = 0;
  7898. Title* prefix_title = 0;
  7899. if (suffix != -1) {
  7900. suffix_title = player->GetPlayerTitles()->GetTitle(suffix);
  7901. strcpy(player->appearance.suffix_title, suffix_title->GetName());
  7902. }
  7903. else
  7904. memset(player->appearance.suffix_title, 0, strlen(player->appearance.suffix_title));
  7905. if (prefix != -1) {
  7906. prefix_title = player->GetPlayerTitles()->GetTitle(prefix);
  7907. strcpy(player->appearance.prefix_title, prefix_title->GetName());
  7908. }
  7909. else
  7910. memset(player->appearance.prefix_title, 0, strlen(player->appearance.prefix_title));
  7911. current_zone->SendUpdateTitles(this, suffix_title, prefix_title);
  7912. }
  7913. void Client::SendLanguagesUpdate(int32 id) {
  7914. list<Language*>* languages = player->GetPlayerLanguages()->GetAllLanguages();
  7915. list<Language*>::iterator itr;
  7916. Language* language;
  7917. int32 i = 0;
  7918. PacketStruct* packet = configReader.getStruct("WS_Languages", GetVersion());
  7919. if (packet) {
  7920. packet->setArrayLengthByName("num_languages", languages->size());
  7921. for (itr = languages->begin(); itr != languages->end(); itr++) {
  7922. language = *itr;
  7923. packet->setArrayDataByName("language_id", language->GetID(), i);
  7924. i++;
  7925. }
  7926. packet->setDataByName("current_language", id);
  7927. LogWrite(CCLIENT__PACKET, 0, "Client", "Dump/Print Packet in func: %s, line: %i", __FUNCTION__, __LINE__);
  7928. #if EQDEBUG >= 9
  7929. packet->PrintPacket();
  7930. #endif
  7931. QueuePacket(packet->serialize());
  7932. safe_delete(packet);
  7933. }
  7934. }
  7935. void Client::SendPetOptionsWindow(const char* pet_name, int8 type) {
  7936. PacketStruct* packet = configReader.getStruct("WS_PetOptions", GetVersion());
  7937. if (packet) {
  7938. if (pet_name)
  7939. packet->setDataByName("pet_name", pet_name);
  7940. if (player->GetInfoStruct()->pet_behavior & 1)
  7941. packet->setDataByName("protect_master", 1);
  7942. if (player->GetInfoStruct()->pet_behavior & 2)
  7943. packet->setDataByName("protect_self", 1);
  7944. if (player->GetInfoStruct()->pet_movement == 2)
  7945. packet->setDataByName("stay_follow_toggle", 1);
  7946. packet->setDataByName("pet_type", type);
  7947. QueuePacket(packet->serialize());
  7948. }
  7949. safe_delete(packet);
  7950. }
  7951. bool Client::IsCrafting() {
  7952. return current_zone->GetTradeskillMgr()->IsClientCrafting(this);
  7953. }
  7954. void Client::SendBiography() {
  7955. PacketStruct* packet = configReader.getStruct("WS_BioUpdate", GetVersion());
  7956. if (packet) {
  7957. if (strlen(player->GetInfoStruct()->biography) > 0)
  7958. packet->setDataByName("biography", player->GetInfoStruct()->biography);
  7959. QueuePacket(packet->serialize());
  7960. }
  7961. safe_delete(packet);
  7962. }
  7963. PendingResurrection* Client::GetCurrentRez() {
  7964. return &current_rez;
  7965. }
  7966. Mutex* Client::GetResurrectMutex() {
  7967. return &m_resurrect;
  7968. }
  7969. void Client::SendResurrectionWindow() {
  7970. Spawn* caster = current_rez.caster;
  7971. if (!caster || !player)
  7972. return;
  7973. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  7974. if (!packet)
  7975. return;
  7976. char* tmp = new char[512];
  7977. sprintf(tmp, "%s would like to cast '%s' on you. Do you accept?", caster->GetName(), current_rez.spell_name.c_str());
  7978. packet->setMediumStringByName("text", tmp);
  7979. packet->setMediumStringByName("accept_text", "Yes");
  7980. packet->setMediumStringByName("cancel_text", "No");
  7981. sprintf(tmp, "accept_resurrection %u", player->GetID());
  7982. packet->setMediumStringByName("accept_command", tmp);
  7983. sprintf(tmp, "decline_resurrection %u", player->GetID());
  7984. packet->setMediumStringByName("cancel_command", tmp);
  7985. packet->setDataByName("time", current_rez.expire_timer->GetRemainingTime() / 1000);
  7986. QueuePacket(packet->serialize());
  7987. safe_delete(packet);
  7988. safe_delete_array(tmp);
  7989. }
  7990. void Client::AcceptResurrection() {
  7991. Spawn* caster = current_rez.caster;
  7992. if (!player || !caster)
  7993. return;
  7994. if (player->Alive())
  7995. return;
  7996. if ((caster->GetZone() != player->GetZone()) || (current_rez.range > 0 && player->GetDistance(caster) > current_rez.range)) {
  7997. SimpleMessage(CHANNEL_COLOR_YELLOW, "The caster must be nearby to complete the spell.");
  7998. SendResurrectionWindow();
  7999. return;
  8000. }
  8001. player->GetZone()->ResurrectSpawn(player, this);
  8002. current_rez.should_delete = true;
  8003. }
  8004. void Client::SetPendingLastName(string last_name) {
  8005. pending_last_name = new string;
  8006. pending_last_name->assign(last_name);
  8007. }
  8008. string* Client::GetPendingLastName() {
  8009. return pending_last_name;
  8010. }
  8011. void Client::RemovePendingLastName() {
  8012. safe_delete(pending_last_name);
  8013. }
  8014. void Client::SendLastNameConfirmation() {
  8015. if (!pending_last_name)
  8016. return;
  8017. PacketStruct* packet = configReader.getStruct("WS_ChoiceWindow", GetVersion());
  8018. if (packet) {
  8019. char* text = new char[128];
  8020. sprintf(text, "Are you sure you want your last name to be \"%s\"?", pending_last_name->c_str());
  8021. packet->setDataByName("text", text);
  8022. packet->setDataByName("accept_text", "Yes");
  8023. packet->setDataByName("accept_command", "confirmedlastname");
  8024. packet->setDataByName("cancel_text", "No");
  8025. packet->setDataByName("max_length", 50);
  8026. packet->setDataByName("unknown4", 1);
  8027. packet->setDataByName("unknown5", 1);
  8028. QueuePacket(packet->serialize());
  8029. safe_delete(packet);
  8030. safe_delete_array(text);
  8031. }
  8032. }
  8033. void Client::AddQuestTimer(int32 quest_id) {
  8034. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8035. quest_timers.push_back(quest_id);
  8036. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8037. }
  8038. void Client::RemoveQuestTimer(int32 quest_id) {
  8039. MQuestTimers.writelock(__FUNCTION__, __LINE__);
  8040. vector<int32>::iterator itr;
  8041. for (itr = quest_timers.begin(); itr != quest_timers.end(); itr++) {
  8042. if ((*itr) == quest_id) {
  8043. quest_timers.erase(itr);
  8044. break;
  8045. }
  8046. }
  8047. MQuestTimers.releasewritelock(__FUNCTION__, __LINE__);
  8048. }
  8049. void Client::SavePlayerImages() {
  8050. LogWrite(CCLIENT__DEBUG, 0, "Client", "Saving %s image for player %s (%u)", (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL ? "paperdoll" : "headshot"), GetPlayer()->GetName(), GetCharacterID());
  8051. // Save the paperdoll image if the server allows it
  8052. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_FULL && rule_manager.GetGlobalRule(R_World, SavePaperdollImage)->GetBool())
  8053. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8054. if (incoming_paperdoll.image_type == PAPERDOLL_TYPE_HEAD) {
  8055. // Save the head shot if the server allows it
  8056. if (rule_manager.GetGlobalRule(R_World, SaveHeadshotImage)->GetBool())
  8057. database.SaveCharacterPicture(GetCharacterID(), incoming_paperdoll.image_type, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8058. // Send the head shot to the login server
  8059. if (rule_manager.GetGlobalRule(R_World, SendPaperdollImagesToLogin)->GetBool()) {
  8060. int32 size = incoming_paperdoll.current_size_bytes + CHARPICSTRUCT_MINSIZE;
  8061. ServerPacket* packet = new ServerPacket(ServerOP_CharacterPicture, size);
  8062. memset(packet->pBuffer, 0, size);
  8063. CharPictureUpdate_Struct* pic = (CharPictureUpdate_Struct*)packet->pBuffer;
  8064. pic->account_id = GetAccountID();
  8065. pic->char_id = GetCharacterID();
  8066. pic->pic_size = (int16)incoming_paperdoll.current_size_bytes;
  8067. memcpy(pic->pic, incoming_paperdoll.image_bytes, incoming_paperdoll.current_size_bytes);
  8068. loginserver.SendPacket(packet);
  8069. safe_delete(packet);
  8070. }
  8071. }
  8072. safe_delete_array(incoming_paperdoll.image_bytes);
  8073. incoming_paperdoll.current_size_bytes = 0;
  8074. }
  8075. void Client::EndAutoMount() {
  8076. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8077. if (packet) {
  8078. packet->setDataByName("parameter1", 128);
  8079. packet->setDataByName("parameter2", 64);
  8080. packet->setDataByName("value", 1);
  8081. QueuePacket(packet->serialize());
  8082. safe_delete(packet);
  8083. }
  8084. packet = configReader.getStruct("WS_ServerControlFlags", GetVersion());
  8085. if (packet) {
  8086. packet->setDataByName("parameter3", 4);
  8087. packet->setDataByName("parameter5", 2);
  8088. packet->setDataByName("value", 0);
  8089. QueuePacket(packet->serialize());
  8090. safe_delete(packet);
  8091. }
  8092. packet = configReader.getStruct("WS_ClearForLanding", GetVersion());
  8093. if (packet) {
  8094. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(GetPlayer()));
  8095. QueuePacket(packet->serialize());
  8096. safe_delete(packet);
  8097. }
  8098. on_auto_mount = false;
  8099. player->SetMount(((Player*)player)->GetTempMount());
  8100. EQ2_Color mount_color = player->GetTempMountColor();
  8101. EQ2_Color saddle_color = player->GetTempMountSaddleColor();
  8102. player->SetMountColor(&mount_color);
  8103. player->SetMountSaddleColor(&saddle_color);
  8104. player->SetTempMount(0);
  8105. }
  8106. bool Client::EntityCommandPrecheck(Spawn* spawn, const char* command) {
  8107. const char* spawn_script = spawn->GetSpawnScript();
  8108. bool should_use_spawn = true;
  8109. if (spawn_script) {
  8110. lua_State* state = lua_interface->GetSpawnScript(spawn_script);
  8111. if (state) {
  8112. Mutex* state_mutex = lua_interface->GetSpawnScriptMutex(spawn_script);
  8113. if (state_mutex)
  8114. state_mutex->writelock(__FUNCTION__, __LINE__);
  8115. lua_getglobal(state, "can_use_command");
  8116. if (lua_isfunction(state, -1)) {
  8117. lua_interface->SetSpawnValue(state, spawn);
  8118. lua_interface->SetSpawnValue(state, GetPlayer());
  8119. lua_interface->SetStringValue(state, command ? command : "");
  8120. if (lua_pcall(state, 3, 1, 0) == 0) {
  8121. should_use_spawn = lua_interface->GetBooleanValue(state, 1);
  8122. }
  8123. }
  8124. lua_interface->ResetFunctionStack(state);
  8125. if (state_mutex)
  8126. state_mutex->releasewritelock(__FUNCTION__, __LINE__);
  8127. }
  8128. }
  8129. return should_use_spawn;
  8130. }
  8131. bool Client::IsCurrentTransmuteID(int32 req_id) {
  8132. return req_id == transmuteID;
  8133. }
  8134. void Client::SetTransmuteID(int32 trans_id) {
  8135. transmuteID = trans_id;
  8136. }
  8137. int32 Client::GetTransmuteID() {
  8138. return transmuteID;
  8139. }
  8140. bool Client::HandleNewLogin(int32 account_id, int32 access_code)
  8141. {
  8142. printf("HandleNewLogin: AcctID: %i AccessCode: %i\n", account_id, access_code);
  8143. ZoneAuthRequest* zar = zone_auth.GetAuth(account_id, access_code);
  8144. if (zar)
  8145. {
  8146. int32 charID = database.GetCharacterID(zar->GetCharacterName());
  8147. if (database.IsActiveQuery(charID))
  8148. {
  8149. delayedLogin = true;
  8150. delayedAccountID = account_id;
  8151. delayedAccessKey = access_code;
  8152. delayTimer.Start(500);
  8153. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Attempt to Login must be delayed, async character save in progress! ... Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  8154. return true;
  8155. }
  8156. delayedLogin = false;
  8157. delayTimer.Disable();
  8158. firstlogin = zar->isFirstLogin();
  8159. LogWrite(ZONE__INFO, 0, "ZoneAuth", "Access Key: %u, Character Name: %s, Account ID: %u, Client Data Version: %u", zar->GetAccessKey(), zar->GetCharacterName(), zar->GetAccountID(), version);
  8160. if (database.loadCharacter(zar->GetCharacterName(), zar->GetAccountID(), this)) {
  8161. GetPlayer()->vis_changed = false;
  8162. GetPlayer()->info_changed = false;
  8163. bool pvp_allowed = rule_manager.GetGlobalRule(R_PVP, AllowPVP)->GetBool();
  8164. if (pvp_allowed)
  8165. this->GetPlayer()->SetAttackable(1);
  8166. MDeletePlayer.writelock(__FUNCTION__, __LINE__);
  8167. Client* client = zone_list.GetClientByCharName(player->GetName());
  8168. if (client) {
  8169. if (client->getConnection())
  8170. client->getConnection()->SendDisconnect();
  8171. if (client->GetCurrentZone() && !client->IsZoning()) {
  8172. //swap players, allowing the client to resume his LD'd player (ONLY if same version of the client)
  8173. if (client->GetVersion() == version) {
  8174. Player* current_player = GetPlayer();
  8175. SetPlayer(client->GetPlayer());
  8176. client->SetPlayer(current_player);
  8177. client->GetPlayer()->SetPendingDeletion(true);
  8178. GetPlayer()->SetPendingDeletion(false);
  8179. GetPlayer()->ResetSavedSpawns();
  8180. GetPlayer()->SetReturningFromLD(true);
  8181. GetPlayer()->GetZone()->RemoveDelayedSpawnRemove(GetPlayer());
  8182. }
  8183. client->GetCurrentZone()->RemoveClientImmediately(client);
  8184. }
  8185. }
  8186. MDeletePlayer.releasewritelock(__FUNCTION__, __LINE__);
  8187. if (!GetCurrentZone()) {
  8188. LogWrite(ZONE__ERROR, 0, "Zone", "Error loading zone for character: %s", player->GetName());
  8189. ClientPacketFunctions::SendLoginDenied(this);
  8190. }
  8191. else if (EQOpcodeManager.count(GetOpcodeVersion(version)) > 0 && getConnection()) {
  8192. getConnection()->SetClientVersion(version);
  8193. GetCurrentZone()->SetSpawnStructs(this);
  8194. connected_to_zone = true;
  8195. client_list.Remove(this); //remove from master client list
  8196. new_client_login = true;
  8197. GetCurrentZone()->AddClient(this); //add to zones client list
  8198. zone_list.AddClientToMap(player->GetName(), this);
  8199. }
  8200. else {
  8201. LogWrite(WORLD__ERROR, 0, "World", "Incompatible version: %i", version);
  8202. ClientPacketFunctions::SendLoginDenied(this);
  8203. return false;
  8204. }
  8205. }
  8206. else {
  8207. LogWrite(WORLD__ERROR, 0, "World", "Could not load character '%s' with account id of: %u", zar->GetCharacterName(), zar->GetAccountID());
  8208. ClientPacketFunctions::SendLoginDenied(this);
  8209. }
  8210. zone_auth.RemoveAuth(zar);
  8211. }
  8212. else
  8213. {
  8214. LogWrite(WORLD__ERROR, 0, "World", "Invalid ZoneAuthRequest, disconnecting client.");
  8215. Disconnect();
  8216. }
  8217. return true;
  8218. }
  8219. void Client::SendSpawnChanges(set<Spawn*>& spawns) {
  8220. if (!IsReadyForUpdates())
  8221. return;
  8222. map<int32, SpawnData> info_changes;
  8223. map<int32, SpawnData> pos_changes;
  8224. map<int32, SpawnData> vis_changes;
  8225. map<int32, SpawnData> empty_changes;
  8226. int32 info_size = 0;
  8227. int32 pos_size = 0;
  8228. int32 vis_size = 0;
  8229. int count = 0;
  8230. for (const auto& spawn : spawns) {
  8231. int16 index = GetPlayer()->GetIndexForSpawn(spawn);
  8232. if (index == 0 || !GetPlayer()->WasSentSpawn(spawn->GetID()) || GetPlayer()->NeedsSpawnResent(spawn) || GetPlayer()->GetDistance(spawn) >= SEND_SPAWN_DISTANCE)
  8233. continue;
  8234. if (spawn->vis_changed)
  8235. {
  8236. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8237. if (vis_change) {
  8238. SpawnData data;
  8239. data.spawn = spawn;
  8240. data.data = vis_change;
  8241. data.size = spawn->vis_packet_size;
  8242. map<int32, SpawnData> tmp_vis_changes;
  8243. tmp_vis_changes[index] = data;
  8244. map<int32, SpawnData> tmp_info_changes;
  8245. map<int32, SpawnData> tmp_pos_changes;
  8246. int32 tmp_info_size = 0;
  8247. int32 tmp_pos_size = 0;
  8248. if (spawn->info_changed) {
  8249. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8250. if (info_change) {
  8251. SpawnData data;
  8252. data.spawn = spawn;
  8253. data.data = info_change;
  8254. data.size = spawn->info_packet_size;
  8255. tmp_info_size = data.size;
  8256. tmp_info_changes[index] = data;
  8257. }
  8258. }
  8259. if (spawn->position_changed) {
  8260. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8261. if (pos_change) {
  8262. SpawnData data;
  8263. data.spawn = spawn;
  8264. data.data = pos_change;
  8265. data.size = spawn->pos_packet_size;
  8266. tmp_pos_size = data.size;
  8267. tmp_pos_changes[index] = data;
  8268. }
  8269. }
  8270. MakeSpawnChangePacket(tmp_info_changes, tmp_pos_changes, tmp_vis_changes, tmp_info_size, tmp_pos_size, data.size);
  8271. continue;
  8272. }
  8273. }
  8274. if (spawn->info_changed) {
  8275. auto info_change = spawn->spawn_info_changes_ex(GetPlayer(), GetVersion());
  8276. if (info_change) {
  8277. SpawnData data;
  8278. data.spawn = spawn;
  8279. data.data = info_change;
  8280. data.size = spawn->info_packet_size;
  8281. info_size += spawn->info_packet_size;
  8282. info_changes[index] = data;
  8283. }
  8284. count++;
  8285. }
  8286. if (spawn->position_changed) {
  8287. auto pos_change = spawn->spawn_pos_changes_ex(GetPlayer(), GetVersion());
  8288. if (pos_change) {
  8289. SpawnData data;
  8290. data.spawn = spawn;
  8291. data.data = pos_change;
  8292. data.size = spawn->pos_packet_size;
  8293. pos_size += spawn->pos_packet_size;
  8294. pos_changes[index] = data;
  8295. }
  8296. count++;
  8297. }
  8298. if (spawn->vis_changed) {
  8299. auto vis_change = spawn->spawn_vis_changes_ex(GetPlayer(), GetVersion());
  8300. if (vis_change) {
  8301. SpawnData data;
  8302. data.spawn = spawn;
  8303. data.data = vis_change;
  8304. data.size = spawn->vis_packet_size;
  8305. vis_size += spawn->vis_packet_size;
  8306. vis_changes[index] = data;
  8307. }
  8308. count++;
  8309. }
  8310. }
  8311. if (info_size == 0 && pos_size == 0 && vis_size == 0) {
  8312. return;
  8313. }
  8314. MakeSpawnChangePacket(info_changes, pos_changes, vis_changes, info_size, pos_size, vis_size);
  8315. for (auto& kv : info_changes) {
  8316. safe_delete_array(kv.second.data);
  8317. }
  8318. for (auto& kv : pos_changes) {
  8319. safe_delete_array(kv.second.data);
  8320. }
  8321. for (auto& kv : vis_changes) {
  8322. safe_delete_array(kv.second.data);
  8323. }
  8324. }
  8325. void Client::MakeSpawnChangePacket(map<int32, SpawnData> info_changes, map<int32, SpawnData> pos_changes, map<int32, SpawnData> vis_changes, int32 info_size, int32 pos_size, int32 vis_size)
  8326. {
  8327. static const int8 oversized = 255;
  8328. int16 opcode_val = EQOpcodeManager[GetOpcodeVersion(version)]->EmuToEQ(OP_EqUpdateGhostCmd);
  8329. int32 size = info_size + pos_size + vis_size + 8;
  8330. if (version > 283) //version 283 and below uses an overload for size, not always 4 bytes
  8331. size += 3;
  8332. size += CheckOverLoadSize(info_size);
  8333. size += CheckOverLoadSize(pos_size);
  8334. size += CheckOverLoadSize(vis_size);
  8335. if (version <= 283 && size >= 255) {//1 byte to 3 for overloaded val
  8336. size += 2;
  8337. }
  8338. uchar* tmp = new uchar[size];
  8339. uchar* ptr = tmp;
  8340. memset(tmp, 0, size);
  8341. if (version <= 283) {
  8342. if (size >= 255) {
  8343. size -= 3;
  8344. memcpy(ptr, &oversized, sizeof(int8));
  8345. ptr += sizeof(int8);
  8346. memcpy(ptr, &size, sizeof(int16));
  8347. ptr += sizeof(int16);
  8348. size += 3;
  8349. }
  8350. else {
  8351. size -= 1;
  8352. memcpy(ptr, &size, sizeof(int8));
  8353. ptr += sizeof(int8);
  8354. size += 1;
  8355. }
  8356. }
  8357. else {
  8358. size -= 4;
  8359. memcpy(ptr, &size, sizeof(int32));
  8360. ptr += sizeof(int32);
  8361. size += 4;
  8362. }
  8363. memcpy(ptr, &oversized, sizeof(int8));
  8364. ptr += sizeof(int8);
  8365. memcpy(ptr, &opcode_val, sizeof(int16));
  8366. ptr += sizeof(int16);
  8367. int32 current_time = Timer::GetCurrentTime2();
  8368. memcpy(ptr, &current_time, sizeof(int32));
  8369. ptr += sizeof(int32);
  8370. ptr += DoOverLoad(info_size, ptr);
  8371. for (const auto& kv : info_changes) {
  8372. auto info = kv.second;
  8373. memcpy(ptr, info.data, info.size);
  8374. ptr += info.size;
  8375. }
  8376. ptr += DoOverLoad(pos_size, ptr);
  8377. for (const auto& kv : pos_changes) {
  8378. auto pos = kv.second;
  8379. memcpy(ptr, pos.data, pos.size);
  8380. ptr += pos.size;
  8381. }
  8382. ptr += DoOverLoad(vis_size, ptr);
  8383. for (const auto& kv : vis_changes) {
  8384. auto vis = kv.second;
  8385. memcpy(ptr, vis.data, vis.size);
  8386. ptr += vis.size;
  8387. }
  8388. EQ2Packet* packet = new EQ2Packet(OP_ClientCmdMsg, tmp, size);
  8389. if (packet) {
  8390. /*char blah[64];
  8391. snprintf(blah, 64, "Sending %i", current_time);
  8392. SimpleMessage(4, blah);*/
  8393. QueuePacket(packet);
  8394. }
  8395. delete[] tmp;
  8396. }
  8397. void Client::SendHailCommand(Spawn* spawn)
  8398. {
  8399. // hardcoded 'hail' entity commands
  8400. switch (spawn->secondary_command_list_id)
  8401. {
  8402. case 9:
  8403. case 1262:
  8404. case 1265:
  8405. case 1267:
  8406. {
  8407. EQ2_16BitString* command = new EQ2_16BitString();
  8408. command->data = "";
  8409. command->size = 0;
  8410. commands.Process(COMMAND_HAIL, command, this, spawn);
  8411. safe_delete(command);
  8412. break;
  8413. }
  8414. }
  8415. }
  8416. void Client::SendDefaultCommand(Spawn* spawn, const char* command, float distance)
  8417. {
  8418. if (GetPlayer()->WasSentSpawn(spawn->GetID()) && GetPlayer()->WasSpawnRemoved(spawn) == false) {
  8419. PacketStruct* packet = configReader.getStruct("WS_SetDefaultCommand", GetVersion());
  8420. if (packet) {
  8421. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8422. packet->setMediumStringByName("command_name", command);
  8423. packet->setDataByName("distance", distance);
  8424. QueuePacket(packet->serialize());
  8425. safe_delete(packet);
  8426. }
  8427. }
  8428. }
  8429. bool Client::HandleHouseEntityCommands(Spawn* spawn, int32 spawnid, string command)
  8430. {
  8431. if (GetCurrentZone()->GetInstanceType() != PERSONAL_HOUSE_INSTANCE)
  8432. return false;
  8433. if (command == "house_spawn_examine")
  8434. {
  8435. uint32 itemID = spawn->GetPickupItemID();
  8436. if (itemID)
  8437. {
  8438. Item* item = master_item_list.GetItem(itemID);
  8439. if (item)
  8440. {
  8441. EQ2Packet* app = item->serialize(GetVersion(), true, GetPlayer());
  8442. //DumpPacket(app);
  8443. QueuePacket(app);
  8444. }
  8445. }
  8446. return true;
  8447. }
  8448. return false;
  8449. }
  8450. bool Client::PopulateHouseSpawn(PacketStruct* place_object)
  8451. {
  8452. if (GetTempPlacementSpawn())
  8453. {
  8454. Spawn* tmp = GetTempPlacementSpawn();
  8455. int32 spawn_group_id = database.GetNextSpawnLocation();
  8456. tmp->SetSpawnLocationID(spawn_group_id);
  8457. float newHeading = place_object->getType_float_ByName("heading") + 180;
  8458. int32 spawnDBID = 0;
  8459. if (GetCurrentZone()->house_object_database_lookup.count(tmp->GetModelType()) > 0)
  8460. {
  8461. spawnDBID = GetCurrentZone()->house_object_database_lookup.Get(tmp->GetModelType());
  8462. tmp->SetDatabaseID(spawnDBID);
  8463. }
  8464. else
  8465. {
  8466. spawnDBID = database.FindHouseInstanceSpawn(tmp);
  8467. if (spawnDBID)
  8468. {
  8469. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), spawnDBID);
  8470. tmp->SetDatabaseID(spawnDBID);
  8471. }
  8472. }
  8473. tmp->SetX(place_object->getType_float_ByName("x"));
  8474. tmp->SetY(place_object->getType_float_ByName("y"));
  8475. tmp->SetZ(place_object->getType_float_ByName("z"));
  8476. tmp->SetHeading(newHeading);
  8477. tmp->SetSpawnOrigX(tmp->GetX());
  8478. tmp->SetSpawnOrigY(tmp->GetY());
  8479. tmp->SetSpawnOrigZ(tmp->GetZ());
  8480. tmp->SetSpawnOrigHeading(tmp->GetHeading());
  8481. database.SaveSpawnInfo(tmp);
  8482. database.SaveSpawnEntry(tmp, "houseplacement", 100, 0, 0, 0);
  8483. if (!spawnDBID)
  8484. {
  8485. GetCurrentZone()->house_object_database_lookup.Put(tmp->GetModelType(), tmp->GetDatabaseID());
  8486. GetCurrentZone()->AddObject(tmp->GetDatabaseID(), (Object*)tmp);
  8487. }
  8488. return true;
  8489. }
  8490. return false;
  8491. }
  8492. bool Client::PopulateHouseSpawnFinalize()
  8493. {
  8494. if (GetTempPlacementSpawn())
  8495. {
  8496. Spawn* tmp = GetTempPlacementSpawn();
  8497. GetCurrentZone()->AddSpawn(tmp);
  8498. GetCurrentZone()->SendSpawnChanges(tmp, this);
  8499. SetTempPlacementSpawn(nullptr);
  8500. int32 uniqueID = GetPlacementUniqueItemID();
  8501. Item* uniqueItem = GetPlayer()->item_list.GetItemFromUniqueID(uniqueID);
  8502. tmp->SetPickupItemID(uniqueItem->details.item_id);
  8503. tmp->SetPickupUniqueItemID(uniqueID);
  8504. if (uniqueItem)
  8505. {
  8506. if (GetCurrentZone()->GetInstanceType() == PERSONAL_HOUSE_INSTANCE)
  8507. {
  8508. Query query;
  8509. query.RunQuery2(Q_INSERT, "insert into spawn_instance_data set spawn_id = %u, spawn_location_id = %u, pickup_item_id = %u, pickup_unique_item_id = %u", tmp->GetDatabaseID(), tmp->GetSpawnLocationID(), tmp->GetPickupItemID(), uniqueID);
  8510. }
  8511. database.DeleteItem(GetCharacterID(), uniqueItem, 0);
  8512. GetPlayer()->item_list.RemoveItem(uniqueItem, true);
  8513. QueuePacket(GetPlayer()->SendInventoryUpdate(GetVersion()));
  8514. SetPlacementUniqueItemID(0);
  8515. }
  8516. return true;
  8517. }
  8518. return false;
  8519. }
  8520. void Client::SendMoveObjectMode(Spawn* spawn, uint8 placementMode, float unknown2_3)
  8521. {
  8522. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", GetVersion());
  8523. packet->setDataByName("placement_mode", placementMode);
  8524. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(spawn));
  8525. packet->setDataByName("model_type", spawn->GetModelType());
  8526. packet->setDataByName("unknown", 1); //size
  8527. packet->setDataByName("unknown2", 1); //size 2
  8528. packet->setDataByName("unknown2", .5, 1); //size 3
  8529. packet->setDataByName("unknown2", 3, 2);
  8530. packet->setDataByName("unknown2", unknown2_3, 3);
  8531. packet->setDataByName("max_distance", 500);
  8532. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  8533. QueuePacket(packet->serialize());
  8534. safe_delete(packet);
  8535. }
  8536. void Client::SendFlightAutoMount(int32 path_id, int16 mount_id, int8 mount_red_color, int8 mount_green_color, int8 mount_blue_color)
  8537. {
  8538. SetPendingFlightPath(path_id);
  8539. ((Player*)player)->SetTempMount(((Entity*)player)->GetMount());
  8540. ((Player*)player)->SetTempMountColor(((Entity*)player)->GetMountColor());
  8541. ((Player*)player)->SetTempMountSaddleColor(((Entity*)player)->GetMountSaddleColor());
  8542. PacketStruct* packet = configReader.getStruct("WS_ReadyForTakeOff", GetVersion());
  8543. if (packet) {
  8544. QueuePacket(packet->serialize());
  8545. safe_delete(packet);
  8546. }
  8547. if (mount_id)
  8548. ((Entity*)GetPlayer())->SetMount(mount_id, mount_red_color, mount_green_color, mount_blue_color);
  8549. }
  8550. void Client::SendShowBook(Spawn* sender, string title, int8 num_pages, ...)
  8551. {
  8552. if (!sender)
  8553. {
  8554. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8555. return;
  8556. }
  8557. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8558. if (!packet) {
  8559. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8560. return;
  8561. }
  8562. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8563. packet->setDataByName("book_title", title.c_str());
  8564. packet->setDataByName("book_type", "simple");
  8565. packet->setDataByName("unknown2", 1);
  8566. if (GetVersion() > 546)
  8567. packet->setDataByName("unknown5", 1, 4);
  8568. packet->setArrayLengthByName("num_pages", num_pages);
  8569. va_list args;
  8570. va_start(args, num_pages);
  8571. std::string endString("");
  8572. for (int8 p = 0; p < num_pages; p++)
  8573. {
  8574. std::string page = va_arg(args, string);
  8575. switch (GetVersion())
  8576. {
  8577. // release client
  8578. case 283:
  8579. {
  8580. endString.append(page);
  8581. break;
  8582. }
  8583. // DoF trial
  8584. case 546:
  8585. {
  8586. if (p == 0)
  8587. packet->setDataByName("cover_page", page.c_str());
  8588. else
  8589. packet->setArrayDataByName("page_text", page.c_str(), p - 1);
  8590. break;
  8591. }
  8592. // all other clients
  8593. default:
  8594. {
  8595. packet->setArrayDataByName("page_text", page.c_str(), p);
  8596. break;
  8597. }
  8598. }
  8599. }
  8600. if (GetVersion() == 283)
  8601. {
  8602. packet->setDataByName("page_text", endString.c_str());
  8603. }
  8604. va_end(args);
  8605. QueuePacket(packet->serialize());
  8606. safe_delete(packet);
  8607. }
  8608. void Client::SendShowBook(Spawn* sender, string title, vector<Item::BookPage*> pages)
  8609. {
  8610. if (!sender)
  8611. {
  8612. LogWrite(CCLIENT__ERROR, 0, "Client", "SendShowBook missing sender for Player %s, book title %s", GetPlayer()->GetName(), title);
  8613. return;
  8614. }
  8615. PacketStruct* packet = configReader.getStruct("WS_EqShowBook", GetVersion());
  8616. if (!packet) {
  8617. LogWrite(CCLIENT__ERROR, 0, "Client", "WS_EqShowBook missing for version %u", GetVersion());
  8618. return;
  8619. }
  8620. packet->setDataByName("spawn_id", GetPlayer()->GetIDWithPlayerSpawn(sender));
  8621. packet->setDataByName("book_title", title.c_str());
  8622. packet->setDataByName("book_type", "simple");
  8623. packet->setDataByName("unknown2", 1);
  8624. if (GetVersion() > 546)
  8625. packet->setDataByName("unknown5", 1, 4);
  8626. packet->setArrayLengthByName("num_pages", pages.size());
  8627. std::string endString("");
  8628. for (int8 p = 0; p < pages.size(); p++)
  8629. {
  8630. Item::BookPage* page = pages[p];
  8631. std::string pageText = string(page->page_text.data);
  8632. switch (GetVersion())
  8633. {
  8634. // release client
  8635. case 283:
  8636. {
  8637. endString.append(pageText);
  8638. break;
  8639. }
  8640. // DoF trial
  8641. case 546:
  8642. {
  8643. if (p == 0)
  8644. packet->setDataByName("cover_page", pageText.c_str());
  8645. else
  8646. packet->setArrayDataByName("page_text", pageText.c_str(), p - 1);
  8647. break;
  8648. }
  8649. // all other clients
  8650. default:
  8651. {
  8652. int8 valign = int8(page->valign);
  8653. int8 halign = int8(page->halign);
  8654. packet->setArrayDataByName("page_text", pageText.c_str(), p);
  8655. packet->setArrayDataByName("page_text_valign", valign, p);
  8656. packet->setArrayDataByName("page_text_halign", halign, p);
  8657. break;
  8658. }
  8659. }
  8660. }
  8661. if (GetVersion() == 283)
  8662. {
  8663. packet->setDataByName("page_text", endString.c_str());
  8664. }
  8665. QueuePacket(packet->serialize());
  8666. safe_delete(packet);
  8667. }
  8668. void Client::TempRemoveGroup()
  8669. {
  8670. if (this->GetPlayer()->GetGroupMemberInfo())
  8671. {
  8672. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8673. PlayerGroup* group = world.GetGroupManager()->GetGroup(this->GetPlayer()->GetGroupMemberInfo()->group_id);
  8674. group->MGroupMembers.writelock();
  8675. this->GetPlayer()->GetGroupMemberInfo()->client = 0;
  8676. this->GetPlayer()->GetGroupMemberInfo()->member = 0;
  8677. group->MGroupMembers.releasewritelock();
  8678. group->RemoveClientReference(this);
  8679. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8680. }
  8681. }