Clone of UAS2 @ https://github.com/drudgedance/uas2

MasterServer.cpp 285KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466
  1. /*
  2. * This file is part of UAS2.
  3. *
  4. * UAS2 is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * UAS2 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 UASv1; if not, write to the Free Software
  15. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. */
  17. /**
  18. * @file MasterServer.cpp
  19. * Implements functionality for Master Server thread.
  20. *
  21. * The Master Server controls the loading and unloading of world objects.
  22. * It also implements basic commands.
  23. */
  24. #include "Client.h"
  25. #include "CommandParser.h"
  26. #include "DatFile.h"
  27. #include "Job.h"
  28. #include "MasterServer.h"
  29. #include "RecvPacket.h"
  30. #include "WorldManager.h"
  31. #include "Database.h"
  32. #include "Status.h"
  33. #include "cItemModels.h"
  34. #include "cWObjectModels.h"
  35. #include "TreasureGen.h"
  36. #include "cNPCModels.h"
  37. #include "cSpell.h"
  38. HANDLE cMasterServer::m_hThread = 0;
  39. HANDLE cMasterServer::m_hExitEvent = 0;
  40. UINT_PTR cMasterServer::m_uipTimer = 0;
  41. UINT_PTR cMasterServer::m_uipStatusTimer = 0;
  42. cJobPool* cMasterServer::m_pcJobPool = 0;
  43. int cMasterServer::m_iLoadCount = 0;
  44. DWORD cMasterServer::m_dwThreadID = 0;
  45. cLocation cMasterServer::m_StartingLoc;
  46. cLocation cMasterServer::m_MarketLoc;
  47. CorpseCleaner* cMasterServer::m_pcCorpse = 0;
  48. SimpleAI* cMasterServer::m_pcSimpleAI = 0;
  49. FILE* cMasterServer::pFile;
  50. CStatus* cMasterServer::cStatus = 0;
  51. char cMasterServer::m_szServerName[64] = { ' ', };
  52. DWORD cMasterServer::m_dwNumUsers = 0;
  53. DWORD cMasterServer::m_UserCount = 0;
  54. std::list< cEnchantment * > cMasterServer::m_lstEnchantments;
  55. std::vector< cTeleTownList > cMasterServer::m_TeleTownList;
  56. std::vector< cAllegiance *> cMasterServer::m_AllegianceList;
  57. std::vector< cFellowship *> cMasterServer::m_FellowshipList;
  58. DWORD cMasterServer::m_dwFellowID = 0;
  59. TreasureGen *trgen = new TreasureGen();
  60. DWORD gNPCCount = 0;
  61. cNPC* npc;
  62. friend class cClient;
  63. void cMasterServer::WriteToFile( char *szMessage )
  64. {
  65. if(pFile == NULL)
  66. {
  67. }
  68. else
  69. {
  70. fprintf(pFile,szMessage );
  71. fprintf(pFile,"\r\n");
  72. }
  73. }
  74. /**
  75. * Loads the server process. Calls cMasterServer::StartThread( ).
  76. *
  77. * This member function is called when the server is started.
  78. */
  79. void cMasterServer::Load( )
  80. {
  81. if( m_iLoadCount > 0 )
  82. {
  83. UpdateConsole( "Server already running!\r\n" );
  84. return;
  85. }
  86. else
  87. {
  88. UpdateConsole( " --------------------------------------------------------------------------\r\n\r\n" );
  89. UpdateConsole( " Starting Master Server ...\r\n" );
  90. }
  91. m_iLoadCount++;
  92. pFile = fopen( "server.log", "wa" );
  93. setbuf(pFile,NULL);
  94. //Karki
  95. cMasterServer::m_UserCount = 0;
  96. if( pFile == NULL )
  97. {
  98. UpdateConsole( " Cannot open c:\\server.log \r\n" );
  99. //exit( 1 );
  100. }
  101. else
  102. {
  103. WriteToFile("Master Server started.\r\n");
  104. UpdateConsole( " Master Server started.\r\n\r\n" );
  105. }
  106. StartThread( );
  107. }
  108. /**
  109. * Unloads the server process. Calls cMasterServer::StopThread( ).
  110. *
  111. * This member function is called when the server is stopped.
  112. */
  113. BOOL cMasterServer::Unload( )
  114. {
  115. m_iLoadCount--;
  116. WriteToFile("Program exiting ...");
  117. if(pFile == NULL)
  118. {
  119. }
  120. else
  121. {
  122. fclose(pFile);
  123. }
  124. if( m_iLoadCount == 0 )
  125. {
  126. UpdateConsole( "\r\n Stopping Master Server. Please wait ...\r\n" );
  127. StopThread( 5000 );
  128. m_iLoadCount = 0;
  129. UpdateConsole( " All services stopped.\r\n\r\n" );
  130. /////////////////////////////
  131. cStatus->ServerShutdown();
  132. /////////////////////////////
  133. cWorldManager::RemoveAllObjects();
  134. cWorldManager::Unload();
  135. return TRUE;
  136. }
  137. else {
  138. WriteToFile("Master Server services failed to stop.");
  139. UpdateConsole( " Master Server services failed to stop.\r\n\r\n" );
  140. return FALSE;
  141. }
  142. }
  143. /**
  144. * Clears all spawned objects.
  145. */
  146. void cMasterServer::ClearAllObjects( )
  147. {
  148. PostThreadMessage( m_dwThreadID, WM_CLEAROBJECTS, 0, 0 );
  149. }
  150. /**
  151. * Starts the MasterServer thread.
  152. *
  153. * This member function is called when the MasterServer thread is to be started.
  154. */
  155. void cMasterServer::StartThread( )
  156. {
  157. m_hExitEvent = CreateEvent( NULL, TRUE, FALSE, NULL );
  158. m_hThread = CreateThread( NULL, NULL, ServerThread, (LPVOID)NULL, NULL, &m_dwThreadID );
  159. }
  160. /**
  161. * Cleans up and closes the MasterServer thread.
  162. *
  163. * This member function is called when the MasterServer thread is to be stopped.
  164. */
  165. void cMasterServer::StopThread( DWORD dwTimeOut )
  166. {
  167. SetEvent( m_hExitEvent );
  168. MSG msg;
  169. BOOL fContinue = TRUE;
  170. DWORD dwKillTime = timeGetTime( );
  171. while ( fContinue )
  172. {
  173. switch( MsgWaitForMultipleObjects( 1, &m_hThread, FALSE, dwTimeOut, QS_ALLINPUT ) )
  174. {
  175. case WAIT_OBJECT_0:
  176. {
  177. fContinue = FALSE;
  178. break;
  179. }
  180. case WAIT_OBJECT_0 + 1:
  181. {
  182. while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  183. {
  184. if( IsDialogMessage( g_hWndMain, &msg ) )
  185. continue;
  186. TranslateMessage( &msg );
  187. DispatchMessage( &msg );
  188. }
  189. if( ( timeGetTime( ) - dwKillTime ) > dwTimeOut )
  190. dwTimeOut = 0;
  191. else
  192. break;
  193. }
  194. case WAIT_TIMEOUT:
  195. {
  196. UpdateConsole( " Thread time-out. Killing the thread...\r\n" );
  197. TerminateThread( m_hThread, 0 );
  198. fContinue = FALSE;
  199. break;
  200. }
  201. }
  202. }
  203. CloseHandle( m_hThread );
  204. CloseHandle( m_hExitEvent );
  205. }
  206. /**
  207. * The thread loop that checks for new packets and passes them on to the correct server.
  208. */
  209. DWORD WINAPI cMasterServer::ServerThread( LPVOID lpVoid )
  210. {
  211. cDatabase::Load( );
  212. cDatabase::InitializeMaxModel( );
  213. LoadStartingLocation( );
  214. LoadTeleTownList( );
  215. LoadAllegiances( );
  216. cCharacterServer::Initialize( g_nCharPort, 0x0B, 0x56FC18E1, 0x53575F2D );
  217. cWorldServer::Initialize( g_nWorldPort, 0x51, 0xD6748919, 0xC01CA84F );
  218. cMonsterServer::Initialize( );
  219. cClient::Hash_Load( );
  220. m_pcSimpleAI = new SimpleAI( );
  221. cWorldManager::Load( );
  222. m_pcJobPool = new cJobPool( );
  223. m_pcJobPool->NextTickTime = clock();
  224. m_pcCorpse = new CorpseCleaner( );
  225. m_uipTimer = SetTimer( NULL, NULL, 10000, cMasterServer::ScavengeIdleSockets );
  226. m_uipStatusTimer = SetTimer( NULL, NULL, 20000, cMasterServer::Status_Update );
  227. HANDLE hEvents[3];
  228. WSANETWORKEVENTS NetEvents;
  229. cRecvPacket cRP;
  230. BOOL fActive = TRUE;
  231. int iSockSize = sizeof( sockaddr_in );
  232. DWORD dwWaitTimeOut = 50;
  233. int iRPDataSize = sizeof( cRP.m_bData );
  234. MSG msg;
  235. int PetCheckNoobCount = 0;
  236. ///////
  237. cStatus->ServerStart();
  238. ///////
  239. hEvents[0] = m_hExitEvent;
  240. hEvents[1] = WSACreateEvent( );
  241. hEvents[2] = WSACreateEvent( );
  242. WSAEventSelect( cWorldServer::m_Socket, hEvents[1], FD_READ );
  243. WSAEventSelect( cCharacterServer::m_Socket, hEvents[2], FD_READ );
  244. while ( fActive )
  245. {
  246. time(&m_pcCorpse->longtime);
  247. if(m_pcCorpse->NextCleanTime < m_pcCorpse->longtime)
  248. {
  249. m_pcCorpse->Cleanup();
  250. }
  251. time(&m_pcSimpleAI->longtime);
  252. if(m_pcSimpleAI->NextActionTime < m_pcSimpleAI->longtime)
  253. {
  254. m_pcSimpleAI->ExecuteActions( );
  255. }
  256. switch ( MsgWaitForMultipleObjects( 3, hEvents, FALSE, dwWaitTimeOut, QS_TIMER | QS_POSTMESSAGE ) )
  257. {
  258. case ( WAIT_OBJECT_0 ):
  259. {
  260. fActive = FALSE;
  261. break; // case WAIT_OBJECT_0
  262. }
  263. case ( WAIT_TIMEOUT ):
  264. {
  265. m_pcJobPool->longtime = clock();
  266. if(m_pcJobPool->longtime - m_pcJobPool->NextTickTime >= (CLOCKS_PER_SEC/TICKS_PER_SEC) )
  267. {
  268. m_pcJobPool->NextTickTime += (CLOCKS_PER_SEC/TICKS_PER_SEC);
  269. //cMasterServer::ServerMessage(ColorGreen,NULL,"Tick: %d, %d", m_pcJobPool->NextTickTime, m_pcJobPool->longtime);
  270. m_pcJobPool->Tick( );
  271. m_pcSimpleAI->MoveMonsters();
  272. }
  273. for ( iterEnchantment_lst itEnchantment = m_lstEnchantments.begin() ; itEnchantment != m_lstEnchantments.end() ; ++itEnchantment )
  274. {
  275. if ( (*itEnchantment)->m_dCastTime + (*itEnchantment)->m_dDuration * 1000 < timeGetTime() )
  276. {
  277. SAFEDELETE ( *itEnchantment )
  278. itEnchantment = m_lstEnchantments.erase( itEnchantment );
  279. }
  280. }
  281. dwWaitTimeOut = 50;
  282. cClient::SendOffAllPackets( );
  283. break; // case WAIT_TIMEOUT
  284. }
  285. case ( WAIT_OBJECT_0 + 1 ):
  286. {
  287. WSAEnumNetworkEvents( cWorldServer::m_Socket, hEvents[1], &NetEvents );
  288. switch ( NetEvents.lNetworkEvents )
  289. {
  290. case FD_READ:
  291. {
  292. dwWaitTimeOut = 0;
  293. cRP.m_wSize = recvfrom( cWorldServer::m_Socket, (char *)cRP.m_bData, iRPDataSize, NULL, (sockaddr *)&cRP.m_saSockAddr, &iSockSize );
  294. if ( (cRP.m_wSize > 0) && (cRP.m_wSize != SOCKET_ERROR) )
  295. {
  296. //cClient::Hash_New( cRP.m_saSockAddr )->ProcessPacket_WS( &cRP );
  297. cClient *pcClient = cClient::Hash_Find( cRP.m_saSockAddr );
  298. // If a client the client does not exist, or has an invalid
  299. // avatar, do not continue.
  300. if ( !pcClient || !pcClient->m_pcAvatar )
  301. break; // case FD_READ
  302. pcClient->ProcessPacket_WS( &cRP );
  303. }
  304. break; // case FD_READ
  305. }
  306. }
  307. break; //case WAIT_OBJECT_0 + 1
  308. }
  309. case ( WAIT_OBJECT_0 + 2 ):
  310. {
  311. WSAEnumNetworkEvents( cCharacterServer::m_Socket, hEvents[2], &NetEvents );
  312. switch ( NetEvents.lNetworkEvents )
  313. {
  314. case FD_READ:
  315. {
  316. dwWaitTimeOut = 0;
  317. cRP.m_wSize = recvfrom( cCharacterServer::m_Socket,(char *)cRP.m_bData, iRPDataSize, NULL,(sockaddr *)&cRP.m_saSockAddr, &iSockSize );
  318. if ( (cRP.m_wSize > 0) && (cRP.m_wSize != SOCKET_ERROR) )
  319. cClient::Hash_New( cRP.m_saSockAddr )->ProcessPacket_CS( &cRP );
  320. break; // case FD_READ
  321. }
  322. }
  323. break; // case WAIT_OBJECT_0 + 2
  324. }
  325. case (WAIT_OBJECT_0 + 3 ):
  326. {
  327. while ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
  328. {
  329. if( msg.message == WM_CLEAROBJECTS )
  330. {
  331. cWorldManager::RemoveAllObjects();
  332. cMasterServer::ServerMessage(ColorGreen,NULL,"The server administrator has cleared all the objects.");
  333. }
  334. DispatchMessage( &msg );
  335. }
  336. break; // case WAIT_OBJECT_0 + 3
  337. }
  338. }
  339. }
  340. CloseHandle( hEvents[1] );
  341. CloseHandle( hEvents[2] );
  342. KillTimer( NULL, m_uipTimer );
  343. DisconnectAllClients( );
  344. SAFEDELETE( m_pcJobPool )
  345. cCharacterServer::Halt( );
  346. cWorldServer::Halt( );
  347. cWorldManager::Unload( );
  348. cDatabase::Unload( );
  349. /////////////////
  350. cStatus->ServerShutdown();
  351. ////////////////
  352. return 0;
  353. }
  354. /**
  355. * Sends a server message to the client.
  356. *
  357. * @param dwColor - The color in which the server message will be displayed.
  358. * @param *pcClient - A pointer to the client who should receieve the message.
  359. * @param *szMessage - A pointer to the text to be sent as the message.
  360. */
  361. void cMasterServer::ServerMessage( DWORD dwColor, cClient *pcClient, char *szMessage, ... )
  362. {
  363. char szTextBuffer[1024];
  364. va_list valMaker;
  365. va_start( valMaker, szMessage );
  366. wvsprintf( szTextBuffer, szMessage, valMaker );
  367. cMessage cmSM;
  368. cmSM << 0xF62CL << szTextBuffer << dwColor;
  369. if ( pcClient == NULL )
  370. cClient::SendToAllClients( cmSM, 4 );
  371. else
  372. pcClient->AddPacket( WORLD_SERVER, cmSM, 4 );
  373. }
  374. /**
  375. * Obtains the avatar's information from the database and creates the client's avatar.
  376. *
  377. * This function is called whenever a client logs in an avatar.
  378. *
  379. * Note: Placeholder code until database code is done.
  380. *
  381. * @param **ppcAvatar - A pointer to the pointer to avatar to be created.
  382. * @param dwGUID - The GUID of the avatar.
  383. */
  384. void cMasterServer::CreateNewAvatar( cAvatar **ppcAvatar, DWORD dwGUID )
  385. {
  386. *ppcAvatar = new cAvatar( dwGUID, &m_StartingLoc );
  387. cDatabase::LoadAvatar( *ppcAvatar );
  388. }
  389. /**
  390. * Obtains the data necessary from the database for login and sends it to the client.
  391. *
  392. * This function is called whenever a client logs in an avatar.
  393. * It is called after the database contents for the avatar have been loaded into memory.
  394. *
  395. * Note: Placeholder code until database code is done.
  396. *
  397. * @param *pcClient - A pointer to the client that should receive the data.
  398. */
  399. void cMasterServer::SendLoginData( cClient *pcClient )
  400. {
  401. ServerMessage( ColorCyan, pcClient, "To view a list of commands, type !help" );
  402. ServerMessage( ColorLightPink, pcClient, "Note: If you are stuck in portal mode, type \"/render radius 5\"" );
  403. // Character data
  404. DWORD dwGUID = pcClient->m_pcAvatar->GetGUID( );
  405. // 0x13 Login
  406. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->CreateLoginPacket(++pcClient->m_dwF7B0Sequence), 4);
  407. // Pack contents
  408. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->SetPackContents(++pcClient->m_dwF7B0Sequence), 4 );
  409. // Housing Info
  410. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->HousingInfo(++pcClient->m_dwF7B0Sequence), 4);
  411. // Creation packet/CreateObject
  412. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->CreatePacket( ), 3 );
  413. // Exit Portal Mode
  414. pcClient->AddPacket( WORLD_SERVER, pcClient->m_pcAvatar->LoginCharacter( ), 3 );
  415. //Karki
  416. ServerMessage( ColorMagenta, NULL, "%s has joined %s. %d client(s) connected.", pcClient->m_pcAvatar->Name( ), cMasterServer::m_szServerName, ++cMasterServer::m_UserCount);
  417. //EndKarki
  418. pcClient->m_pcAvatar->SetArmorLevel(0);
  419. }
  420. /**
  421. * Parses commands from users and executes them.
  422. *
  423. * Used for server-specific commands.
  424. * Executes the proper cCommandParser function based upon the command.
  425. *
  426. * @param *szCommand - A pointer to the text that comprises the command.
  427. * @param wSize - The length of the command (excluding the terminating character ('\0')
  428. * @param *pcClient - A pointer to the client that should receive the data.
  429. */
  430. void cMasterServer::ParseCommand( char *szCommand, WORD wSize, cClient *pcClient )
  431. {
  432. cCommandParser::m_pcClient = pcClient;
  433. if ( *szCommand == '!' )
  434. {
  435. char *szCommandName = strtok( szCommand, " ," );
  436. ++szCommandName;
  437. WORD wCommandSize = lstrlen( szCommandName ) + 2;
  438. if( wCommandSize < wSize )
  439. szCommand += wCommandSize;
  440. else
  441. *szCommand = 0;
  442. switch ( pcClient->m_pcAvatar->m_bAccessLevel )
  443. {
  444. case eDeveloper:
  445. if ( !lstrcmpi( szCommandName, "teleloc" ) ) cCommandParser::TeleLoc( szCommand );
  446. if ( !lstrcmpi( szCommandName, "telemap" ) ) cCommandParser::Telemap( szCommand );
  447. if ( !lstrcmpi( szCommandName, "teletown" ) ) cCommandParser::TeleTown( szCommand );
  448. if ( !lstrcmpi( szCommandName, "turn" ) ) cCommandParser::Turn( szCommand );
  449. case eAdmin:
  450. if ( lstrcmpi( szCommandName, "spawnsave" ) == 0 ) cCommandParser::SpawnSave( szCommand );
  451. else if ( lstrcmpi( szCommandName, "spawnmonster" ) == 0 ) cCommandParser::SpawnMonster( szCommand );
  452. else if ( lstrcmpi( szCommandName, "spawntype" ) == 0 ) cCommandParser::Spawntype( szCommand );
  453. else if ( !lstrcmpi( szCommandName, "SpawnItem") ) cCommandParser::SpawnItem( szCommand );
  454. else if ( !lstrcmpi( szCommandName, "SpawnItemLB") ) cCommandParser::SpawnItemLB (szCommand);
  455. else if ( !lstrcmpi( szCommandName, "RandomPyreals") ) cCommandParser::RandomPyreals();
  456. else if ( !lstrcmpi( szCommandName, "particle" ) ) cCommandParser::Particle( szCommand );
  457. else if ( !lstrcmpi( szCommandName, "sound" ) ) cCommandParser::SoundEffect( szCommand );
  458. case eUeber:
  459. if ( !lstrcmpi( szCommandName, "clearobjects" ) ) cCommandParser::ClearObjects( );
  460. else if ( !lstrcmpi( szCommandName, "wb" ) ) cCommandParser::WorldBroadcast( szCommand );
  461. case eSentinel:
  462. case eAdvocate:
  463. if ( !lstrcmpi( szCommandName, "getchar" ) ) cCommandParser::GetCharacter( szCommand );
  464. else if ( !lstrcmpi( szCommandName, "gotochar" ) ) cCommandParser::GotoCharacter( szCommand );
  465. else if ( !lstrcmpi( szCommandName, "returnchar" ) ) cCommandParser::ReturnCharacter( szCommand );
  466. else if ( !lstrcmpi( szCommandName, "sendchar" ) ) cCommandParser::SendCharacter( szCommand );
  467. else if ( !lstrcmpi( szCommandName, "spawnid") ) cCommandParser::SpawnID( szCommand );
  468. case eStaff:
  469. case eVIP:
  470. case eNormal:
  471. default:
  472. if ( !lstrcmpi( szCommandName, "help" ) ) cCommandParser::Help( szCommand, pcClient->m_pcAvatar->m_bAccessLevel );
  473. else if ( !lstrcmpi( szCommandName, "global" ) ) cCommandParser::GlobalChat( szCommand );
  474. else if ( !lstrcmpi( szCommandName, "g" ) ) cCommandParser::GlobalChat( szCommand );
  475. else if ( !lstrcmpi( szCommandName, "shout" ) ) cCommandParser::GlobalChat( szCommand );
  476. else if ( !lstrcmpi( szCommandName, "s" ) ) cCommandParser::GlobalChat( szCommand );
  477. else if ( !lstrcmpi( szCommandName, "home" ) ) cCommandParser::Home();
  478. else if ( !lstrcmpi( szCommandName, "invisible") ) cCommandParser::Invisible( );
  479. else if ( !lstrcmpi( szCommandName, "visible") ) cCommandParser::Visible( );
  480. else if ( !lstrcmpi( szCommandName, "who") ) cCommandParser::Who( );
  481. else if ( !lstrcmpi( szCommandName, "animation" ) ) cCommandParser::Animation( szCommand );
  482. else if ( !lstrcmpi( szCommandName, "setmodel" ) ) cCommandParser::SetModel( szCommand );
  483. else if ( !lstrcmpi( szCommandName, "setscale" ) ) cCommandParser::SetScale( szCommand );
  484. else if ( !lstrcmpi( szCommandName, "version") ) cCommandParser::Version( );
  485. else if ( !lstrcmpi( szCommandName, "boot") )
  486. {
  487. cMessage cMsg;
  488. cMsg << 0xF7B0L << pcClient->m_pcAvatar->GetGUID() << ++pcClient->m_dwF7B0Sequence << 0x01C8L << 0x00L << 0x35L;
  489. cMsg << 0x0229L << BYTE(0x00) << pcClient->m_pcAvatar->GetGUID() << 0x0L << 0xFFFFFFFF;
  490. pcClient->AddPacket(WORLD_SERVER,cMsg,4);
  491. }
  492. else if ( !lstrcmpi( szCommandName, "...") ) cCommandParser::ODOA( );
  493. //Karki
  494. }
  495. //else if ( lstrcmpi( szCommandName, "munster" ) == 0 ) Munster( );
  496. //else if ( lstrcmpi( szCommandName, "dungeon" ) == 0 ) Dungeon( szCommand );
  497. //else if ( lstrcmpi( szCommandName, "punch" ) == 0 ) Punch( );
  498. //else if ( lstrcmpi( szCommandName, "dungeonlist" ) == 0 ) DungeonList( szCommand );
  499. //else if ( lstrcmpi( szCommandName, "spawn" ) == 0 ) SpawnMonster( szCommand );
  500. //else if ( lstrcmpi( szCommandName, "spawnplayer" ) == 0 ) SpawnPlayer( );
  501. //else if ( lstrcmpi( szCommandName, "portal" ) == 0 ) SpawnPortal( );
  502. //else if ( lstrcmpi( szCommandName, "spawnid") == 0 ) SpawnID(szCommand);
  503. //else if ( lstrcmpi( szCommandName, "npcsave" ) == 0 ) cCommandParser::SaveNPC( szCommand );
  504. //else if ( !lstrcmpi( szCommandName, "Wear") ) cCommandParser::Wear( );
  505. //else if ( !lstrcmpi( szCommandName, "Remove") ) cCommandParser::Remove( );
  506. //else if ( !lstrcmpi( szCommandName, "acid") ) cCommandParser::Acid( szCommand );
  507. //else if ( !lstrcmpi( szCommandName, "recordloc" ) ) cCommandParser::RecordLocation( ); // szCommand );
  508. //else if ( !lstrcmpi( szCommandName, "spwnid") ) cCommandParser::SpwnID( szCommand );
  509. }
  510. else
  511. {
  512. if ( *szCommand == '@' )
  513. {
  514. }
  515. else
  516. {
  517. cMessage cmChat;
  518. cmChat << 0x0037L << szCommand << (char *)pcClient->m_pcAvatar->Name( )
  519. << pcClient->m_pcAvatar->GetGUID( ) << 0x02;
  520. cWorldManager::SendToAllWithin( 1, pcClient->m_pcAvatar->m_Location, cmChat, 4 );
  521. }
  522. }
  523. }
  524. /**
  525. * Encapsulates functionality to send a private message to another user
  526. *
  527. * This function is called whenever a client sends a "tell" to another client.
  528. *
  529. * @param *szCommand - A pointer to the text that comprises the command.
  530. * @param *pcDestination - A pointer to the client that should receive the tell.
  531. * @param *pcOrigin - A pointer to the client sending the the tell.
  532. */
  533. void cMasterServer::SendTell( char *szMessage, cClient *pcDestination, cClient *pcOrigin )
  534. {
  535. if ( !pcDestination )
  536. {
  537. cMessage cmNA;
  538. cmNA << 0xF7B0L << pcOrigin->m_pcAvatar->GetGUID( ) << ++pcOrigin->m_dwF7B0Sequence
  539. << 0x0016L << "Talking to your invisible friend again?";
  540. pcOrigin->AddPacket( WORLD_SERVER, cmNA, 4 );
  541. return ;
  542. }
  543. cMessage cmChat;
  544. DWORD dwDestinationGUID = pcDestination->m_pcAvatar->GetGUID( );
  545. cmChat << 0xF7B0L << dwDestinationGUID << ++pcDestination->m_dwF7B0Sequence
  546. << 0x0038L << szMessage << pcOrigin->m_pcAvatar->Name( )
  547. << pcOrigin->m_pcAvatar->GetGUID( ) << dwDestinationGUID << 0x04L;
  548. pcDestination->AddPacket( WORLD_SERVER, cmChat, 4 );
  549. if ( pcDestination != pcOrigin )
  550. ServerMessage( ColorBrown, pcOrigin, "You tell %s, \"%s\"", pcDestination->m_pcAvatar->Name( ), szMessage );
  551. }
  552. /**
  553. * Removes a client after logout or loss of signal.
  554. *
  555. * @param *pcClient - A pointer to the client to be disconnected.
  556. */
  557. BOOL cMasterServer::DisconnectClient( cClient *pcClient )
  558. {
  559. char szIP[32];
  560. if (pcClient->m_wAccountNameLength < 40) {
  561. FormatIP_Port( pcClient->m_saSockAddr, szIP );
  562. UpdateConsole( " Client logout:\r\n"
  563. " User: %s\r\n"
  564. " IP: %s\r\n", pcClient->m_szAccountName, szIP );
  565. }
  566. cClient::Hash_Remove( pcClient );
  567. return TRUE;
  568. }
  569. /**
  570. * Changes a Client's PKLite status.
  571. *
  572. * @param *pcClient - A pointer to the client whose PKLite status is to be changed.
  573. * @param bState - A boolean representation of whether the client is PKLite.
  574. */
  575. BOOL cMasterServer::PKLite( cClient *pcClient, bool bState )
  576. {
  577. if (bState == true)
  578. {
  579. char szNotice[200];
  580. wsprintf( szNotice, "%s is looking for a fight!",pcClient->m_pcAvatar->Name( ) );
  581. cMessage cmNotice;
  582. cmNotice << 0xF62C << szNotice << ColorGreen;
  583. cWorldManager::SendToAllInFocus( pcClient->m_pcAvatar->m_Location, cmNotice, 4 );
  584. cMasterServer::ServerMessage( ColorBlue, pcClient, "A cold wind touches your heart. You are now a Player Killer Lite.");
  585. cMessage cmCoverME;
  586. cmCoverME << 0x0229L << pcClient->m_pcAvatar->m_bFlagCount++<< pcClient->m_pcAvatar->GetGUID() << DWORD(134) << 0x40L;
  587. cWorldManager::SendToAllInFocus( pcClient->m_pcAvatar->m_Location, cmCoverME, 4 );
  588. pcClient->m_pcAvatar->m_fIsPK = 2;
  589. }
  590. else
  591. {
  592. cMessage cmCoverME;
  593. cmCoverME << 0x0229L << pcClient->m_pcAvatar->m_bFlagCount++ << pcClient->m_pcAvatar->GetGUID() << DWORD(134) << 0x0L;
  594. cWorldManager::SendToAllWithin( 5 , pcClient->m_pcAvatar->m_Location, cmCoverME, 4 );
  595. pcClient->AddPacket(WORLD_SERVER,cmCoverME,4);
  596. pcClient->m_pcAvatar->m_fIsPK = 0;
  597. }
  598. return bState;
  599. }
  600. /**
  601. * Removes all clients in preparation for server shutdown.
  602. */
  603. BOOL cMasterServer::DisconnectAllClients( )
  604. {
  605. UpdateConsole( " Disconnecting all clients ...\r\n" );
  606. ServerMessage( ColorBlue, NULL, "The server has been shut down." );
  607. cClient::SendOffAllPackets( );
  608. cClient::Hash_Erase( );
  609. return TRUE;
  610. }
  611. /**
  612. * Searches for and disconnects inactive clients.
  613. */
  614. VOID CALLBACK cMasterServer::ScavengeIdleSockets( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
  615. {
  616. cClient *pcClient, *pcPrevClient;
  617. DWORD dwCurrentTime = timeGetTime( );
  618. for ( int i = 0; i < 1020; ++i )
  619. {
  620. pcClient = cClient::m_lpcHashTable[i];
  621. while ( pcClient )
  622. {
  623. pcPrevClient = pcClient;
  624. pcClient = pcClient->m_pcNext;
  625. if ( dwCurrentTime - pcPrevClient->m_dwLastRecvTime > 40000 )
  626. DisconnectClient( pcPrevClient );
  627. }
  628. }
  629. }
  630. /**
  631. * Updates the Master Server.
  632. *
  633. * Author: G70mb2
  634. */
  635. VOID CALLBACK cMasterServer::Status_Update( HWND hwnd, UINT uMsg, UINT idEvent, DWORD dwTime )
  636. {
  637. DWORD dwCurrentTime = timeGetTime( );
  638. //UpdateConsole( " Update status timer check.\r\n" );
  639. if( dwCurrentTime - cMasterServer::cStatus->m_ulLastUpdate > 200000 )
  640. {
  641. cMasterServer::cStatus->m_cAvg = m_dwNumUsers;
  642. //UpdateConsole( " Update time has been reached.\r\n");
  643. cMasterServer::cStatus->UpDate();
  644. }
  645. }
  646. /**
  647. * Converts '_' into a space character.
  648. */
  649. void cMasterServer::FixSpaces(char* str)
  650. {
  651. for(int a = 0;a<strlen(str);a++)
  652. {
  653. if(str[a] == '_')
  654. {
  655. str[a] = 0x20;
  656. }
  657. }
  658. }
  659. /**
  660. * Converts * into a ' (apostrophe).
  661. */
  662. void cMasterServer::FixName(char* str)
  663. {
  664. for(int a = 0;a<strlen(str);a++)
  665. {
  666. if(str[a] == '*')
  667. {
  668. str[a] = 0x27;
  669. }
  670. }
  671. }
  672. BOOL cMasterServer::FindHeaderInFile( FILE* fin, char* header )
  673. {
  674. char findstr[100];
  675. wsprintf(findstr,"[%s]\n",header);
  676. rewind(fin);
  677. while(!feof(fin))
  678. {
  679. char inbuf[300];
  680. fgets(inbuf,299,fin);
  681. if(strcmp(inbuf,findstr)==0)
  682. {
  683. return TRUE;
  684. }
  685. }
  686. return FALSE;
  687. }
  688. /**
  689. * Initalizes an avatar's inventory by loading each item from the database.
  690. *
  691. * This function should be called before the avatar's Create Message is formed.
  692. * The information loaded here is used in the Create Message.
  693. *
  694. * @param *pcClient - A pointer to the client whose avatar's inventory is to be loaded.
  695. */
  696. void cMasterServer::CreateInventory( cClient *pcClient )
  697. {
  698. //The avatar's GUID
  699. DWORD avatarGUID = pcClient->m_pcAvatar->GetGUID( );
  700. char szCommand [200];
  701. RETCODE retcode;
  702. std::list< DWORD > lstInventory;
  703. DWORD dwObjectGUID;
  704. DWORD fEquipped;
  705. char data[512];
  706. DWORD dwItemModelNumber;
  707. DWORD dwItemAmount;
  708. WORD wIcon;
  709. int intColor;
  710. char spells[255];
  711. sprintf( szCommand, "SELECT GUID FROM items_instance_inventory WHERE OwnerGUID=%lu; ", avatarGUID );
  712. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  713. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  714. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwObjectGUID, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  715. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  716. {
  717. lstInventory.push_back( dwObjectGUID );
  718. }
  719. for ( std::list<DWORD>::iterator list_iter = lstInventory.begin(); list_iter != lstInventory.end(); ++list_iter )
  720. {
  721. sprintf( szCommand, "SELECT GUID,Equipped,data FROM items_instance_inventory WHERE GUID=%lu; ", *list_iter );
  722. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  723. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  724. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwObjectGUID, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  725. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_LONG, &fEquipped, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  726. retcode = SQLBindCol( cDatabase::m_hStmt, 3, SQL_C_CHAR, &data, sizeof( data ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  727. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS )
  728. {
  729. sscanf(data,"%d %d %d %d %s",&dwItemModelNumber,&dwItemAmount,&intColor,&wIcon,&spells);
  730. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  731. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  732. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  733. //Find the model
  734. cItemModels *pcModel = cItemModels::FindModel(dwItemModelNumber);
  735. switch(pcModel->m_ItemType)
  736. {
  737. case 1:
  738. {
  739. // cWeapon* aWeapon = new cWeapon(pcClient->m_pcAvatar->m_vInventory[i].dwObjectGUID,avatarGUID,dwItemModelNumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_wBurden,pcModel->m_dwValue,pcModel->m_bWieldType,pcModel->m_dwIconHighlight,pcModel->m_fWorkmanship,pcModel->m_dwMaterialType,pcModel->);
  740. // cWorldManager::AddObject(aWeapon,true);
  741. // pcClient->AddPacket( WORLD_SERVER, aWeapon->CreatePacketContainer(avatarGUID,pcModel->m_dwModelID),3);
  742. // pcClient->m_pcAvatar->AddInventory(aWeapon);
  743. cWeapon* aWeapon = new cWeapon(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_bWieldType,pcModel->m_dwIconHighlight,pcModel->m_fWorkmanship,pcModel->m_dwMaterialType,pcModel->m_dwWeaponDamage,pcModel->m_dwWeaponSpeed,pcModel->m_dwWeaponSkill,pcModel->m_dwDamageType,pcModel->m_dWeaponVariance,pcModel->m_dWeaponModifier,pcModel->m_dWeaponPower,pcModel->m_dWeaponAttack);
  744. aWeapon->m_fEquipped = fEquipped;
  745. LoadItem(aWeapon);
  746. pcClient->m_pcAvatar->AddInventory(aWeapon);
  747. pcClient->AddPacket( WORLD_SERVER, aWeapon->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  748. break;
  749. }
  750. case 2:
  751. {
  752. cFood* aFood = new cFood(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wStack, pcModel->m_wBurden, pcModel->m_dwVitalID, pcModel->m_vital_affect);
  753. aFood->m_fEquipped = fEquipped;
  754. LoadItem(aFood);
  755. pcClient->m_pcAvatar->AddInventory(aFood);
  756. pcClient->AddPacket( WORLD_SERVER, aFood->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  757. break;
  758. }
  759. case 3:
  760. {
  761. //cArmor* aArmor = new cArmor(cWorldManager::NewGUID_Object(),pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_dwArmor_Level,pcModel->m_fProt_Slashing,pcModel->m_fProt_Piercing,pcModel->m_fProt_Bludgeon,pcModel->m_fProt_Fire,pcModel->m_fProt_Cold,pcModel->m_fProt_Acid,pcModel->m_fProt_Electric);
  762. cArmor* aArmor = new cArmor(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_dwArmor_Level,pcModel->m_fProt_Slashing,pcModel->m_fProt_Piercing,pcModel->m_fProt_Bludgeon,pcModel->m_fProt_Fire,pcModel->m_fProt_Cold,pcModel->m_fProt_Acid,pcModel->m_fProt_Electric);
  763. aArmor->m_fEquipped = fEquipped;
  764. if (aArmor->m_fEquipped == 2)
  765. {
  766. aArmor->m_dwOwnerID = pcClient->m_pcAvatar->GetGUID();
  767. }
  768. aArmor->m_intColor = intColor;
  769. LoadItem(aArmor);
  770. pcClient->m_pcAvatar->AddInventory(aArmor);
  771. pcClient->AddPacket( WORLD_SERVER, aArmor->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  772. break;
  773. }
  774. case 4:
  775. {
  776. cBooks* Book = new cBooks(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  777. Book->m_fEquipped = fEquipped;
  778. LoadItem(Book);
  779. pcClient->m_pcAvatar->AddInventory(Book);
  780. pcClient->AddPacket(WORLD_SERVER,Book->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  781. break;
  782. }
  783. case 6:
  784. {
  785. cHealingCon *kit = new cHealingCon(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_wBurden,pcModel->m_dwValue,pcModel->m_wUses,pcModel->m_wUseLimit);
  786. kit->m_fEquipped = fEquipped;
  787. LoadItem(kit);
  788. pcClient->m_pcAvatar->AddInventory(kit);
  789. pcClient->AddPacket(WORLD_SERVER,kit->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  790. break;
  791. }
  792. case 7:
  793. {
  794. cLockpicks* Picks = new cLockpicks(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_wUses, pcModel->m_wUseLimit);
  795. Picks->m_fEquipped = fEquipped;
  796. LoadItem(Picks);
  797. pcClient->m_pcAvatar->AddInventory(Picks);
  798. pcClient->AddPacket(WORLD_SERVER,Picks->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  799. break;
  800. }
  801. case 8:
  802. {
  803. cWands* aWand = new cWands(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  804. aWand->m_fEquipped = fEquipped;
  805. LoadItem(aWand);
  806. pcClient->m_pcAvatar->AddInventory(aWand);
  807. pcClient->AddPacket( WORLD_SERVER, aWand->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  808. break;
  809. }
  810. /*
  811. case 9:
  812. {
  813. cPyreals* Cash = new cPyreals(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,dwItemAmount,25000);
  814. Cash->m_fEquipped = fEquipped;
  815. LoadItem(Cash);
  816. pcClient->m_pcAvatar->AddInventory(Cash);
  817. pcClient->AddPacket( WORLD_SERVER, Cash->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  818. break;
  819. }
  820. */
  821. case 11:
  822. {
  823. cAmmo* Ammo = new cAmmo(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,dwItemAmount,dwItemAmount);
  824. Ammo->m_fEquipped = fEquipped;
  825. LoadItem(Ammo);
  826. pcClient->m_pcAvatar->AddInventory(Ammo);
  827. pcClient->AddPacket( WORLD_SERVER, Ammo->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  828. break;
  829. }
  830. case 13:
  831. {
  832. cSpellComps* aComps = new cSpellComps(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, dwItemAmount ,pcModel->m_wBurden);
  833. aComps->m_fEquipped = fEquipped;
  834. LoadItem(aComps);
  835. pcClient->m_pcAvatar->AddInventory(aComps);
  836. pcClient->AddPacket( WORLD_SERVER, aComps->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  837. break;
  838. }
  839. case 14:
  840. {
  841. cGems* aGem = new cGems(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  842. aGem->m_fEquipped = fEquipped;
  843. LoadItem(aGem);
  844. pcClient->m_pcAvatar->AddInventory(aGem);
  845. pcClient->AddPacket( WORLD_SERVER, aGem->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  846. break;
  847. }
  848. case 18:
  849. {
  850. //cClothes* aClothes = new cClothes(cWorldManager::NewGUID_Object(),pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  851. cClothes* aClothes = new cClothes(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  852. aClothes->m_fEquipped = fEquipped;
  853. if (aClothes->m_fEquipped == 2)
  854. {
  855. aClothes->m_dwOwnerID = pcClient->m_pcAvatar->GetGUID();
  856. }
  857. aClothes->m_intColor = intColor;
  858. LoadItem(aClothes);
  859. pcClient->m_pcAvatar->AddInventory(aClothes);
  860. pcClient->AddPacket( WORLD_SERVER, aClothes->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  861. break;
  862. }
  863. case 22:
  864. {
  865. //cFoci* aFoci = new cFoci(cWorldManager::NewGUID_Object(),pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  866. cFoci* aFoci = new cFoci(dwObjectGUID,pcClient->m_pcAvatar->GetGUID(),dwItemModelNumber,1.0,TRUE,wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden);
  867. aFoci->m_fEquipped = fEquipped;
  868. LoadItem(aFoci);
  869. pcClient->m_pcAvatar->AddInventory(aFoci);
  870. pcClient->AddPacket( WORLD_SERVER, aFoci->CreatePacketContainer(pcClient->m_pcAvatar->GetGUID(),pcModel->m_dwModelID),3);
  871. break;
  872. }
  873. }
  874. } else {
  875. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  876. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  877. }
  878. }
  879. lstInventory.clear();
  880. }
  881. /**
  882. * Creates a corpse upon user's death.
  883. *
  884. * @param *pcClient - A pointer to the client creating the corpse.
  885. *
  886. * Author: G70mb2
  887. */
  888. BOOL cMasterServer::Corpse( cClient *pcClient )
  889. {
  890. DWORD dwModel = 2185;
  891. DWORD dwIcon = 1024;
  892. float flScale = 1.0;
  893. BOOL fSolid = 0;
  894. BOOL fSelectable = 1;
  895. BOOL fEquippable = 0;
  896. char szName[60] = { ' ',};
  897. std::ostringstream ssDescription;
  898. ssDescription << "Corpse";
  899. sprintf( szName, "Corpse");
  900. cAbiotic *pcModel = new cAbiotic( cWorldManager::NewGUID_Object( ), pcClient->m_pcAvatar->m_Location, dwModel, flScale, fSolid, dwIcon, szName, ssDescription.str( ), 500, 2500, fSelectable, fEquippable );
  901. pcModel->SetStatic( FALSE );
  902. CorpseCleaner::AddCorpse( pcModel->GetGUID(),120,0);
  903. cWorldManager::AddObject( pcModel );
  904. return TRUE;
  905. }
  906. /**
  907. * Obtains the default starting location from the database.
  908. *
  909. * Author: G70mb2
  910. */
  911. void cMasterServer::LoadStartingLocation( )
  912. {
  913. char szCommand[512];
  914. RETCODE retcode;
  915. char readbuff[9];
  916. char dwPosX[9];
  917. char dwPosY[9];
  918. char dwPosZ[9];
  919. char dwOrientW[9];
  920. char dwOrientX[9];
  921. char dwOrientY[9];
  922. char dwOrientZ[9];
  923. sprintf( szCommand, "SELECT * FROM starting_locations WHERE LocID=1;" );
  924. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  925. retcode = SQLExecute( cDatabase::m_hStmt );
  926. int iCol = 3;
  927. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, readbuff, sizeof( readbuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  928. /*
  929. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flX, sizeof( m_StartingLoc.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  930. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flY, sizeof( m_StartingLoc.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  931. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flZ, sizeof( m_StartingLoc.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  932. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flA, sizeof( m_StartingLoc.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  933. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flB, sizeof( m_StartingLoc.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  934. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flC, sizeof( m_StartingLoc.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  935. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_StartingLoc.m_flW, sizeof( m_StartingLoc.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  936. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  937. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  938. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  939. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  940. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  941. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  942. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  943. retcode = SQLFetch( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  944. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  945. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  946. sscanf(readbuff,"%08x",&m_StartingLoc.m_dwLandBlock);
  947. sscanf(dwPosX,"%08x",&m_StartingLoc.m_flX);
  948. sscanf(dwPosY,"%08x",&m_StartingLoc.m_flY);
  949. sscanf(dwPosZ,"%08x",&m_StartingLoc.m_flZ);
  950. sscanf(dwOrientW,"%08x",&m_StartingLoc.m_flA);
  951. sscanf(dwOrientX,"%08x",&m_StartingLoc.m_flB);
  952. sscanf(dwOrientY,"%08x",&m_StartingLoc.m_flC);
  953. sscanf(dwOrientZ,"%08x",&m_StartingLoc.m_flW);
  954. UpdateConsole( " Starting locations loaded.\r\n" );
  955. // Load Marketplace Location
  956. sprintf( szCommand, "SELECT * FROM starting_locations WHERE LocID=2;" );
  957. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  958. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  959. iCol = 3;
  960. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, readbuff, sizeof( readbuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  961. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flX, sizeof( m_MarketLoc.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  962. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flY, sizeof( m_MarketLoc.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  963. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flZ, sizeof( m_MarketLoc.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  964. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flA, sizeof( m_MarketLoc.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  965. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flB, sizeof( m_MarketLoc.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  966. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flC, sizeof( m_MarketLoc.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  967. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &m_MarketLoc.m_flW, sizeof( m_MarketLoc.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  968. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  969. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  970. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  971. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  972. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  973. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  974. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  975. retcode = SQLFetch( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  976. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  977. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  978. sscanf(readbuff,"%08x",&m_MarketLoc.m_dwLandBlock);
  979. sscanf(dwPosX,"%08x",&m_MarketLoc.m_flX);
  980. sscanf(dwPosY,"%08x",&m_MarketLoc.m_flY);
  981. sscanf(dwPosZ,"%08x",&m_MarketLoc.m_flZ);
  982. sscanf(dwOrientW,"%08x",&m_MarketLoc.m_flA);
  983. sscanf(dwOrientX,"%08x",&m_MarketLoc.m_flB);
  984. sscanf(dwOrientY,"%08x",&m_MarketLoc.m_flC);
  985. sscanf(dwOrientZ,"%08x",&m_MarketLoc.m_flW);
  986. UpdateConsole( " Marketplace location loaded.\r\n" );
  987. }
  988. /**
  989. * Obtains the locations used by the TeleTown command from the database.
  990. */
  991. void cMasterServer::LoadTeleTownList( )
  992. {
  993. m_TeleTownList.clear();
  994. cTeleTownList cTL;
  995. char szCommand[200];
  996. RETCODE retcode;
  997. char szName[75];
  998. char dwLandblock[9];
  999. char dwPosX[9];
  1000. char dwPosY[9];
  1001. char dwPosZ[9];
  1002. char dwOrientW[9];
  1003. char dwOrientX[9];
  1004. char dwOrientY[9];
  1005. char dwOrientZ[9];
  1006. sprintf( szCommand, "SELECT * FROM tele_locations;" );
  1007. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1008. retcode = SQLExecute( cDatabase::m_hStmt );
  1009. int iCol = 3;
  1010. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szName, sizeof( szName ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  1011. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1012. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1013. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1014. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1015. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1016. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1017. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1018. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1019. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  1020. sscanf(dwLandblock,"%08x",&cTL.m_dwLandblock);
  1021. sscanf(dwPosX,"%08x",&cTL.m_flPosX);
  1022. sscanf(dwPosY,"%08x",&cTL.m_flPosY);
  1023. sscanf(dwPosZ,"%08x",&cTL.m_flPosZ);
  1024. sscanf(dwOrientW,"%08x",&cTL.m_flOrientW);
  1025. sscanf(dwOrientX,"%08x",&cTL.m_flOrientX);
  1026. sscanf(dwOrientY,"%08x",&cTL.m_flOrientY);
  1027. sscanf(dwOrientZ,"%08x",&cTL.m_flOrientZ);
  1028. cTL.m_teleString = szName;
  1029. m_TeleTownList.push_back( cTL );
  1030. }
  1031. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1032. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1033. UpdateConsole( " TeleTown locations loaded.\r\n" );
  1034. }
  1035. /**
  1036. * Loads currently existing allegiances from the database.
  1037. *
  1038. * This data is updated as allegiances are altered in-game.
  1039. * The data is used to populate allegiance information sent to clients.
  1040. */
  1041. void cMasterServer::LoadAllegiances( )
  1042. {
  1043. m_AllegianceList.clear();
  1044. char szCommand[200];
  1045. RETCODE retcode;
  1046. DWORD AllegianceID;
  1047. char szName[40];
  1048. DWORD LeaderGUID;
  1049. char MOTD[255];
  1050. unsigned long CreationDate;
  1051. sprintf( szCommand, "SELECT * FROM allegiance;" );
  1052. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1053. retcode = SQLExecute( cDatabase::m_hStmt );
  1054. int iCol = 2;
  1055. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &AllegianceID, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  1056. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szName, sizeof( szName ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1057. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &LeaderGUID, sizeof( DWORD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1058. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, MOTD, sizeof( MOTD ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1059. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &CreationDate, sizeof( unsigned long ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1060. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1061. {
  1062. cAllegiance* aAllegiance = new cAllegiance();
  1063. aAllegiance->LoadAllegiance(AllegianceID,LeaderGUID,szName,MOTD);
  1064. }
  1065. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1066. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1067. for ( std::vector<cAllegiance*>::iterator itAllegiance = m_AllegianceList.begin() ; itAllegiance != m_AllegianceList.end() ; ++itAllegiance )
  1068. {
  1069. cAllegiance::LoadMembersFromDB(*itAllegiance);
  1070. }
  1071. UpdateConsole( " Allegiances loaded.\r\n" );
  1072. }
  1073. /**
  1074. * Loads pre-defined magic models from database.
  1075. *
  1076. * Author: G70mb2
  1077. */
  1078. void cMasterServer::LoadSpellModels( )
  1079. {
  1080. RETCODE retcode;
  1081. char szCommand[512];
  1082. char szMessage[155];
  1083. DWORD dwModelCount;
  1084. DWORD dwNumModels;
  1085. char ModelName[75];
  1086. char szFlags1[9];
  1087. WORD wPortalMode;
  1088. WORD wModel;
  1089. WORD wIcon;
  1090. char szParticle[5];
  1091. char szSoundSet[5];
  1092. char szModelNumber[5];
  1093. float flScale;
  1094. DWORD dwMedGrey;
  1095. DWORD dwBlueGrey;
  1096. WORD wSpellAss;
  1097. DWORD dwSpellID;
  1098. // Start the loading
  1099. sprintf( szCommand, "SELECT MAX(dwSpellID), COUNT(dwSpellID) FROM spellmodels;" );
  1100. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1101. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1102. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwModelCount, sizeof( dwModelCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1103. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwNumModels, sizeof( dwNumModels ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1104. retcode = SQLFetch( cDatabase::m_hStmt );
  1105. if( retcode == SQL_NO_DATA )
  1106. {
  1107. dwModelCount = 0;
  1108. dwNumModels = 0;
  1109. }
  1110. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1111. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1112. sprintf( szMessage, " Loading %d spell models ... ",dwNumModels );
  1113. UpdateConsole((char *)szMessage);
  1114. // Now all that data needs to be loaded
  1115. sprintf( szCommand, "SELECT * FROM spellmodels ORDER BY ID;" );
  1116. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1117. retcode = SQLExecute( cDatabase::m_hStmt );
  1118. int iCol = 1;
  1119. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelName, sizeof( ModelName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1120. // dwFlags1
  1121. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags1, sizeof( szFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1122. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT,&wPortalMode, sizeof( wPortalMode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1123. // Animconfig, Soundset
  1124. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szSoundSet, sizeof( szSoundSet ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1125. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szParticle, sizeof( szParticle ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1126. // dwModelNumber
  1127. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szModelNumber, sizeof( szModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1128. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flScale, sizeof( flScale ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1129. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( wModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1130. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( wIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1131. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMedGrey, sizeof( dwMedGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1132. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwBlueGrey, sizeof( dwBlueGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1133. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSpellAss, sizeof( wSpellAss ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1134. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwSpellID, sizeof( dwSpellID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1135. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1136. {
  1137. cMagicModels* pcModel = new cMagicModels( dwSpellID );
  1138. pcModel->m_strName.assign(ModelName);
  1139. pcModel->m_wPortalMode = wPortalMode;
  1140. pcModel->m_wModel = wModel;
  1141. pcModel->m_wIcon = wIcon;
  1142. sscanf(szParticle,"%08x",&pcModel->m_wParticle);
  1143. sscanf(szSoundSet,"%08x",&pcModel->m_wSoundSet);
  1144. sscanf(szModelNumber,"%08x",&pcModel->m_dwModelNumber);
  1145. pcModel->m_flScale = flScale;
  1146. pcModel->m_dwMedGrey = dwMedGrey;
  1147. pcModel->m_dwBlueGrey = dwBlueGrey;
  1148. pcModel->m_wAssociatedSpell = wSpellAss;
  1149. pcModel->m_dwSpellID = dwSpellID;
  1150. sscanf(szFlags1,"%08x",&pcModel->m_dwFlags1);
  1151. // UpdateConsole( "+" );
  1152. }
  1153. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1154. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1155. }
  1156. /**
  1157. * Loads magic from the database.
  1158. *
  1159. * This member function loads each spell's characteristics from the database.
  1160. *
  1161. * TODO: Load from the 0x0E00000E table in the portal.dat instead.
  1162. */
  1163. void cMasterServer::LoadSpells( )
  1164. {
  1165. RETCODE retcode;
  1166. char szCommand[512];
  1167. char szMessage[155];
  1168. DWORD dwSpellMax;
  1169. DWORD dwSpellCount;
  1170. char SpellName[150];
  1171. char Desc[255];
  1172. char School[50];
  1173. char szIconID[50];
  1174. DWORD dwEffect;
  1175. char szResearchable[5];
  1176. DWORD dwManaCost;
  1177. float flUnkFloat1;
  1178. float flUnkFloat2;
  1179. DWORD dwDifficulty;
  1180. DWORD dwEconomy;
  1181. char szVersion[50];
  1182. float flSpeed;
  1183. DWORD dwType;
  1184. DWORD dwSecondID;
  1185. DWORD dwDuration;
  1186. DWORD dwUnkDouble;
  1187. char szComponents[255];
  1188. char szFiveUnkDoubles[255];
  1189. DWORD dwSpellID;
  1190. // Start the Loading
  1191. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM spells;" );
  1192. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1193. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1194. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwSpellMax, sizeof( dwSpellMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1195. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwSpellCount, sizeof( dwSpellCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1196. retcode = SQLFetch( cDatabase::m_hStmt );
  1197. if( retcode == SQL_NO_DATA )
  1198. {
  1199. dwSpellMax = 0;
  1200. dwSpellCount = 0;
  1201. }
  1202. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1203. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1204. sprintf( szMessage, " Loading %d spells ... ",dwSpellCount );
  1205. UpdateConsole((char *)szMessage);
  1206. // Now all that Data needs to be loaded
  1207. sprintf( szCommand, "SELECT * FROM spells ORDER BY ID;" );
  1208. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1209. retcode = SQLExecute( cDatabase::m_hStmt );
  1210. int iCol = 1;
  1211. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwSpellID, sizeof( dwSpellID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1212. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, SpellName, sizeof( SpellName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1213. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Desc, sizeof( Desc ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1214. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, School, sizeof( School ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1215. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szIconID, sizeof( szIconID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1216. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwEffect, sizeof( dwEffect ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1217. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szResearchable, sizeof( szResearchable ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1218. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwManaCost, sizeof( dwManaCost ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1219. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flUnkFloat1, sizeof( flUnkFloat1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1220. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flUnkFloat2, sizeof( flUnkFloat2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1221. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDifficulty, sizeof( dwDifficulty ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1222. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwEconomy, sizeof( dwEconomy ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1223. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szVersion, sizeof( szVersion ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1224. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flSpeed, sizeof( flSpeed ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1225. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwType, sizeof( dwType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1226. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwSecondID, sizeof( dwSecondID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1227. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDuration, sizeof( dwDuration ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1228. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnkDouble, sizeof( dwUnkDouble ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1229. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szComponents, sizeof( szComponents ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1230. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFiveUnkDoubles, sizeof( szFiveUnkDoubles ), NULL );CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1231. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1232. {
  1233. cSpell* pcSpell = new cSpell( dwSpellID );
  1234. pcSpell->m_strName.assign(SpellName);
  1235. pcSpell->m_strDesc.assign(Desc);
  1236. pcSpell->m_strSchool.assign(School);
  1237. sscanf(szIconID,"%x",&pcSpell->m_dwIconID);
  1238. pcSpell->m_dwEffect = dwEffect;
  1239. if ( strcmp(szResearchable, "Yes") == 0)
  1240. pcSpell->m_fResearchable = true;
  1241. else
  1242. pcSpell->m_fResearchable = false;
  1243. pcSpell->m_dwManaCost = dwManaCost;
  1244. pcSpell->m_flUnkFloat1 = flUnkFloat1;
  1245. pcSpell->m_flUnkFloat2 = flUnkFloat2;
  1246. pcSpell->m_dwDifficulty = dwDifficulty;
  1247. pcSpell->m_fEconomy = dwEconomy;
  1248. pcSpell->m_flSpeed = flSpeed;
  1249. pcSpell->m_dwType = dwType;
  1250. pcSpell->m_iDuration = dwDuration;
  1251. sscanf(szComponents,"%08x %08x %08x %08x %08x %08x %08x %08x %08x",&pcSpell->m_dwComponents[0],&pcSpell->m_dwComponents[1],&pcSpell->m_dwComponents[2],&pcSpell->m_dwComponents[3],&pcSpell->m_dwComponents[4],&pcSpell->m_dwComponents[5],&pcSpell->m_dwComponents[6],&pcSpell->m_dwComponents[7],&pcSpell->m_dwComponents[8],&pcSpell->m_dwComponents[9]);
  1252. DWORD iComp = pcSpell->m_dwComponents[0] & 0xF;
  1253. if (pcSpell->m_dwComponents[5] == 0)
  1254. {
  1255. pcSpell->m_dwLevel = 1;
  1256. }
  1257. else if (pcSpell->m_dwComponents[6] == 0)
  1258. {
  1259. pcSpell->m_dwLevel = 2;
  1260. }
  1261. else if (pcSpell->m_dwComponents[7] == 0)
  1262. {
  1263. if (iComp == 0x0000000A)
  1264. {
  1265. pcSpell->m_dwLevel = 3;
  1266. }
  1267. else if (iComp == 0x00000008)
  1268. {
  1269. pcSpell->m_dwLevel = 4;
  1270. }
  1271. }
  1272. else if (iComp == 0x00000009)
  1273. {
  1274. pcSpell->m_dwLevel = 5;
  1275. }
  1276. else if (iComp == 0x0000000D)
  1277. {
  1278. pcSpell->m_dwLevel = 6;
  1279. }
  1280. sscanf(szFiveUnkDoubles,"%08x",&pcSpell->m_dwEffectAnim);
  1281. // UpdateConsole( "+" );
  1282. }
  1283. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1284. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1285. }
  1286. /**
  1287. * Loads magic components from the database.
  1288. *
  1289. * This member function loads each spell component's characteristics from the database.
  1290. *
  1291. * TODO: Load from the 0x0E00000F table in the portal.dat instead.
  1292. */
  1293. void cMasterServer::LoadSpellComps( )
  1294. {
  1295. RETCODE retcode;
  1296. char szCommand[512];
  1297. char szMessage[155];
  1298. DWORD dwCompMax;
  1299. DWORD dwCompCount;
  1300. DWORD dwCompID;
  1301. char CompName[150];
  1302. char Type[50];
  1303. char Words[50];
  1304. char szIconID[50];
  1305. float flChargeID;
  1306. float flBurnRate;
  1307. char szAnimID[50];
  1308. // Start the Loading
  1309. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM spellcomps;" );
  1310. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1311. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1312. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwCompMax, sizeof( dwCompMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1313. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwCompCount, sizeof( dwCompCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1314. retcode = SQLFetch( cDatabase::m_hStmt );
  1315. if( retcode == SQL_NO_DATA )
  1316. {
  1317. dwCompMax = 0;
  1318. dwCompCount = 0;
  1319. }
  1320. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1321. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1322. sprintf( szMessage, " Loading %d spell components ... ",dwCompCount );
  1323. UpdateConsole((char *)szMessage);
  1324. // Now all that Data needs to be loaded
  1325. sprintf( szCommand, "SELECT * FROM spellcomps ORDER BY ID;" );
  1326. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1327. retcode = SQLExecute( cDatabase::m_hStmt );
  1328. int iCol = 1;
  1329. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwCompID, sizeof( dwCompID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1330. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, CompName, sizeof( CompName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1331. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Type, sizeof( Type ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1332. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szIconID, sizeof( szIconID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1333. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szAnimID, sizeof( szAnimID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1334. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flChargeID, sizeof( flChargeID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1335. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Words, sizeof( Words ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1336. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flBurnRate, sizeof( flBurnRate ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1337. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1338. {
  1339. cSpellComp* pcComp = new cSpellComp( dwCompID );
  1340. pcComp->m_strName.assign(CompName);
  1341. pcComp->m_strType.assign(Type);
  1342. pcComp->m_strWords.assign(Words);
  1343. sscanf(szIconID,"%x",&pcComp->m_dwIconID);
  1344. sscanf(szAnimID,"%8x",&pcComp->m_dwAnimID);
  1345. pcComp->m_flChargeID = flChargeID;
  1346. pcComp->m_flBurnRate = flBurnRate;
  1347. // UpdateConsole( "+" );
  1348. }
  1349. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1350. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1351. }
  1352. /**
  1353. * Loads the data for the specific item.
  1354. *
  1355. * This member function initializes the model information for the given item.
  1356. *
  1357. * @param *pcItem - A pointer to the item to load.
  1358. */
  1359. void cMasterServer::LoadItem( cObject *pcItem )
  1360. {
  1361. RETCODE retcode;
  1362. char szCommand[512];
  1363. char readbuff01[5];
  1364. char readbuff02[3];
  1365. char readbuff03[3];
  1366. BYTE bWearVectorCount;
  1367. sprintf( szCommand, "SELECT * FROM avatar_clothing_palettes WHERE ObjectGUID = %lu;",pcItem->GetGUID() );
  1368. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1369. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1370. int iCol = 3;
  1371. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bWearVectorCount, sizeof( BYTE ), NULL );
  1372. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff01 , sizeof( readbuff01 ), NULL );
  1373. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff02 , sizeof( readbuff02 ), NULL );
  1374. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff03 , sizeof( readbuff03 ), NULL );
  1375. pcItem->m_bWearPaletteChange = 0;
  1376. for ( int palCount = 0 ; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS); ++palCount )
  1377. {
  1378. sscanf(readbuff01,"%04x",&pcItem->m_WearVectorPal[palCount].m_wNewPalette);
  1379. sscanf(readbuff02,"%02x",&pcItem->m_WearVectorPal[palCount].m_ucOffset);
  1380. sscanf(readbuff03,"%02x",&pcItem->m_WearVectorPal[palCount].m_ucLength);
  1381. pcItem->m_bWearPaletteChange = pcItem->m_bWearPaletteChange + 1;
  1382. }
  1383. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1384. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1385. cItemModels *pcModel = cItemModels::FindModel(pcItem->GetItemModelID());
  1386. if (pcModel->m_PortalLinker != 0)
  1387. {
  1388. pcItem->m_bPaletteChange = 0;
  1389. pcModel->m_bModelChange = 0;
  1390. pcModel->m_bTextureChange = 0;
  1391. cPortalDat::LoadItemModel(pcItem, DWORD(0x02000000 | pcModel->m_dwModelNumber),pcItem->m_intColor);
  1392. }
  1393. }
  1394. /**
  1395. * Loads predefined item models from the database.
  1396. *
  1397. * An item model comprises the general characteristics of a given item.
  1398. *
  1399. * Note: Used for items.
  1400. *
  1401. * TODO: Load from the 0x10000000 entries in the portal.dat instead.
  1402. *
  1403. * Author: Cubem0j0
  1404. */
  1405. void cMasterServer::LoadItemModels( )
  1406. {
  1407. RETCODE retcode;
  1408. char szCommand[512];
  1409. char szMessage[155];
  1410. DWORD dwModelCount;
  1411. DWORD dwNumModels;
  1412. char ModelName[75];
  1413. char ModelDescription[512];
  1414. char PortalLinker[9];
  1415. int item_type;
  1416. DWORD dwModelID;
  1417. BYTE bPaletteChange;
  1418. sPaletteChange vPalettes[255];
  1419. BYTE bTextureChange;
  1420. sTextureChange vTextures[255];
  1421. BYTE bModelChange;
  1422. sModelChange vModels[255];
  1423. char szFlags1[9];
  1424. char szFlags2[9];
  1425. char szObjFlags1[9];
  1426. char szObjFlags2[9];
  1427. WORD wPortalMode;
  1428. // char szModel[5];
  1429. // char szIcon[5];
  1430. WORD wModel;
  1431. WORD wIcon;
  1432. char szSoundSet[5];
  1433. char szwUnknown_1[5];
  1434. int bIsContainer;
  1435. int bIsClothing;
  1436. DWORD dwUnknown_Blue;
  1437. char szModelNumber[5];
  1438. float flScale;
  1439. DWORD dwUnknown_LightGrey;
  1440. DWORD dwTrio1[3];
  1441. DWORD dwMedGrey;
  1442. DWORD dwBlueGrey;
  1443. WORD wSeagreen8;
  1444. DWORD dwUnknownCount;
  1445. DWORD dwUnknown_v2;
  1446. DWORD dwUnknown_v6;
  1447. DWORD dwValue;
  1448. char szUseableOn[9];
  1449. // float fApproachDistance;
  1450. DWORD dwIconHighlight;
  1451. WORD wAmmoType;
  1452. BYTE bWieldType;
  1453. WORD wUses;
  1454. WORD wUseLimit;
  1455. WORD wStack;
  1456. WORD wStackLimit;
  1457. // DWORD dwContainerID;
  1458. DWORD dwVitalID;
  1459. char szEquipPossible[9];
  1460. char szEquipActual[9];
  1461. char szCoverage[9];
  1462. float fWorkmanship;
  1463. WORD wBurden;
  1464. //DWORD dwSpellID;
  1465. WORD wSpellID;
  1466. DWORD dwOwner;
  1467. WORD wHooks;
  1468. DWORD dwMaterialType;
  1469. DWORD dwQuestItemID;
  1470. int vital_affect;
  1471. int IsUAWeapon;
  1472. DWORD dwArmorLevel;
  1473. float fProt_S;
  1474. float fProt_P;
  1475. float fProt_B;
  1476. float fProt_F;
  1477. float fProt_C;
  1478. float fProt_A;
  1479. float fProt_E;
  1480. DWORD dwWeaponDamage;
  1481. DWORD dwWeaponSpeed;
  1482. DWORD dwWeaponSkill;
  1483. DWORD dwDamageType;
  1484. double dWeaponVariance;
  1485. double dWeaponModifier;
  1486. double dWeaponPower;
  1487. double dWeaponAttack;
  1488. char szTitle[100]; // = "Asherons Call";
  1489. char szAuthor[100]; // = "prewritten";
  1490. char szComment[100]; // = "Welcome To Asheron's Call";
  1491. char szCommentAuthorName[100]; // = "CommentAuthorName";
  1492. DWORD dwUsedPages;
  1493. DWORD dwContentPages;
  1494. DWORD dwTotalPages;
  1495. char szPageOneText[2048];
  1496. char szPageTwoText[2048];
  1497. char szPageThreeText[2048];
  1498. //Start the loading
  1499. sprintf( szCommand, "SELECT MAX(dwLinker),COUNT(dwLinker) FROM items_templates;" );
  1500. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1501. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1502. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwModelCount, sizeof( dwModelCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1503. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwNumModels, sizeof( dwNumModels ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1504. retcode = SQLFetch( cDatabase::m_hStmt );
  1505. if( retcode == SQL_NO_DATA )
  1506. {
  1507. dwModelCount = 0;
  1508. dwNumModels = 0;
  1509. }
  1510. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1511. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1512. sprintf( szMessage, " Loading %d pre-defined item models ... ",dwNumModels );
  1513. UpdateConsole((char *)szMessage);
  1514. //Now all that data needs to be loaded
  1515. // sprintf( szCommand, "SELECT ID,quest_item_id,Name,Description,ItemType,bPalette,bTexture,bModel,dwFlags1,wPortalMode,wUnknown_1,wModel,wIcon,SoundSet,dwUnknown_Blue,dwModelNumber,flScale,dwUnknown_LightGrey,dwTrio1_1,dwTrio1_2,dwTrio1_3,dwMedGrey,dwBlueGrey,dwSeagreen8,dwUnknown_v2,dwUnknown_v6,dwUnkCount,dwLinker,dwFlags2,dwObjectFlags1,dwObjectFlags2,dwValue,dwUseableOn,dwIconHighlight,wAmmoType,bWieldType,wUses,wUseLimit,wStack,wStackLimit,dwVitalID,dwEquipPoss,dwEquipAct,dwCoverage,fWorkmanship,wBurden,dwSpellID,dwOwner,wHooks,dwMaterial,vital_effect,dwArmorLevel,fProt_Slashing,fProt_Piercing,fProt_Bludgeon,fProt_Fire,fProt_Cold,fProt_Acid,fProt_Electric,dwWeaponDamage,dwWeaponSpeed,dwWeaponSkill,dwDamageType,dWeaponVariance,dWeaponModifier,dWeaponPower,ddWeaponAttack FROM items_templates ORDER BY ID;" );
  1516. sprintf( szCommand, "SELECT * FROM items_templates ORDER BY ID;" );
  1517. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1518. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1519. int iCol = 2;
  1520. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwQuestItemID, sizeof( dwQuestItemID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1521. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelName, sizeof( ModelName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1522. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelDescription, sizeof( ModelDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1523. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &item_type, sizeof( item_type), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1524. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, PortalLinker, sizeof( PortalLinker ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1525. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bPaletteChange, sizeof( BYTE), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1526. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bTextureChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1527. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bModelChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1528. // dwFlags1
  1529. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags1, sizeof( szFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1530. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wPortalMode, sizeof( wPortalMode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1531. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szwUnknown_1, sizeof( szwUnknown_1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1532. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bIsContainer, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1533. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bIsClothing, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1534. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &IsUAWeapon, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1535. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( wModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1536. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( wIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1537. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szModel, sizeof( szModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1538. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szIcon, sizeof( szIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1539. //Animconfig, Soundset
  1540. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szAnimConfig, sizeof( szAnimConfig ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1541. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szSoundSet, sizeof( szSoundSet ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1542. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_Blue, sizeof( dwUnknown_Blue ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1543. //dwModelNumber
  1544. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szModelNumber, sizeof( szModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1545. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flScale, sizeof( flScale ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1546. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_LightGrey, sizeof( dwUnknown_LightGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1547. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[0], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1548. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[1], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1549. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[2], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1550. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMedGrey, sizeof( dwMedGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1551. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwBlueGrey, sizeof( dwBlueGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1552. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSeagreen8, sizeof( wSeagreen8 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1553. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v2, sizeof( dwUnknown_v2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1554. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v6, sizeof( dwUnknown_v6 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1555. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknownCount, sizeof( dwUnknownCount ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1556. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelID, sizeof( dwModelID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1557. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags2, sizeof( szFlags2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1558. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szObjFlags1, sizeof( szObjFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1559. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szObjFlags2, sizeof( szObjFlags2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1560. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwValue, sizeof( dwValue ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1561. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szUseableOn, sizeof( szUseableOn ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1562. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fApproachDistance, sizeof( fApproachDistance ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1563. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwIconHighlight, sizeof( dwIconHighlight ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1564. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAmmoType, sizeof( wAmmoType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1565. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bWieldType, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1566. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wUses, sizeof( wUses ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1567. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wUseLimit, sizeof( wUseLimit ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1568. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wStack, sizeof( wStack ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1569. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wStackLimit, sizeof( wStackLimit ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1570. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwContainerID, sizeof( dwContainerID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1571. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwVitalID, sizeof( dwVitalID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1572. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szEquipPossible, sizeof( szEquipPossible ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1573. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szEquipActual, sizeof( szEquipActual ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1574. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szCoverage, sizeof( szCoverage ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1575. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fWorkmanship, sizeof( fWorkmanship ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1576. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wBurden, sizeof( wBurden ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1577. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSpellID, sizeof( wSpellID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1578. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwOwner, sizeof( dwOwner ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1579. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wHooks, sizeof( wHooks ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1580. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMaterialType, sizeof( dwMaterialType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1581. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &vital_affect, sizeof( vital_affect ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1582. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwArmorLevel, sizeof( dwArmorLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1583. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_S, sizeof( fProt_S ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1584. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_P, sizeof( fProt_P ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1585. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_B, sizeof( fProt_B ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1586. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_F, sizeof( fProt_F ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1587. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_C, sizeof( fProt_C ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1588. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_A, sizeof( fProt_A ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1589. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &fProt_E, sizeof( fProt_E ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1590. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwWeaponDamage, sizeof( dwWeaponDamage ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1591. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwWeaponSpeed, sizeof( dwWeaponSpeed ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1592. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwWeaponSkill, sizeof( dwWeaponSkill ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1593. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDamageType, sizeof( dwDamageType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1594. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &dWeaponVariance, sizeof( dWeaponVariance ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1595. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &dWeaponModifier, sizeof( dWeaponModifier ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1596. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &dWeaponPower, sizeof( dWeaponPower ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1597. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &dWeaponAttack, sizeof( dWeaponAttack ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1598. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS ; ++i )
  1599. {
  1600. cItemModels* pcModel = new cItemModels( dwModelID );
  1601. pcModel->m_dwQuestItemID = dwQuestItemID;
  1602. pcModel->m_strName.assign(ModelName);
  1603. pcModel->m_strDescription.assign(ModelDescription);
  1604. sscanf(PortalLinker,"%08x",&pcModel->m_PortalLinker);
  1605. pcModel->m_ItemType = item_type;
  1606. pcModel->m_bPaletteChange = bPaletteChange;
  1607. pcModel->m_wPaletteVector = dwModelID;
  1608. pcModel->m_bTextureChange = bTextureChange;
  1609. pcModel->m_wTextureVector = dwModelID;
  1610. pcModel->m_bModelChange = bModelChange;
  1611. pcModel->m_wModelVector = dwModelID;
  1612. pcModel->m_wWearPaletteVector = dwModelID;
  1613. pcModel->m_wWearTextureVector = dwModelID;
  1614. pcModel->m_wWearModelVector = dwModelID;
  1615. sscanf(szFlags1,"%08x",&pcModel->m_dwFlags1);
  1616. pcModel->m_wPortalMode = wPortalMode;
  1617. sscanf(szwUnknown_1, "%04x",&pcModel->m_wUnknown_1);
  1618. pcModel->m_isContainer = bIsContainer;
  1619. pcModel->m_isClothing = bIsClothing;
  1620. pcModel->m_isUAWeapon = IsUAWeapon;
  1621. pcModel->m_wModel = wModel;
  1622. pcModel->m_wIcon = wIcon;
  1623. // sscanf(szModel,"%04x",&pcModel->m_wModel);
  1624. // sscanf(szIcon,"%04x",&pcModel->m_wIcon);
  1625. sscanf(szSoundSet,"%08x",&pcModel->m_wSoundSet);
  1626. pcModel->m_dwUnknown_Blue = dwUnknown_Blue;
  1627. sscanf(szModelNumber,"%08x",&pcModel->m_dwModelNumber);
  1628. pcModel->m_flScale = flScale;
  1629. pcModel->m_dwUnknown_LightGrey = dwUnknown_LightGrey;
  1630. pcModel->m_dwTrio1[0] = dwTrio1[0];
  1631. pcModel->m_dwTrio1[1] = dwTrio1[1];
  1632. pcModel->m_dwTrio1[2] = dwTrio1[2];
  1633. pcModel->m_dwMedGrey = dwMedGrey;
  1634. pcModel->m_dwBlueGrey = dwBlueGrey;
  1635. pcModel->m_wSeagreen8 = wSeagreen8;
  1636. pcModel->m_dwUnknown_v2 = dwUnknown_v2;
  1637. pcModel->m_dwUnknown_v6 = dwUnknown_v6;
  1638. pcModel->m_dwUnknownCount = dwUnknownCount;
  1639. sscanf(szFlags2, "%08x",&pcModel->m_dwFlags2);
  1640. sscanf(szObjFlags1, "%08x",&pcModel->m_dwObjectFlags1);
  1641. sscanf(szObjFlags2, "%08x",&pcModel->m_dwObjectFlags2);
  1642. pcModel->m_dwValue = dwValue;
  1643. sscanf(szUseableOn, "%08x",&pcModel->m_dwUseableOn);
  1644. //pcModel->m_fApproachDistance = fApproachDistance;
  1645. pcModel->m_dwIconHighlight = dwIconHighlight;
  1646. pcModel->m_wAmmoType = wAmmoType;
  1647. pcModel->m_bWieldType = bWieldType;
  1648. pcModel->m_wUses = wUses;
  1649. pcModel->m_wUseLimit = wUseLimit;
  1650. pcModel->m_wStack = wStack;
  1651. pcModel->m_wStackLimit = wStackLimit;
  1652. //pcModel->m_dwContainerID = dwContainerID;
  1653. pcModel->m_dwVitalID = dwVitalID;
  1654. sscanf(szEquipPossible, "%08x",&pcModel->m_dwEquipPossible);
  1655. sscanf(szEquipActual, "%08x",&pcModel->m_dwEquipActual);
  1656. sscanf(szCoverage, "%08x",&pcModel->m_dwCoverage);
  1657. pcModel->m_fWorkmanship = fWorkmanship;
  1658. pcModel->m_wBurden = wBurden;
  1659. pcModel->m_wSpellID = wSpellID;
  1660. pcModel->m_dwOwner = dwOwner;
  1661. pcModel->m_wHooks = wHooks;
  1662. pcModel->m_dwMaterialType = dwMaterialType;
  1663. pcModel->m_vital_affect = vital_affect;
  1664. pcModel->m_dwArmor_Level = dwArmorLevel;
  1665. pcModel->m_fProt_Slashing = fProt_S;
  1666. pcModel->m_fProt_Piercing = fProt_P;
  1667. pcModel->m_fProt_Bludgeon = fProt_B;
  1668. pcModel->m_fProt_Fire = fProt_F;
  1669. pcModel->m_fProt_Cold = fProt_C;
  1670. pcModel->m_fProt_Acid = fProt_A;
  1671. pcModel->m_fProt_Electric = fProt_E;
  1672. pcModel->m_dwWeaponDamage = dwWeaponDamage;
  1673. pcModel->m_dwWeaponSpeed = dwWeaponSpeed;
  1674. pcModel->m_dwWeaponSkill = dwWeaponSkill;
  1675. pcModel->m_dwDamageType = dwDamageType;
  1676. pcModel->m_dWeaponVariance = dWeaponVariance;
  1677. pcModel->m_dWeaponModifier = dWeaponModifier;
  1678. pcModel->m_dWeaponPower = dWeaponPower;
  1679. pcModel->m_dWeaponAttack = dWeaponAttack;
  1680. }
  1681. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1682. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1683. /* k109: Load book data */
  1684. for ( DWORD d = 0; d < dwModelCount+1; d++)
  1685. {
  1686. cItemModels *pcModel = cItemModels::Hash_Find( d );
  1687. if(pcModel)
  1688. {
  1689. if(pcModel->m_ItemType == 4)
  1690. {
  1691. sprintf( szCommand, "SELECT * FROM items_books WHERE dwLinker = %d;",pcModel->m_dwModelID );
  1692. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1693. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1694. int iCol = 5;
  1695. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szTitle, sizeof( szTitle ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1696. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szAuthor, sizeof( szAuthor ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1697. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szComment, sizeof( szComment ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1698. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szCommentAuthorName, sizeof( szCommentAuthorName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1699. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUsedPages, sizeof( dwUsedPages ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1700. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwContentPages, sizeof( dwContentPages ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1701. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwTotalPages, sizeof( dwTotalPages ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1702. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szPageOneText, sizeof( szPageOneText ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1703. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szPageTwoText, sizeof( szPageTwoText ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1704. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szPageThreeText, sizeof( szPageThreeText ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1705. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1706. {
  1707. pcModel->m_Title.assign(szTitle);
  1708. pcModel->m_Author.assign(szAuthor);
  1709. pcModel->m_Comment.assign(szComment);
  1710. pcModel->m_CommentAuthor.assign(szCommentAuthorName);
  1711. pcModel->m_UsedPages = dwUsedPages;
  1712. pcModel->m_ContentPages = dwContentPages;
  1713. pcModel->m_TotalPages = dwTotalPages;
  1714. pcModel->m_Pages[0].textPages = szPageOneText;
  1715. pcModel->m_Pages[1].textPages = szPageTwoText;
  1716. pcModel->m_Pages[2].textPages = szPageThreeText;
  1717. //pcModel->m_Page1.assign(szPageOneText);
  1718. //pcModel->m_Page2.assign(szPageTwoText);
  1719. //pcModel->m_Page3.assign(szPageThreeText);
  1720. }
  1721. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1722. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1723. }
  1724. }
  1725. }
  1726. //===============================================================
  1727. // Load all of the Vector Data for Each Model ID
  1728. //
  1729. //===============================================================
  1730. for ( d = 0; d < dwModelCount+1; d++)
  1731. {
  1732. cItemModels *pcModel = cItemModels::Hash_Find( d );
  1733. if(pcModel)
  1734. {
  1735. sprintf( szCommand, "SELECT * FROM items_vector_palettes WHERE ModelVector=%d ORDER BY VectorCount;", pcModel->m_wPaletteVector);
  1736. // Load Palette vector into array
  1737. // Define Temp Variables
  1738. BYTE bVectorCount;
  1739. char readbuff01[5];
  1740. char readbuff02[3];
  1741. char readbuff03[3];
  1742. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1743. retcode = SQLExecute( cDatabase::m_hStmt );
  1744. iCol = 3;
  1745. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  1746. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff01 , sizeof( readbuff01 ), NULL );
  1747. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff02 , sizeof( readbuff02 ), NULL );
  1748. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff03 , sizeof( readbuff03 ), NULL );
  1749. for ( int intPcount = 0 ; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intPcount < pcModel->m_bPaletteChange +1); ++intPcount )
  1750. {
  1751. // Scan the text into hexadecimal
  1752. sscanf(readbuff01,"%04x",&pcModel->m_vectorPal[intPcount].m_wNewPalette);
  1753. sscanf(readbuff02,"%02x",&pcModel->m_vectorPal[intPcount].m_ucOffset);
  1754. sscanf(readbuff03,"%02x",&pcModel->m_vectorPal[intPcount].m_ucLength);
  1755. }
  1756. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1757. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1758. // Load Texture Vector into Array
  1759. // Define Temp Variables
  1760. char readbuff04[3];
  1761. char readbuff05[5];
  1762. char readbuff06[5];
  1763. sprintf( szCommand, "SELECT * FROM items_vector_textures WHERE ModelVector=%d ORDER BY VectorCount;",pcModel->m_wTextureVector);
  1764. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1765. retcode = SQLExecute( cDatabase::m_hStmt );
  1766. iCol = 3;
  1767. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  1768. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff04, sizeof( readbuff04 ), NULL );
  1769. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff05, sizeof( readbuff05 ), NULL );
  1770. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff06 , sizeof( readbuff06 ), NULL );
  1771. for ( int intT = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intT < pcModel->m_bTextureChange + 1); ++intT )
  1772. {
  1773. sscanf(readbuff04,"%02x",&pcModel->m_vectorTex[intT].m_bModelIndex);
  1774. sscanf(readbuff05,"%04x",&pcModel->m_vectorTex[intT].m_wOldTexture);
  1775. sscanf(readbuff06,"%04x",&pcModel->m_vectorTex[intT].m_wNewTexture);
  1776. }
  1777. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1778. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1779. // Load Model Vectors into Array
  1780. // Define Temp Variables
  1781. char readbuff07[3];
  1782. char readbuff08[5];
  1783. sprintf( szCommand, "SELECT * FROM items_vector_models WHERE ModelVector=%d ORDER BY VectorCount;", pcModel->m_wModelVector);
  1784. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1785. retcode = SQLExecute( cDatabase::m_hStmt );
  1786. iCol = 3;
  1787. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  1788. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff07, sizeof( readbuff07 ), NULL );
  1789. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff08 , sizeof( readbuff08 ), NULL );
  1790. for ( int intM = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intM < pcModel->m_bModelChange + 1); ++intM )
  1791. {
  1792. sscanf(readbuff07,"%02x",&pcModel->m_vectorMod[intM].m_bModelIndex);
  1793. sscanf(readbuff08,"%04x",&pcModel->m_vectorMod[intM].m_wNewModel);
  1794. }
  1795. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1796. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1797. }
  1798. }
  1799. //===============================================================
  1800. // Load all of the Avatar Model Vector Data for Each Model ID
  1801. //
  1802. //===============================================================
  1803. for ( d = 0; d < dwModelCount+1; d++)
  1804. {
  1805. cItemModels *pcModel = cItemModels::Hash_Find( d );
  1806. if(pcModel && pcModel->m_isClothing == 1)
  1807. {
  1808. if (pcModel->m_PortalLinker != 0)
  1809. {
  1810. pcModel->m_bWearModelChange = 0;
  1811. pcModel->m_bWearTextureChange = 0;
  1812. pcModel->m_clothingModelLoaded = false;
  1813. } else {
  1814. pcModel->m_clothingModelLoaded = true;
  1815. // Define Temp Variables
  1816. sprintf( szCommand, "SELECT * FROM avatar_clothing_palettes WHERE ObjectGUID=%d ORDER BY VectorCount;", pcModel->m_wWearPaletteVector);
  1817. // Load Palette vector into array
  1818. // Define Temp Variables
  1819. BYTE bWearVectorCount;
  1820. char readbuff09[5];
  1821. char readbuff10[3];
  1822. char readbuff11[3];
  1823. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1824. retcode = SQLExecute( cDatabase::m_hStmt );
  1825. iCol = 3;
  1826. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bWearVectorCount, sizeof( BYTE ), NULL );
  1827. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff09 , sizeof( readbuff09 ), NULL );
  1828. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff10 , sizeof( readbuff10 ), NULL );
  1829. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff11 , sizeof( readbuff11 ), NULL );
  1830. pcModel->m_bWearPaletteChange = 0;
  1831. for ( int intPcount = 0 ; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS); ++intPcount )
  1832. {
  1833. sscanf(readbuff09,"%04x",&pcModel->m_WearVectorPal[intPcount].m_wNewPalette);
  1834. sscanf(readbuff10,"%02x",&pcModel->m_WearVectorPal[intPcount].m_ucOffset);
  1835. sscanf(readbuff11,"%02x",&pcModel->m_WearVectorPal[intPcount].m_ucLength);
  1836. pcModel->m_bWearPaletteChange = pcModel->m_bWearPaletteChange + 1;
  1837. }
  1838. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1839. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1840. // Load Texture Vector into Array
  1841. char readbuff12[3];
  1842. char readbuff13[5];
  1843. char readbuff14[5];
  1844. sprintf( szCommand, "SELECT * FROM avatar_clothing_textures WHERE Linker=%d ORDER BY VectorCount;",pcModel->m_wWearTextureVector);
  1845. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1846. retcode = SQLExecute( cDatabase::m_hStmt );
  1847. iCol = 3;
  1848. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bWearVectorCount, sizeof( BYTE ), NULL );
  1849. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff12, sizeof( readbuff12 ), NULL );
  1850. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff13, sizeof( readbuff13 ), NULL );
  1851. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff14 , sizeof( readbuff14 ), NULL );
  1852. pcModel->m_bWearTextureChange = 0;
  1853. for ( int intT = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS); ++intT )
  1854. {
  1855. sscanf(readbuff12,"%02x",&pcModel->m_WearVectorTex[intT].m_bModelIndex);
  1856. sscanf(readbuff13,"%04x",&pcModel->m_WearVectorTex[intT].m_wOldTexture);
  1857. sscanf(readbuff14,"%04x",&pcModel->m_WearVectorTex[intT].m_wNewTexture);
  1858. pcModel->m_bWearTextureChange = pcModel->m_bWearTextureChange + 1;
  1859. }
  1860. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1861. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1862. // Load Model Vectors into Array
  1863. // Define Temp Variables
  1864. char readbuff15[3];
  1865. char readbuff16[5];
  1866. sprintf( szCommand, "SELECT * FROM avatar_clothing_models WHERE Linker=%d ORDER BY VectorCount;", pcModel->m_wWearModelVector);
  1867. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  1868. retcode = SQLExecute( cDatabase::m_hStmt );
  1869. iCol = 3;
  1870. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bWearVectorCount, sizeof( BYTE ), NULL );
  1871. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff15, sizeof( readbuff15 ), NULL );
  1872. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff16 , sizeof( readbuff16 ), NULL );
  1873. pcModel->m_bWearModelChange = 0;
  1874. for ( int intM = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS); ++intM )
  1875. {
  1876. sscanf(readbuff15,"%02x",&pcModel->m_WearVectorMod[intM].m_bModelIndex);
  1877. sscanf(readbuff16,"%04x",&pcModel->m_WearVectorMod[intM].m_wNewModel);
  1878. pcModel->m_bWearModelChange = pcModel->m_bWearModelChange + 1;
  1879. }
  1880. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1881. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  1882. // UpdateConsole( "+" );
  1883. }
  1884. }
  1885. }
  1886. }
  1887. /**
  1888. * Loads pre-defined world object models from the database.
  1889. *
  1890. * A world object model comprises the general characteristics of a world object item.
  1891. *
  1892. * Author: Cubem0j0
  1893. */
  1894. void cMasterServer::LoadWorldModels( )
  1895. {
  1896. RETCODE retcode;
  1897. char szCommand[512];
  1898. char szMessage[155];
  1899. DWORD dwModelCount;
  1900. DWORD dwNumModels;
  1901. char ModelName[75];
  1902. char ModelDescription[512];
  1903. char ModelDescription2[512];
  1904. DWORD dwModelID;
  1905. BYTE bPaletteChange;
  1906. sPaletteChange vPalettes[255];
  1907. BYTE bTextureChange;
  1908. sTextureChange vTextures[255];
  1909. BYTE bModelChange;
  1910. sModelChange vModels[255];
  1911. char szFlags1[9];
  1912. char szFlags2[9];
  1913. char szObjFlags1[9];
  1914. char szObjFlags2[9];
  1915. WORD wPortalMode;
  1916. WORD wUnknown_1;
  1917. WORD wModel;
  1918. WORD wIcon;
  1919. char szSoundSet[5];
  1920. char szAnimConfig[5];
  1921. DWORD dwUnknown_Blue;
  1922. char szModelNumber[5];
  1923. float flScale;
  1924. DWORD dwUnknown_LightGrey;
  1925. DWORD dwTrio1[3];
  1926. DWORD dwMedGrey;
  1927. DWORD dwBlueGrey;
  1928. WORD wSeagreen8;
  1929. DWORD dwUnknownCount;
  1930. char bInitialAnimation[200];
  1931. DWORD dwUnknown_v2;
  1932. DWORD dwUnknown_v6;
  1933. // Start the loading
  1934. sprintf( szCommand, "SELECT MAX(dwLinker),COUNT(dwLinker) FROM worldobjects_templates;" );
  1935. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1936. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1937. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwModelCount, sizeof( dwModelCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1938. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwNumModels, sizeof( dwNumModels ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  1939. retcode = SQLFetch( cDatabase::m_hStmt );
  1940. if( retcode == SQL_NO_DATA )
  1941. {
  1942. dwModelCount = 0;
  1943. dwNumModels = 0;
  1944. }
  1945. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1946. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  1947. sprintf( szMessage, " Loading %d pre-defined world object models ... ",dwNumModels );
  1948. UpdateConsole((char *)szMessage);
  1949. // Now all that data needs to be loaded
  1950. // sprintf( szCommand, "SELECT ID,Name,Description,Description2,bPalette,bTexture,bModel,dwFlags1,wPortalMode,wUnknown_1,wModel,wIcon,SoundSet,AnimConfig,dwUnknown_Blue,dwModelNumber,flScale,dwUnknown_LightGrey,dwTrio1_1,dwTrio1_2,dwTrio1_3,dwMedGrey,dwBlueGrey,dwSeagreen8,dwUnknown_v2,dwUnknown_v6,dwUnkCount,unknownBytes,dwLinker,dwFlags2,dwObjectFlags1,dwObjectFlags2 FROM worldobjects_templates ORDER BY ID;" );
  1951. sprintf( szCommand, "SELECT * FROM worldobjects_templates ORDER BY ID;" );
  1952. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1953. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1954. int iCol = 2;
  1955. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelName, sizeof( ModelName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1956. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelDescription, sizeof( ModelDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1957. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelDescription2, sizeof( ModelDescription2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1958. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bPaletteChange, sizeof( BYTE), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1959. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bTextureChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1960. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bModelChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1961. // dwFlags1
  1962. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags1, sizeof( szFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1963. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wPortalMode, sizeof( wPortalMode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1964. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wUnknown_1, sizeof( wUnknown_1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1965. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( wModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1966. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( wIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1967. // Animconfig, Soundset
  1968. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szSoundSet, sizeof( szSoundSet ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1969. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szAnimConfig, sizeof( szAnimConfig ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1970. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_Blue, sizeof( dwUnknown_Blue ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1971. // dwModelNumber
  1972. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szModelNumber, sizeof( szModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1973. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flScale, sizeof( flScale ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1974. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_LightGrey, sizeof( dwUnknown_LightGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1975. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[0], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1976. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[1], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1977. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[2], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1978. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMedGrey, sizeof( dwMedGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1979. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwBlueGrey, sizeof( dwBlueGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1980. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSeagreen8, sizeof( wSeagreen8 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1981. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v2, sizeof( dwUnknown_v2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1982. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v6, sizeof( dwUnknown_v6 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1983. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknownCount, sizeof( dwUnknownCount ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1984. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &bInitialAnimation, sizeof( bInitialAnimation ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1985. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelID, sizeof( dwModelID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1986. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags2, sizeof( szFlags2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1987. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR,&szObjFlags1, sizeof( szObjFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1988. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR,&szObjFlags2, sizeof( szObjFlags2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  1989. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  1990. {
  1991. // #pragma warning(disable:4786)
  1992. cWObjectModels* pcModel = new cWObjectModels( dwModelID );
  1993. pcModel->m_strName.assign(ModelName);
  1994. pcModel->m_strDescription.assign(ModelDescription);
  1995. pcModel->m_bPaletteChange = bPaletteChange;
  1996. pcModel->m_wPaletteVector = dwModelID;
  1997. pcModel->m_bTextureChange = bTextureChange;
  1998. pcModel->m_wTextureVector = dwModelID;
  1999. pcModel->m_bModelChange = bModelChange;
  2000. pcModel->m_wModelVector = dwModelID;
  2001. sscanf(szFlags1,"%08x",&pcModel->m_dwFlags1);
  2002. pcModel->m_wPortalMode = wPortalMode;
  2003. pcModel->m_wUnknown_1 = wUnknown_1;
  2004. pcModel->m_wModel = wModel;
  2005. pcModel->m_wIcon = wIcon;
  2006. sscanf(szSoundSet,"%08x",&pcModel->m_wSoundSet);
  2007. sscanf(szAnimConfig,"%08x",&pcModel->m_wAnimConfig);
  2008. pcModel->m_dwUnknown_Blue = dwUnknown_Blue;
  2009. sscanf(szModelNumber,"%08x",&pcModel->m_dwModelNumber);
  2010. pcModel->m_flScale = flScale;
  2011. pcModel->m_dwUnknown_LightGrey = dwUnknown_LightGrey;
  2012. pcModel->m_dwTrio1[0] = dwTrio1[0];
  2013. pcModel->m_dwTrio1[1] = dwTrio1[1];
  2014. pcModel->m_dwTrio1[2] = dwTrio1[2];
  2015. pcModel->m_dwMedGrey = dwMedGrey;
  2016. pcModel->m_dwBlueGrey = dwBlueGrey;
  2017. pcModel->m_wSeagreen8 = wSeagreen8;
  2018. pcModel->m_dwUnknown_v2 = dwUnknown_v2;
  2019. pcModel->m_dwUnknown_v6 = dwUnknown_v6;
  2020. pcModel->m_dwUnknownCount = dwUnknownCount;
  2021. sscanf(szFlags2, "%08x",&pcModel->m_dwFlags2);
  2022. sscanf(szObjFlags1, "%08x",&pcModel->m_dwObjectFlags1);
  2023. sscanf(szObjFlags2, "%08x",&pcModel->m_dwObjectFlags2);
  2024. int b = 0;
  2025. char cTemp[2];
  2026. for(int i = 0; i < (dwUnknownCount); i++)
  2027. {
  2028. CopyMemory( &cTemp[0], &bInitialAnimation[b], 2 );
  2029. sscanf(cTemp,"%08x",&pcModel->m_bInitialAnimation[i]);
  2030. b = b + 2;
  2031. }
  2032. }
  2033. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2034. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2035. //===============================================================
  2036. // Load all the Vector Data for Each Model ID
  2037. //
  2038. //===============================================================
  2039. for ( DWORD d = 0; d < dwModelCount+1; d++)
  2040. {
  2041. cWObjectModels *pcModel = cWObjectModels::Hash_Find( d );
  2042. if(pcModel)
  2043. {
  2044. sprintf( szCommand, "SELECT * FROM worldobjects_vector_palettes WHERE dwLinker=%d ORDER BY VectorCount;", pcModel->m_wPaletteVector);
  2045. // Load Palette vector into array
  2046. // Define Temp Variables
  2047. BYTE bVectorCount;
  2048. char readbuff01[5];
  2049. char readbuff02[3];
  2050. char readbuff03[3];
  2051. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  2052. retcode = SQLExecute( cDatabase::m_hStmt );
  2053. iCol = 3;
  2054. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( bVectorCount ), NULL );
  2055. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff01 , sizeof( readbuff01 ), NULL );
  2056. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff02 , sizeof( readbuff02 ), NULL );
  2057. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff03 , sizeof( readbuff03 ), NULL );
  2058. for ( int intPcount = 0 ; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intPcount < pcModel->m_bPaletteChange +1); ++intPcount )
  2059. {
  2060. // Let's Scan that Text into Hex
  2061. sscanf(readbuff01,"%04x",&pcModel->m_vectorPal[intPcount].m_wNewPalette);
  2062. sscanf(readbuff02,"%02x",&pcModel->m_vectorPal[intPcount].m_ucOffset);
  2063. sscanf(readbuff03,"%02x",&pcModel->m_vectorPal[intPcount].m_ucLength);
  2064. }
  2065. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2066. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2067. // Load Texture Vector into Array
  2068. // Define Temp Variables
  2069. char readbuff04[3];
  2070. char readbuff05[5];
  2071. char readbuff06[5];
  2072. sprintf( szCommand, "SELECT * FROM worldobjects_vector_textures WHERE dwLinker=%d ORDER BY VectorCount;",pcModel->m_wTextureVector);
  2073. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  2074. retcode = SQLExecute( cDatabase::m_hStmt );
  2075. iCol = 3;
  2076. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  2077. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff04, sizeof( readbuff04 ), NULL );
  2078. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff05, sizeof( readbuff05 ), NULL );
  2079. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff06 , sizeof( readbuff06 ), NULL );
  2080. for ( int intT = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intT < pcModel->m_bTextureChange + 1); ++intT )
  2081. {
  2082. // Let's Scan that Text into Hex
  2083. sscanf(readbuff04,"%02x",&pcModel->m_vectorTex[intT].m_bModelIndex);
  2084. sscanf(readbuff05,"%04x",&pcModel->m_vectorTex[intT].m_wOldTexture);
  2085. sscanf(readbuff06,"%04x",&pcModel->m_vectorTex[intT].m_wNewTexture);
  2086. }
  2087. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2088. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2089. // Load Model Vectors into Array
  2090. // Define Temp Variables
  2091. char readbuff07[3];
  2092. char readbuff08[5];
  2093. sprintf( szCommand, "SELECT * FROM worldobjects_vector_models WHERE dwLinker=%d ORDER BY VectorCount;", pcModel->m_wModelVector);
  2094. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  2095. retcode = SQLExecute( cDatabase::m_hStmt );
  2096. iCol = 3;
  2097. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  2098. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff07, sizeof( readbuff07 ), NULL );
  2099. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff08 , sizeof( readbuff08 ), NULL );
  2100. for ( int intM = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intM < pcModel->m_bModelChange + 1); ++intM )
  2101. {
  2102. // Scan the Text to HEX
  2103. sscanf(readbuff07,"%02x",&pcModel->m_vectorMod[intM].m_bModelIndex);
  2104. sscanf(readbuff08,"%04x",&pcModel->m_vectorMod[intM].m_wNewModel);
  2105. }
  2106. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2107. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2108. // UpdateConsole( "+" );
  2109. }
  2110. }
  2111. }
  2112. /**
  2113. * Loads merchant signs from the database.
  2114. *
  2115. * Author: Cubem0j0
  2116. */
  2117. void cMasterServer::LoadWorldObjects2( )
  2118. {
  2119. RETCODE retcode;
  2120. char szCommand[512];
  2121. // char szItems[150];
  2122. cLocation locWO;
  2123. char dwLandblock[9];
  2124. char dwPosX[9];
  2125. char dwPosY[9];
  2126. char dwPosZ[9];
  2127. char dwOrientW[9];
  2128. char dwOrientX[9];
  2129. char dwOrientY[9];
  2130. char dwOrientZ[9];
  2131. char Name[100];
  2132. char Description[255];
  2133. // DWORD dwItemCount;
  2134. // cLocation locItem;
  2135. DWORD dwModelNumber;
  2136. WORD wModel;
  2137. WORD wIcon;
  2138. int iObjectType = 0;
  2139. WORD wWOcount = 0;
  2140. char szWorldObjects[150];
  2141. // DWORD dwModelID;
  2142. sprintf( szCommand, "SELECT COUNT(ID) FROM worldobjects2;" );
  2143. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2144. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2145. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wWOcount, sizeof( wWOcount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2146. retcode = SQLFetch( cDatabase::m_hStmt );
  2147. if( retcode == SQL_NO_DATA )
  2148. wWOcount = 0;
  2149. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2150. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2151. sprintf( szWorldObjects, " Loading %d merchant signs ... ",wWOcount );
  2152. UpdateConsole((char *)szWorldObjects);
  2153. sprintf( szCommand, "SELECT * FROM worldobjects2;" );
  2154. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2155. retcode = SQLExecute( cDatabase::m_hStmt );
  2156. int iCol = 3;
  2157. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2158. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2159. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2160. // Landblock Data
  2161. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2162. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flX, sizeof( &locWO.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2163. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flY, sizeof( &locWO.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2164. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flZ, sizeof( &locWO.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2165. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flA, sizeof( &locWO.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2166. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flB, sizeof( &locWO.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2167. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flC, sizeof( &locWO.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2168. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flW, sizeof( &locWO.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2169. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2170. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2171. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2172. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2173. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2174. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2175. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2176. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT,&wModel, sizeof( wModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2177. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( wIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2178. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &iObjectType, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2179. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  2180. sscanf(dwLandblock,"%08x",&locWO.m_dwLandBlock);
  2181. sscanf(dwPosX,"%08x",&locWO.m_flX);
  2182. sscanf(dwPosY,"%08x",&locWO.m_flY);
  2183. sscanf(dwPosZ,"%08x",&locWO.m_flZ);
  2184. sscanf(dwOrientW,"%08x",&locWO.m_flA);
  2185. sscanf(dwOrientX,"%08x",&locWO.m_flB);
  2186. sscanf(dwOrientY,"%08x",&locWO.m_flC);
  2187. sscanf(dwOrientZ,"%08x",&locWO.m_flW);
  2188. cMerchantSign* aObject = new cMerchantSign(cWorldManager::NewGUID_Object(),locWO,dwModelNumber,1.0,TRUE,wIcon,Name,Description,4,7,TRUE);
  2189. aObject->SetObjectType(iObjectType);
  2190. cWorldManager::AddObject( aObject, TRUE );
  2191. // UpdateConsole( "+" );
  2192. }
  2193. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2194. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2195. }
  2196. /**
  2197. * Loads ground spawns from the database
  2198. *
  2199. * Note: Use ModelNumber to reference pre-loaded model data.
  2200. *
  2201. * Author: Cubem0j0
  2202. */
  2203. void cMasterServer::LoadGroundSpawns( )
  2204. {
  2205. RETCODE retcode;
  2206. char szCommand[512];
  2207. char szItems[150];
  2208. char dwLandblock[9];
  2209. char dwPosX[9];
  2210. char dwPosY[9];
  2211. char dwPosZ[9];
  2212. char dwOrientW[9];
  2213. char dwOrientX[9];
  2214. char dwOrientY[9];
  2215. char dwOrientZ[9];
  2216. char Name[100];
  2217. char Description[255];
  2218. DWORD dwItemCount;
  2219. cLocation locItem;
  2220. DWORD dwModelNumber;
  2221. int itemType = 0;
  2222. DWORD dwQuantity;
  2223. DWORD dwQuestItemID;
  2224. sprintf( szCommand, "SELECT COUNT(ID) FROM items_instance_ground;" );
  2225. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2226. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2227. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwItemCount, sizeof( dwItemCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2228. retcode = SQLFetch( cDatabase::m_hStmt );
  2229. if( retcode == SQL_NO_DATA )
  2230. dwItemCount = 0;
  2231. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2232. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2233. sprintf( szItems, " Loading %d ground spawns ... ",dwItemCount );
  2234. UpdateConsole((char *)szItems);
  2235. sprintf( szCommand, "SELECT * FROM items_instance_ground;" );
  2236. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2237. retcode = SQLExecute( cDatabase::m_hStmt );
  2238. int iCol = 2;
  2239. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwQuestItemID, sizeof( dwQuestItemID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2240. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2241. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2242. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2243. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &itemType, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2244. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwQuantity, sizeof( dwQuantity ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2245. // Landblock Data
  2246. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2247. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flX, sizeof( &locItem.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2248. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flY, sizeof( &locItem.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2249. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flZ, sizeof( &locItem.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2250. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flA, sizeof( &locItem.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2251. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flB, sizeof( &locItem.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2252. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flC, sizeof( &locItem.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2253. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locItem.m_flW, sizeof( &locItem.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2254. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2255. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2256. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2257. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2258. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2259. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2260. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2261. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  2262. {
  2263. sscanf(dwLandblock,"%08x",&locItem.m_dwLandBlock);
  2264. sscanf(dwPosX,"%08x",&locItem.m_flX);
  2265. sscanf(dwPosY,"%08x",&locItem.m_flY);
  2266. sscanf(dwPosZ,"%08x",&locItem.m_flZ);
  2267. sscanf(dwOrientW,"%08x",&locItem.m_flA);
  2268. sscanf(dwOrientX,"%08x",&locItem.m_flB);
  2269. sscanf(dwOrientY,"%08x",&locItem.m_flC);
  2270. sscanf(dwOrientZ,"%08x",&locItem.m_flW);
  2271. //Cubem0j0: We find the model number so we can get some vars.
  2272. cItemModels *pcModel = cItemModels::FindModel(dwModelNumber);
  2273. switch(itemType)
  2274. {
  2275. //Weapon
  2276. case 1:
  2277. {
  2278. cWeapon* aWeapon = new cWeapon(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_bWieldType,pcModel->m_dwIconHighlight,pcModel->m_fWorkmanship,pcModel->m_dwMaterialType,pcModel->m_dwWeaponDamage,pcModel->m_dwWeaponSpeed,pcModel->m_dwWeaponSkill,pcModel->m_dwDamageType,pcModel->m_dWeaponVariance,pcModel->m_dWeaponModifier,pcModel->m_dWeaponPower,pcModel->m_dWeaponAttack);
  2279. aWeapon->SetStatic(false);
  2280. cWorldManager::AddObject( aWeapon, true );
  2281. break;
  2282. }
  2283. //Food
  2284. case 2:
  2285. {
  2286. cFood* aFood = new cFood(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,pcModel->m_wIcon,Name,Description, pcModel->m_dwValue, pcModel->m_wBurden, pcModel->m_dwVitalID, pcModel->m_vital_affect);
  2287. aFood->SetStatic(false);
  2288. cWorldManager::AddObject( aFood, true );
  2289. break;
  2290. }
  2291. //Armor
  2292. case 3:
  2293. {
  2294. cArmor* aArmor = new cArmor(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,Name,Description);
  2295. aArmor->SetStatic(false);
  2296. cWorldManager::AddObject(aArmor,true);
  2297. break;
  2298. }
  2299. //Book
  2300. case 4:
  2301. {
  2302. cBooks* aBook = new cBooks(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,pcModel->m_wIcon,Name,Description);
  2303. aBook->SetStatic(false);
  2304. cWorldManager::AddObject(aBook,true);
  2305. break;
  2306. }
  2307. //Scrolls
  2308. case 5:
  2309. {
  2310. cScrolls* aScroll = new cScrolls(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,Name,Description);
  2311. aScroll->SetStatic(false);
  2312. cWorldManager::AddObject(aScroll,true);
  2313. break;
  2314. }
  2315. //Healing Kits
  2316. case 6:
  2317. {
  2318. cHealingKits* aHealingKit = new cHealingKits(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,Name,Description,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_wUses,pcModel->m_wUseLimit);
  2319. aHealingKit->SetStatic(false);
  2320. cWorldManager::AddObject(aHealingKit,true);
  2321. break;
  2322. }
  2323. //Wands
  2324. case 8:
  2325. {
  2326. cWands* aWand = new cWands(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,Name,Description);
  2327. aWand->SetStatic(false);
  2328. cWorldManager::AddObject(aWand,true);
  2329. break;
  2330. }
  2331. //Pyreals
  2332. /*
  2333. case 9:
  2334. {
  2335. cPyreals* aPyreal = new cPyreals(cWorldManager::NewGUID_Object(),locItem,dwModelNumber,1.0,TRUE,pcModel->m_wIcon,Name,Description, pcModel->m_wStack, pcModel->m_wStackLimit);
  2336. aPyreal->SetStatic(false);
  2337. cWorldManager::AddObject(aPyreal,true);
  2338. break;
  2339. }
  2340. */
  2341. // UpdateConsole( "+" );
  2342. }
  2343. }
  2344. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2345. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2346. }
  2347. /**
  2348. * Loads world objects from the database.
  2349. *
  2350. * Author: Cubem0j0
  2351. */
  2352. void cMasterServer::LoadWorldObjects( )
  2353. {
  2354. char szCommand[512];
  2355. char dwLandblock[9];
  2356. char dwPosX[9];
  2357. char dwPosY[9];
  2358. char dwPosZ[9];
  2359. char dwOrientW[9];
  2360. char dwOrientX[9];
  2361. char dwOrientY[9];
  2362. char dwOrientZ[9];
  2363. RETCODE retcode;
  2364. WORD wWOcount = 0;
  2365. WORD wModel;
  2366. WORD wIcon;
  2367. char szWorldObjects[150];
  2368. char WOName[50];
  2369. char WODescription[20];
  2370. WORD wType;
  2371. int iObjectType = 0;
  2372. sprintf( szCommand, "SELECT COUNT(ID) FROM worldobjects;" );
  2373. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2374. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2375. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wWOcount, sizeof( wWOcount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2376. retcode = SQLFetch( cDatabase::m_hStmt );
  2377. if( retcode == SQL_NO_DATA )
  2378. wWOcount = 0;
  2379. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2380. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2381. sprintf( szWorldObjects, " Loading %d WorldObjects ... ",wWOcount );
  2382. UpdateConsole((char *)szWorldObjects);
  2383. cLocation locWO;
  2384. sprintf( szCommand, "SELECT * FROM worldobjects;" );
  2385. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2386. retcode = SQLExecute( cDatabase::m_hStmt );
  2387. int iCol = 3;
  2388. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wType, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2389. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2390. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flX, sizeof( &locWO.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2391. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flY, sizeof( &locWO.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2392. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flZ, sizeof( &locWO.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2393. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flA, sizeof( &locWO.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2394. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flB, sizeof( &locWO.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2395. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flC, sizeof( &locWO.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2396. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locWO.m_flW, sizeof( &locWO.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2397. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2398. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2399. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2400. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2401. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2402. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2403. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2404. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, WOName, sizeof( WOName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2405. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, WODescription, sizeof( WODescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2406. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2407. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2408. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &iObjectType, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2409. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  2410. sscanf(dwLandblock,"%08x",&locWO.m_dwLandBlock);
  2411. sscanf(dwPosX,"%08x",&locWO.m_flX);
  2412. sscanf(dwPosY,"%08x",&locWO.m_flY);
  2413. sscanf(dwPosZ,"%08x",&locWO.m_flZ);
  2414. sscanf(dwOrientW,"%08x",&locWO.m_flA);
  2415. sscanf(dwOrientX,"%08x",&locWO.m_flB);
  2416. sscanf(dwOrientY,"%08x",&locWO.m_flC);
  2417. sscanf(dwOrientZ,"%08x",&locWO.m_flW);
  2418. cWorldObject* aObject = new cWorldObject(wType, cWorldManager::NewGUID_Object(), &locWO, WOName, WODescription);
  2419. aObject->SetData(wModel,wIcon);
  2420. aObject->SetObjectType(iObjectType);
  2421. cWorldManager::AddObject( aObject, TRUE );
  2422. // UpdateConsole( "+" );
  2423. }
  2424. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2425. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2426. }
  2427. /**
  2428. * Loads housing objects from database.
  2429. *
  2430. * Author: G70mb2
  2431. */
  2432. void cMasterServer::LoadHousing( )
  2433. {
  2434. char szCommand[512];
  2435. RETCODE retcode;
  2436. WORD wHouseCount = 0;
  2437. char szHouse[50];
  2438. char HouseIDBuff[9];
  2439. DWORD HouseID;
  2440. char OwnerIDBuff[9];
  2441. DWORD OwnerID;
  2442. WORD wHouseType;
  2443. cLocation locHouse;
  2444. char dwLandblock[9];
  2445. char dwPosX[9];
  2446. char dwPosY[9];
  2447. char dwPosZ[9];
  2448. char dwOrientW[9];
  2449. char dwOrientX[9];
  2450. char dwOrientY[9];
  2451. char dwOrientZ[9];
  2452. char HouseName[100];
  2453. char HouseDescription[500];
  2454. WORD wModel;
  2455. WORD wIcon;
  2456. DWORD IsOpen;
  2457. sprintf( szCommand, "SELECT COUNT(ID) FROM houses;" );
  2458. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2459. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2460. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wHouseCount, sizeof( wHouseCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2461. retcode = SQLFetch( cDatabase::m_hStmt );
  2462. if( retcode == SQL_NO_DATA )
  2463. wHouseCount = 0;
  2464. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2465. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2466. sprintf( szHouse, " Loading %d house objects ... ",wHouseCount );
  2467. UpdateConsole((char *)szHouse);
  2468. for ( int iTmp = 1; iTmp < wHouseCount + 1; iTmp++)
  2469. {
  2470. sprintf( szCommand, "SELECT * FROM houses WHERE ID=%d;", iTmp );
  2471. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2472. retcode = SQLExecute( cDatabase::m_hStmt );
  2473. DWORD ID;
  2474. int iCol = 1;
  2475. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &ID, sizeof( DWORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2476. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HouseIDBuff, sizeof( HouseIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2477. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2478. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wHouseType, sizeof( wHouseType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2479. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2480. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flX, sizeof( &locHouse.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2481. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flY, sizeof( &locHouse.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2482. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flZ, sizeof( &locHouse.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2483. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flA, sizeof( &locHouse.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2484. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flB, sizeof( &locHouse.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2485. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flC, sizeof( &locHouse.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2486. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHouse.m_flW, sizeof( &locHouse.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2487. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2488. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2489. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2490. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2491. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2492. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2493. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2494. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HouseName, sizeof( HouseName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2495. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HouseDescription, sizeof( HouseDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2496. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2497. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2498. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &IsOpen, sizeof( IsOpen ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2499. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS)
  2500. {
  2501. // to access houses, house GUIDs must be the same as those encoded into the cell.dat
  2502. sscanf(HouseIDBuff,"%08x",&HouseID);
  2503. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  2504. sscanf(dwLandblock,"%08x",&locHouse.m_dwLandBlock);
  2505. sscanf(dwPosX,"%08x",&locHouse.m_flX);
  2506. sscanf(dwPosY,"%08x",&locHouse.m_flY);
  2507. sscanf(dwPosZ,"%08x",&locHouse.m_flZ);
  2508. sscanf(dwOrientW,"%08x",&locHouse.m_flA);
  2509. sscanf(dwOrientX,"%08x",&locHouse.m_flB);
  2510. sscanf(dwOrientY,"%08x",&locHouse.m_flC);
  2511. sscanf(dwOrientZ,"%08x",&locHouse.m_flW);
  2512. // cHouse* aHouse = new cHouse(HouseName,HouseDescription,wHouseType,cWorldManager::NewGUID_Object(),&locHouse);
  2513. cHouse* aHouse = new cHouse(HouseName,HouseDescription,wHouseType,HouseID,&locHouse);
  2514. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2515. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2516. aHouse->SetData(wModel,wIcon);
  2517. aHouse->SetIsOpen(IsOpen);
  2518. aHouse->SetOwner(OwnerID);
  2519. cWorldManager::AddObject( aHouse, TRUE );
  2520. // UpdateConsole( "+" );
  2521. } else {
  2522. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2523. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2524. }
  2525. }
  2526. }
  2527. /**
  2528. * Loads covenant crystals from the database.
  2529. *
  2530. * Author: G70mb2
  2531. */
  2532. void cMasterServer::LoadCovenants( )
  2533. {
  2534. char szCommand[512];
  2535. RETCODE retcode;
  2536. char szCovenant[50];
  2537. DWORD dwCovenantMax;
  2538. DWORD dwCovenantCount;
  2539. char CovenantIDBuff[9];
  2540. DWORD CovenantID;
  2541. char OwnerIDBuff[9];
  2542. DWORD OwnerID;
  2543. DWORD dwHouseID;
  2544. WORD wHouseType;
  2545. WORD dwCrystalType;
  2546. cLocation locCovenant;
  2547. char dwLandblock[9];
  2548. char dwPosX[9];
  2549. char dwPosY[9];
  2550. char dwPosZ[9];
  2551. char dwOrientW[9];
  2552. char dwOrientX[9];
  2553. char dwOrientY[9];
  2554. char dwOrientZ[9];
  2555. char CrystalName[100];
  2556. char CrystalDescription[500];
  2557. WORD wAnimconfig;
  2558. WORD wModel;
  2559. WORD wIcon;
  2560. WORD wIsPaid;
  2561. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM houses_covenants;" );
  2562. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2563. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2564. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwCovenantMax, sizeof( dwCovenantMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2565. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwCovenantCount, sizeof( dwCovenantCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2566. retcode = SQLFetch( cDatabase::m_hStmt );
  2567. if( retcode == SQL_NO_DATA )
  2568. {
  2569. dwCovenantMax = 0;
  2570. dwCovenantCount = 0;
  2571. }
  2572. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2573. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2574. sprintf( szCovenant, " Loading %d covenant crystals ... ",dwCovenantCount );
  2575. UpdateConsole((char *)szCovenant);
  2576. for ( int iTmp = 1; iTmp < dwCovenantMax + 1; iTmp++)
  2577. {
  2578. sprintf( szCommand, "SELECT * FROM houses_covenants WHERE ID=%d;", iTmp );
  2579. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2580. retcode = SQLExecute( cDatabase::m_hStmt );
  2581. int iCol = 2;
  2582. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, CovenantIDBuff, sizeof( CovenantIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2583. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2584. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHouseID, sizeof( dwHouseID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2585. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wHouseType, sizeof( wHouseType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2586. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &dwCrystalType, sizeof( dwCrystalType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2587. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2588. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flX, sizeof( &locCovenant.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2589. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flY, sizeof( &locCovenant.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2590. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flZ, sizeof( &locCovenant.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2591. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flA, sizeof( &locCovenant.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2592. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flB, sizeof( &locCovenant.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2593. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flC, sizeof( &locCovenant.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2594. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locCovenant.m_flW, sizeof( &locCovenant.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2595. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2596. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2597. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2598. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2599. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2600. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2601. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2602. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, CrystalName, sizeof( CrystalName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2603. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, CrystalDescription, sizeof( CrystalDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2604. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAnimconfig, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2605. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2606. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL) CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2607. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIsPaid, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2608. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS)
  2609. {
  2610. sscanf(CovenantIDBuff,"%08x",&CovenantID);
  2611. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  2612. sscanf(dwLandblock,"%08x",&locCovenant.m_dwLandBlock);
  2613. sscanf(dwPosX,"%08x",&locCovenant.m_flX);
  2614. sscanf(dwPosY,"%08x",&locCovenant.m_flY);
  2615. sscanf(dwPosZ,"%08x",&locCovenant.m_flZ);
  2616. sscanf(dwOrientW,"%08x",&locCovenant.m_flA);
  2617. sscanf(dwOrientX,"%08x",&locCovenant.m_flB);
  2618. sscanf(dwOrientY,"%08x",&locCovenant.m_flC);
  2619. sscanf(dwOrientZ,"%08x",&locCovenant.m_flW);
  2620. cCovenant* aCovenant = new cCovenant(dwCrystalType,CovenantID,dwHouseID,CrystalName,CrystalDescription,&locCovenant);
  2621. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2622. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2623. aCovenant->SetData(wAnimconfig,wModel,wIcon);
  2624. aCovenant->SetOwner(OwnerID);
  2625. cWorldManager::AddObject( aCovenant, TRUE );
  2626. // UpdateConsole( "+" );
  2627. } else {
  2628. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2629. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2630. }
  2631. }
  2632. }
  2633. /**
  2634. * Loads housing hooks from the database.
  2635. */
  2636. void cMasterServer::LoadHooks( )
  2637. {
  2638. char szCommand[512];
  2639. RETCODE retcode;
  2640. DWORD dwHookMax;
  2641. DWORD dwHookCount;
  2642. char szHook[50];
  2643. char HookIDBuff[9];
  2644. DWORD HookID;
  2645. char OwnerIDBuff[9];
  2646. DWORD OwnerID;
  2647. DWORD dwHouseID;
  2648. WORD dwHookType;
  2649. cLocation locHook;
  2650. char dwLandblock[9];
  2651. char dwPosX[9];
  2652. char dwPosY[9];
  2653. char dwPosZ[9];
  2654. char dwOrientW[9];
  2655. char dwOrientX[9];
  2656. char dwOrientY[9];
  2657. char dwOrientZ[9];
  2658. char HookName[100];
  2659. char HookDescription[500];
  2660. WORD wAnimconfig;
  2661. WORD wSoundSet;
  2662. WORD wModel;
  2663. WORD wIcon;
  2664. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM houses_hooks;" );
  2665. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2666. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2667. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwHookMax, sizeof( dwHookMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2668. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwHookCount, sizeof( dwHookCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2669. retcode = SQLFetch( cDatabase::m_hStmt );
  2670. if( retcode == SQL_NO_DATA )
  2671. {
  2672. dwHookMax = 0;
  2673. dwHookCount = 0;
  2674. }
  2675. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2676. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2677. sprintf( szHook, " Loading %d housing hooks ... ",dwHookCount );
  2678. UpdateConsole((char *)szHook);
  2679. for ( int iTmp = 1; iTmp < dwHookMax + 1; iTmp++)
  2680. {
  2681. sprintf( szCommand, "SELECT * FROM houses_hooks WHERE ID=%d;", iTmp );
  2682. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2683. retcode = SQLExecute( cDatabase::m_hStmt );
  2684. int iCol = 2;
  2685. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HookIDBuff, sizeof( HookIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2686. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2687. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHouseID, sizeof( dwHouseID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2688. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &dwHookType, sizeof( dwHookType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2689. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2690. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flX, sizeof( &locHook.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2691. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flY, sizeof( &locHook.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2692. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flZ, sizeof( &locHook.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2693. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flA, sizeof( &locHook.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2694. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flB, sizeof( &locHook.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2695. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flC, sizeof( &locHook.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2696. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locHook.m_flW, sizeof( &locHook.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2697. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2698. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2699. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2700. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2701. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2702. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2703. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2704. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HookName, sizeof( HookName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2705. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, HookDescription, sizeof( HookDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2706. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAnimconfig, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2707. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSoundSet, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2708. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2709. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2710. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS)
  2711. {
  2712. sscanf(HookIDBuff,"%08x",&HookID);
  2713. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  2714. sscanf(dwLandblock,"%08x",&locHook.m_dwLandBlock);
  2715. sscanf(dwPosX,"%08x",&locHook.m_flX);
  2716. sscanf(dwPosY,"%08x",&locHook.m_flY);
  2717. sscanf(dwPosZ,"%08x",&locHook.m_flZ);
  2718. sscanf(dwOrientW,"%08x",&locHook.m_flA);
  2719. sscanf(dwOrientX,"%08x",&locHook.m_flB);
  2720. sscanf(dwOrientY,"%08x",&locHook.m_flC);
  2721. sscanf(dwOrientZ,"%08x",&locHook.m_flW);
  2722. cHooks* aHook = new cHooks(dwHookType,HookID,dwHouseID,HookName,HookDescription,&locHook);
  2723. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2724. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2725. cWorldManager::AddObject( aHook, TRUE );
  2726. aHook->SetData(wAnimconfig,wSoundSet,wModel,wIcon);
  2727. // UpdateConsole( "+" );
  2728. } else {
  2729. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2730. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2731. }
  2732. }
  2733. }
  2734. /**
  2735. * Loads housing storage chests from the database.
  2736. */
  2737. void cMasterServer::LoadStorage( )
  2738. {
  2739. char szCommand[512];
  2740. RETCODE retcode;
  2741. DWORD dwStorageMax;
  2742. DWORD dwStorageCount;
  2743. char szStorage[50];
  2744. char StorageName[100];
  2745. char StorageDescription[500];
  2746. char StorageIDBuff[9];
  2747. DWORD StorageID;
  2748. char OwnerIDBuff[9];
  2749. DWORD OwnerID;
  2750. DWORD dwHouseID;
  2751. WORD dwStorageType;
  2752. cLocation locStorage;
  2753. char dwLandblock[9];
  2754. char dwPosX[9];
  2755. char dwPosY[9];
  2756. char dwPosZ[9];
  2757. char dwOrientW[9];
  2758. char dwOrientX[9];
  2759. char dwOrientY[9];
  2760. char dwOrientZ[9];
  2761. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM houses_storage;" );
  2762. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2763. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2764. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwStorageMax, sizeof( dwStorageMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2765. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwStorageCount, sizeof( dwStorageCount ), NULL );CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2766. retcode = SQLFetch( cDatabase::m_hStmt );
  2767. if( retcode == SQL_NO_DATA )
  2768. {
  2769. dwStorageMax = 0;
  2770. dwStorageCount = 0;
  2771. }
  2772. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2773. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2774. sprintf( szStorage, " Loading %d housing storage chests ... ",dwStorageCount );
  2775. UpdateConsole((char *)szStorage);
  2776. for ( int iTmp = 1; iTmp < dwStorageMax + 1; iTmp++)
  2777. {
  2778. sprintf( szCommand, "SELECT * FROM houses_storage WHERE ID=%d;", iTmp );
  2779. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2780. retcode = SQLExecute( cDatabase::m_hStmt );
  2781. int iCol = 2;
  2782. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, StorageIDBuff, sizeof( StorageIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2783. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, OwnerIDBuff, sizeof( OwnerIDBuff ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2784. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHouseID, sizeof( dwHouseID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2785. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &dwStorageType, sizeof( dwStorageType ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2786. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2787. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flX, sizeof( &locStorage.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2788. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flY, sizeof( &locStorage.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2789. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flZ, sizeof( &locStorage.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2790. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flA, sizeof( &locStorage.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2791. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flB, sizeof( &locStorage.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2792. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flC, sizeof( &locStorage.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2793. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locStorage.m_flW, sizeof( &locStorage.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2794. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2795. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2796. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2797. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2798. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2799. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2800. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2801. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, StorageName, sizeof( StorageName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2802. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, StorageDescription, sizeof( StorageDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2803. if (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS)
  2804. {
  2805. sscanf(StorageIDBuff,"%08x",&StorageID);
  2806. sscanf(OwnerIDBuff,"%08x",&OwnerID);
  2807. sscanf(dwLandblock,"%08x",&locStorage.m_dwLandBlock);
  2808. sscanf(dwPosX,"%08x",&locStorage.m_flX);
  2809. sscanf(dwPosY,"%08x",&locStorage.m_flY);
  2810. sscanf(dwPosZ,"%08x",&locStorage.m_flZ);
  2811. sscanf(dwOrientW,"%08x",&locStorage.m_flA);
  2812. sscanf(dwOrientX,"%08x",&locStorage.m_flB);
  2813. sscanf(dwOrientY,"%08x",&locStorage.m_flC);
  2814. sscanf(dwOrientZ,"%08x",&locStorage.m_flW);
  2815. cStorage* aStorage = new cStorage(dwStorageType,StorageID,dwHouseID,StorageName,StorageDescription,&locStorage);
  2816. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2817. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2818. cWorldManager::AddObject( aStorage, TRUE );
  2819. // UpdateConsole( "+" );
  2820. } else {
  2821. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2822. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  2823. }
  2824. }
  2825. }
  2826. /**
  2827. * Loads doors from the database.
  2828. *
  2829. * Author: G70mb2
  2830. */
  2831. void cMasterServer::LoadDoors( )
  2832. {
  2833. char szCommand[512];
  2834. RETCODE retcode;
  2835. DWORD dwDoorMax;
  2836. DWORD dwDoorCount;
  2837. char dwLandblock[9];
  2838. char dwPosX[9];
  2839. char dwPosY[9];
  2840. char dwPosZ[9];
  2841. char dwOrientW[9];
  2842. char dwOrientX[9];
  2843. char dwOrientY[9];
  2844. char dwOrientZ[9];
  2845. WORD wAnimconfig;
  2846. WORD wSoundSet;
  2847. WORD wModel;
  2848. WORD wIcon;
  2849. char szDoors[50];
  2850. char DoorName[100];
  2851. char DoorDescription[500];
  2852. WORD wType;
  2853. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM gameobjects_doors;" );
  2854. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2855. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2856. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwDoorMax, sizeof( dwDoorMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2857. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwDoorCount, sizeof( dwDoorCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2858. retcode = SQLFetch( cDatabase::m_hStmt );
  2859. if( retcode == SQL_NO_DATA )
  2860. {
  2861. dwDoorCount = 0;
  2862. dwDoorMax = 0;
  2863. }
  2864. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2865. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2866. sprintf( szDoors, " Loading %d doors ... ",dwDoorCount );
  2867. UpdateConsole((char *)szDoors);
  2868. cLocation locDoor;
  2869. sprintf( szCommand, "SELECT * FROM gameobjects_doors;" );
  2870. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2871. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2872. int iCol = 3;
  2873. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wType, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2874. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2875. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2876. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2877. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2878. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2879. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2880. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2881. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2882. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, DoorName, sizeof( DoorName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2883. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, DoorDescription, sizeof( DoorDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2884. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAnimconfig, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2885. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSoundSet, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2886. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2887. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2888. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  2889. {
  2890. sscanf(dwLandblock,"%08x",&locDoor.m_dwLandBlock);
  2891. sscanf(dwPosX,"%08x",&locDoor.m_flX);
  2892. sscanf(dwPosY,"%08x",&locDoor.m_flY);
  2893. sscanf(dwPosZ,"%08x",&locDoor.m_flZ);
  2894. sscanf(dwOrientW,"%08x",&locDoor.m_flA);
  2895. sscanf(dwOrientX,"%08x",&locDoor.m_flB);
  2896. sscanf(dwOrientY,"%08x",&locDoor.m_flC);
  2897. sscanf(dwOrientZ,"%08x",&locDoor.m_flW);
  2898. cDoor* aDoor = new cDoor(wType, cWorldManager::NewGUID_Object(), &locDoor, DoorName, DoorDescription);
  2899. aDoor->SetData(wAnimconfig,wSoundSet,wModel,wIcon);
  2900. cWorldManager::AddObject( aDoor, TRUE );
  2901. }
  2902. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2903. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2904. }
  2905. /**
  2906. * Loads chests from the database.
  2907. *
  2908. * Author: Cubem0j0
  2909. */
  2910. void cMasterServer::LoadChests( )
  2911. {
  2912. char szCommand[512];
  2913. char dwLandblock[9];
  2914. char dwPosX[9];
  2915. char dwPosY[9];
  2916. char dwPosZ[9];
  2917. char dwOrientW[9];
  2918. char dwOrientX[9];
  2919. char dwOrientY[9];
  2920. char dwOrientZ[9];
  2921. RETCODE retcode;
  2922. WORD wChestcount = 0;
  2923. WORD wAnimconfig;
  2924. WORD wSoundSet;
  2925. WORD wModel;
  2926. WORD wIcon;
  2927. DWORD dwObject1;
  2928. DWORD dwObject2;
  2929. char szChests[50];
  2930. char ChestName[100];
  2931. char ChestDescription[500];
  2932. char strdwObject1[9];
  2933. char strdwObject2[9];
  2934. WORD wType;
  2935. int IsLocked;
  2936. int LockDiff;
  2937. sprintf( szCommand, "SELECT COUNT(ID) FROM gameobjects_chests;" );
  2938. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2939. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2940. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wChestcount, sizeof( wChestcount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  2941. retcode = SQLFetch( cDatabase::m_hStmt );
  2942. if( retcode == SQL_NO_DATA )
  2943. wChestcount = 0;
  2944. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2945. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  2946. sprintf( szChests, " Loading %d chests ... ",wChestcount );
  2947. UpdateConsole((char *)szChests);
  2948. cLocation locChest;
  2949. sprintf( szCommand, "SELECT * FROM gameobjects_chests;" );
  2950. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2951. retcode = SQLExecute( cDatabase::m_hStmt );
  2952. int iCol = 3;
  2953. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wType, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2954. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2955. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flX, sizeof( &locChest.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2956. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flY, sizeof( &locChest.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2957. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flZ, sizeof( &locChest.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2958. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flA, sizeof( &locChest.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2959. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flB, sizeof( &locChest.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2960. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flC, sizeof( &locChest.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2961. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locChest.m_flW, sizeof( &locChest.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2962. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2963. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2964. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2965. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2966. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2967. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2968. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2969. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ChestName, sizeof( ChestName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2970. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ChestDescription, sizeof( ChestDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2971. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAnimconfig, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2972. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSoundSet, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2973. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2974. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2975. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, strdwObject1, sizeof( strdwObject1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2976. // retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, strdwObject2, sizeof( strdwObject2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2977. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &IsLocked, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2978. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &LockDiff, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  2979. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  2980. sscanf(dwLandblock,"%08x",&locChest.m_dwLandBlock);
  2981. sscanf(dwPosX,"%08x",&locChest.m_flX);
  2982. sscanf(dwPosY,"%08x",&locChest.m_flY);
  2983. sscanf(dwPosZ,"%08x",&locChest.m_flZ);
  2984. sscanf(dwOrientW,"%08x",&locChest.m_flA);
  2985. sscanf(dwOrientX,"%08x",&locChest.m_flB);
  2986. sscanf(dwOrientY,"%08x",&locChest.m_flC);
  2987. sscanf(dwOrientZ,"%08x",&locChest.m_flW);
  2988. sscanf(strdwObject1,"%08x",&dwObject1);
  2989. sscanf(strdwObject2,"%08x",&dwObject2);
  2990. cChest* aChest = new cChest(wType, cWorldManager::NewGUID_Object(), &locChest, ChestName, ChestDescription);
  2991. aChest->SetData(wAnimconfig,wSoundSet,wModel,wIcon,dwObject1,dwObject2);
  2992. aChest->SetIsLocked(IsLocked);
  2993. aChest->SetLDiff(LockDiff);
  2994. cWorldManager::AddObject( aChest, TRUE );
  2995. // UpdateConsole( "+" );
  2996. }
  2997. //retcode = SQLFetch( cDatabase::m_hStmt ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2998. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  2999. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3000. }
  3001. /**
  3002. * Loads lifestones from the database.
  3003. *
  3004. * Author: G70mb2
  3005. */
  3006. void cMasterServer::LoadLifestones( )
  3007. {
  3008. char szCommand[512];
  3009. char dwLandblock[9];
  3010. char dwPosX[9];
  3011. char dwPosY[9];
  3012. char dwPosZ[9];
  3013. char dwOrientW[9];
  3014. char dwOrientX[9];
  3015. char dwOrientY[9];
  3016. char dwOrientZ[9];
  3017. RETCODE retcode;
  3018. WORD wLScount = 0;
  3019. WORD wAnimconfig;
  3020. WORD wSoundSet;
  3021. WORD wModel;
  3022. WORD wIcon;
  3023. DWORD dwObject1;
  3024. DWORD dwObject2;
  3025. char szLifestones[50];
  3026. char LSName[100];
  3027. char LSDescription[500];
  3028. char strdwObject1[9];
  3029. char strdwObject2[9];
  3030. WORD wType;
  3031. sprintf( szCommand, "SELECT COUNT(ID) FROM gameobjects_lifestones;" );
  3032. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3033. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3034. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wLScount, sizeof( wLScount ), NULL );CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3035. retcode = SQLFetch( cDatabase::m_hStmt );
  3036. if( retcode == SQL_NO_DATA )
  3037. wLScount = 0;
  3038. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3039. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3040. sprintf( szLifestones, " Loading %d lifestones ... ",wLScount );
  3041. UpdateConsole((char *)szLifestones);
  3042. cLocation locLifestone;
  3043. sprintf( szCommand, "SELECT * FROM gameobjects_lifestones;" );
  3044. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3045. retcode = SQLExecute( cDatabase::m_hStmt );
  3046. int iCol = 3;
  3047. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wType, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3048. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3049. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flX, sizeof( &locLifestone.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3050. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flY, sizeof( &locLifestone.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3051. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flZ, sizeof( &locLifestone.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3052. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flA, sizeof( &locLifestone.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3053. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flB, sizeof( &locLifestone.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3054. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flC, sizeof( &locLifestone.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3055. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locLifestone.m_flW, sizeof( &locLifestone.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3056. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3057. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3058. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3059. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3060. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3061. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3062. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3063. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, LSName, sizeof( LSName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3064. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, LSDescription, sizeof( LSDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3065. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wAnimconfig, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3066. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSoundSet, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3067. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3068. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3069. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, strdwObject1, sizeof( strdwObject1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3070. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, strdwObject2, sizeof( strdwObject2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3071. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  3072. sscanf(dwLandblock,"%08x",&locLifestone.m_dwLandBlock);
  3073. sscanf(dwPosX,"%08x",&locLifestone.m_flX);
  3074. sscanf(dwPosY,"%08x",&locLifestone.m_flY);
  3075. sscanf(dwPosZ,"%08x",&locLifestone.m_flZ);
  3076. sscanf(dwOrientW,"%08x",&locLifestone.m_flA);
  3077. sscanf(dwOrientX,"%08x",&locLifestone.m_flB);
  3078. sscanf(dwOrientY,"%08x",&locLifestone.m_flC);
  3079. sscanf(dwOrientZ,"%08x",&locLifestone.m_flW);
  3080. sscanf(strdwObject1,"%08x",&dwObject1);
  3081. sscanf(strdwObject2,"%08x",&dwObject2);
  3082. cLifestone* aLifestone = new cLifestone(wType, cWorldManager::NewGUID_Object(), &locLifestone, LSName, LSDescription);
  3083. aLifestone->SetData(wAnimconfig,wSoundSet,wModel,wIcon,dwObject1,dwObject2);
  3084. cWorldManager::AddObject( aLifestone, TRUE );
  3085. // UpdateConsole( "+" );
  3086. }
  3087. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3088. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3089. }
  3090. /**
  3091. * Loads portals from the database.
  3092. *
  3093. * Author: G70mb2
  3094. */
  3095. void cMasterServer::LoadPortals( )
  3096. {
  3097. char szCommand[512];
  3098. RETCODE retcode;
  3099. // Load Portals
  3100. cLocation location;
  3101. cLocation destination;
  3102. char PortalColor[25];
  3103. char PortalName[100];
  3104. char PortalDescription[500];
  3105. char dwLandblock[9];
  3106. char dwPosX[9];
  3107. char dwPosY[9];
  3108. char dwPosZ[9];
  3109. char dwOrientW[9];
  3110. char dwOrientX[9];
  3111. char dwOrientY[9];
  3112. char dwOrientZ[9];
  3113. char dwDestLandblock[9];
  3114. char dwDestPosX[9];
  3115. char dwDestPosY[9];
  3116. char dwDestPosZ[9];
  3117. char dwDestOrientW[9];
  3118. char dwDestOrientX[9];
  3119. char dwDestOrientY[9];
  3120. char dwDestOrientZ[9];
  3121. DWORD dwMinLevel;
  3122. DWORD dwMaxLevel;
  3123. DWORD dwPortalMax;
  3124. DWORD dwPortalCount;
  3125. char szPortals[50];
  3126. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM gameobjects_portals;" );
  3127. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3128. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3129. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwPortalMax, sizeof( dwPortalMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3130. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwPortalCount, sizeof( dwPortalCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3131. retcode = SQLFetch( cDatabase::m_hStmt );
  3132. if( retcode == SQL_NO_DATA )
  3133. {
  3134. dwPortalMax = 0;
  3135. dwPortalCount = 0;
  3136. }
  3137. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3138. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3139. sprintf( szPortals, " Loading %d portals ... ",dwPortalCount );
  3140. UpdateConsole((char *)szPortals);
  3141. sprintf( szCommand, "SELECT * FROM gameobjects_portals;");
  3142. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3143. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3144. int iCol = 4;
  3145. CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3146. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, PortalName, sizeof( PortalName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3147. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, PortalDescription, sizeof( PortalDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3148. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, PortalColor, sizeof( PortalColor ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3149. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3150. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3151. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3152. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3153. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3154. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3155. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3156. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3157. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestLandblock, sizeof( dwDestLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3158. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestPosX, sizeof( dwDestPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3159. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestPosY, sizeof( dwDestPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3160. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestPosZ, sizeof( dwDestPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3161. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestOrientW, sizeof( dwDestOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3162. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestOrientX, sizeof( dwDestOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3163. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestOrientY, sizeof( dwDestOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3164. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwDestOrientZ, sizeof( dwDestOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3165. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwMinLevel, sizeof( &dwMinLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  3166. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwMaxLevel, sizeof( &dwMaxLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  3167. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; i++ )
  3168. {
  3169. sscanf(dwLandblock,"%08x",&location.m_dwLandBlock);
  3170. sscanf(dwPosX,"%08x",&location.m_flX);
  3171. sscanf(dwPosY,"%08x",&location.m_flY);
  3172. sscanf(dwPosZ,"%08x",&location.m_flZ);
  3173. sscanf(dwOrientW,"%08x",&location.m_flA);
  3174. sscanf(dwOrientX,"%08x",&location.m_flB);
  3175. sscanf(dwOrientY,"%08x",&location.m_flC);
  3176. sscanf(dwOrientZ,"%08x",&location.m_flW);
  3177. sscanf(dwDestLandblock,"%08x",&destination.m_dwLandBlock);
  3178. sscanf(dwDestPosX,"%08x",&destination.m_flX);
  3179. sscanf(dwDestPosY,"%08x",&destination.m_flY);
  3180. sscanf(dwDestPosZ,"%08x",&destination.m_flZ);
  3181. sscanf(dwDestOrientW,"%08x",&destination.m_flA);
  3182. sscanf(dwDestOrientX,"%08x",&destination.m_flB);
  3183. sscanf(dwDestOrientY,"%08x",&destination.m_flC);
  3184. sscanf(dwDestOrientZ,"%08x",&destination.m_flW);
  3185. DWORD color;
  3186. if(lstrcmpi(PortalColor,"blue")==0)
  3187. color = ColorBlue;
  3188. else if(lstrcmpi(PortalColor,"green")==0)
  3189. color = ColorGreen;
  3190. else if(lstrcmpi(PortalColor,"orange")==0)
  3191. color = ColorBrown;
  3192. else if(lstrcmpi(PortalColor,"red")==0)
  3193. color = ColorRed;
  3194. else if(lstrcmpi(PortalColor,"yellow")==0)
  3195. color = ColorYellow;
  3196. else if(lstrcmpi(PortalColor,"purple")==0)
  3197. color = ColorMagenta;
  3198. else if(lstrcmpi(PortalColor,"white")==0)
  3199. color = ColorWhite;
  3200. else
  3201. color = ColorMagenta;
  3202. cPortal* cpl = new cPortal( cWorldManager::NewGUID_Object(),color,&location, &destination, PortalName,PortalDescription, dwMinLevel, dwMaxLevel );
  3203. cWorldManager::AddObject( cpl );
  3204. }
  3205. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3206. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3207. }
  3208. /**
  3209. * Loads altars from the database.
  3210. *
  3211. * Author: G70mb2
  3212. */
  3213. void cMasterServer::LoadAltars( )
  3214. {
  3215. char szCommand[512];
  3216. char dwLandblock[9];
  3217. char dwPosX[9];
  3218. char dwPosY[9];
  3219. char dwPosZ[9];
  3220. char dwOrientW[9];
  3221. char dwOrientX[9];
  3222. char dwOrientY[9];
  3223. char dwOrientZ[9];
  3224. RETCODE retcode;
  3225. int i;
  3226. WORD wAltarcount = 0;
  3227. char szAltars[50];
  3228. sprintf( szCommand, "SELECT COUNT(ID) FROM gameobjects_altars;" );
  3229. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3230. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3231. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wAltarcount, sizeof( wAltarcount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3232. retcode = SQLFetch( cDatabase::m_hStmt );
  3233. if( retcode == SQL_NO_DATA )
  3234. wAltarcount = 0;
  3235. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3236. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3237. sprintf( szAltars, " Loading %d altars ... ",wAltarcount );
  3238. UpdateConsole((char *)szAltars);
  3239. // PK ALtar Load
  3240. cLocation PKAltar;
  3241. sprintf( szCommand, "SELECT * FROM gameobjects_altars WHERE Type = 'PKALTAR';" );
  3242. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3243. retcode = SQLExecute( cDatabase::m_hStmt );
  3244. int iCol = 4;
  3245. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3246. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flX, sizeof( &NPKAltar.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3247. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flY, sizeof( &NPKAltar.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3248. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flZ, sizeof( &NPKAltar.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3249. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flA, sizeof( &NPKAltar.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3250. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flB, sizeof( &NPKAltar.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3251. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flC, sizeof( &NPKAltar.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3252. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flW, sizeof( &NPKAltar.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3253. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3254. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3255. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3256. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3257. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3258. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3259. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3260. for (i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ){
  3261. sscanf(dwLandblock,"%08x",&PKAltar.m_dwLandBlock);
  3262. sscanf(dwPosX,"%08x",&PKAltar.m_flX);
  3263. sscanf(dwPosY,"%08x",&PKAltar.m_flY);
  3264. sscanf(dwPosZ,"%08x",&PKAltar.m_flZ);
  3265. sscanf(dwOrientW,"%08x",&PKAltar.m_flA);
  3266. sscanf(dwOrientX,"%08x",&PKAltar.m_flB);
  3267. sscanf(dwOrientY,"%08x",&PKAltar.m_flC);
  3268. sscanf(dwOrientZ,"%08x",&PKAltar.m_flW);
  3269. cAltar* anAltar = new cAltar(1,cWorldManager::NewGUID_Object(),&PKAltar,"Altar of Bael'Zharon","Double click to go PK");
  3270. cWorldManager::AddObject( anAltar, TRUE );
  3271. // UpdateConsole( "+" );
  3272. }
  3273. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3274. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3275. // NPK Altar Load
  3276. cLocation NPKAltar;
  3277. sprintf( szCommand, "SELECT * FROM gameobjects_altars WHERE Type = 'NPKALTAR';" );
  3278. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3279. retcode = SQLExecute( cDatabase::m_hStmt );
  3280. iCol = 4;
  3281. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3282. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flX, sizeof( &NPKAltar.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3283. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flY, sizeof( &NPKAltar.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3284. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flZ, sizeof( &NPKAltar.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3285. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flA, sizeof( &NPKAltar.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3286. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flB, sizeof( &NPKAltar.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3287. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flC, sizeof( &NPKAltar.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3288. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &NPKAltar.m_flW, sizeof( &NPKAltar.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3289. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3290. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3291. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3292. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3293. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3294. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3295. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3296. for (i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  3297. {
  3298. sscanf(dwLandblock,"%08x",&NPKAltar.m_dwLandBlock);
  3299. sscanf(dwPosX,"%08x",&PKAltar.m_flX);
  3300. sscanf(dwPosY,"%08x",&PKAltar.m_flY);
  3301. sscanf(dwPosZ,"%08x",&PKAltar.m_flZ);
  3302. sscanf(dwOrientW,"%08x",&PKAltar.m_flA);
  3303. sscanf(dwOrientX,"%08x",&PKAltar.m_flB);
  3304. sscanf(dwOrientY,"%08x",&PKAltar.m_flC);
  3305. sscanf(dwOrientZ,"%08x",&PKAltar.m_flW);
  3306. //UpdateConsole( "+" );
  3307. cAltar* poopo = new cAltar(0,cWorldManager::NewGUID_Object(),&NPKAltar,"Altar of Asheron","Double Click to go NPK");
  3308. cWorldManager::AddObject( poopo, TRUE );
  3309. }
  3310. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3311. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3312. }
  3313. /**
  3314. * Loads pre-defined non-player character (NPC) models from the database.
  3315. *
  3316. * Note: Used to speed up the loading of NPCs.
  3317. *
  3318. * Author: G70mb2
  3319. */
  3320. void cMasterServer::LoadNPCModels( )
  3321. {
  3322. RETCODE retcode;
  3323. char szCommand[512];
  3324. char szMessage[155];
  3325. DWORD dwModelCount;
  3326. DWORD dwNumModels;
  3327. char ModelName[75];
  3328. DWORD dwModelID;
  3329. BYTE bPaletteChange;
  3330. sPaletteChange vPalettes[255];
  3331. BYTE bTextureChange;
  3332. sTextureChange vTextures[255];
  3333. BYTE bModelChange;
  3334. sModelChange vModels[255];
  3335. char szModel[5];
  3336. char szIcon[5];
  3337. // WORD wModel;
  3338. // WORD wIcon;
  3339. char szPaletteCode[5];
  3340. char szModelNumber[5];
  3341. //char bInitialAnimation[200];
  3342. float flScale;
  3343. // Start the loading
  3344. sprintf( szCommand, "SELECT MAX(ModelNum),COUNT(ModelNum) FROM npcs_models;" );
  3345. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3346. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3347. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwModelCount, sizeof( dwModelCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3348. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwNumModels, sizeof( dwNumModels ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3349. retcode = SQLFetch( cDatabase::m_hStmt );
  3350. if( retcode == SQL_NO_DATA )
  3351. {
  3352. dwModelCount = 0;
  3353. dwNumModels = 0;
  3354. }
  3355. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3356. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3357. sprintf( szMessage, " Loading %d pre-defined NPC models ... ",dwNumModels );
  3358. UpdateConsole((char *)szMessage);
  3359. // Now all that data needs to be loaded
  3360. sprintf( szCommand, "SELECT * FROM npcs_models ORDER BY ID;" );
  3361. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3362. retcode = SQLExecute( cDatabase::m_hStmt );
  3363. int iCol = 2;
  3364. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelID, sizeof( dwModelID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3365. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelName, sizeof( ModelName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3366. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flScale, sizeof( flScale ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3367. //TODO: Edit the Modeldata table..remove a bunch of stuff.
  3368. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bPaletteChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3369. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bTextureChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3370. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bModelChange , sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3371. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szModel, sizeof( szModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3372. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szIcon, sizeof( szIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3373. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szPaletteCode, sizeof( szPaletteCode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3374. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, szModelNumber, sizeof( szModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3375. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  3376. {
  3377. cNPCModels* pcModel = new cNPCModels( dwModelID );
  3378. pcModel->m_strName.assign(ModelName);
  3379. pcModel->m_flScale = flScale;
  3380. pcModel->m_bPaletteChange = bPaletteChange;
  3381. pcModel->m_wPaletteVector = dwModelID;
  3382. pcModel->m_bTextureChange = bTextureChange;
  3383. pcModel->m_wTextureVector = dwModelID;
  3384. pcModel->m_bModelChange = bModelChange;
  3385. pcModel->m_wModelVector = dwModelID;
  3386. sscanf(szModel,"%04x",&pcModel->m_wModel);
  3387. sscanf(szIcon,"%04x",&pcModel->m_wIcon);
  3388. sscanf(szPaletteCode,"%04x",&pcModel->m_wPaletteCode);
  3389. sscanf(szModelNumber,"%08x",&pcModel->m_dwModelNumber);
  3390. /*
  3391. int b = 0;
  3392. char cTemp[2];
  3393. for(int i = 0; i < (dwUnknownCount); i++)
  3394. {
  3395. CopyMemory( &cTemp[0], &bInitialAnimation[b], 2 );
  3396. sscanf(cTemp,"%08x",&pcModel->m_bInitialAnimation[i]);
  3397. b = b + 2;
  3398. }
  3399. */
  3400. }
  3401. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3402. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3403. //===============================================================
  3404. // Load all the Vector Data for Each Model ID
  3405. //
  3406. //===============================================================
  3407. for ( DWORD d = 0; d < dwModelCount+1; d++)
  3408. {
  3409. cNPCModels *pcModel = cNPCModels::Hash_Find( d );
  3410. if(pcModel)
  3411. {
  3412. sprintf( szCommand, "SELECT * FROM npcs_vector_palettes WHERE modelvector=%d ORDER BY VectorCount;", pcModel->m_wPaletteVector);
  3413. // Load Palette vector into array
  3414. // Define Temp Variables
  3415. BYTE bVectorCount;
  3416. char readbuff01[5];
  3417. char readbuff02[3];
  3418. char readbuff03[3];
  3419. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  3420. retcode = SQLExecute( cDatabase::m_hStmt );
  3421. iCol = 3;
  3422. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( bVectorCount ), NULL );
  3423. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff01 , sizeof( readbuff01 ), NULL );
  3424. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff02 , sizeof( readbuff02 ), NULL );
  3425. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff03 , sizeof( readbuff03 ), NULL );
  3426. for ( int intPcount = 0 ; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS && intPcount < pcModel->m_bPaletteChange +1; ++intPcount )
  3427. {
  3428. // Let's scan that text into Hex
  3429. sscanf(readbuff01,"%04x",&pcModel->m_vectorPal[intPcount].m_wNewPalette);
  3430. sscanf(readbuff02,"%02x",&pcModel->m_vectorPal[intPcount].m_ucOffset);
  3431. sscanf(readbuff03,"%02x",&pcModel->m_vectorPal[intPcount].m_ucLength);
  3432. }
  3433. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  3434. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3435. // Load Texture Vector into Array
  3436. // Define Temp Variables
  3437. char readbuff04[3];
  3438. char readbuff05[5];
  3439. char readbuff06[5];
  3440. sprintf( szCommand, "SELECT * FROM npcs_vector_textures WHERE modelvector=%d ORDER BY VectorCount;",pcModel->m_wTextureVector);
  3441. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  3442. retcode = SQLExecute( cDatabase::m_hStmt );
  3443. iCol = 3;
  3444. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  3445. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff04, sizeof( readbuff04 ), NULL );
  3446. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff05, sizeof( readbuff05 ), NULL );
  3447. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff06 , sizeof( readbuff06 ), NULL );
  3448. for ( int intT = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS && intT < pcModel->m_bTextureChange + 1; ++intT )
  3449. {
  3450. // Let's scan that text into Hex
  3451. sscanf(readbuff04,"%02x",&pcModel->m_vectorTex[intT].m_bModelIndex);
  3452. sscanf(readbuff05,"%04x",&pcModel->m_vectorTex[intT].m_wOldTexture);
  3453. sscanf(readbuff06,"%04x",&pcModel->m_vectorTex[intT].m_wNewTexture);
  3454. }
  3455. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  3456. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3457. // Load Model Vectors into Array
  3458. // Define Temp Variables
  3459. char readbuff07[3];
  3460. char readbuff08[5];
  3461. sprintf( szCommand, "SELECT * FROM npcs_vector_models WHERE modelvector=%d ORDER BY VectorCount;", pcModel->m_wModelVector);
  3462. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  3463. retcode = SQLExecute( cDatabase::m_hStmt );
  3464. iCol = 3;
  3465. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  3466. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff07, sizeof( readbuff07 ), NULL );
  3467. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff08 , sizeof( readbuff08 ), NULL );
  3468. for ( int intM = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intM < pcModel->m_bModelChange + 1); ++intM )
  3469. {
  3470. // Scan the text to HEX
  3471. sscanf(readbuff07,"%02x",&pcModel->m_vectorMod[intM].m_bModelIndex);
  3472. sscanf(readbuff08,"%04x",&pcModel->m_vectorMod[intM].m_wNewModel);
  3473. }
  3474. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  3475. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3476. // UpdateConsole( "+" );
  3477. }
  3478. }
  3479. }
  3480. /**
  3481. * Loads non-player characters (NPCs) from the database.
  3482. *
  3483. * Author: G70mb2
  3484. */
  3485. void cMasterServer::LoadNPCs( )
  3486. {
  3487. char szCommand[512];
  3488. RETCODE retcode;
  3489. char AvatarName[100];
  3490. char ReadMode[15];
  3491. char cGender[2];
  3492. WORD wGender;
  3493. cLocation avatarloc;
  3494. DWORD dwSellCategories;
  3495. DWORD dwMode;
  3496. int iNumMessages = 0;
  3497. char Message_1[500];
  3498. char Message_2[500];
  3499. char Message_3[500];
  3500. char Message_4[500];
  3501. char Message_5[500];
  3502. char Message_6[500];
  3503. char Message_7[500];
  3504. char Message_8[500];
  3505. char Message_9[500];
  3506. char Message_10[500];
  3507. char NPCLoc[9];
  3508. char dwPosX[9];
  3509. char dwPosY[9];
  3510. char dwPosZ[9];
  3511. char dwOrientW[9];
  3512. char dwOrientX[9];
  3513. char dwOrientY[9];
  3514. char dwOrientZ[9];
  3515. WORD wNPCModel = 0;
  3516. WORD wNPCcount = 0;
  3517. int IsVendor = 0;
  3518. char szNPCs[50];
  3519. char SellCat[9];
  3520. DWORD NPC_ID;
  3521. DWORD qitem_id1;
  3522. DWORD vendor_item_modelnumber;
  3523. sprintf( szCommand, "SELECT max(ID) FROM npcs;" );
  3524. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3525. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3526. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &wNPCcount, sizeof( wNPCcount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3527. retcode = SQLFetch( cDatabase::m_hStmt );
  3528. if( retcode == SQL_NO_DATA )
  3529. wNPCcount = 0;
  3530. sprintf( szNPCs, " Loading %d NPCs ... ",wNPCcount );
  3531. UpdateConsole((char *)szNPCs);
  3532. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3533. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3534. // Now process all NPC models
  3535. for ( int iTmp = 0; iTmp < wNPCcount + 1; iTmp++)
  3536. {
  3537. sprintf( szCommand, "SELECT * FROM npcs WHERE ID = %d;", iTmp );
  3538. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3539. retcode = SQLExecute( cDatabase::m_hStmt );
  3540. int iCol = 3;
  3541. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &NPC_ID, sizeof( NPC_ID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3542. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, AvatarName, sizeof( AvatarName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3543. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, cGender, sizeof( cGender ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3544. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wNPCModel, sizeof( WORD ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3545. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ReadMode, sizeof( ReadMode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3546. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &iNumMessages, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3547. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_1, sizeof( Message_1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3548. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_2, sizeof( Message_2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3549. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_3, sizeof( Message_3 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3550. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_4, sizeof( Message_4 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3551. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_5, sizeof( Message_5 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3552. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_6, sizeof( Message_6 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3553. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_7, sizeof( Message_7 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3554. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_8, sizeof( Message_8 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3555. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_9, sizeof( Message_9 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3556. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Message_10, sizeof( Message_10 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3557. iCol = 19;
  3558. // Location
  3559. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, NPCLoc, sizeof( NPCLoc ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3560. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flX, sizeof( &avatarloc.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3561. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flY, sizeof( &avatarloc.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3562. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flZ, sizeof( &avatarloc.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3563. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flA, sizeof( &avatarloc.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3564. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flB, sizeof( &avatarloc.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3565. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flC, sizeof( &avatarloc.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3566. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &avatarloc.m_flW, sizeof( &avatarloc.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3567. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3568. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3569. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3570. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3571. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3572. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3573. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3574. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &IsVendor, sizeof( INT ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1)
  3575. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, SellCat, sizeof( SellCat ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3576. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &qitem_id1, sizeof( qitem_id1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3577. if( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS )
  3578. {
  3579. sscanf(NPCLoc,"%08x",&avatarloc.m_dwLandBlock);
  3580. sscanf(dwPosX,"%08x",&avatarloc.m_flX);
  3581. sscanf(dwPosY,"%08x",&avatarloc.m_flY);
  3582. sscanf(dwPosZ,"%08x",&avatarloc.m_flZ);
  3583. sscanf(dwOrientW,"%08x",&avatarloc.m_flA);
  3584. sscanf(dwOrientX,"%08x",&avatarloc.m_flB);
  3585. sscanf(dwOrientY,"%08x",&avatarloc.m_flC);
  3586. sscanf(dwOrientZ,"%08x",&avatarloc.m_flW);
  3587. sscanf(SellCat, "%08x",&dwSellCategories);
  3588. // Set Gender
  3589. tolower(cGender[1]);
  3590. if(cGender[1] == 'f')
  3591. {
  3592. wGender = 0;
  3593. } else {
  3594. wGender = 1;
  3595. }
  3596. cNPC* npc = new cNPC(cWorldManager::NewGUID_Object(), wNPCModel, AvatarName, wGender, &avatarloc, dwSellCategories);
  3597. // Set Message Type
  3598. if(lstrcmpi(ReadMode,"RANDOM")==0)
  3599. dwMode = NPCMODE_RANDOM;
  3600. else if(lstrcmpi(ReadMode,"MULTI")==0)
  3601. dwMode = NPCMODE_MULTI;
  3602. else if(lstrcmpi(ReadMode,"SINGLE")==0)
  3603. dwMode = NPCMODE_SINGLE;
  3604. npc->SetMode(dwMode); // Message Mode
  3605. npc->SetNumMessages(iNumMessages); // Number of Messages
  3606. npc->SetIsVendor(IsVendor);
  3607. npc->Set_npc_id(NPC_ID);
  3608. npc->m_qitem_id1 = qitem_id1;
  3609. // Store the Messages
  3610. if (iNumMessages >= 1 ) {
  3611. char* sz = strchr(Message_1,' ');
  3612. //*sz = 0;
  3613. npc->SetString(Message_1,0);
  3614. }
  3615. if (iNumMessages >= 2 ) {
  3616. char* sz = strchr(Message_2,' ');
  3617. //*sz = 0;
  3618. npc->SetString(Message_2,1);
  3619. }
  3620. if (iNumMessages >= 3 ) {
  3621. char* sz = strchr(Message_3,' ');
  3622. //*sz = 0;
  3623. npc->SetString(Message_3,2);
  3624. }
  3625. if (iNumMessages >= 4 ) {
  3626. char* sz = strchr(Message_4,' ');
  3627. //*sz = 0;
  3628. npc->SetString(Message_4,3);
  3629. }
  3630. if (iNumMessages >= 5 ) {
  3631. char* sz = strchr(Message_5,' ');
  3632. //*sz = 0;
  3633. npc->SetString(Message_5,4);
  3634. }
  3635. if (iNumMessages >= 6 ) {
  3636. char* sz = strchr(Message_6,' ');
  3637. //*sz = 0;
  3638. npc->SetString(Message_6,5);
  3639. }
  3640. if (iNumMessages >= 7 ) {
  3641. char* sz = strchr(Message_7,' ');
  3642. //*sz = 0;
  3643. npc->SetString(Message_7,6);
  3644. }
  3645. if (iNumMessages >= 8 ) {
  3646. char* sz = strchr(Message_8,' ');
  3647. //*sz = 0;
  3648. npc->SetString(Message_8,7);
  3649. }
  3650. if (iNumMessages >= 9 ) {
  3651. char* sz = strchr(Message_9,' ');
  3652. //*sz = 0;
  3653. npc->SetString(Message_9,8);
  3654. }
  3655. if (iNumMessages == 10 ) {
  3656. char* sz = strchr(Message_10,' ');
  3657. //*sz = 0;
  3658. npc->SetString(Message_10,9);
  3659. }
  3660. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3661. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3662. cWorldManager::AddObject( npc, TRUE );
  3663. // UpdateConsole( "+" );
  3664. if (npc->GetIsVendor() == 1)
  3665. {
  3666. sprintf( szCommand, "SELECT * FROM npcs_vendor_items WHERE vendor_id = %d;", npc->Get_npc_id() );
  3667. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3668. retcode = SQLExecute( cDatabase::m_hStmt );
  3669. int iCol = 3;
  3670. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &vendor_item_modelnumber, sizeof( vendor_item_modelnumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3671. for (int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  3672. {
  3673. //Cubem0j0: We find the model number so we can get some vars.
  3674. cItemModels *pcModel = cItemModels::FindModel(vendor_item_modelnumber);
  3675. switch(pcModel->m_ItemType)
  3676. {
  3677. case 1: //Weapons
  3678. {
  3679. cWeapon* weapon = new cWeapon(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_bWieldType,pcModel->m_dwIconHighlight,pcModel->m_fWorkmanship,pcModel->m_dwMaterialType,pcModel->m_dwWeaponDamage,pcModel->m_dwWeaponSpeed,pcModel->m_dwWeaponSkill,pcModel->m_dwDamageType,pcModel->m_dWeaponVariance,pcModel->m_dWeaponModifier,pcModel->m_dWeaponPower,pcModel->m_dWeaponAttack);
  3680. npc->v_guids[i] = weapon->GetGUID();
  3681. npc->AddInventory(weapon);
  3682. }
  3683. break;
  3684. case 2:
  3685. {
  3686. cFood* food = new cFood(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wStack, pcModel->m_wBurden, pcModel->m_dwVitalID, pcModel->m_vital_affect);
  3687. npc->v_guids[i] = food->GetGUID();
  3688. npc->AddInventory(food);
  3689. }
  3690. break;
  3691. case 3: //Armor
  3692. {
  3693. cArmor* armor = new cArmor(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue, pcModel->m_wBurden,pcModel->m_dwArmor_Level,pcModel->m_fProt_Slashing, pcModel->m_fProt_Piercing, pcModel->m_fProt_Bludgeon, pcModel->m_fProt_Fire, pcModel->m_fProt_Cold, pcModel->m_fProt_Acid, pcModel->m_fProt_Electric);
  3694. npc->v_guids[i] = armor->GetGUID();
  3695. npc->AddInventory(armor);
  3696. }
  3697. break;
  3698. case 4:
  3699. break;
  3700. case 5:
  3701. {
  3702. cScrolls* scrolls = new cScrolls(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription);
  3703. npc->v_guids[i] = scrolls->GetGUID();
  3704. npc->AddInventory(scrolls);
  3705. }
  3706. break;
  3707. case 6:
  3708. break;
  3709. case 7:
  3710. {
  3711. cLockpicks* lockpick = new cLockpicks(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_wUses,pcModel->m_wUseLimit);
  3712. npc->v_guids[i] = lockpick->GetGUID();
  3713. npc->AddInventory(lockpick);
  3714. }
  3715. break;
  3716. case 8: //Casting Items
  3717. {
  3718. cWands* wands = new cWands(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3719. npc->v_guids[i] = wands->GetGUID();
  3720. npc->AddInventory(wands);
  3721. }
  3722. break;
  3723. case 9:
  3724. break;
  3725. case 10: //Mana Stones
  3726. {
  3727. cManaStones* manastones = new cManaStones(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3728. npc->v_guids[i] = manastones->GetGUID();
  3729. npc->AddInventory(manastones);
  3730. }
  3731. break;
  3732. case 11: //Missile Weapons/Ammo
  3733. {
  3734. cAmmo* ammo = new cAmmo(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_wStack,pcModel->m_wStackLimit);
  3735. npc->v_guids[i] = ammo->GetGUID();
  3736. npc->AddInventory(ammo);
  3737. }
  3738. break;
  3739. case 12:
  3740. {
  3741. cShield* shield = new cShield(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden,pcModel->m_dwArmor_Level);
  3742. npc->v_guids[i] = shield->GetGUID();
  3743. npc->AddInventory(shield);
  3744. }
  3745. break;
  3746. case 13:
  3747. {
  3748. cSpellComps* comps = new cSpellComps(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wStack,pcModel->m_wBurden);
  3749. npc->v_guids[i] = comps->GetGUID();
  3750. npc->AddInventory(comps);
  3751. }
  3752. break;
  3753. case 14:
  3754. {
  3755. cGems* gem = new cGems(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3756. npc->v_guids[i] = gem->GetGUID();
  3757. npc->AddInventory(gem);
  3758. }
  3759. break;
  3760. case 15:
  3761. {
  3762. cTradeNotes* tradenotes = new cTradeNotes(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3763. npc->v_guids[i] = tradenotes->GetGUID();
  3764. npc->AddInventory(tradenotes);
  3765. }
  3766. break;
  3767. case 16:
  3768. {
  3769. cTradeSkillMats* mats = new cTradeSkillMats(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3770. npc->v_guids[i] = mats->GetGUID();
  3771. npc->AddInventory(mats);
  3772. }
  3773. break;
  3774. case 17:
  3775. {
  3776. }
  3777. break;
  3778. case 18:
  3779. {
  3780. cClothes* rags = new cClothes(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3781. npc->v_guids[i] = rags->GetGUID();
  3782. npc->AddInventory(rags);
  3783. }
  3784. break;
  3785. case 19:
  3786. {
  3787. cJewelry* ring = new cJewelry(cWorldManager::NewGUID_Object(),npc->GetGUID(),vendor_item_modelnumber,1.0,TRUE,pcModel->m_wIcon,pcModel->m_strName,pcModel->m_strDescription,pcModel->m_dwValue,pcModel->m_wBurden);
  3788. npc->v_guids[i] = ring->GetGUID();
  3789. npc->AddInventory(ring);
  3790. }
  3791. break;
  3792. }
  3793. }
  3794. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3795. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3796. }
  3797. } // End For Loop thru NPC objects
  3798. else
  3799. {
  3800. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3801. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3802. }
  3803. }
  3804. }
  3805. /**
  3806. * Loads pre-defined monster models from the database.
  3807. *
  3808. * Note: Primarily used for monsters, since there are several copies of
  3809. * the same data. One model needs to be loaded for each creature,
  3810. * which may then be referenced by the Model Number as needed.
  3811. *
  3812. * TODO: Load monster models from the portal.dat instead.
  3813. *
  3814. * Author: G70mb2
  3815. */
  3816. void cMasterServer::LoadMonsterModels( )
  3817. {
  3818. RETCODE retcode;
  3819. char szCommand[512];
  3820. char szMessage[155];
  3821. DWORD dwModelCount;
  3822. DWORD dwNumModels;
  3823. char ModelName[75];
  3824. char ModelDescription[255];
  3825. DWORD dwModelID;
  3826. BYTE bPaletteChange;
  3827. sPaletteChange vPalettes[255];
  3828. BYTE bTextureChange;
  3829. sTextureChange vTextures[255];
  3830. BYTE bModelChange;
  3831. sModelChange vModels[255];
  3832. char szFlags1[9];
  3833. WORD wPortalMode;
  3834. WORD wUnknown_1;
  3835. WORD wModel;
  3836. WORD wIcon;
  3837. char szAnimConfig[5];
  3838. char szSoundSet[5];
  3839. DWORD dwUnknown_Blue;
  3840. char szModelNumber[5];
  3841. float flScale;
  3842. DWORD dwUnknown_LightGrey;
  3843. DWORD dwTrio1[3];
  3844. DWORD dwMedGrey;
  3845. DWORD dwBlueGrey;
  3846. WORD wSeagreen8;
  3847. DWORD dwUnknownCount;
  3848. char bInitialAnimation[200];
  3849. DWORD dwUnknown_v2;
  3850. DWORD dwUnknown_v6;
  3851. DWORD dwSpecies;
  3852. // Start the loading
  3853. sprintf( szCommand, "SELECT MAX(dwLinker),COUNT(dwLinker) FROM monsters_templates;" );
  3854. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3855. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3856. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwModelCount, sizeof( dwModelCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3857. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwNumModels, sizeof( dwNumModels ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  3858. retcode = SQLFetch( cDatabase::m_hStmt );
  3859. if( retcode == SQL_NO_DATA )
  3860. {
  3861. dwModelCount = 0;
  3862. dwNumModels = 0;
  3863. }
  3864. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3865. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  3866. sprintf( szMessage, " Loading %d pre-defined monster models ... ",dwNumModels );
  3867. UpdateConsole((char *)szMessage);
  3868. // Now all that data needs to be loaded
  3869. sprintf( szCommand, "SELECT * FROM monsters_templates ORDER BY ID;" );
  3870. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3871. retcode = SQLExecute( cDatabase::m_hStmt );
  3872. int iCol = 2;
  3873. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelName, sizeof( ModelName ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3874. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, ModelDescription, sizeof( ModelDescription ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3875. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bPaletteChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3876. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bTextureChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3877. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &bModelChange, sizeof( BYTE ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3878. // dwFlags1
  3879. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szFlags1, sizeof( szFlags1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3880. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wPortalMode, sizeof( wPortalMode ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3881. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wUnknown_1, sizeof( wUnknown_1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3882. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wModel, sizeof( wModel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3883. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wIcon, sizeof( wIcon ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3884. // Animconfig, Soundset
  3885. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szAnimConfig, sizeof( szAnimConfig ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3886. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szSoundSet, sizeof( szSoundSet ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3887. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_Blue, sizeof( dwUnknown_Blue ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3888. // dwModelNumber
  3889. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &szModelNumber, sizeof( szModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3890. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &flScale, sizeof( flScale ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3891. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_LightGrey, sizeof( dwUnknown_LightGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3892. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[0], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3893. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[1], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3894. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &dwTrio1[2], sizeof( dwTrio1 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3895. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMedGrey, sizeof( dwMedGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3896. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwBlueGrey, sizeof( dwBlueGrey ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3897. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &wSeagreen8, sizeof( wSeagreen8 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3898. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v2, sizeof( dwUnknown_v2 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3899. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknown_v6, sizeof( dwUnknown_v6 ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3900. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwUnknownCount, sizeof( dwUnknownCount ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3901. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &bInitialAnimation, sizeof( bInitialAnimation ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3902. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelID, sizeof( dwModelID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3903. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwSpecies, sizeof( dwSpecies ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3904. for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i )
  3905. {
  3906. cModels* pcModel = new cModels( dwModelID );
  3907. pcModel->m_strName.assign(ModelName);
  3908. pcModel->m_strDescription.assign(ModelDescription);
  3909. pcModel->m_bPaletteChange = bPaletteChange;
  3910. pcModel->m_wPaletteVector = dwModelID;
  3911. pcModel->m_bTextureChange = bTextureChange;
  3912. pcModel->m_wTextureVector = dwModelID;
  3913. pcModel->m_bModelChange = bModelChange;
  3914. pcModel->m_wModelVector = dwModelID;
  3915. sscanf(szFlags1,"%08x",&pcModel->m_dwFlags1);
  3916. pcModel->m_wPortalMode = wPortalMode;
  3917. pcModel->m_wUnknown_1 = wUnknown_1;
  3918. pcModel->m_wModel = wModel;
  3919. pcModel->m_wIcon = wIcon;
  3920. sscanf(szAnimConfig,"%08x",&pcModel->m_wAnimConfig);
  3921. sscanf(szSoundSet,"%08x",&pcModel->m_wSoundSet);
  3922. pcModel->m_dwUnknown_Blue = dwUnknown_Blue;
  3923. sscanf(szModelNumber,"%08x",&pcModel->m_dwModelNumber);
  3924. pcModel->m_flScale = flScale;
  3925. pcModel->m_dwUnknown_LightGrey = dwUnknown_LightGrey;
  3926. pcModel->m_dwTrio1[0] = dwTrio1[0];
  3927. pcModel->m_dwTrio1[1] = dwTrio1[1];
  3928. pcModel->m_dwTrio1[2] = dwTrio1[2];
  3929. pcModel->m_dwMedGrey = dwMedGrey;
  3930. pcModel->m_dwBlueGrey = dwBlueGrey;
  3931. pcModel->m_wSeagreen8 = wSeagreen8;
  3932. pcModel->m_dwUnknown_v2 = dwUnknown_v2;
  3933. pcModel->m_dwUnknown_v6 = dwUnknown_v6;
  3934. pcModel->m_dwUnknownCount = dwUnknownCount;
  3935. pcModel->m_dwSpecies = dwSpecies;
  3936. int b = 0;
  3937. char cTemp[2];
  3938. for(int i = 0; i < (dwUnknownCount); i++) {
  3939. CopyMemory( &cTemp[0], &bInitialAnimation[b], 2 );
  3940. sscanf(cTemp,"%08x",&pcModel->m_bInitialAnimation[i]);
  3941. b = b + 2;
  3942. }
  3943. }
  3944. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  3945. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3946. //===============================================================
  3947. // Load all the Vector Data for Each Model ID
  3948. //
  3949. //===============================================================
  3950. for ( DWORD d = 0; d < dwModelCount+1; d++)
  3951. {
  3952. cModels *pcModel = cModels::Hash_Find( d );
  3953. if(pcModel)
  3954. {
  3955. sprintf( szCommand, "SELECT * FROM monsters_vector_palettes WHERE dwLinker=%d ORDER BY VectorCount;", pcModel->m_wPaletteVector);
  3956. // Load Palette vector into array
  3957. // Define Temp Variables
  3958. BYTE bVectorCount;
  3959. char readbuff01[5];
  3960. char readbuff02[3];
  3961. char readbuff03[3];
  3962. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  3963. retcode = SQLExecute( cDatabase::m_hStmt );
  3964. iCol = 3;
  3965. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( bVectorCount ), NULL );
  3966. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff01 , sizeof( readbuff01 ), NULL );
  3967. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff02 , sizeof( readbuff02 ), NULL );
  3968. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff03 , sizeof( readbuff03 ), NULL );
  3969. for ( int intPcount = 0 ; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS && intPcount < pcModel->m_bPaletteChange +1; ++intPcount )
  3970. {
  3971. // Let's scan that text into Hex
  3972. sscanf(readbuff01,"%04x",&pcModel->m_vectorPal[intPcount].m_wNewPalette);
  3973. sscanf(readbuff02,"%02x",&pcModel->m_vectorPal[intPcount].m_ucOffset);
  3974. sscanf(readbuff03,"%02x",&pcModel->m_vectorPal[intPcount].m_ucLength);
  3975. }
  3976. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  3977. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  3978. // Load Texture Vector into Array
  3979. // Define Temp Variables
  3980. char readbuff04[3];
  3981. char readbuff05[5];
  3982. char readbuff06[5];
  3983. sprintf( szCommand, "SELECT * FROM monsters_vector_textures WHERE dwLinker=%d ORDER BY VectorCount;",pcModel->m_wTextureVector);
  3984. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  3985. retcode = SQLExecute( cDatabase::m_hStmt );
  3986. iCol = 3;
  3987. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  3988. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff04, sizeof( readbuff04 ), NULL );
  3989. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff05, sizeof( readbuff05 ), NULL );
  3990. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff06 , sizeof( readbuff06 ), NULL );
  3991. for ( int intT = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS && intT < pcModel->m_bTextureChange + 1; ++intT )
  3992. {
  3993. //scan the text into hexadecimal
  3994. sscanf(readbuff04,"%02x",&pcModel->m_vectorTex[intT].m_bModelIndex);
  3995. sscanf(readbuff05,"%04x",&pcModel->m_vectorTex[intT].m_wOldTexture);
  3996. sscanf(readbuff06,"%04x",&pcModel->m_vectorTex[intT].m_wNewTexture);
  3997. }
  3998. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  3999. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4000. // Load Model Vectors into Array
  4001. // Define Temp Variables
  4002. char readbuff07[3];
  4003. char readbuff08[5];
  4004. sprintf( szCommand, "SELECT * FROM monsters_vector_models WHERE dwLinker=%d ORDER BY VectorCount;", pcModel->m_wModelVector);
  4005. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  4006. retcode = SQLExecute( cDatabase::m_hStmt );
  4007. iCol = 3;
  4008. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_LONG, &bVectorCount, sizeof( BYTE ), NULL );
  4009. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff07, sizeof( readbuff07 ), NULL );
  4010. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, &readbuff08 , sizeof( readbuff08 ), NULL );
  4011. for ( int intM = 0; (SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS) && (intM < pcModel->m_bModelChange + 1); ++intM )
  4012. {
  4013. // Scan the Text to HEX
  4014. sscanf(readbuff07,"%02x",&pcModel->m_vectorMod[intM].m_bModelIndex);
  4015. sscanf(readbuff08,"%04x",&pcModel->m_vectorMod[intM].m_wNewModel);
  4016. }
  4017. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  4018. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4019. // Load Model Animations into cAnimation
  4020. sprintf( szCommand, "SELECT * FROM monsters_species_animation WHERE dwSpecies=%d;", pcModel->m_dwSpecies);
  4021. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS );
  4022. retcode = SQLExecute( cDatabase::m_hStmt );
  4023. iCol = 4;
  4024. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wDeath, sizeof( WORD ), NULL );
  4025. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[0], sizeof( WORD ), NULL );
  4026. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[1], sizeof( WORD ), NULL );
  4027. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[2], sizeof( WORD ), NULL );
  4028. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[3], sizeof( WORD ), NULL );
  4029. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[4], sizeof( WORD ), NULL );
  4030. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[5], sizeof( WORD ), NULL );
  4031. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[6], sizeof( WORD ), NULL );
  4032. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[7], sizeof( WORD ), NULL );
  4033. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[8], sizeof( WORD ), NULL );
  4034. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wStance[9], sizeof( WORD ), NULL );
  4035. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[0], sizeof( WORD ), NULL );
  4036. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[1], sizeof( WORD ), NULL );
  4037. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[2], sizeof( WORD ), NULL );
  4038. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[3], sizeof( WORD ), NULL );
  4039. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[4], sizeof( WORD ), NULL );
  4040. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[5], sizeof( WORD ), NULL );
  4041. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[6], sizeof( WORD ), NULL );
  4042. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[7], sizeof( WORD ), NULL );
  4043. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[8], sizeof( WORD ), NULL );
  4044. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[9], sizeof( WORD ), NULL );
  4045. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wAttack[5], sizeof( WORD ), NULL );
  4046. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[0], sizeof( WORD ), NULL );
  4047. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[1], sizeof( WORD ), NULL );
  4048. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[2], sizeof( WORD ), NULL );
  4049. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[3], sizeof( WORD ), NULL );
  4050. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[4], sizeof( WORD ), NULL );
  4051. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wIdle[5], sizeof( WORD ), NULL );
  4052. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[0], sizeof( WORD ), NULL );
  4053. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[1], sizeof( WORD ), NULL );
  4054. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[2], sizeof( WORD ), NULL );
  4055. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[3], sizeof( WORD ), NULL );
  4056. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[4], sizeof( WORD ), NULL );
  4057. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_USHORT, &pcModel->m_cAnimations.m_wReact[5], sizeof( WORD ), NULL );
  4058. retcode = SQLFetch( cDatabase::m_hStmt );
  4059. retcode = SQLCloseCursor( cDatabase::m_hStmt );
  4060. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4061. // UpdateConsole( "+" );
  4062. }
  4063. }
  4064. }
  4065. /**
  4066. * Loads monsters from the database.
  4067. *
  4068. * Note: Use ModelNumber to reference pre-loaded model data.
  4069. * This should become obsolete once spawn control is developed
  4070. * Spawn Generators will then be loaded instead of individual
  4071. * monsters, which will then spawn as needed.
  4072. *
  4073. * Cube:
  4074. * Changing this: We will pull monsters for dungeons only from the
  4075. * monster table. This makes more sense, as dungeons are static spawns.
  4076. *
  4077. * Author: G70mb2
  4078. */
  4079. void cMasterServer::LoadMonsters( )
  4080. {
  4081. RETCODE retcode;
  4082. char szCommand[768];
  4083. char szMonsters[150];
  4084. DWORD dwMonsterMax;
  4085. DWORD dwMonsterCount;
  4086. DWORD ID;
  4087. char Name[100];
  4088. char Description[255];
  4089. cLocation locMonster;
  4090. char dwLandblock[9];
  4091. char dwPosX[9];
  4092. char dwPosY[9];
  4093. char dwPosZ[9];
  4094. char dwOrientW[9];
  4095. char dwOrientX[9];
  4096. char dwOrientY[9];
  4097. char dwOrientZ[9];
  4098. DWORD dwModelNumber;
  4099. cMonStats cmsStats;
  4100. DWORD dwRespawn;
  4101. DWORD dwDecay;
  4102. DWORD dwChase;
  4103. DWORD dwInfluence;
  4104. DWORD dwExp_Value;
  4105. DWORD dwHealth;
  4106. DWORD dwStamina;
  4107. DWORD dwMana;
  4108. sprintf( szCommand, "SELECT MAX(ID), COUNT(ID) FROM monsters;" );
  4109. retcode = SQLPrepare( cDatabase::m_hStmt, (BYTE *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4110. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4111. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwMonsterMax, sizeof( dwMonsterMax ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4112. retcode = SQLBindCol( cDatabase::m_hStmt, 2, SQL_C_ULONG, &dwMonsterCount, sizeof( dwMonsterCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4113. retcode = SQLFetch( cDatabase::m_hStmt );
  4114. if( retcode == SQL_NO_DATA )
  4115. {
  4116. dwMonsterMax = 0;
  4117. dwMonsterCount = 0;
  4118. }
  4119. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  4120. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  4121. sprintf( szMonsters, " Loading %d monsters ... ",dwMonsterCount );
  4122. UpdateConsole((char *)szMonsters);
  4123. for ( int iTmp = 1; iTmp < dwMonsterMax + 1; iTmp++) {
  4124. sprintf( szCommand, "SELECT ID,dwModelNumber,strName,strDescription,Landblock,Position_X,Position_Y,Position_Z,Orientation_W,Orientation_X,Orientation_Y,Orientation_Z FROM monsters WHERE ID=%d;", iTmp );
  4125. // sprintf( szCommand, "SELECT m.dwModelNumber,m.strName,m.strDescription,m.Landblock,m.Position_X,m.Position_Y,m.Position_Z,m.Orientation_W,m.Orientation_X,m.Orientation_Y,m.Orientation_Z,mt.Level,mt.Strength,mt.Endurance,mt.Quickness,mt.Coordination,mt.Focus,mt.Self,mt.Species,mt.Respawn,mt.Decay,mt.Chase,mt.Influence,mt.Health,mt.Stamina,mt.Mana,mt.XP FROM Monsters m LEFT OUTER JOIN monsters_type mt on m.dwModelNumber = mt.Modeldata;" );
  4126. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4127. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4128. int iCol = 1;
  4129. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &ID, sizeof( ID ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4130. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4131. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4132. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4133. // Landblock Data
  4134. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4135. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flX, sizeof( &locMonster.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4136. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flY, sizeof( &locMonster.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4137. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flZ, sizeof( &locMonster.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4138. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flA, sizeof( &locMonster.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4139. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flB, sizeof( &locMonster.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4140. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flC, sizeof( &locMonster.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4141. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &locMonster.m_flW, sizeof( &locMonster.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4142. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4143. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4144. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4145. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4146. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4147. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4148. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4149. if ( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS ) {
  4150. // for ( int i = 0; SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS; ++i ) {
  4151. sscanf(dwLandblock,"%08x",&locMonster.m_dwLandBlock);
  4152. sscanf(dwPosX,"%08x",&locMonster.m_flX);
  4153. sscanf(dwPosY,"%08x",&locMonster.m_flY);
  4154. sscanf(dwPosZ,"%08x",&locMonster.m_flZ);
  4155. sscanf(dwOrientW,"%08x",&locMonster.m_flA);
  4156. sscanf(dwOrientX,"%08x",&locMonster.m_flB);
  4157. sscanf(dwOrientY,"%08x",&locMonster.m_flC);
  4158. sscanf(dwOrientZ,"%08x",&locMonster.m_flW);
  4159. cMasterServer::FixName(Name);
  4160. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4161. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4162. sprintf( szCommand, "SELECT m.ModelData,m.Level,m.Strength,m.Endurance,m.Quickness,m.Coordination,m.Focus,m.Self,m.Species,m.Respawn,m.Decay,m.Chase,m.Influence,m.Health,m.Stamina,m.Mana,m.XP FROM monsters_type m WHERE m.Modeldata = %d;", dwModelNumber );
  4163. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4164. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4165. iCol = 2;
  4166. // Monster Level
  4167. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwLevel, sizeof( cmsStats.m_dwLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4168. // Monster Attributes
  4169. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwStr, sizeof( cmsStats.m_dwStr ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4170. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwEnd, sizeof( cmsStats.m_dwEnd ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4171. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwQuick, sizeof( cmsStats.m_dwQuick ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4172. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwCoord, sizeof( cmsStats.m_dwCoord ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4173. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwFocus, sizeof( cmsStats.m_dwFocus ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4174. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSelf, sizeof( cmsStats.m_dwSelf ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4175. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSpecies, sizeof( cmsStats.m_dwSpecies ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4176. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwRespawn, sizeof( dwRespawn ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4177. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDecay, sizeof( dwDecay ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4178. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwChase, sizeof( dwChase ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4179. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwInfluence, sizeof( dwInfluence ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4180. // Monster Vitals
  4181. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHealth, sizeof( dwHealth ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4182. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwStamina, sizeof( dwStamina), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4183. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMana, sizeof( dwMana ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4184. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwExp_Value, sizeof( dwExp_Value ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4185. if ( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS )
  4186. {
  4187. cMonster* aMonster = new cMonster(cWorldManager::NewGUID_Object(), dwModelNumber, &locMonster, Name, Description, &cmsStats, dwRespawn, dwDecay, dwChase, dwInfluence, dwExp_Value, dwHealth, dwStamina, dwMana);
  4188. cWorldManager::AddObject( aMonster, TRUE );
  4189. }
  4190. }
  4191. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4192. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4193. }
  4194. }
  4195. /**
  4196. * Loads monster spawn points from the database.
  4197. *
  4198. * Author: G70mb2
  4199. */
  4200. void cMasterServer::LoadSpawns(WORD LB)
  4201. {
  4202. RETCODE retcode;
  4203. char szCommand[768];
  4204. char szMonsters[150];
  4205. char dwLandblock[9];
  4206. char dwPosX[9];
  4207. char dwPosY[9];
  4208. char dwPosZ[9];
  4209. char dwOrientW[9];
  4210. char dwOrientX[9];
  4211. char dwOrientY[9];
  4212. char dwOrientZ[9];
  4213. char Name[100];
  4214. char Description[255];
  4215. DWORD dwMonsterCount;
  4216. DWORD dwModelNumber;
  4217. cMonStats cmsStats;
  4218. DWORD dwRespawn;
  4219. DWORD dwDecay;
  4220. DWORD dwChase;
  4221. DWORD dwInfluence;
  4222. DWORD dwExp_Value;
  4223. DWORD dwHealth;
  4224. DWORD dwStamina;
  4225. DWORD dwMana;
  4226. cLocation spLoc;
  4227. char buffer [33];
  4228. itoa(LB,buffer,16);
  4229. sprintf( szCommand, "SELECT * FROM monsters WHERE landblock = %s;",buffer);
  4230. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4231. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4232. retcode = SQLBindCol( cDatabase::m_hStmt, 1, SQL_C_ULONG, &dwMonsterCount, sizeof( dwMonsterCount ), NULL ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4233. retcode = SQLFetch( cDatabase::m_hStmt );
  4234. if( retcode == SQL_NO_DATA )
  4235. dwMonsterCount = 0;
  4236. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  4237. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL )
  4238. sprintf( szMonsters, " Loading %d monsters ... \n Landblock: %s",dwMonsterCount,buffer );
  4239. UpdateConsole((char *)szMonsters);
  4240. for ( int iTmp = 1; iTmp < dwMonsterCount + 1; iTmp++ )
  4241. {
  4242. sprintf( szCommand, "SELECT ID, m.dwModelNumber,m.strName,m.strDescription,m.Landblock,m.Position_X,m.Position_Y,m.Position_Z,m.Orientation_W,m.Orientation_X,m.Orientation_Y,m.Orientation_Z,mt.dwlevel,mt.dwstr,mt.dwend,mt.dwquick,mt.dwcoord,mt.dwfocus,mt.dwself,mt.dwspecies,mt.dwrespawn,mt.decay,mt.chase,mt.influence,mt.Experience_Value,mt.dwHealth,mt.dwStamina,mt.dwMana FROM Monsters m LEFT OUTER JOIN monstertype mt on m.dwModelNumber = mt.dwModeldata WHERE ID=%d;", iTmp );
  4243. // sprintf( szCommand, "SELECT ID, m.dwModelNumber,m.strName,m.strDescription,m.Landblock,m.Position_X,m.Position_Y,m.Position_Z,m.Orientation_W,m.Orientation_X,m.Orientation_Y,m.Orientation_Z,mt.dwlevel,mt.dwstr,mt.dwend,mt.dwquick,mt.dwcoord,mt.dwfocus,mt.dwself,mt.dwspecies,mt.dwrespawn,mt.decay,mt.chase,mt.influence,mt.Experience_Value,mt.dwHealth,mt.dwStamina,mt.dwMana FROM Monsters m LEFT OUTER JOIN monstertype mt on m.dwModelNumber = mt.dwModeldata;" );
  4244. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4245. retcode = SQLExecute( cDatabase::m_hStmt );
  4246. int iCol = 2;
  4247. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4248. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4249. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4250. // Landblock Data
  4251. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwLandblock, sizeof( dwLandblock ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4252. /* retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flX, sizeof( &spLoc.m_flX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4253. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flY, sizeof( &spLoc.m_flY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4254. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flZ, sizeof( &spLoc.m_flZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4255. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flA, sizeof( &spLoc.m_flA ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4256. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flB, sizeof( &spLoc.m_flB ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4257. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flC, sizeof( &spLoc.m_flC ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4258. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_FLOAT, &spLoc.m_flW, sizeof( &spLoc.m_flW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4259. */ retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosX, sizeof( dwPosX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4260. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosY, sizeof( dwPosY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4261. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwPosZ, sizeof( dwPosZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4262. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientW, sizeof( dwOrientW ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4263. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientX, sizeof( dwOrientX ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4264. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientY, sizeof( dwOrientY ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4265. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, dwOrientZ, sizeof( dwOrientZ ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4266. // Monster Stats
  4267. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwLevel, sizeof( cmsStats.m_dwLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4268. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwStr, sizeof( cmsStats.m_dwStr ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4269. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwEnd, sizeof( cmsStats.m_dwEnd ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4270. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwQuick, sizeof( cmsStats.m_dwQuick ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4271. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwCoord, sizeof( cmsStats.m_dwCoord ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4272. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwFocus, sizeof( cmsStats.m_dwFocus ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4273. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSelf, sizeof( cmsStats.m_dwSelf ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4274. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSpecies, sizeof( cmsStats.m_dwSpecies ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4275. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwRespawn, sizeof( dwRespawn ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4276. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDecay, sizeof( dwDecay ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4277. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwChase, sizeof( dwChase ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4278. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwInfluence, sizeof( dwInfluence ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4279. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwExp_Value, sizeof( dwExp_Value ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4280. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHealth, sizeof( dwHealth ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4281. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwStamina, sizeof( dwStamina), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4282. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMana, sizeof( dwMana ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4283. if ( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS ) {
  4284. sscanf(dwLandblock,"%08x",&spLoc.m_dwLandBlock);
  4285. sscanf(dwPosX,"%08x",&spLoc.m_flX);
  4286. sscanf(dwPosY,"%08x",&spLoc.m_flY);
  4287. sscanf(dwPosZ,"%08x",&spLoc.m_flZ);
  4288. sscanf(dwOrientW,"%08x",&spLoc.m_flA);
  4289. sscanf(dwOrientX,"%08x",&spLoc.m_flB);
  4290. sscanf(dwOrientY,"%08x",&spLoc.m_flC);
  4291. sscanf(dwOrientZ,"%08x",&spLoc.m_flW);
  4292. cMasterServer::FixName(Name);
  4293. cMonster* aMonster = new cMonster(cWorldManager::NewGUID_Object(), dwModelNumber, &spLoc, Name, Description, &cmsStats, dwRespawn, dwDecay, dwChase, dwInfluence, dwExp_Value, dwHealth, dwStamina, dwMana);
  4294. cWorldManager::AddObject( aMonster, TRUE );
  4295. // UpdateConsole( "+" );
  4296. }
  4297. }
  4298. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4299. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4300. }
  4301. /**
  4302. * Spawns a monster from database by name.
  4303. *
  4304. * Note: Use ModelNumber to reference pre-loaded model data.
  4305. * This should become obsolete once spawn control is developed
  4306. * Spawn Generators will then be loaded instead of individual
  4307. * monsters, which will then spawn as needed.
  4308. *
  4309. * @param *szMonster - A pointer to the text representing the monster's name.
  4310. * @param pcLoc - A cLocation struct describing the avatar's present location.
  4311. * @param Respawn - A value describing whether the monster should be respawned (0 = No, 1 = Yes).
  4312. *
  4313. * Author: G70mb2
  4314. */
  4315. bool cMasterServer::SpawnMonster( char* szMonster,cLocation pcLoc,DWORD Respawn )
  4316. {
  4317. RETCODE retcode;
  4318. char szCommand[512];
  4319. char Name[100];
  4320. char Description[255];
  4321. cLocation locMonster;
  4322. DWORD dwModelNumber;
  4323. cMonStats cmsStats;
  4324. bool fSQLOK;
  4325. DWORD dwRespawn;
  4326. DWORD dwDecay;
  4327. DWORD dwChase;
  4328. DWORD dwInfluence;
  4329. DWORD dwExp_Value;
  4330. DWORD dwHealth;
  4331. DWORD dwStamina;
  4332. DWORD dwMana;
  4333. fSQLOK = false;
  4334. sprintf( szCommand, "SELECT * FROM monsters_type WHERE Name='%s';", szMonster );
  4335. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4336. retcode = SQLExecute( cDatabase::m_hStmt );
  4337. UpdateConsole (szMonster);
  4338. int iCol = 2;
  4339. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4340. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4341. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4342. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwLevel, sizeof( cmsStats.m_dwLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4343. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwStr, sizeof( cmsStats.m_dwStr ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4344. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwEnd, sizeof( cmsStats.m_dwEnd ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4345. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwQuick, sizeof( cmsStats.m_dwQuick ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4346. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwCoord, sizeof( cmsStats.m_dwCoord ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4347. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwFocus, sizeof( cmsStats.m_dwFocus ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4348. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSelf, sizeof( cmsStats.m_dwSelf ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4349. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSpecies, sizeof( cmsStats.m_dwSpecies ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4350. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwRespawn, sizeof( dwRespawn ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4351. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDecay, sizeof( dwDecay ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4352. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwChase, sizeof( dwChase ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4353. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwInfluence, sizeof( dwInfluence ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4354. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHealth, sizeof( dwHealth ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4355. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwStamina, sizeof( dwStamina), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4356. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMana, sizeof( dwMana ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4357. retcode = SQLBindCol( cDatabase::m_hStmt, iCol+6, SQL_C_ULONG, &dwExp_Value, sizeof( dwExp_Value ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4358. if( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS )
  4359. {
  4360. fSQLOK = true;
  4361. locMonster.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4362. locMonster.m_flA = pcLoc.m_flA;
  4363. locMonster.m_flB = pcLoc.m_flB;
  4364. locMonster.m_flC = pcLoc.m_flC;
  4365. locMonster.m_flW = pcLoc.m_flW;
  4366. locMonster.m_flX = pcLoc.m_flX;
  4367. locMonster.m_flY = pcLoc.m_flY;
  4368. locMonster.m_flZ = pcLoc.m_flZ;
  4369. if(Respawn == 0)
  4370. {
  4371. dwRespawn = 0;
  4372. }
  4373. cMasterServer::FixName(Name);
  4374. cMonster* aMonster = new cMonster(cWorldManager::NewGUID_Object(), dwModelNumber, &locMonster, Name, Description, &cmsStats, dwRespawn, dwDecay, dwChase, dwInfluence, dwExp_Value, dwHealth, dwStamina, dwMana);
  4375. cWorldManager::AddObject( aMonster , true );
  4376. }
  4377. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4378. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4379. return fSQLOK;
  4380. }
  4381. /**
  4382. * Spawn monster from the database by modelID only.
  4383. *
  4384. * @param *szMonster - A pointer to the text representing the monster's name.
  4385. * @param pcLoc - A cLocation struct describing the avatar's present location.
  4386. * @param dwModelNumber - The model number of the monster to be spawned.
  4387. * @param dwExp_Value - The experience value of the monster to be spawned.
  4388. * @param dwHealth - The Health of the monster to be spawned.
  4389. * @param dwStamina - The Stamina of the monster to be spawned.
  4390. * @param dwMana - The Mana of the monster to be spawned.
  4391. *
  4392. * Author: G70mb2
  4393. */
  4394. bool cMasterServer::SpawnType( char* szMonster, cLocation pcLoc, DWORD dwModelNumber, DWORD dwExp_Value, DWORD dwHealth, DWORD dwStamina, DWORD dwMana )
  4395. {
  4396. cLocation locMonster;
  4397. cMonStats cmsStats;
  4398. cmsStats.m_dwSpecies = 0x40L;
  4399. cmsStats.m_dwLevel = 10;
  4400. cmsStats.m_dwStr = 100;
  4401. cmsStats.m_dwEnd = 100;
  4402. cmsStats.m_dwCoord = 100;
  4403. cmsStats.m_dwQuick = 50;
  4404. cmsStats.m_dwFocus = 50;
  4405. cmsStats.m_dwSelf = 50;
  4406. dwExp_Value = 100;
  4407. dwHealth = 50;
  4408. dwStamina = 50;
  4409. dwMana = 25;
  4410. locMonster.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4411. locMonster.m_flA = pcLoc.m_flA;
  4412. locMonster.m_flB = pcLoc.m_flB;
  4413. locMonster.m_flC = pcLoc.m_flC;
  4414. locMonster.m_flW = pcLoc.m_flW;
  4415. locMonster.m_flX = pcLoc.m_flX;
  4416. locMonster.m_flY = pcLoc.m_flY;
  4417. locMonster.m_flZ = pcLoc.m_flZ;
  4418. cMonster* aMonster = new cMonster(cWorldManager::NewGUID_Object(), dwModelNumber, &locMonster, szMonster, "-", &cmsStats, 0, 120, 8, 2,dwExp_Value,dwHealth,dwStamina,dwMana);
  4419. cWorldManager::AddObject( aMonster , true );
  4420. return true;
  4421. }
  4422. /**
  4423. * Spawns a monster from the database and saves a copy into the auto-load database.
  4424. *
  4425. * @param *szMonster - A pointer to the text representing the monster's name.
  4426. * @param pcLoc - A cLocation struct describing the avatar's present location.
  4427. * @param bFacing - A boolean value for whether the monster should be facing the avatar.
  4428. * @param bOverride - A boolean value for whether the monster's default respawn, decay, and influence values should be overwriten.
  4429. * @param Decay -
  4430. * @param Chase -
  4431. * @param Influence -
  4432. *
  4433. * Author: G70mb2
  4434. */
  4435. bool cMasterServer::SpawnSave( char* szMonster, cLocation pcLoc, bool bFacing, bool bOverride, DWORD Respawn, DWORD Decay, DWORD Chase, DWORD Influence )
  4436. {
  4437. RETCODE retcode;
  4438. char szCommand[512];
  4439. char Name[100];
  4440. char Description[255];
  4441. cLocation locMonster;
  4442. DWORD dwModelNumber;
  4443. cMonStats cmsStats;
  4444. bool fSQLOK;
  4445. DWORD dwRespawn;
  4446. DWORD dwDecay;
  4447. DWORD dwChase;
  4448. DWORD dwInfluence;
  4449. DWORD dwExp_Value;
  4450. DWORD dwHealth;
  4451. DWORD dwStamina;
  4452. DWORD dwMana;
  4453. cMonster* aMonster;
  4454. fSQLOK = false;
  4455. sprintf( szCommand, "SELECT * FROM monsters_type WHERE Name='%s';", szMonster );
  4456. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)szCommand, SQL_NTS ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4457. retcode = SQLExecute( cDatabase::m_hStmt );
  4458. int iCol = 2;
  4459. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwModelNumber, sizeof( dwModelNumber ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4460. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Name, sizeof( Name ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4461. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_CHAR, Description, sizeof( Description ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4462. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwLevel, sizeof( cmsStats.m_dwLevel ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4463. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwStr, sizeof( cmsStats.m_dwStr ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4464. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwEnd, sizeof( cmsStats.m_dwEnd ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4465. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwQuick, sizeof( cmsStats.m_dwQuick ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4466. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwCoord, sizeof( cmsStats.m_dwCoord ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4467. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwFocus, sizeof( cmsStats.m_dwFocus ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4468. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSelf, sizeof( cmsStats.m_dwSelf ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4469. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &cmsStats.m_dwSpecies, sizeof( cmsStats.m_dwSpecies ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4470. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwRespawn, sizeof( dwRespawn ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4471. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwDecay, sizeof( dwDecay ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4472. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwChase, sizeof( dwChase ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4473. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwInfluence, sizeof( dwInfluence ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4474. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwExp_Value, sizeof( dwExp_Value ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4475. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwHealth, sizeof( dwHealth ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4476. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwStamina, sizeof( dwStamina), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4477. retcode = SQLBindCol( cDatabase::m_hStmt, iCol++, SQL_C_ULONG, &dwMana, sizeof( dwMana ), NULL ); CHECKRETURN(1, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4478. if( SQLFetch( cDatabase::m_hStmt ) == SQL_SUCCESS )
  4479. {
  4480. fSQLOK = true;
  4481. if(bFacing == true)
  4482. {
  4483. locMonster.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4484. locMonster.m_flA = pcLoc.m_flA;
  4485. locMonster.m_flB = pcLoc.m_flB;
  4486. locMonster.m_flC = pcLoc.m_flC;
  4487. locMonster.m_flW = pcLoc.m_flW;
  4488. locMonster.m_flX = pcLoc.m_flX;
  4489. locMonster.m_flY = pcLoc.m_flY;
  4490. locMonster.m_flZ = pcLoc.m_flZ;
  4491. }
  4492. else
  4493. {
  4494. locMonster.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4495. locMonster.m_flW = -pcLoc.m_flA;
  4496. locMonster.m_flB = pcLoc.m_flB;
  4497. locMonster.m_flC = pcLoc.m_flC;
  4498. locMonster.m_flA = pcLoc.m_flW;
  4499. locMonster.m_flX = pcLoc.m_flX;
  4500. locMonster.m_flY = pcLoc.m_flY;
  4501. locMonster.m_flZ = pcLoc.m_flZ;
  4502. }
  4503. if(bOverride == true)
  4504. {
  4505. dwRespawn = Respawn;
  4506. dwDecay = Decay;
  4507. dwChase = Chase;
  4508. dwInfluence = Influence;
  4509. }
  4510. cMasterServer::FixName(Name);
  4511. aMonster = new cMonster(cWorldManager::NewGUID_Object(), dwModelNumber, &locMonster, Name, Description, &cmsStats, dwRespawn, dwDecay, dwChase, dwInfluence, dwExp_Value, dwHealth, dwStamina, dwMana);
  4512. cWorldManager::AddObject( aMonster , true );
  4513. }
  4514. retcode = SQLCloseCursor( cDatabase::m_hStmt ); CHECKRETURN(0, SQL_HANDLE_STMT, cDatabase::m_hStmt, NULL)
  4515. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_UNBIND );
  4516. if (fSQLOK == true)
  4517. {
  4518. DWORD flX;
  4519. DWORD flY;
  4520. DWORD flZ;
  4521. DWORD flA;
  4522. DWORD flB;
  4523. DWORD flC;
  4524. DWORD flW;
  4525. // floating point to 32-bit hexadecimal
  4526. flX = cDatabase::Float2Hex(locMonster.m_flX);
  4527. flY = cDatabase::Float2Hex(locMonster.m_flY);
  4528. flZ = cDatabase::Float2Hex(locMonster.m_flZ);
  4529. flA = cDatabase::Float2Hex(locMonster.m_flA);
  4530. flB = cDatabase::Float2Hex(locMonster.m_flB);
  4531. flC = cDatabase::Float2Hex(locMonster.m_flC);
  4532. flW = cDatabase::Float2Hex(locMonster.m_flW);
  4533. BOOL fVerify = TRUE;
  4534. char Command[200];
  4535. sprintf( Command, "INSERT INTO Monsters (dwGUID, dwModelNumber, strName, strDescription, Landblock, Position_X,Position_Y,Position_Z,Orientation_W,Orientation_X,Orientation_Y,Orientation_Z) VALUES (%lu,%d,'%s', '%s','%08x','%08x','%08x','%08x','%08x','%08x','%08x','%08x');",aMonster->GetGUID(),aMonster->m_dwMonsterModelID,szMonster,Description,locMonster.m_dwLandBlock,flX,flY,flZ,flA,flB,flC,flW);
  4536. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)Command, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4537. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4538. if( retcode == SQL_ERROR )
  4539. fVerify = FALSE;
  4540. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_CLOSE ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4541. if(fVerify == false)
  4542. {
  4543. UpdateConsole( " <SQL> Monster creation failed!\r\n" );
  4544. fSQLOK = false;
  4545. }
  4546. else
  4547. {
  4548. UpdateConsole( " <SQL> Creating monster entry ...\r\n" );
  4549. fSQLOK = true;
  4550. }
  4551. }
  4552. else
  4553. {
  4554. fSQLOK = false;
  4555. }
  4556. return fSQLOK;
  4557. }
  4558. /**
  4559. * Spawns an NPC from the database and saves a copy into the auto-load database.
  4560. *
  4561. * @param *szNPC - A pointer to the text representing the NPC's name.
  4562. * @param pcLoc - A cLocation struct describing the avatar's present location.
  4563. * @param bFacing - A boolean value for whether the NPC should be facing the avatar.
  4564. *
  4565. * Author: G70mb2
  4566. */
  4567. /* Disabling this...
  4568. bool cMasterServer::NPC_Save( char* szNPC, cLocation pcLoc, bool bFacing )
  4569. {
  4570. RETCODE retcode;
  4571. bool fSQLOK;
  4572. fSQLOK = false;
  4573. cLocation locNPC;
  4574. if(bFacing == true)
  4575. {
  4576. locNPC.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4577. locNPC.m_flA = pcLoc.m_flA;
  4578. locNPC.m_flB = pcLoc.m_flB;
  4579. locNPC.m_flC = pcLoc.m_flC;
  4580. locNPC.m_flW = pcLoc.m_flW;
  4581. locNPC.m_flX = pcLoc.m_flX;
  4582. locNPC.m_flY = pcLoc.m_flY;
  4583. locNPC.m_flZ = pcLoc.m_flZ;
  4584. }
  4585. else
  4586. {
  4587. locNPC.m_dwLandBlock = pcLoc.m_dwLandBlock;
  4588. locNPC.m_flW = -pcLoc.m_flA;
  4589. locNPC.m_flB = pcLoc.m_flB;
  4590. locNPC.m_flC = pcLoc.m_flC;
  4591. locNPC.m_flA = pcLoc.m_flW;
  4592. locNPC.m_flX = pcLoc.m_flX;
  4593. locNPC.m_flY = pcLoc.m_flY;
  4594. locNPC.m_flZ = pcLoc.m_flZ;
  4595. }
  4596. cNPC* npc = new cNPC(szNPC, 0x1, &locNPC, 0);
  4597. npc->SetMode(NPCMODE_SINGLE); // Message Mode
  4598. npc->SetNumMessages(1); // Number of Messages
  4599. npc->SetModel(0); // Use Default NPC Model
  4600. // Store Blank Messages
  4601. npc->SetString("I can be Customized by Editing the NPCs table in the Database",0);
  4602. npc->SetString(" ",1);
  4603. npc->SetString(" ",2);
  4604. npc->SetString(" ",3);
  4605. npc->SetString(" ",4);
  4606. npc->SetString(" ",5);
  4607. npc->SetString(" ",6);
  4608. npc->SetString(" ",7);
  4609. npc->SetString(" ",8);
  4610. npc->SetString(" ",9);
  4611. cWorldManager::AddObject( npc , true );
  4612. BOOL fVerify = true;
  4613. char Command[300];
  4614. cMasterServer::FixName(szNPC);
  4615. sprintf( Command, "INSERT INTO NPCs (Name, Gender, wModelNum, Message_Type,Message_Count,Message_1,Landblock, fl_X,fl_Y,fl_Z,fl_Heading,Unknown_1,Unknown_2,Heading_2 ) VALUES ('%s','m',88,'SINGLE', 1, 'I can be Customized by Editing the NPCs table in the Database', %lu,%f,%f,%f,%f,%f,%f,%f);",cWorldManager::NewGUID_Object(),szNPC,locNPC.m_dwLandBlock,locNPC.m_flX,locNPC.m_flY,locNPC.m_flZ,locNPC.m_flA,locNPC.m_flB,locNPC.m_flC,locNPC.m_flW );
  4616. retcode = SQLPrepare( cDatabase::m_hStmt, (unsigned char *)Command, SQL_NTS ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4617. retcode = SQLExecute( cDatabase::m_hStmt ); CHECKRETURN( 1, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4618. if( retcode == SQL_ERROR )
  4619. {
  4620. fVerify = false;
  4621. }
  4622. if(fVerify == false)
  4623. {
  4624. UpdateConsole( " <SQL> Creating NPC failed!\r\n" );
  4625. fSQLOK = false;
  4626. }
  4627. else
  4628. {
  4629. UpdateConsole( " <SQL> NPC created.\r\n" );
  4630. fSQLOK = true;
  4631. }
  4632. retcode = SQLFreeStmt( cDatabase::m_hStmt, SQL_CLOSE ); CHECKRETURN( 0, SQL_HANDLE_STMT, cDatabase::m_hStmt, 1 )
  4633. return fSQLOK;
  4634. }
  4635. */