Changeset 149
- Timestamp:
- 11/19/08 13:40:46 (17 years ago)
- Location:
- trunk
- Files:
-
- 30 modified
Legend:
- Unmodified
- Added
- Removed
-
trunk/contrib/extractor/libmpq/mpq.cpp
r2 r149 60 60 61 61 /* 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); 63 63 if (fd == LIBMPQ_EFILE) { 64 64 return LIBMPQ_EFILE; -
trunk/src/bindings/scripts/ScriptMgr.cpp
r109 r149 1839 1839 //*** Functions used internally *** 1840 1840 1841 //Trinity_DLL_EXPORT 1842 //char const* ScriptsVersion() 1843 //{ 1844 // return "Default Trinity scripting library"; 1845 //} 1846 1841 1847 Script* GetScriptByName(std::string Name) 1842 1848 { -
trunk/src/bindings/scripts/ScriptMgr.h
r109 r149 78 78 #define TRINITY_DLL_EXPORT extern "C" __declspec(dllexport) 79 79 #elif defined( __GNUC__ ) 80 80 #define TRINITY_DLL_EXPORT extern "C" 81 81 #else 82 82 #define TRINITY_DLL_EXPORT extern "C" export 83 83 #endif 84 84 -
trunk/src/game/CharacterHandler.cpp
r102 r149 380 380 SendPacket( &data ); 381 381 382 std::string IP_str = GetRemoteAddress() .c_str();382 std::string IP_str = GetRemoteAddress(); 383 383 sLog.outBasic("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); 384 384 sLog.outChar("Account: %d (IP: %s) Create Character:[%s]",GetAccountId(),IP_str.c_str(),name.c_str()); -
trunk/src/game/Chat.cpp
r134 r149 70 70 { "idlerestart", SEC_ADMINISTRATOR, true, &ChatHandler::HandleIdleRestartCommand, "", NULL }, 71 71 { "idleshutdown", SEC_ADMINISTRATOR, true, &ChatHandler::HandleIdleShutDownCommand, "", NULL }, 72 { "info", SEC_PLAYER, true, &ChatHandler::Handle InfoCommand,"", NULL },72 { "info", SEC_PLAYER, true, &ChatHandler::HandleServerInfoCommand, "", NULL }, 73 73 { "motd", SEC_PLAYER, true, &ChatHandler::HandleServerMotdCommand, "", NULL }, 74 74 { "restart", SEC_ADMINISTRATOR, true, &ChatHandler::HandleRestartCommand, "", NULL }, -
trunk/src/game/Chat.h
r132 r149 100 100 bool HandleCommandsCommand(const char* args); 101 101 bool HandleStartCommand(const char* args); 102 bool HandleInfoCommand(const char* args);103 102 bool HandleDismountCommand(const char* args); 104 103 bool HandleSaveCommand(const char* args); … … 230 229 bool HandleServerCorpsesCommand(const char* args); 231 230 bool HandleServerExitCommand(const char* args); 231 bool HandleServerInfoCommand(const char* args); 232 232 bool HandleServerMotdCommand(const char* args); 233 233 bool HandleServerSetMotdCommand(const char* args); -
trunk/src/game/Language.h
r132 r149 83 83 LANG_PASSWORD_TOO_LONG = 55, 84 84 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 86 88 87 89 // level 1 chat -
trunk/src/game/Level0.cpp
r112 r149 87 87 } 88 88 89 bool ChatHandler::Handle InfoCommand(const char* /*args*/)89 bool ChatHandler::HandleServerInfoCommand(const char* /*args*/) 90 90 { 91 91 uint32 activeClientsNum = sWorld.GetActiveSessionCount(); … … 95 95 std::string str = secsToTimeString(sWorld.GetUptime()); 96 96 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()); 98 106 PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum, queuedClientsNum, maxQueuedClientsNum); 99 107 PSendSysMessage(LANG_UPTIME, str.c_str()); -
trunk/src/game/Level2.cpp
r132 r149 1955 1955 if(num > 0) 1956 1956 { 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); 1958 1958 1959 1959 if(!result) … … 2067 2067 if(num > 0) 2068 2068 { 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) 2072 2072 { 2073 2073 PSendSysMessage(LANG_COMMAND_TICKENOTEXIST, num); … … 2076 2076 return false; 2077 2077 } 2078 2079 for(int i = 1; i < num; ++i)2080 result->NextRow();2081 2078 2082 2079 Field* fields = result->Fetch(); -
trunk/src/game/Level3.cpp
r132 r149 5543 5543 return false; 5544 5544 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); 5546 5546 SetSentErrorMessage(true); 5547 5547 return false; -
trunk/src/game/Mail.cpp
r102 r149 188 188 return; 189 189 } 190 190 191 if (mailItem.item->HasFlag(ITEM_FIELD_FLAGS, ITEM_FLAGS_CONJURED) || mailItem.item->GetUInt32Value(ITEM_FIELD_DURATION)) 191 192 { … … 193 194 return; 194 195 } 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 } 195 202 } 196 203 } -
trunk/src/game/Map.cpp
r141 r149 579 579 } 580 580 } 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 590 581 591 582 void Map::Remove(Player *player, bool remove) … … 1558 1549 } 1559 1550 1551 void 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 1560 1559 void InstanceMap::Remove(Player *player, bool remove) 1561 1560 { -
trunk/src/game/ObjectMgr.cpp
r144 r149 6570 6570 return false; 6571 6571 } 6572 case CONDITION_NO_AURA: 6573 return !player->HasAura(value1, value2); 6574 case CONDITION_ACTIVE_EVENT: 6575 return gameeventmgr.IsActiveEvent(value1); 6572 6576 default: 6573 6577 return false; … … 6690 6694 break; 6691 6695 } 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 } 6692 6720 } 6693 6721 return true; -
trunk/src/game/ObjectMgr.h
r112 r149 206 206 CONDITION_QUESTTAKEN = 9, // quest_id 0, for condition true while quest active. 207 207 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 211 213 212 214 //Player's info … … 771 773 bool RemoveVendorItem(uint32 entry,uint32 item, bool savetodb = true); 772 774 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 773 776 protected: 774 777 uint32 m_auctionid; -
trunk/src/game/Pet.cpp
r120 r149 1367 1367 remaincharges = -1; 1368 1368 1369 /// do not load single target auras (unless they were cast by the player) 1370 if (caster_guid != GetGUID() && IsSingleTargetSpell(spellproto)) 1371 continue; 1372 1369 1373 Aura* aura = CreateAura(spellproto, effindex, NULL, this, NULL); 1370 1374 … … 1396 1400 break; 1397 1401 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)); 1402 1415 } 1403 1416 } -
trunk/src/game/Player.cpp
r142 r149 3258 3258 updateVisualBits.SetCount(PLAYER_END); 3259 3259 3260 // TODO: really implement OWNER_ONLY and GROUP_ONLY. Flags can be found in UpdateFields.h 3261 3260 3262 updateVisualBits.SetBit(OBJECT_FIELD_GUID); 3261 3263 updateVisualBits.SetBit(OBJECT_FIELD_TYPE); … … 3269 3271 3270 3272 updateVisualBits.SetBit(UNIT_FIELD_CHARMEDBY); 3273 updateVisualBits.SetBit(UNIT_FIELD_CHARMEDBY+1); 3271 3274 3272 3275 updateVisualBits.SetBit(UNIT_FIELD_TARGET); … … 3300 3303 updateVisualBits.SetBit(UNIT_FIELD_BASEATTACKTIME); 3301 3304 updateVisualBits.SetBit(UNIT_FIELD_BASEATTACKTIME + 1); 3302 updateVisualBits.SetBit(UNIT_FIELD_RANGEDATTACKTIME);3303 3305 updateVisualBits.SetBit(UNIT_FIELD_BOUNDINGRADIUS); 3304 3306 updateVisualBits.SetBit(UNIT_FIELD_COMBATREACH); 3305 3307 updateVisualBits.SetBit(UNIT_FIELD_DISPLAYID); 3306 3308 updateVisualBits.SetBit(UNIT_FIELD_NATIVEDISPLAYID); 3307 updateVisualBits.SetBit(UNIT_FIELD_MOUNTDISPLAYID);3308 3309 updateVisualBits.SetBit(UNIT_FIELD_BYTES_1); 3309 3310 updateVisualBits.SetBit(UNIT_FIELD_MOUNTDISPLAYID); … … 3315 3316 updateVisualBits.SetBit(UNIT_FIELD_BYTES_2); 3316 3317 3318 updateVisualBits.SetBit(PLAYER_DUEL_ARBITER); 3319 updateVisualBits.SetBit(PLAYER_DUEL_ARBITER+1); 3317 3320 updateVisualBits.SetBit(PLAYER_FLAGS); 3321 updateVisualBits.SetBit(PLAYER_GUILDID); 3322 updateVisualBits.SetBit(PLAYER_GUILDRANK); 3318 3323 updateVisualBits.SetBit(PLAYER_BYTES); 3319 3324 updateVisualBits.SetBit(PLAYER_BYTES_2); 3320 3325 updateVisualBits.SetBit(PLAYER_BYTES_3); 3321 updateVisualBits.SetBit(PLAYER_GUILDID); 3322 updateVisualBits.SetBit(PLAYER_GUILDRANK); 3326 updateVisualBits.SetBit(PLAYER_DUEL_TEAM); 3323 3327 updateVisualBits.SetBit(PLAYER_GUILD_TIMESTAMP); 3324 updateVisualBits.SetBit(PLAYER_DUEL_TEAM);3325 updateVisualBits.SetBit(PLAYER_DUEL_ARBITER);3326 updateVisualBits.SetBit(PLAYER_DUEL_ARBITER+1);3327 3328 3328 3329 // PLAYER_QUEST_LOG_x also visible bit on official (but only on party/raid)... … … 3353 3354 3354 3355 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);3365 3356 } 3366 3357 -
trunk/src/game/ScriptCalls.cpp
r102 r149 25 25 #include "Platform/Define.h" 26 26 #include "ScriptCalls.h" 27 #include "World.h" 27 28 28 29 ScriptsSet Script=NULL; … … 58 59 if( !(testScript->ScriptsInit =(scriptCallScriptsInit )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsInit" )) 59 60 ||!(testScript->ScriptsFree =(scriptCallScriptsFree )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsFree" )) 61 ||!(testScript->ScriptsVersion =(scriptCallScriptsVersion )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"ScriptsVersion" )) 60 62 ||!(testScript->GossipHello =(scriptCallGossipHello )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GossipHello" )) 61 63 ||!(testScript->GOChooseReward =(scriptCallGOChooseReward )TRINITY_GET_PROC_ADDR(testScript->hScriptsLib,"GOChooseReward" )) … … 94 96 Script->ScriptsInit(); 95 97 98 sWorld.SetScriptsVersion(Script->ScriptsVersion()); 99 96 100 return true; 97 101 } -
trunk/src/game/ScriptCalls.h
r102 r149 40 40 typedef void(TRINITY_IMPORT * scriptCallScriptsInit) (); 41 41 typedef void(TRINITY_IMPORT * scriptCallScriptsFree) (); 42 typedef char const* (TRINITY_IMPORT * scriptCallScriptsVersion) (); 42 43 43 44 typedef bool(TRINITY_IMPORT * scriptCallGossipHello) (Player *player, Creature *_Creature ); … … 65 66 scriptCallScriptsInit ScriptsInit; 66 67 scriptCallScriptsFree ScriptsFree; 68 scriptCallScriptsVersion ScriptsVersion; 67 69 68 70 scriptCallGossipHello GossipHello; -
trunk/src/game/SpellEffects.cpp
r145 r149 4074 4074 4075 4075 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); 4082 4082 } 4083 4083 -
trunk/src/game/SpellMgr.cpp
r131 r149 2193 2193 return zone_id ==3522 || map_id==565; 2194 2194 } 2195 if(mask & ELIXIR_ UNSTABLE_MASK)2195 if(mask & ELIXIR_SHATTRATH_MASK) 2196 2196 { 2197 2197 // in Tempest Keep, Serpentshrine Cavern, Caverns of Time: Mount Hyjal, Black Temple -
trunk/src/game/Unit.cpp
r143 r149 6485 6485 case 836: // Improved Blizzard (Rank 1) 6486 6486 { 6487 if( !procSpell || procSpell->SpellVisual!=9487 6487 if( !procSpell || procSpell->SpellVisual!=9487) 6488 6488 return false; 6489 6489 triggered_spell_id = 12484; … … 6492 6492 case 988: // Improved Blizzard (Rank 2) 6493 6493 { 6494 if( !procSpell || procSpell->SpellVisual!=9487 6494 if( !procSpell || procSpell->SpellVisual!=9487) 6495 6495 return false; 6496 6496 triggered_spell_id = 12485; … … 6499 6499 case 989: // Improved Blizzard (Rank 3) 6500 6500 { 6501 if( !procSpell || procSpell->SpellVisual!=9487 6501 if( !procSpell || procSpell->SpellVisual!=9487) 6502 6502 return false; 6503 6503 triggered_spell_id = 12486; … … 9871 9871 9872 9872 CharmInfo::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) 9874 9874 { 9875 9875 for(int i =0; i<4; ++i) -
trunk/src/game/Unit.h
r143 r149 647 647 CommandStates GetCommandState() { return m_CommandState; } 648 648 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); } 652 652 653 653 void InitPossessCreateSpells(); … … 666 666 CharmSpellEntry m_charmspells[4]; 667 667 CommandStates m_CommandState; 668 ReactStates m_ ReactSate;668 ReactStates m_reactState; 669 669 uint32 m_petnumber; 670 670 }; -
trunk/src/game/World.cpp
r138 r149 2613 2613 m_maxQueuedSessionCount = std::max(m_maxQueuedSessionCount,uint32(m_QueuedPlayer.size())); 2614 2614 } 2615 2616 void 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 481 481 482 482 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 483 492 protected: 484 493 void _UpdateGameTime(); … … 541 550 void AddSession_(WorldSession* s); 542 551 ZThread::LockedQueue<WorldSession*, ZThread::FastMutex> addSessQueue; 552 553 //used versions 554 std::string m_DBVersion; 555 std::string m_ScriptsVersion; 543 556 }; 544 557 -
trunk/src/game/WorldSession.cpp
r128 r149 52 52 { 53 53 if (sock) 54 55 56 57 54 { 55 m_Address = sock->GetRemoteAddress (); 56 sock->AddReference (); 57 } 58 58 } 59 59 … … 100 100 if (!m_Socket) 101 101 return; 102 102 103 #ifdef TRINITY_DEBUG 104 103 105 // Code for network use statistic 104 106 static uint64 sendPacketCount = 0; … … 132 134 sendLastPacketBytes = packet->wpos(); // wpos is real written size 133 135 } 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 (); 140 141 } 141 142 … … 158 159 bool WorldSession::Update(uint32 /*diff*/) 159 160 { 160 if (m_Socket) 161 if (m_Socket->IsClosed ()) 162 { 161 if (m_Socket && m_Socket->IsClosed ()) 162 { 163 163 m_Socket->RemoveReference (); 164 164 m_Socket = NULL; 165 165 } 166 166 167 167 WorldPacket *packet; … … 396 396 ///- Since each account can only have one online character at any given time, ensure all characters for active account are marked as offline 397 397 //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()); 399 400 sLog.outDebug( "SESSION: Sent SMSG_LOGOUT_COMPLETE Message" ); 400 401 } … … 408 409 void WorldSession::KickPlayer() 409 410 { 410 if (m_Socket) 411 { 412 m_Socket->CloseSocket (); 413 } 411 if (m_Socket) 412 m_Socket->CloseSocket (); 414 413 } 415 414 -
trunk/src/game/WorldSocket.cpp
r102 r149 19 19 */ 20 20 21 #include "Common.h"22 #include "WorldSocket.h"23 24 21 #include <ace/Message_Block.h> 25 22 #include <ace/OS_NS_string.h> … … 32 29 #include <ace/Reactor.h> 33 30 #include <ace/Auto_Ptr.h> 31 32 #include "WorldSocket.h" 33 #include "Common.h" 34 34 35 35 #include "Util.h" -
trunk/src/game/WorldSocketMgr.cpp
r102 r149 1 1 /* 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 */ 20 20 21 21 /** \file WorldSocketMgr.cpp 22 23 24 22 * \ingroup u2w 23 * \author Derex <derex101@gmail.com> 24 */ 25 25 26 26 #include "WorldSocketMgr.h" … … 48 48 49 49 /** 50 51 52 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 */ 54 54 class ReactorRunnable : protected ACE_Task_Base 55 55 { 56 56 public: 57 57 58 59 m_ThreadId (-1),60 m_Connections (0),61 m_Reactor (0)62 {63 58 ReactorRunnable () : 59 m_ThreadId (-1), 60 m_Connections (0), 61 m_Reactor (0) 62 { 63 ACE_Reactor_Impl* imp = 0; 64 64 65 65 #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 70 72 #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 73 77 #endif 74 78 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 133 131 protected: 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 } 203 199 204 200 private: 205 206 207 208 209 210 211 212 213 214 215 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; 216 212 }; 217 213 … … 228 224 WorldSocketMgr::~WorldSocketMgr () 229 225 { 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 233 int 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 278 int 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 289 void 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 308 void 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 317 int 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 357 WorldSocketMgr* WorldSocketMgr::Instance () 358 { 359 return ACE_Singleton<WorldSocketMgr,ACE_Thread_Mutex>::instance(); 360 } -
trunk/src/shared/Database/DatabaseEnv.h
r102 r149 35 35 #include "Database/DatabasePostgre.h" 36 36 typedef DatabasePostgre DatabaseType; 37 #define _LIKE_ "ILIKE"38 #define _TABLE_SIM_ "\""37 #define _LIKE_ "ILIKE" 38 #define _TABLE_SIM_ "\"" 39 39 #define _CONCAT3_(A,B,C) "( " A " || " B " || " C " )" 40 #define _OFFSET_ "LIMIT 1 OFFSET %d" 40 41 #else 41 42 #include "Database/QueryResultMysql.h" … … 45 46 #include "Database/DatabaseSqlite.h" 46 47 typedef DatabaseMysql DatabaseType; 47 #define _LIKE_ "LIKE"48 #define _TABLE_SIM_ "`"48 #define _LIKE_ "LIKE" 49 #define _TABLE_SIM_ "`" 49 50 #define _CONCAT3_(A,B,C) "CONCAT( " A " , " B " , " C " )" 51 #define _OFFSET_ "LIMIT %d,1" 50 52 #endif 51 53 -
trunk/src/trinitycore/Master.cpp
r102 r149 458 458 clearOnlineAccounts(); 459 459 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()); 471 463 return true; 472 464 } -
trunk/src/trinitycore/RASocket.cpp
r112 r149 197 197 loginDatabase.escape_string(pw); 198 198 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 200 203 if(check) 201 204 {