client.cpp 287 KB

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