Changeset 149 for trunk

Show
Ignore:
Timestamp:
11/19/08 13:40:46 (17 years ago)
Author:
yumileroy
Message:

[svn] *Implement new player conditions CONDITION_NO_AURA, CONDITION_ACTIVE_EVENT
* Default behaviour of pets for creatures changed to REACT_DEFENSIVE
* Disallowed sending wrapped items as COD
* Prevent loading and saving single target auras for pet in same way as already implemented for player
* Correctly limit use some flask types to zones.
* Fixed extracting common.MPQ under *nix
* Many small xleanups and fixes.
** mangos merge rev.

TEST REV so be careful of creepy crawly bugs!

Original author: KingPin?
Date: 2008-11-02 16:53:46-06:00

Location:
trunk
Files:
30 modified

Legend:

Unmodified
Added
Removed
  • trunk/contrib/extractor/libmpq/mpq.cpp

    r2 r149  
    6060 
    6161        /* Check if file exists and is readable */ 
    62         fd = _open((char *)mpq_filename, O_RDONLY | O_BINARY); 
     62        fd = _open((char *)mpq_filename, O_RDONLY | O_BINARY | O_LARGEFILE); 
    6363        if (fd == LIBMPQ_EFILE) { 
    6464                return LIBMPQ_EFILE; 
  • trunk/src/bindings/scripts/ScriptMgr.cpp

    r109 r149  
    18391839//*** Functions used internally *** 
    18401840 
     1841//Trinity_DLL_EXPORT 
     1842//char const* ScriptsVersion() 
     1843//{ 
     1844//      return "Default Trinity scripting library"; 
     1845//} 
     1846 
    18411847Script* GetScriptByName(std::string Name) 
    18421848{ 
  • trunk/src/bindings/scripts/ScriptMgr.h

    r109 r149  
    7878  #define TRINITY_DLL_EXPORT extern "C" __declspec(dllexport) 
    7979#elif defined( __GNUC__ ) 
    80   #define TRINITY_DLL_EXPORT extern "C" 
     80#define TRINITY_DLL_EXPORT extern "C" 
    8181#else 
    82   #define TRINITY_DLL_EXPORT extern "C" export 
     82#define TRINITY_DLL_EXPORT extern "C" export 
    8383#endif 
    8484 
  • trunk/src/game/CharacterHandler.cpp

    r102 r149  
    380380    SendPacket( &data ); 
    381381 
    382     std::string IP_str = GetRemoteAddress().c_str(); 
     382    std::string IP_str = GetRemoteAddress(); 
    383383    sLog.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); 
    384384    sLog.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); 
  • trunk/src/game/Chat.cpp

    r134 r149  
    7070                { "idlerestart",    SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleIdleRestartCommand,         "", NULL }, 
    7171                { "idleshutdown",   SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleIdleShutDownCommand,        "", NULL }, 
    72                 { "info",           SEC_PLAYER,         true,  &ChatHandler::HandleInfoCommand,                "", NULL }, 
     72                { "info",           SEC_PLAYER,         true,  &ChatHandler::HandleServerInfoCommand,          "", NULL }, 
    7373                { "motd",           SEC_PLAYER,         true,  &ChatHandler::HandleServerMotdCommand,          "", NULL }, 
    7474                { "restart",        SEC_ADMINISTRATOR,  true,  &ChatHandler::HandleRestartCommand,             "", NULL }, 
  • trunk/src/game/Chat.h

    r132 r149  
    100100        bool HandleCommandsCommand(const char* args); 
    101101        bool HandleStartCommand(const char* args); 
    102         bool HandleInfoCommand(const char* args); 
    103102        bool HandleDismountCommand(const char* args); 
    104103        bool HandleSaveCommand(const char* args); 
     
    230229                bool HandleServerCorpsesCommand(const char* args); 
    231230                bool HandleServerExitCommand(const char* args); 
     231                bool HandleServerInfoCommand(const char* args); 
    232232                bool HandleServerMotdCommand(const char* args); 
    233233                bool HandleServerSetMotdCommand(const char* args); 
  • trunk/src/game/Language.h

    r132 r149  
    8383        LANG_PASSWORD_TOO_LONG              = 55, 
    8484        LANG_MOTD_CURRENT                   = 56, 
    85         // Room for more level 0              57-99 not used 
     85        LANG_USING_WORLD_DB                 = 57, 
     86        LANG_USING_SCRIPT_LIB               = 58, 
     87        // Room for more level 0              59-99 not used 
    8688 
    8789    // level 1 chat 
  • trunk/src/game/Level0.cpp

    r112 r149  
    8787} 
    8888 
    89 bool ChatHandler::HandleInfoCommand(const char* /*args*/) 
     89bool ChatHandler::HandleServerInfoCommand(const char* /*args*/) 
    9090{ 
    9191    uint32 activeClientsNum = sWorld.GetActiveSessionCount(); 
     
    9595    std::string str = secsToTimeString(sWorld.GetUptime()); 
    9696 
    97     PSendSysMessage(_FULLVERSION); 
     97    PSendSysMessage(_FULLVERSION); //char const* full; 
     98    //if(m_session) 
     99    //    full = _FULLVERSION(REVISION_DATE,REVISION_TIME,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r"); 
     100    //else 
     101    //    full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_ID); 
     102 
     103    //SendSysMessage(full); 
     104    //PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion()); 
     105    //PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion()); 
    98106    PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum); 
    99107    PSendSysMessage(LANG_UPTIME, str.c_str()); 
  • trunk/src/game/Level2.cpp

    r132 r149  
    19551955    if(num > 0) 
    19561956    { 
    1957         QueryResult *result = CharacterDatabase.PQuery("SELECT guid,ticket_text,ticket_lastchange FROM character_ticket ORDER BY ticket_id ASC LIMIT %d,1",num-1); 
     1957        QueryResult *result = CharacterDatabase.PQuery("SELECT guid,ticket_text,ticket_lastchange FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_, num-1); 
    19581958 
    19591959        if(!result) 
     
    20672067    if(num > 0) 
    20682068    { 
    2069         QueryResult *result = CharacterDatabase.PQuery("SELECT ticket_id,guid FROM character_ticket LIMIT %i",num); 
    2070  
    2071         if(!result || uint64(num) > result->GetRowCount()) 
     2069        QueryResult *result = CharacterDatabase.PQuery("SELECT ticket_id,guid FROM character_ticket ORDER BY ticket_id ASC "_OFFSET_,num-1); 
     2070 
     2071        if(!result) 
    20722072        { 
    20732073            PSendSysMessage(LANG_COMMAND_TICKENOTEXIST, num); 
     
    20762076            return false; 
    20772077        } 
    2078  
    2079         for(int i = 1; i < num; ++i) 
    2080             result->NextRow(); 
    20812078 
    20822079        Field* fields = result->Fetch(); 
  • trunk/src/game/Level3.cpp

    r132 r149  
    55435543                        return false; 
    55445544                case DUMP_TOO_MANY_CHARS: 
    5545                         PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name,account_id); 
     5545                        PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id); 
    55465546                        SetSentErrorMessage(true); 
    55475547                        return false; 
  • trunk/src/game/Mail.cpp

    r102 r149  
    188188                return; 
    189189            } 
     190 
    190191            if (mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || mailItem.item->GetUInt32Value(ITEM_FIELD_DURATION)) 
    191192            { 
     
    193194                return; 
    194195            } 
     196 
     197                        if(COD && mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_WRAPPED)) 
     198                        { 
     199                                pl->SendMailResult(0, 0, MAIL_ERR_CANT_SEND_WRAPPED_COD); 
     200                                return; 
     201                        } 
    195202        } 
    196203    } 
  • trunk/src/game/Map.cpp

    r141 r149  
    579579    } 
    580580} 
    581  
    582 void InstanceMap::Update(const uint32& t_diff) 
    583 { 
    584     Map::Update(t_diff); 
    585  
    586     if(i_data) 
    587         i_data->Update(t_diff); 
    588 } 
    589  
    590581 
    591582void Map::Remove(Player *player, bool remove) 
     
    15581549} 
    15591550 
     1551void InstanceMap::Update(const uint32& t_diff) 
     1552{ 
     1553        Map::Update(t_diff); 
     1554 
     1555        if(i_data) 
     1556                i_data->Update(t_diff); 
     1557} 
     1558 
    15601559void InstanceMap::Remove(Player *player, bool remove) 
    15611560{ 
  • trunk/src/game/ObjectMgr.cpp

    r144 r149  
    65706570            return false; 
    65716571        } 
     6572                case CONDITION_NO_AURA: 
     6573                        return !player->HasAura(value1, value2); 
     6574                case CONDITION_ACTIVE_EVENT: 
     6575                        return gameeventmgr.IsActiveEvent(value1); 
    65726576        default: 
    65736577            return false; 
     
    66906694            break; 
    66916695        } 
     6696                case CONDITION_NO_AURA: 
     6697                { 
     6698                        if(!sSpellStore.LookupEntry(value1)) 
     6699                        { 
     6700                                sLog.outErrorDb("Aura condition requires to have non existing spell (Id: %d), skipped", value1); 
     6701                                return false; 
     6702                        } 
     6703                        if(value2 > 2) 
     6704                        { 
     6705                                sLog.outErrorDb("Aura condition requires to have non existing effect index (%u) (must be 0..2), skipped", value2); 
     6706                                return false; 
     6707                        } 
     6708                        break; 
     6709                } 
     6710                case CONDITION_ACTIVE_EVENT: 
     6711                { 
     6712                        GameEvent::GameEventDataMap const& events = gameeventmgr.GetEventMap(); 
     6713                        if(value1 >=events.size() || !events[value1].isValid()) 
     6714                        { 
     6715                                sLog.outErrorDb("Active event condition requires existed event id (%u), skipped", value1); 
     6716                                return false; 
     6717                        } 
     6718                        break; 
     6719                } 
    66926720    } 
    66936721    return true; 
  • trunk/src/game/ObjectMgr.h

    r112 r149  
    206206    CONDITION_QUESTTAKEN            = 9,                    // quest_id     0,      for condition true while quest active. 
    207207    CONDITION_AD_COMMISSION_AURA    = 10,                   // 0            0,      for condition true while one from AD ñommission aura active 
    208 }; 
    209  
    210 #define MAX_CONDITION                 11                    // maximum value in ConditionType enum 
     208        CONDITION_NO_AURA               = 11,                   // spell_id     effindex 
     209        CONDITION_ACTIVE_EVENT          = 12,                   // event_id 
     210}; 
     211 
     212#define MAX_CONDITION                 13                    // maximum value in ConditionType enum 
    211213 
    212214//Player's info 
     
    771773        bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true); 
    772774        bool IsVendorItemValid( uint32 vendor_entry, uint32 item, uint32 maxcount, uint32 ptime, uint32 ExtendedCost, Player* pl = NULL, std::set<uint32>* skip_vendors = NULL, uint32 ORnpcflag = 0) const; 
     775 
    773776    protected: 
    774777        uint32 m_auctionid; 
  • trunk/src/game/Pet.cpp

    r120 r149  
    13671367                remaincharges = -1; 
    13681368 
     1369                        /// do not load single target auras (unless they were cast by the player) 
     1370                        if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) 
     1371                                continue; 
     1372 
    13691373            Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); 
    13701374 
     
    13961400                break; 
    13971401 
    1398         if (i == 3 && !itr->second->IsPassive()) 
    1399             CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " 
    1400                 "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", 
    1401                 m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); 
     1402        if (i != 3) 
     1403                        continue; 
     1404 
     1405                if(itr->second->IsPassive()) 
     1406                        continue; 
     1407 
     1408                /// do not save single target auras (unless they were cast by the player) 
     1409                if (itr->second->GetCasterGUID() != GetGUID() && IsSingleTargetSpell(spellInfo)) 
     1410                        continue; 
     1411 
     1412                CharacterDatabase.PExecute("INSERT INTO pet_aura (guid,caster_guid,spell,effect_index,amount,maxduration,remaintime,remaincharges) " 
     1413                        "VALUES ('%u', '" I64FMTD "', '%u', '%u', '%d', '%d', '%d', '%d')", 
     1414                        m_charmInfo->GetPetNumber(), itr->second->GetCasterGUID(),(uint32)(*itr).second->GetId(), (uint32)(*itr).second->GetEffIndex(),(*itr).second->GetModifier()->m_amount,int((*itr).second->GetAuraMaxDuration()),int((*itr).second->GetAuraDuration()),int((*itr).second->m_procCharges)); 
    14021415    } 
    14031416} 
  • trunk/src/game/Player.cpp

    r142 r149  
    32583258    updateVisualBits.SetCount(PLAYER_END); 
    32593259 
     3260        // TODO: really implement OWNER_ONLY and GROUP_ONLY. Flags can be found in UpdateFields.h 
     3261 
    32603262    updateVisualBits.SetBit(OBJECT_FIELD_GUID); 
    32613263    updateVisualBits.SetBit(OBJECT_FIELD_TYPE); 
     
    32693271 
    32703272    updateVisualBits.SetBit(UNIT_FIELD_CHARMEDBY); 
     3273        updateVisualBits.SetBit(UNIT_FIELD_CHARMEDBY+1); 
    32713274 
    32723275    updateVisualBits.SetBit(UNIT_FIELD_TARGET); 
     
    33003303    updateVisualBits.SetBit(UNIT_FIELD_BASEATTACKTIME); 
    33013304    updateVisualBits.SetBit(UNIT_FIELD_BASEATTACKTIME + 1); 
    3302     updateVisualBits.SetBit(UNIT_FIELD_RANGEDATTACKTIME); 
    33033305    updateVisualBits.SetBit(UNIT_FIELD_BOUNDINGRADIUS); 
    33043306    updateVisualBits.SetBit(UNIT_FIELD_COMBATREACH); 
    33053307    updateVisualBits.SetBit(UNIT_FIELD_DISPLAYID); 
    33063308    updateVisualBits.SetBit(UNIT_FIELD_NATIVEDISPLAYID); 
    3307     updateVisualBits.SetBit(UNIT_FIELD_MOUNTDISPLAYID); 
    33083309    updateVisualBits.SetBit(UNIT_FIELD_BYTES_1); 
    33093310    updateVisualBits.SetBit(UNIT_FIELD_MOUNTDISPLAYID); 
     
    33153316    updateVisualBits.SetBit(UNIT_FIELD_BYTES_2); 
    33163317 
     3318        updateVisualBits.SetBit(PLAYER_DUEL_ARBITER); 
     3319        updateVisualBits.SetBit(PLAYER_DUEL_ARBITER+1); 
    33173320    updateVisualBits.SetBit(PLAYER_FLAGS); 
     3321        updateVisualBits.SetBit(PLAYER_GUILDID); 
     3322        updateVisualBits.SetBit(PLAYER_GUILDRANK); 
    33183323    updateVisualBits.SetBit(PLAYER_BYTES); 
    33193324    updateVisualBits.SetBit(PLAYER_BYTES_2); 
    33203325    updateVisualBits.SetBit(PLAYER_BYTES_3); 
    3321     updateVisualBits.SetBit(PLAYER_GUILDID); 
    3322     updateVisualBits.SetBit(PLAYER_GUILDRANK); 
     3326    updateVisualBits.SetBit(PLAYER_DUEL_TEAM); 
    33233327    updateVisualBits.SetBit(PLAYER_GUILD_TIMESTAMP); 
    3324     updateVisualBits.SetBit(PLAYER_DUEL_TEAM); 
    3325     updateVisualBits.SetBit(PLAYER_DUEL_ARBITER); 
    3326     updateVisualBits.SetBit(PLAYER_DUEL_ARBITER+1); 
    33273328 
    33283329    // PLAYER_QUEST_LOG_x also visible bit on official (but only on party/raid)... 
     
    33533354 
    33543355    updateVisualBits.SetBit(PLAYER_CHOSEN_TITLE); 
    3355  
    3356     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY); 
    3357     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY + 1); 
    3358     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY + 2); 
    3359     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO); 
    3360     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO + 1); 
    3361     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO + 2); 
    3362     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO + 3); 
    3363     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO + 4); 
    3364     updateVisualBits.SetBit(UNIT_VIRTUAL_ITEM_INFO + 5); 
    33653356} 
    33663357 
  • trunk/src/game/ScriptCalls.cpp

    r102 r149  
    2525#include "Platform/Define.h" 
    2626#include "ScriptCalls.h" 
     27#include "World.h" 
    2728 
    2829ScriptsSet Script=NULL; 
     
    5859    if(   !(testScript->ScriptsInit         =(scriptCallScriptsInit         )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit"         )) 
    5960        ||!(testScript->ScriptsFree         =(scriptCallScriptsFree         )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree"         )) 
     61                ||!(testScript->ScriptsVersion      =(scriptCallScriptsVersion      )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion"      )) 
    6062        ||!(testScript->GossipHello         =(scriptCallGossipHello         )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello"         )) 
    6163        ||!(testScript->GOChooseReward      =(scriptCallGOChooseReward      )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward"      )) 
     
    9496    Script->ScriptsInit(); 
    9597 
     98        sWorld.SetScriptsVersion(Script->ScriptsVersion()); 
     99 
    96100    return true; 
    97101} 
  • trunk/src/game/ScriptCalls.h

    r102 r149  
    4040typedef void(TRINITY_IMPORT * scriptCallScriptsInit) (); 
    4141typedef void(TRINITY_IMPORT * scriptCallScriptsFree) (); 
     42typedef char const* (TRINITY_IMPORT * scriptCallScriptsVersion) (); 
    4243 
    4344typedef bool(TRINITY_IMPORT * scriptCallGossipHello) (Player *player, Creature *_Creature ); 
     
    6566    scriptCallScriptsInit ScriptsInit; 
    6667    scriptCallScriptsFree ScriptsFree; 
     68        scriptCallScriptsVersion ScriptsVersion; 
    6769 
    6870    scriptCallGossipHello GossipHello; 
  • trunk/src/game/SpellEffects.cpp

    r145 r149  
    40744074 
    40754075    uint32 faction = m_caster->getFaction(); 
    4076     if(m_caster->GetTypeId() == TYPEID_UNIT && ((Creature*)m_caster)->isTotem()) 
    4077     { 
    4078         Unit* owner = ((Totem*)m_caster)->GetOwner(); 
    4079         if(owner) 
    4080             faction = owner->getFaction(); 
    4081         NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE); 
     4076    if(m_caster->GetTypeId() == TYPEID_UNIT) 
     4077    { 
     4078                if ( ((Creature*)m_caster)->isTotem() ) 
     4079                        NewSummon->GetCharmInfo()->SetReactState(REACT_AGGRESSIVE); 
     4080                else 
     4081                        NewSummon->GetCharmInfo()->SetReactState(REACT_DEFENSIVE); 
    40824082    } 
    40834083 
  • trunk/src/game/SpellMgr.cpp

    r131 r149  
    21932193                return zone_id ==3522 || map_id==565; 
    21942194            } 
    2195             if(mask & ELIXIR_UNSTABLE_MASK) 
     2195            if(mask & ELIXIR_SHATTRATH_MASK) 
    21962196            { 
    21972197                // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple 
  • trunk/src/game/Unit.cpp

    r143 r149  
    64856485        case 836:                                           // Improved Blizzard (Rank 1) 
    64866486        { 
    6487             if( !procSpell || procSpell->SpellVisual!=9487 ) 
     6487            if( !procSpell || procSpell->SpellVisual!=9487) 
    64886488                return false; 
    64896489            triggered_spell_id = 12484; 
     
    64926492        case 988:                                           // Improved Blizzard (Rank 2) 
    64936493        { 
    6494             if( !procSpell || procSpell->SpellVisual!=9487 ) 
     6494            if( !procSpell || procSpell->SpellVisual!=9487) 
    64956495                return false; 
    64966496            triggered_spell_id = 12485; 
     
    64996499        case 989:                                           // Improved Blizzard (Rank 3) 
    65006500        { 
    6501             if( !procSpell || procSpell->SpellVisual!=9487 ) 
     6501            if( !procSpell || procSpell->SpellVisual!=9487) 
    65026502                return false; 
    65036503            triggered_spell_id = 12486; 
     
    98719871 
    98729872CharmInfo::CharmInfo(Unit* unit) 
    9873 : m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_ReactSate(REACT_PASSIVE), m_petnumber(0) 
     9873: m_unit(unit), m_CommandState(COMMAND_FOLLOW), m_reactState(REACT_PASSIVE), m_petnumber(0) 
    98749874{ 
    98759875    for(int i =0; i<4; ++i) 
  • trunk/src/game/Unit.h

    r143 r149  
    647647        CommandStates GetCommandState() { return m_CommandState; } 
    648648        bool HasCommandState(CommandStates state) { return (m_CommandState == state); } 
    649         void SetReactState(ReactStates st) { m_ReactSate = st; } 
    650         ReactStates GetReactState() { return m_ReactSate; } 
    651         bool HasReactState(ReactStates state) { return (m_ReactSate == state); } 
     649        void SetReactState(ReactStates st) { m_reactState = st; } 
     650                ReactStates GetReactState() { return m_reactState; } 
     651                bool HasReactState(ReactStates state) { return (m_reactState == state); } 
    652652 
    653653        void InitPossessCreateSpells(); 
     
    666666        CharmSpellEntry m_charmspells[4]; 
    667667        CommandStates   m_CommandState; 
    668         ReactStates     m_ReactSate; 
     668        ReactStates     m_reactState; 
    669669        uint32          m_petnumber; 
    670670}; 
  • trunk/src/game/World.cpp

    r138 r149  
    26132613    m_maxQueuedSessionCount = std::max(m_maxQueuedSessionCount,uint32(m_QueuedPlayer.size())); 
    26142614} 
     2615 
     2616void World::LoadDBVersion() 
     2617{ 
     2618        QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1"); 
     2619        if(result) 
     2620        { 
     2621                Field* fields = result->Fetch(); 
     2622 
     2623                m_DBVersion = fields[0].GetString(); 
     2624                delete result; 
     2625        } 
     2626        else 
     2627                m_DBVersion = "unknown world database"; 
     2628} 
  • trunk/src/game/World.h

    r112 r149  
    481481 
    482482        LocaleConstant GetAvailableDbcLocale(LocaleConstant locale) const { if(m_availableDbcLocaleMask & (1 << locale)) return locale; else return m_defaultDbcLocale; } 
     483 
     484                //used World DB version 
     485                void LoadDBVersion(); 
     486                char const* GetDBVersion() { return m_DBVersion.c_str(); } 
     487 
     488                //used Script version 
     489                void SetScriptsVersion(char const* version) { m_ScriptsVersion = version ? version : "unknown scripting library"; } 
     490                char const* GetScriptsVersion() { return m_ScriptsVersion.c_str(); } 
     491 
    483492    protected: 
    484493        void _UpdateGameTime(); 
     
    541550        void AddSession_(WorldSession* s); 
    542551        ZThread::LockedQueue<WorldSession*, ZThread::FastMutex> addSessQueue; 
     552 
     553                //used versions 
     554                std::string m_DBVersion; 
     555                std::string m_ScriptsVersion; 
    543556}; 
    544557 
  • trunk/src/game/WorldSession.cpp

    r128 r149  
    5252{ 
    5353   if (sock) 
    54      { 
    55        m_Address = sock->GetRemoteAddress (); 
    56        sock->AddReference (); 
    57      } 
     54   { 
     55           m_Address = sock->GetRemoteAddress (); 
     56           sock->AddReference (); 
     57   } 
    5858} 
    5959 
     
    100100    if (!m_Socket) 
    101101        return; 
     102 
    102103    #ifdef TRINITY_DEBUG 
     104 
    103105    // Code for network use statistic 
    104106    static uint64 sendPacketCount = 0; 
     
    132134        sendLastPacketBytes = packet->wpos();               // wpos is real written size 
    133135    } 
    134 #endif                                                  // !TRINITY_DEBUG 
    135  
    136   if (m_Socket->SendPacket (*packet) == -1) 
    137     { 
    138       m_Socket->CloseSocket (); 
    139     } 
     136 
     137        #endif                                                  // !TRINITY_DEBUG 
     138 
     139        if (m_Socket->SendPacket (*packet) == -1) 
     140                m_Socket->CloseSocket (); 
    140141} 
    141142 
     
    158159bool WorldSession::Update(uint32 /*diff*/) 
    159160{ 
    160   if (m_Socket) 
    161     if (m_Socket->IsClosed ()) 
    162       {  
     161  if (m_Socket && m_Socket->IsClosed ()) 
     162  { 
    163163        m_Socket->RemoveReference (); 
    164164        m_Socket = NULL; 
    165       } 
     165  } 
    166166   
    167167    WorldPacket *packet; 
     
    396396        ///- Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline 
    397397        //No SQL injection as AccountId is uint32 
    398         CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'", GetAccountId()); 
     398        CharacterDatabase.PExecute("UPDATE characters SET online = 0 WHERE account = '%u'", 
     399                        GetAccountId()); 
    399400        sLog.outDebug( "SESSION: Sent SMSG_LOGOUT_COMPLETE Message" ); 
    400401    } 
     
    408409void WorldSession::KickPlayer() 
    409410{ 
    410   if (m_Socket) 
    411     { 
    412       m_Socket->CloseSocket (); 
    413     } 
     411        if (m_Socket) 
     412                m_Socket->CloseSocket (); 
    414413} 
    415414 
  • trunk/src/game/WorldSocket.cpp

    r102 r149  
    1919 */ 
    2020 
    21 #include "Common.h" 
    22 #include "WorldSocket.h"  
    23  
    2421#include <ace/Message_Block.h> 
    2522#include <ace/OS_NS_string.h> 
     
    3229#include <ace/Reactor.h> 
    3330#include <ace/Auto_Ptr.h> 
     31 
     32#include "WorldSocket.h" 
     33#include "Common.h" 
    3434 
    3535#include "Util.h" 
  • trunk/src/game/WorldSocketMgr.cpp

    r102 r149  
    11/* 
    2  * Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> 
    3  * 
    4  * Copyright (C) 2008 Trinity <http://www.trinitycore.org/> 
    5  * 
    6  * This program is free software; you can redistribute it and/or modify 
    7  * it under the terms of the GNU General Public License as published by 
    8  * the Free Software Foundation; either version 2 of the License, or 
    9  * (at your option) any later version. 
    10  * 
    11  * This program is distributed in the hope that it will be useful, 
    12  * but WITHOUT ANY WARRANTY; without even the implied warranty of 
    13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
    14  * GNU General Public License for more details. 
    15  * 
    16  * You should have received a copy of the GNU General Public License 
    17  * along with this program; if not, write to the Free Software 
    18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
    19  */ 
     2* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/> 
     3* 
     4* Copyright (C) 2008 Trinity <http://www.trinitycore.org/> 
     5* 
     6* This program is free software; you can redistribute it and/or modify 
     7* it under the terms of the GNU General Public License as published by 
     8* the Free Software Foundation; either version 2 of the License, or 
     9* (at your option) any later version. 
     10* 
     11* This program is distributed in the hope that it will be useful, 
     12* but WITHOUT ANY WARRANTY; without even the implied warranty of 
     13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 
     14* GNU General Public License for more details. 
     15* 
     16* You should have received a copy of the GNU General Public License 
     17* along with this program; if not, write to the Free Software 
     18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
     19*/ 
    2020 
    2121/** \file WorldSocketMgr.cpp 
    22  *  \ingroup u2w 
    23  *  \author Derex <derex101@gmail.com> 
    24  */ 
     22*  \ingroup u2w 
     23*  \author Derex <derex101@gmail.com> 
     24*/ 
    2525 
    2626#include "WorldSocketMgr.h" 
     
    4848 
    4949/**  
    50  * This is a helper class to WorldSocketMgr ,that manages  
    51  * network threads, and assigning connections from acceptor thread 
    52  * to other network threads 
    53  */ 
     50* This is a helper class to WorldSocketMgr ,that manages  
     51* network threads, and assigning connections from acceptor thread 
     52* to other network threads 
     53*/ 
    5454class ReactorRunnable : protected ACE_Task_Base 
    5555{ 
    5656public: 
    5757 
    58   ReactorRunnable () : 
    59   m_ThreadId (-1), 
    60   m_Connections (0), 
    61   m_Reactor (0) 
    62   { 
    63     ACE_Reactor_Impl* imp = 0; 
     58        ReactorRunnable () : 
     59          m_ThreadId (-1), 
     60                  m_Connections (0), 
     61                  m_Reactor (0) 
     62          { 
     63                  ACE_Reactor_Impl* imp = 0; 
    6464 
    6565#if defined (ACE_HAS_EVENT_POLL) || defined (ACE_HAS_DEV_POLL) 
    66     imp = new ACE_Dev_Poll_Reactor (); 
    67  
    68     imp->max_notify_iterations (128); 
    69     imp->restart (1); 
     66 
     67                  imp = new ACE_Dev_Poll_Reactor (); 
     68 
     69                  imp->max_notify_iterations (128); 
     70                  imp->restart (1); 
     71 
    7072#else 
    71     imp = new ACE_TP_Reactor (); 
    72     imp->max_notify_iterations (128); 
     73 
     74                  imp = new ACE_TP_Reactor (); 
     75                  imp->max_notify_iterations (128); 
     76 
    7377#endif 
    7478 
    75     m_Reactor = new ACE_Reactor (imp, 1); 
    76   } 
    77  
    78   virtual 
    79   ~ReactorRunnable () 
    80   { 
    81     this->Stop (); 
    82     this->Wait (); 
    83  
    84     if (m_Reactor) 
    85       delete m_Reactor; 
    86   } 
    87  
    88   void 
    89   Stop () 
    90   { 
    91     m_Reactor->end_reactor_event_loop (); 
    92   } 
    93  
    94   int 
    95   Start () 
    96   { 
    97     if (m_ThreadId != -1) 
    98       return -1; 
    99  
    100     return (m_ThreadId = this->activate ()); 
    101   } 
    102  
    103   void 
    104   Wait () 
    105   { 
    106     ACE_Task_Base::wait (); 
    107   } 
    108  
    109   long 
    110   Connections () 
    111   { 
    112     return static_cast<long> (m_Connections.value ()); 
    113   } 
    114  
    115   int 
    116   AddSocket (WorldSocket* sock) 
    117   { 
    118     ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1); 
    119  
    120     ++m_Connections; 
    121     sock->AddReference(); 
    122     sock->reactor (m_Reactor); 
    123     m_NewSockets.insert (sock); 
    124  
    125     return 0; 
    126   } 
    127    
    128   ACE_Reactor* GetReactor () 
    129   { 
    130     return m_Reactor; 
    131   } 
    132    
     79                  m_Reactor = new ACE_Reactor (imp, 1); 
     80          } 
     81 
     82          virtual ~ReactorRunnable () 
     83          { 
     84                  this->Stop (); 
     85                  this->Wait (); 
     86 
     87                  if (m_Reactor) 
     88                          delete m_Reactor; 
     89          } 
     90 
     91          void Stop () 
     92          { 
     93                  m_Reactor->end_reactor_event_loop (); 
     94          } 
     95 
     96          int Start () 
     97          { 
     98                  if (m_ThreadId != -1) 
     99                          return -1; 
     100 
     101                  return (m_ThreadId = this->activate ()); 
     102          } 
     103 
     104          void Wait () 
     105          { 
     106                  ACE_Task_Base::wait (); 
     107          } 
     108 
     109          long Connections () 
     110          { 
     111                  return static_cast<long> (m_Connections.value ()); 
     112          } 
     113 
     114          int AddSocket (WorldSocket* sock) 
     115          { 
     116                  ACE_GUARD_RETURN (ACE_Thread_Mutex, Guard, m_NewSockets_Lock, -1); 
     117 
     118                  ++m_Connections; 
     119                  sock->AddReference(); 
     120                  sock->reactor (m_Reactor); 
     121                  m_NewSockets.insert (sock); 
     122 
     123                  return 0; 
     124          } 
     125 
     126          ACE_Reactor* GetReactor () 
     127          { 
     128                  return m_Reactor; 
     129          } 
     130 
    133131protected: 
    134    
    135   void 
    136   AddNewSockets () 
    137   { 
    138     ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock); 
    139  
    140     if (m_NewSockets.empty ()) 
    141       return; 
    142  
    143     for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i) 
    144       { 
    145         WorldSocket* sock = (*i); 
    146  
    147         if (sock->IsClosed ()) 
    148           { 
    149             sock->RemoveReference (); 
    150             --m_Connections; 
    151           } 
    152         else 
    153           m_Sockets.insert (sock); 
    154       } 
    155  
    156     m_NewSockets.clear (); 
    157   } 
    158  
    159   virtual int 
    160   svc (void) 
    161   { 
    162     DEBUG_LOG ("Network Thread Starting"); 
    163  
    164     WorldDatabase.ThreadStart (); 
    165  
    166     ACE_ASSERT (m_Reactor); 
    167  
    168     SocketSet::iterator i, t; 
    169  
    170     while (!m_Reactor->reactor_event_loop_done ()) 
    171       { 
    172         // dont be too smart to move this outside the loop  
    173         // the run_reactor_event_loop will modify interval 
    174         ACE_Time_Value interval (0, 10000); 
    175  
    176         if (m_Reactor->run_reactor_event_loop (interval) == -1) 
    177           break; 
    178  
    179         AddNewSockets (); 
    180  
    181         for (i = m_Sockets.begin (); i != m_Sockets.end ();) 
    182           { 
    183             if ((*i)->Update () == -1) 
    184               { 
    185                 t = i; 
    186                 i++; 
    187                 (*t)->CloseSocket (); 
    188                 (*t)->RemoveReference (); 
    189                 --m_Connections; 
    190                 m_Sockets.erase (t); 
    191               } 
    192             else 
    193               i++; 
    194           } 
    195       } 
    196  
    197     WorldDatabase.ThreadEnd (); 
    198  
    199     DEBUG_LOG ("Network Thread Exitting"); 
    200  
    201     return 0; 
    202   } 
     132 
     133        void AddNewSockets () 
     134        { 
     135                ACE_GUARD (ACE_Thread_Mutex, Guard, m_NewSockets_Lock); 
     136 
     137                if (m_NewSockets.empty ()) 
     138                        return; 
     139 
     140                for (SocketSet::iterator i = m_NewSockets.begin (); i != m_NewSockets.end (); ++i) 
     141                { 
     142                        WorldSocket* sock = (*i); 
     143 
     144                        if (sock->IsClosed ()) 
     145                        { 
     146                                sock->RemoveReference (); 
     147                                --m_Connections; 
     148                        } 
     149                        else 
     150                                m_Sockets.insert (sock); 
     151                } 
     152 
     153                m_NewSockets.clear (); 
     154        } 
     155 
     156        virtual int svc (void) 
     157        { 
     158                DEBUG_LOG ("Network Thread Starting"); 
     159 
     160                WorldDatabase.ThreadStart (); 
     161 
     162                ACE_ASSERT (m_Reactor); 
     163 
     164                SocketSet::iterator i, t; 
     165 
     166                while (!m_Reactor->reactor_event_loop_done ()) 
     167                { 
     168                        // dont be too smart to move this outside the loop  
     169                        // the run_reactor_event_loop will modify interval 
     170                        ACE_Time_Value interval (0, 10000); 
     171 
     172                        if (m_Reactor->run_reactor_event_loop (interval) == -1) 
     173                                break; 
     174 
     175                        AddNewSockets (); 
     176 
     177                        for (i = m_Sockets.begin (); i != m_Sockets.end ();) 
     178                        { 
     179                                if ((*i)->Update () == -1) 
     180                                { 
     181                                        t = i; 
     182                                        i++; 
     183                                        (*t)->CloseSocket (); 
     184                                        (*t)->RemoveReference (); 
     185                                        --m_Connections; 
     186                                        m_Sockets.erase (t); 
     187                                } 
     188                                else 
     189                                        i++; 
     190                        } 
     191                } 
     192 
     193                WorldDatabase.ThreadEnd (); 
     194 
     195                DEBUG_LOG ("Network Thread Exitting"); 
     196 
     197                return 0; 
     198        } 
    203199 
    204200private: 
    205   typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt; 
    206   typedef std::set<WorldSocket*> SocketSet; 
    207  
    208   ACE_Reactor* m_Reactor; 
    209   AtomicInt m_Connections; 
    210   int m_ThreadId; 
    211  
    212   SocketSet m_Sockets; 
    213  
    214   SocketSet m_NewSockets; 
    215   ACE_Thread_Mutex m_NewSockets_Lock; 
     201        typedef ACE_Atomic_Op<ACE_SYNCH_MUTEX, long> AtomicInt; 
     202        typedef std::set<WorldSocket*> SocketSet; 
     203 
     204        ACE_Reactor* m_Reactor; 
     205        AtomicInt m_Connections; 
     206        int m_ThreadId; 
     207 
     208        SocketSet m_Sockets; 
     209 
     210        SocketSet m_NewSockets; 
     211        ACE_Thread_Mutex m_NewSockets_Lock; 
    216212}; 
    217213 
     
    228224WorldSocketMgr::~WorldSocketMgr () 
    229225{ 
    230   if (m_NetThreads) 
    231     delete [] m_NetThreads; 
    232    
    233   if(m_Acceptor) 
    234     delete m_Acceptor; 
    235 } 
    236  
    237 int 
    238 WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address) 
    239 { 
    240   m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true); 
    241  
    242   int num_threads = sConfig.GetIntDefault ("Network.Threads", 1); 
    243  
    244   if (num_threads <= 0) 
    245     { 
    246       sLog.outError ("Network.Threads is wrong in your config file"); 
    247       return -1; 
    248     } 
    249  
    250   m_NetThreadsCount = static_cast<size_t> (num_threads + 1); 
    251  
    252   m_NetThreads = new ReactorRunnable[m_NetThreadsCount]; 
    253  
    254   sLog.outBasic ("Max alowed socket connections %d",ACE::max_handles ()); 
    255  
    256   m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1); // -1 means use default 
    257  
    258   m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536); 
    259  
    260   if ( m_SockOutUBuff <= 0 ) 
    261     { 
    262       sLog.outError ("Network.OutUBuff is wrong in your config file"); 
    263       return -1; 
    264     } 
    265  
    266   WorldSocket::Acceptor *acc = new WorldSocket::Acceptor; 
    267   m_Acceptor = acc; 
    268  
    269   ACE_INET_Addr listen_addr (port, address); 
    270  
    271   if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1) 
    272     { 
    273       sLog.outError ("Failed to open acceptor ,check if the port is free"); 
    274       return -1; 
    275     } 
    276  
    277   for (size_t i = 0; i < m_NetThreadsCount; ++i) 
    278     m_NetThreads[i].Start (); 
    279  
    280   return 0; 
    281 } 
    282  
    283 int 
    284 WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address) 
    285 { 
    286   if (!sLog.IsOutDebug ()) 
    287     ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS); 
    288  
    289   if (this->StartReactiveIO (port, address) == -1) 
    290     return -1; 
    291  
    292   return 0; 
    293 } 
    294  
    295 void 
    296 WorldSocketMgr::StopNetwork () 
    297 { 
    298   if (m_Acceptor) 
    299     { 
    300       WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor); 
    301  
    302       if (acc) 
    303         acc->close (); 
    304     } 
    305  
    306   if (m_NetThreadsCount != 0) 
    307     { 
    308       for (size_t i = 0; i < m_NetThreadsCount; ++i) 
    309         m_NetThreads[i].Stop (); 
    310     } 
    311    
    312   this->Wait (); 
    313 } 
    314  
    315 void  
    316 WorldSocketMgr::Wait () 
    317 { 
    318   if (m_NetThreadsCount != 0) 
    319     { 
    320       for (size_t i = 0; i < m_NetThreadsCount; ++i) 
    321         m_NetThreads[i].Wait (); 
    322     } 
    323 } 
    324  
    325 int 
    326 WorldSocketMgr::OnSocketOpen (WorldSocket* sock) 
    327 { 
    328   // set some options here 
    329   if (m_SockOutKBuff >= 0) 
    330     if (sock->peer ().set_option (SOL_SOCKET, 
    331                                   SO_SNDBUF, 
    332                                   (void*) & m_SockOutKBuff, 
    333                                   sizeof (int)) == -1 && errno != ENOTSUP) 
    334       { 
    335         sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF"); 
    336         return -1; 
    337       } 
    338  
    339   static const int ndoption = 1; 
    340  
    341   // Set TCP_NODELAY. 
    342   if (m_UseNoDelay) 
    343     if (sock->peer ().set_option (ACE_IPPROTO_TCP, 
    344                                   TCP_NODELAY, 
    345                                   (void*) & ndoption, 
    346                                   sizeof (int)) == -1) 
    347       { 
    348         sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno)); 
    349         return -1; 
    350       } 
    351    
    352   sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff); 
    353  
    354   // we skip the Acceptor Thread 
    355   size_t min = 1; 
    356  
    357   ACE_ASSERT (m_NetThreadsCount >= 1); 
    358  
    359   for (size_t i = 1; i < m_NetThreadsCount; ++i) 
    360     if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ()) 
    361       min = i; 
    362  
    363   return m_NetThreads[min].AddSocket (sock); 
    364  
    365 } 
    366  
    367 WorldSocketMgr* 
    368 WorldSocketMgr::Instance () 
    369 { 
    370   return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance(); 
    371 } 
     226        if (m_NetThreads) 
     227                delete [] m_NetThreads; 
     228 
     229        if(m_Acceptor) 
     230                delete m_Acceptor; 
     231} 
     232 
     233int WorldSocketMgr::StartReactiveIO (ACE_UINT16 port, const char* address) 
     234{ 
     235        m_UseNoDelay = sConfig.GetBoolDefault ("Network.TcpNodelay", true); 
     236 
     237        int num_threads = sConfig.GetIntDefault ("Network.Threads", 1); 
     238 
     239        if (num_threads <= 0) 
     240        { 
     241                sLog.outError ("Network.Threads is wrong in your config file"); 
     242                return -1; 
     243        } 
     244 
     245        m_NetThreadsCount = static_cast<size_t> (num_threads + 1); 
     246 
     247        m_NetThreads = new ReactorRunnable[m_NetThreadsCount]; 
     248 
     249        sLog.outBasic ("Max alowed socket connections %d",ACE::max_handles ()); 
     250 
     251        m_SockOutKBuff = sConfig.GetIntDefault ("Network.OutKBuff", -1); // -1 means use default 
     252 
     253        m_SockOutUBuff = sConfig.GetIntDefault ("Network.OutUBuff", 65536); 
     254 
     255        if ( m_SockOutUBuff <= 0 ) 
     256        { 
     257                sLog.outError ("Network.OutUBuff is wrong in your config file"); 
     258                return -1; 
     259        } 
     260 
     261        WorldSocket::Acceptor *acc = new WorldSocket::Acceptor; 
     262        m_Acceptor = acc; 
     263 
     264        ACE_INET_Addr listen_addr (port, address); 
     265 
     266        if (acc->open (listen_addr, m_NetThreads[0].GetReactor (), ACE_NONBLOCK) == -1) 
     267        { 
     268                sLog.outError ("Failed to open acceptor ,check if the port is free"); 
     269                return -1; 
     270        } 
     271 
     272        for (size_t i = 0; i < m_NetThreadsCount; ++i) 
     273                m_NetThreads[i].Start (); 
     274 
     275        return 0; 
     276} 
     277 
     278int WorldSocketMgr::StartNetwork (ACE_UINT16 port, const char* address) 
     279{ 
     280        if (!sLog.IsOutDebug ()) 
     281                ACE_Log_Msg::instance ()->priority_mask (LM_ERROR, ACE_Log_Msg::PROCESS); 
     282 
     283        if (this->StartReactiveIO (port, address) == -1) 
     284                return -1; 
     285 
     286        return 0; 
     287} 
     288 
     289void WorldSocketMgr::StopNetwork () 
     290{ 
     291        if (m_Acceptor) 
     292        { 
     293                WorldSocket::Acceptor* acc = dynamic_cast<WorldSocket::Acceptor*> (m_Acceptor); 
     294 
     295                if (acc) 
     296                        acc->close (); 
     297        } 
     298 
     299        if (m_NetThreadsCount != 0) 
     300        { 
     301                for (size_t i = 0; i < m_NetThreadsCount; ++i) 
     302                        m_NetThreads[i].Stop (); 
     303        } 
     304 
     305        this->Wait (); 
     306} 
     307 
     308void WorldSocketMgr::Wait () 
     309{ 
     310        if (m_NetThreadsCount != 0) 
     311        { 
     312                for (size_t i = 0; i < m_NetThreadsCount; ++i) 
     313                        m_NetThreads[i].Wait (); 
     314        } 
     315} 
     316 
     317int WorldSocketMgr::OnSocketOpen (WorldSocket* sock) 
     318{ 
     319        // set some options here 
     320        if (m_SockOutKBuff >= 0) 
     321                if (sock->peer ().set_option (SOL_SOCKET, 
     322                        SO_SNDBUF, 
     323                        (void*) & m_SockOutKBuff, 
     324                        sizeof (int)) == -1 && errno != ENOTSUP) 
     325                { 
     326                        sLog.outError ("WorldSocketMgr::OnSocketOpen set_option SO_SNDBUF"); 
     327                        return -1; 
     328                } 
     329 
     330                static const int ndoption = 1; 
     331 
     332                // Set TCP_NODELAY. 
     333                if (m_UseNoDelay) 
     334                        if (sock->peer ().set_option (ACE_IPPROTO_TCP, 
     335                                TCP_NODELAY, 
     336                                (void*) & ndoption, 
     337                                sizeof (int)) == -1) 
     338                        { 
     339                                sLog.outError ("WorldSocketMgr::OnSocketOpen: peer ().set_option TCP_NODELAY errno = %s", ACE_OS::strerror (errno)); 
     340                                return -1; 
     341                        } 
     342 
     343                        sock->m_OutBufferSize = static_cast<size_t> (m_SockOutUBuff); 
     344 
     345                        // we skip the Acceptor Thread 
     346                        size_t min = 1; 
     347 
     348                        ACE_ASSERT (m_NetThreadsCount >= 1); 
     349 
     350                        for (size_t i = 1; i < m_NetThreadsCount; ++i) 
     351                                if (m_NetThreads[i].Connections () < m_NetThreads[min].Connections ()) 
     352                                        min = i; 
     353 
     354                        return m_NetThreads[min].AddSocket (sock); 
     355} 
     356 
     357WorldSocketMgr* WorldSocketMgr::Instance () 
     358{ 
     359        return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance(); 
     360} 
  • trunk/src/shared/Database/DatabaseEnv.h

    r102 r149  
    3535#include "Database/DatabasePostgre.h" 
    3636typedef DatabasePostgre DatabaseType; 
    37 #define _LIKE_          "ILIKE" 
    38 #define _TABLE_SIM_     "\"" 
     37#define _LIKE_           "ILIKE" 
     38#define _TABLE_SIM_      "\"" 
    3939#define _CONCAT3_(A,B,C) "( " A " || " B " || " C " )" 
     40#define _OFFSET_         "LIMIT 1 OFFSET %d" 
    4041#else 
    4142#include "Database/QueryResultMysql.h" 
     
    4546#include "Database/DatabaseSqlite.h" 
    4647typedef DatabaseMysql DatabaseType; 
    47 #define _LIKE_          "LIKE" 
    48 #define _TABLE_SIM_     "`" 
     48#define _LIKE_           "LIKE" 
     49#define _TABLE_SIM_      "`" 
    4950#define _CONCAT3_(A,B,C) "CONCAT( " A " , " B " , " C " )" 
     51#define _OFFSET_         "LIMIT %d,1" 
    5052#endif 
    5153 
  • trunk/src/trinitycore/Master.cpp

    r102 r149  
    458458    clearOnlineAccounts(); 
    459459 
    460     QueryResult* result = WorldDatabase.Query("SELECT version FROM db_version LIMIT 1"); 
    461     if(result) 
    462     { 
    463         Field* fields = result->Fetch(); 
    464  
    465         sLog.outString("Using %s", fields[0].GetString()); 
    466         delete result; 
    467     } 
    468     else 
    469         sLog.outString("Using unknown world database."); 
    470  
     460    sWorld.LoadDBVersion(); 
     461 
     462        sLog.outString("Using %s", sWorld.GetDBVersion()); 
    471463    return true; 
    472464} 
  • trunk/src/trinitycore/RASocket.cpp

    r112 r149  
    197197                    loginDatabase.escape_string(pw); 
    198198 
    199                     QueryResult *check = loginDatabase.PQuery("SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT(username,':','%s'))", login.c_str(), pw.c_str()); 
     199                    QueryResult *check = loginDatabase.PQuery( 
     200                                                "SELECT 1 FROM account WHERE username = '%s' AND sha_pass_hash=SHA1(CONCAT(username,':','%s'))", 
     201                                                login.c_str(), pw.c_str()); 
     202 
    200203                    if(check) 
    201204                    {