Skip to content

Commit

Permalink
CharDB Schema/Cleanup: cleanup channels table:
Browse files Browse the repository at this point in the history
* rename columns (remove m_ prefix and convert to lowerCamel case);
* rename prepared statements to conform to standards (there is no CLEAN statement).
  • Loading branch information
Azazel committed Mar 11, 2011
1 parent 20b44e8 commit 3973d1b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 18 deletions.
16 changes: 8 additions & 8 deletions sql/base/characters_database.sql
Original file line number Diff line number Diff line change
Expand Up @@ -267,14 +267,14 @@ DROP TABLE IF EXISTS `channels`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `channels` (
`m_name` varchar(128) NOT NULL,
`m_team` int(10) unsigned NOT NULL,
`m_announce` tinyint(3) unsigned NOT NULL DEFAULT '1',
`m_ownership` tinyint(3) unsigned NOT NULL DEFAULT '1',
`m_password` varchar(32) DEFAULT NULL,
`BannedList` text,
`last_used` int(10) unsigned NOT NULL,
PRIMARY KEY (`m_name`,`m_team`)
`name` varchar(128) NOT NULL,
`team` int(10) unsigned NOT NULL,
`announce` tinyint(3) unsigned NOT NULL DEFAULT '1',
`ownership` tinyint(3) unsigned NOT NULL DEFAULT '1',
`password` varchar(32) DEFAULT NULL,
`bannedList` text,
`lastUsed` int(10) unsigned NOT NULL,
PRIMARY KEY (`name`,`team`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Channel System';
/*!40101 SET character_set_client = @saved_cs_client */;

Expand Down
7 changes: 7 additions & 0 deletions sql/updates/auth_char/2011_03_11_0_characters_channels.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE `channels` CHANGE COLUMN `m_name` `name` varchar(128) NOT NULL,
CHANGE COLUMN `m_team` `team` int(10) unsigned NOT NULL,
CHANGE COLUMN `m_announce` `announce` tinyint(3) unsigned NOT NULL DEFAULT '1',
CHANGE COLUMN `m_ownership` `ownership` tinyint(3) unsigned NOT NULL DEFAULT '1',
CHANGE COLUMN `m_password` `password` varchar(32) DEFAULT NULL,
CHANGE COLUMN `BannedList` `bannedList` text,
CHANGE COLUMN `last_used` `lastUsed` int(10) unsigned NOT NULL;
4 changes: 2 additions & 2 deletions src/server/game/Chat/Channels/Channel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ void Channel::CleanOldChannelsInDB()
{
if (sWorld->getIntConfig(CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION) > 0)
{
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_CLEAN_CHANNEL);
stmt->setUInt32(0, sWorld->getIntConfig(CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION)*DAY);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_OLD_CHANNELS);
stmt->setUInt32(0, sWorld->getIntConfig(CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION) * DAY);
CharacterDatabase.Execute(stmt);

sLog->outDebug(LOG_FILTER_CHATSYS,"Cleaned out unused custom chat channels.");
Expand Down
10 changes: 8 additions & 2 deletions src/server/game/Chat/Commands/Level3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4431,14 +4431,20 @@ bool ChatHandler::HandleChannelSetOwnership(const char *args)
{
if(chn)
chn->SetOwnership(true);
CharacterDatabase.PExecute("UPDATE channels SET m_ownership = 1 WHERE m_name LIKE '%s'", channel);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_CHANNEL_OWNERSHIP);
stmt->setUInt8 (0, 1);
stmt->setString(1, channel);
CharacterDatabase.Execute(stmt);
PSendSysMessage(LANG_CHANNEL_ENABLE_OWNERSHIP, channel);
}
else if (strcmp(argstr, "off") == 0)
{
if(chn)
chn->SetOwnership(false);
CharacterDatabase.PExecute("UPDATE channels SET m_ownership = 0 WHERE m_name LIKE '%s'", channel);
PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_CHANNEL_OWNERSHIP);
stmt->setUInt8 (0, 0);
stmt->setString(1, channel);
CharacterDatabase.Execute(stmt);
PSendSysMessage(LANG_CHANNEL_DISABLE_OWNERSHIP, channel);
}
else
Expand Down
11 changes: 6 additions & 5 deletions src/server/shared/Database/Implementation/CharacterDatabase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,11 +237,12 @@ bool CharacterDatabaseConnection::Open()
PREPARE_STATEMENT(CHAR_ADD_GO_RESPAWN_TIME, "REPLACE INTO gameobject_respawn VALUES (?, ?, ?)", CONNECTION_ASYNC)

// Chat channel handling
PREPARE_STATEMENT(CHAR_LOAD_CHANNEL, "SELECT m_announce, m_ownership, m_password, BannedList FROM channels WHERE m_name = ? AND m_team = ?", CONNECTION_SYNCH)
PREPARE_STATEMENT(CHAR_ADD_CHANNEL, "INSERT INTO channels (m_name, m_team, last_used) VALUES (? , ?, UNIX_TIMESTAMP())", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_SET_CHANNEL, "UPDATE channels SET m_announce = ?, m_ownership = ?, m_password = ?, BannedList = ?, last_used = UNIX_TIMESTAMP() WHERE m_name = ? AND m_team = ?", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_SET_CHANNEL_USAGE, "UPDATE channels SET last_used = UNIX_TIMESTAMP() WHERE m_name = ? AND m_team = ?", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_CLEAN_CHANNEL, "DELETE FROM channels WHERE m_ownership = 1 AND (last_used + ?) < UNIX_TIMESTAMP()", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_LOAD_CHANNEL, "SELECT announce, ownership, password, bannedList FROM channels WHERE name = ? AND team = ?", CONNECTION_SYNCH)
PREPARE_STATEMENT(CHAR_ADD_CHANNEL, "INSERT INTO channels(name, team, lastUsed) VALUES (?, ?, UNIX_TIMESTAMP())", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_SET_CHANNEL, "UPDATE channels SET announce = ?, ownership = ?, password = ?, bannedList = ?, lastUsed = UNIX_TIMESTAMP() WHERE name = ? AND team = ?", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_SET_CHANNEL_USAGE, "UPDATE channels SET lastUsed = UNIX_TIMESTAMP() WHERE name = ? AND team = ?", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_SET_CHANNEL_OWNERSHIP, "UPDATE channels SET ownership = ? WHERE name LIKE ?", CONNECTION_ASYNC)
PREPARE_STATEMENT(CHAR_DEL_OLD_CHANNELS, "DELETE FROM channels WHERE ownership = 1 AND lastUsed + ? < UNIX_TIMESTAMP()", CONNECTION_ASYNC)

// Equipmentsets
PREPARE_STATEMENT(CHAR_SET_EQUIP_SET, "UPDATE character_equipmentsets SET name=?, iconname=?, item0=?, item1=?, item2=?, item3=?, item4=?, item5=?, item6=?, item7=?, item8=?, item9=?, item10=?, item11=?, item12=?, item13=?, item14=?, item15=?, item16=?, item17=?, item18=? WHERE guid=? AND setguid=? AND setindex=?", CONNECTION_ASYNC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ enum CharacterDatabaseStatements
CHAR_ADD_CHANNEL,
CHAR_SET_CHANNEL,
CHAR_SET_CHANNEL_USAGE,
CHAR_CLEAN_CHANNEL,
CHAR_SET_CHANNEL_OWNERSHIP,
CHAR_DEL_OLD_CHANNELS,

CHAR_SET_EQUIP_SET,
CHAR_ADD_EQUIP_SET,
Expand Down

1 comment on commit 3973d1b

@Machiavell1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:)

Please sign in to comment.