aboutsummaryrefslogtreecommitdiff
path: root/patch
blob: 54b189c46bee7ed8b3d285cf3882e8854c7f2dcb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
diff -r 9b294adafcde src/server/game/Chat/Channels/Channel.cpp
--- a/src/server/game/Chat/Channels/Channel.cpp Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Chat/Channels/Channel.cpp Thu Dec 02 03:14:06 2010 +0100
@@ -21,14 +21,17 @@
 #include "ObjectMgr.h"
 #include "SocialMgr.h"
 #include "World.h"
+#include "DatabaseEnv.h"
 
 Channel::Channel(const std::string& name, uint32 channel_id, uint32 Team)
- : m_announce(true), m_moderate(false), m_name(name), m_password(""), m_flags(0), m_channelId(channel_id), m_ownerGUID(0), m_Team(Team)
+ : m_announce(true), m_ownership(true), m_name(name), m_password(""), m_flags(0), m_channelId(channel_id), m_ownerGUID(0), m_Team(Team)
 {
+    m_IsSaved = false;
     // set special flags if built-in channel
     if (ChatChannelsEntry const* ch = sChatChannelsStore.LookupEntry(channel_id)) // check whether it's a built-in channel
     {
         m_announce = false;                                 // no join/leave announces
+        m_ownership = false;                                // no ownership handout
 
         m_flags |= CHANNEL_FLAG_GENERAL;                    // for all built-in channels
 
@@ -42,92 +45,103 @@
             m_flags |= CHANNEL_FLAG_LFG;
         else                                                // for all other channels
             m_flags |= CHANNEL_FLAG_NOT_LFG;
-        m_IsSaved = false;
     }
     else                                                    // it's custom channel
     {
         channel_id = 0;
         m_flags |= CHANNEL_FLAG_CUSTOM;
+        
+        // If storing custom channels in the db is enabled either load or save the channel
+        if (sWorld.getBoolConfig(CONFIG_PRESERVE_CUSTOM_CHANNELS))
+        {
+            PreparedStatement *stmt = CharacterDatabase.GetPreparedStatement(CHAR_LOAD_CHANNEL);
+            stmt->setString(0, name);
+            stmt->setUInt32(1, m_Team);
+            PreparedQueryResult result = CharacterDatabase.Query(stmt);
 
-        //load not built in channel if saved
-        std::string _name(name);
-        CharacterDatabase.escape_string(_name);
-        QueryResult result = CharacterDatabase.PQuery("SELECT m_announce, m_moderate, m_public, m_password, BannedList FROM channels WHERE m_name = '%s' AND m_team = '%u'", _name.c_str(), m_Team);
+            if (result) //load
+            {
+                Field *fields = result->Fetch();
+                m_announce = fields[0].GetBool();
+                m_ownership = fields[1].GetBool();
+                m_password  = fields[2].GetString();
+                const char* db_BannedList = fields[3].GetCString();
 
-        if (result)//load
-        {
-            Field *fields = result->Fetch();
-            m_announce = fields[0].GetBool();
-            m_moderate = fields[1].GetBool();
-            m_public = fields[2].GetBool();
-            m_password  = fields[3].GetString();
-            const char* db_BannedList = fields[4].GetCString();
-
-            m_IsSaved = true;
-
-            if (db_BannedList)
-            {
-                Tokens tokens(db_BannedList, ' ');
-                Tokens::iterator iter;
-                for (iter = tokens.begin(); iter != tokens.end(); ++iter)
+                if (db_BannedList)
                 {
-                    uint64 banned_guid = atol(*iter);
-                    if (banned_guid)
+                    Tokens tokens(db_BannedList, ' ');
+                    Tokens::iterator iter;
+                    for (iter = tokens.begin(); iter != tokens.end(); ++iter)
                     {
-                        sLog.outDebug("Channel(%s) loaded banned guid:" UI64FMTD "",name.c_str(), banned_guid);
-                        banned.insert(banned_guid);
+                        uint64 banned_guid = atol(*iter);
+                        if (banned_guid)
+                        {
+                            sLog.outDebug("Channel(%s) loaded banned guid:" UI64FMTD "",name.c_str(), banned_guid);
+                            banned.insert(banned_guid);
+                        }
                     }
                 }
             }
-        }
-        else // save
-        {
-            // _name is already escaped at this point.
-            CharacterDatabase.PExecute("INSERT INTO channels (m_name, m_team, m_announce, m_moderate, m_public, m_password) "
-                "VALUES ('%s', '%u', '1', '0', '1', '')", _name.c_str(), m_Team);
-            sLog.outDebug("New Channel(%s) saved", name.c_str());
+            else // save
+            {
+                PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_ADD_CHANNEL);
+                stmt->setString(0, name);
+                stmt->setUInt32(1, m_Team);
+                CharacterDatabase.Execute(stmt);
+                sLog.outDebug("Channel(%s) saved in database", name.c_str());
+            }
+
             m_IsSaved = true;
         }
     }
 }
 
-bool Channel::_UpdateStringInDB(const std::string& colName, const std::string& colValue) const
+void Channel::UpdateChannelInDB() const
 {
-    // Prevent SQL-injection
-    std::string _name(m_name);
-    std::string _colValue(colValue);
-    CharacterDatabase.escape_string(_colValue);
-    CharacterDatabase.escape_string(_name);
-    CharacterDatabase.PExecute("UPDATE channels SET %s = '%s' WHERE m_name = '%s' AND m_team = '%u'",
-        colName.c_str(), _colValue.c_str(), _name.c_str(), m_Team);
-    return true;
-}
-
-bool Channel::_UpdateIntInDB(const std::string& colName, int colValue) const
-{
-    // Prevent SQL-injection
-    std::string _name(m_name);
-    CharacterDatabase.escape_string(_name);
-    CharacterDatabase.PExecute("UPDATE channels SET %s = '%u' WHERE m_name = '%s' AND m_team = '%u'",
-        colName.c_str(), colValue, _name.c_str(), m_Team);
-    return true;
-}
-
-void Channel::_UpdateBanListInDB() const
-{
-    // save banlist
     if (m_IsSaved)
     {
         std::ostringstream banlist;
         BannedList::const_iterator iter;
         for (iter = banned.begin(); iter != banned.end(); ++iter)
             banlist << (*iter) << " ";
+
         std::string banListStr = banlist.str();
-        if (_UpdateStringInDB("BannedList", banListStr))
-            sLog.outDebug("Channel(%s) BannedList saved", m_name.c_str());
+
+        PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_CHANNEL);
+        stmt->setBool(0, m_announce);
+        stmt->setBool(1, m_ownership);
+        stmt->setString(2, m_password);
+        stmt->setString(3, banListStr);
+        stmt->setString(4, m_name);
+        stmt->setUInt32(5, m_Team);
+        CharacterDatabase.Execute(stmt);
+
+        sLog.outDebug("Channel(%s) updated in database", m_name.c_str());
+    }
+
+}
+
+void Channel::UpdateChannelUseageInDB() const
+{
+    PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_SET_CHANNEL_USAGE);
+    stmt->setString(0, m_name);
+    stmt->setUInt32(1, m_Team);
+    CharacterDatabase.Execute(stmt);
+}
+
+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);
+        CharacterDatabase.Execute(stmt);
+
+        sLog.outDebug("Cleaned out unused custom chat channels.");
     }
 }
 
+
 void Channel::Join(uint64 p, const char *pass)
 {
     WorldPacket data;
@@ -188,18 +202,20 @@
 
     JoinNotify(p);
 
-    // if no owner first logged will become
-    if (!IsConstant() && !m_ownerGUID)
+    // Custom channel handling
+    if (!IsConstant())
     {
-        SetOwner(p, (players.size() > 1 ? true : false));
-        players[p].SetModerator(true);
+        // Update last_used timestamp in db
+        if(!players.empty())
+            UpdateChannelUseageInDB();
+
+        // If the channel has no owner yet and ownership is allowed, set the new owner.
+        if ( !m_ownerGUID && m_ownership)
+        {
+            SetOwner(p, (players.size() > 1 ? true : false));
+            players[p].SetModerator(true);
+        }
     }
-    /*
-    else if (!IsConstant() && m_ownerGUID && plr && m_ownerGUID == plr->GetGUID()))
-    {
-        SetOwner(p, (players.size() > 1 ? true : false));
-        players[p].SetModerator(true);
-    }*/
 }
 
 void Channel::Leave(uint64 p, bool send)
@@ -239,11 +255,18 @@
 
         LeaveNotify(p);
 
-        if (changeowner)
+        if (!IsConstant())
         {
-            uint64 newowner = !players.empty() ? players.begin()->second.player : 0;
-            players[newowner].SetModerator(true);
-            SetOwner(newowner);
+            // Update last_used timestamp in db
+            UpdateChannelUseageInDB();
+
+            // If the channel owner left and there are still players inside, pick a new owner
+            if (changeowner && m_ownership && !players.empty())
+            {
+                uint64 newowner = players.begin()->second.player;
+                players[newowner].SetModerator(true);
+                SetOwner(newowner);
+            }
         }
     }
 }
@@ -292,8 +315,8 @@
             {
                 banned.insert(bad->GetGUID());
                 MakePlayerBanned(&data, bad->GetGUID(), good);
-                _UpdateBanListInDB();
 
+                UpdateChannelInDB();
             }
             else
                 MakePlayerKicked(&data, bad->GetGUID(), good);
@@ -302,9 +325,9 @@
             players.erase(bad->GetGUID());
             bad->LeftChannel(this);
 
-            if (changeowner)
+            if (changeowner && m_ownership && !players.empty())
             {
-                uint64 newowner = !players.empty() ? good : false;
+                uint64 newowner = good;
                 players[newowner].SetModerator(true);
                 SetOwner(newowner);
             }
@@ -347,8 +370,8 @@
             WorldPacket data;
             MakePlayerUnbanned(&data, bad->GetGUID(), good);
             SendToAll(&data);
-            //save banlist
-            _UpdateBanListInDB();
+
+            UpdateChannelInDB();
         }
     }
 }
@@ -363,12 +386,6 @@
 
     ChatHandler chat(plr);
 
-    if (!m_public && sec <= SEC_MODERATOR)
-    {
-        chat.PSendSysMessage(LANG_CHANNEL_NOT_PUBLIC);
-        return;
-    }
-
     if (!IsOn(p))
     {
         WorldPacket data;
@@ -388,8 +405,8 @@
         WorldPacket data;
         MakePasswordChanged(&data, p);
         SendToAll(&data);
-        if (m_IsSaved && _UpdateStringInDB("m_password", m_password))
-            sLog.outDebug("Channel(%s) password saved", m_name.c_str());
+
+        UpdateChannelInDB();
     }
 }
 
@@ -595,43 +612,8 @@
         else
             MakeAnnouncementsOff(&data, p);
         SendToAll(&data);
-        if (m_IsSaved && _UpdateIntInDB("m_announce", m_announce ? 1 : 0))
-            sLog.outDebug("Channel(%s) announce saved", m_name.c_str());
 
-    }
-}
-
-void Channel::Moderate(uint64 p)
-{
-    uint32 sec = 0;
-    Player *plr = sObjectMgr.GetPlayer(p);
-    if (plr)
-        sec = plr->GetSession()->GetSecurity();
-
-    if (!IsOn(p))
-    {
-        WorldPacket data;
-        MakeNotMember(&data);
-        SendToOne(&data, p);
-    }
-    else if (!players[p].IsModerator() && sec < SEC_GAMEMASTER)
-    {
-        WorldPacket data;
-        MakeNotModerator(&data);
-        SendToOne(&data, p);
-    }
-    else
-    {
-        m_moderate = !m_moderate;
-
-        WorldPacket data;
-        if (m_moderate)
-            MakeModerationOn(&data, p);
-        else
-            MakeModerationOff(&data, p);
-        SendToAll(&data);
-        if (m_IsSaved && _UpdateIntInDB("m_announce", m_announce ? 1 : 0))
-            sLog.outDebug("Channel(%s) announce saved", m_name.c_str());
+        UpdateChannelInDB();
     }
 }
 
@@ -659,7 +641,7 @@
         MakeMuted(&data);
         SendToOne(&data, p);
     }
-    else if (m_moderate && !players[p].IsModerator() && sec < SEC_GAMEMASTER)
+    else if (!players[p].IsModerator() && sec < SEC_GAMEMASTER)
     {
         WorldPacket data;
         MakeNotModerator(&data);
@@ -768,9 +750,8 @@
             MakeOwnerChanged(&data, m_ownerGUID);
             SendToAll(&data);
         }
-        if (m_IsSaved && _UpdateIntInDB("m_moderate", m_moderate ? 1 : 0))
-            sLog.outDebug("Channel(%s) moderate saved", m_name.c_str());
 
+        UpdateChannelInDB();
     }
 }
 
@@ -936,20 +917,6 @@
     *data << uint64(guid);
 }
 
-// done 0x0F
-void Channel::MakeModerationOn(WorldPacket *data, uint64 guid)
-{
-    MakeNotifyPacket(data, CHAT_MODERATION_ON_NOTICE);
-    *data << uint64(guid);
-}
-
-// done 0x10
-void Channel::MakeModerationOff(WorldPacket *data, uint64 guid)
-{
-    MakeNotifyPacket(data, CHAT_MODERATION_OFF_NOTICE);
-    *data << uint64(guid);
-}
-
 // done 0x11
 void Channel::MakeMuted(WorldPacket *data)
 {
diff -r 9b294adafcde src/server/game/Chat/Channels/Channel.h
--- a/src/server/game/Chat/Channels/Channel.h   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Chat/Channels/Channel.h   Thu Dec 02 03:14:06 2010 +0100
@@ -48,8 +48,8 @@
     CHAT_MODE_CHANGE_NOTICE           = 0x0C,           //?
     CHAT_ANNOUNCEMENTS_ON_NOTICE      = 0x0D,           //+ "[%s] Channel announcements enabled by %s.";
     CHAT_ANNOUNCEMENTS_OFF_NOTICE     = 0x0E,           //+ "[%s] Channel announcements disabled by %s.";
-    CHAT_MODERATION_ON_NOTICE         = 0x0F,           //+ "[%s] Channel moderation enabled by %s.";
-    CHAT_MODERATION_OFF_NOTICE        = 0x10,           //+ "[%s] Channel moderation disabled by %s.";
+    // CHAT_MODERATION_ON_NOTICE         = 0x0F,           //+ "[%s] Channel moderation enabled by %s.";
+    // CHAT_MODERATION_OFF_NOTICE        = 0x10,           //+ "[%s] Channel moderation disabled by %s.";
     CHAT_MUTED_NOTICE                 = 0x11,           //+ "[%s] You do not have permission to speak.";
     CHAT_PLAYER_KICKED_NOTICE         = 0x12,           //? "[%s] Player %s kicked by %s.";
     CHAT_BANNED_NOTICE                = 0x13,           //+ "[%s] You are banned from that channel.";
@@ -150,8 +150,7 @@
     typedef     std::set<uint64> BannedList;
     BannedList  banned;
     bool        m_announce;
-    bool        m_moderate;
-    bool        m_public;
+    bool        m_ownership;
     std::string m_name;
     std::string m_password;
     uint8       m_flags;
@@ -178,8 +177,6 @@
         void MakeModeChange(WorldPacket *data, uint64 guid, uint8 oldflags);    //+ 0x0C
         void MakeAnnouncementsOn(WorldPacket *data, uint64 guid);               //+ 0x0D
         void MakeAnnouncementsOff(WorldPacket *data, uint64 guid);              //+ 0x0E
-        void MakeModerationOn(WorldPacket *data, uint64 guid);                  //+ 0x0F
-        void MakeModerationOff(WorldPacket *data, uint64 guid);                 //+ 0x10
         void MakeMuted(WorldPacket *data);                                      //? 0x11
         void MakePlayerKicked(WorldPacket *data, uint64 bad, uint64 good);      //? 0x12
         void MakeBanned(WorldPacket *data);                                     //? 0x13
@@ -207,9 +204,8 @@
         bool IsOn(uint64 who) const { return players.find(who) != players.end(); }
         bool IsBanned(uint64 guid) const { return banned.find(guid) != banned.end(); }
 
-        bool _UpdateStringInDB(const std::string& colName, const std::string& colValue) const;
-        bool _UpdateIntInDB(const std::string& colName, int colValue) const;
-        void _UpdateBanListInDB() const;
+        void UpdateChannelInDB() const;
+        void UpdateChannelUseageInDB() const;
 
         uint8 GetPlayerFlags(uint64 p) const
         {
@@ -278,13 +274,14 @@
         void UnsetMute(uint64 p, const char *newname) { SetMode(p, newname, false, false); }
         void List(Player* p);
         void Announce(uint64 p);
-        void Moderate(uint64 p);
         void Say(uint64 p, const char *what, uint32 lang);
         void Invite(uint64 p, const char *newp);
         void Voice(uint64 guid1, uint64 guid2);
         void DeVoice(uint64 guid1, uint64 guid2);
         void JoinNotify(uint64 guid);                                           // invisible notify
         void LeaveNotify(uint64 guid);                                          // invisible notify
+        void SetOwnership(bool ownership) { m_ownership = ownership; };
+        static void CleanOldChannelsInDB();
 };
 #endif
 
diff -r 9b294adafcde src/server/game/Chat/Chat.cpp
--- a/src/server/game/Chat/Chat.cpp Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Chat/Chat.cpp Thu Dec 02 03:14:06 2010 +0100
@@ -150,8 +150,8 @@
 
     static ChatCommand channelSetCommandTable[] =
     {
-        { "public",      SEC_ADMINISTRATOR,     true,  OldHandler<&ChatHandler::HandleChannelSetPublic>,  "", NULL },
-        { NULL,          0,                     false, NULL,                                  "", NULL }
+        { "ownership",      SEC_ADMINISTRATOR,  false,  OldHandler<&ChatHandler::HandleChannelSetOwnership>, "", NULL },
+        { NULL,             0,                  false, NULL,                                                "", NULL }
     };
 
     static ChatCommand channelCommandTable[] =
diff -r 9b294adafcde src/server/game/Chat/Chat.h
--- a/src/server/game/Chat/Chat.h   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Chat/Chat.h   Thu Dec 02 03:14:06 2010 +0100
@@ -166,7 +166,7 @@
         bool HandleCharacterReputationCommand(const char* args);
         bool HandleCharacterTitlesCommand(const char* args);
 
-        bool HandleChannelSetPublic(const char *args);
+        bool HandleChannelSetOwnership(const char *args);
 
         bool HandlePossessCommand(const char* args);
         bool HandleUnPossessCommand(const char* args);
diff -r 9b294adafcde src/server/game/Chat/Commands/Level3.cpp
--- a/src/server/game/Chat/Commands/Level3.cpp  Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Chat/Commands/Level3.cpp  Thu Dec 02 03:14:06 2010 +0100
@@ -61,6 +61,7 @@
 #include "CreatureTextMgr.h"
 #include "SmartAI.h"
 #include "Group.h"
+#include "ChannelMgr.h"
 
 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
 {
@@ -4400,25 +4401,38 @@
     return true;
 }
 
-bool ChatHandler::HandleChannelSetPublic(const char *args)
+bool ChatHandler::HandleChannelSetOwnership(const char *args)
 {
     if (!*args)
         return false;
-    std::string channel = strtok((char*)args, " ");
-    uint32 val = atoi((char*)args);
-
-    if (val)
+    char *channel = strtok((char*)args, " ");
+    char *argstr =  strtok(NULL, "");
+
+    if (!channel || !argstr)
+        return false;
+
+    Player *player = m_session->GetPlayer();
+    Channel *chn;
+
+    if (ChannelMgr* cMgr = channelMgr(player->GetTeam()))
+        chn = cMgr->GetChannel(channel, player);
+
+    if (strcmp(argstr, "on") == 0)
     {
-        CharacterDatabase.PExecute("UPDATE channels SET m_public = 1 WHERE m_name LIKE '%s'", channel.c_str());
-        val = 1;
+        if(chn)
+            chn->SetOwnership(true);
+        CharacterDatabase.PExecute("UPDATE channels SET m_ownership = 1 WHERE m_name LIKE '%s'", channel);
+        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);
+        PSendSysMessage(LANG_CHANNEL_DISABLE_OWNERSHIP, channel);
     }
     else
-    {
-        CharacterDatabase.PExecute("UPDATE channels SET m_public = 0 WHERE m_name LIKE '%s'", channel.c_str());
-        val = 0;
-    }
-
-    PSendSysMessage(LANG_CHANNEL_PUBLIC_CHANGED, channel.c_str(), val);
+        return false;
 
     return true;
 }
diff -r 9b294adafcde src/server/game/Miscellaneous/Language.h
--- a/src/server/game/Miscellaneous/Language.h  Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Miscellaneous/Language.h  Thu Dec 02 03:14:06 2010 +0100
@@ -906,8 +906,8 @@
     LANG_MOUNTABLE                      = 5019,
     LANG_NPCINFO_PHASEMASK              = 5020,
     LANG_NPCINFO_ARMOR                  = 5021,
-    LANG_CHANNEL_NOT_PUBLIC             = 5022,
-    LANG_CHANNEL_PUBLIC_CHANGED         = 5023,
+    LANG_CHANNEL_ENABLE_OWNERSHIP       = 5022,
+    LANG_CHANNEL_DISABLE_OWNERSHIP      = 5023,
     LANG_GOINFO_ENTRY                   = 5024,
     LANG_GOINFO_TYPE                    = 5025,
     LANG_GOINFO_DISPLAYID               = 5026,
diff -r 9b294adafcde src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp
--- a/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Server/Protocol/Handlers/ChannelHandler.cpp   Thu Dec 02 03:14:06 2010 +0100
@@ -281,17 +281,6 @@
             chn->Announce(_player->GetGUID());
 }
 
-void WorldSession::HandleChannelModerate(WorldPacket& recvPacket)
-{
-    sLog.outDebug("Opcode %u", recvPacket.GetOpcode());
-    //recvPacket.hexlike();
-    std::string channelname;
-    recvPacket >> channelname;
-    if (ChannelMgr* cMgr = channelMgr(_player->GetTeam()))
-        if (Channel *chn = cMgr->GetChannel(channelname, _player))
-            chn->Moderate(_player->GetGUID());
-}
-
 void WorldSession::HandleChannelDisplayListQuery(WorldPacket &recvPacket)
 {
     sLog.outDebug("Opcode %u", recvPacket.GetOpcode());
diff -r 9b294adafcde src/server/game/Server/Protocol/Opcodes.cpp
--- a/src/server/game/Server/Protocol/Opcodes.cpp   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/Server/Protocol/Opcodes.cpp   Thu Dec 02 03:14:06 2010 +0100
@@ -194,7 +194,7 @@
     /*0x0A5*/ { "CMSG_CHANNEL_BAN",                             STATUS_LOGGEDIN, &WorldSession::HandleChannelBan                },
     /*0x0A6*/ { "CMSG_CHANNEL_UNBAN",                           STATUS_LOGGEDIN, &WorldSession::HandleChannelUnban              },
     /*0x0A7*/ { "CMSG_CHANNEL_ANNOUNCEMENTS",                   STATUS_LOGGEDIN, &WorldSession::HandleChannelAnnouncements      },
-    /*0x0A8*/ { "CMSG_CHANNEL_MODERATE",                        STATUS_LOGGEDIN, &WorldSession::HandleChannelModerate           },
+    /*0x0A8*/ { "CMSG_CHANNEL_MODERATE",                        STATUS_NEVER,    &WorldSession::Handle_NULL                     },
     /*0x0A9*/ { "SMSG_UPDATE_OBJECT",                           STATUS_NEVER,    &WorldSession::Handle_ServerSide               },
     /*0x0AA*/ { "SMSG_DESTROY_OBJECT",                          STATUS_NEVER,    &WorldSession::Handle_ServerSide               },
     /*0x0AB*/ { "CMSG_USE_ITEM",                                STATUS_LOGGEDIN, &WorldSession::HandleUseItemOpcode             },
diff -r 9b294adafcde src/server/game/World/World.cpp
--- a/src/server/game/World/World.cpp   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/World/World.cpp   Thu Dec 02 03:14:06 2010 +0100
@@ -71,6 +71,7 @@
 #include "WeatherMgr.h"
 #include "CreatureTextMgr.h"
 #include "SmartAI.h"
+#include "Channel.h"
 
 volatile bool World::m_stopEvent = false;
 uint8 World::m_ExitCode = SHUTDOWN_EXIT_CODE;
@@ -576,6 +577,8 @@
     m_int_configs[CONFIG_AUCTION_LEVEL_REQ] = sConfig.GetIntDefault("LevelReq.Auction", 1);
     m_int_configs[CONFIG_MAIL_LEVEL_REQ] = sConfig.GetIntDefault("LevelReq.Mail", 1);
     m_bool_configs[CONFIG_ALLOW_PLAYER_COMMANDS] = sConfig.GetBoolDefault("AllowPlayerCommands", 1);
+    m_bool_configs[CONFIG_PRESERVE_CUSTOM_CHANNELS] = sConfig.GetBoolDefault("PreserveCustomChannels", false);
+    m_int_configs[CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION] = sConfig.GetIntDefault("PreserveCustomChannelDuration", 14);
     m_bool_configs[CONFIG_GRID_UNLOAD] = sConfig.GetBoolDefault("GridUnload", true);
     m_int_configs[CONFIG_INTERVAL_SAVE] = sConfig.GetIntDefault("PlayerSaveInterval", 15 * MINUTE * IN_MILLISECONDS);
     m_int_configs[CONFIG_INTERVAL_DISCONNECT_TOLERANCE] = sConfig.GetIntDefault("DisconnectToleranceInterval", 0);
@@ -1673,6 +1676,9 @@
     // Delete all characters which have been deleted X days before
     Player::DeleteOldCharacters();
 
+    // Delete all custom channels which haven't been used for PreserveCustomChannelDuration days.
+    Channel::CleanOldChannelsInDB();
+
     sLog.outString("Starting Arena Season...");
     sGameEventMgr.StartArenaSeason();
 
diff -r 9b294adafcde src/server/game/World/World.h
--- a/src/server/game/World/World.h Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/game/World/World.h Thu Dec 02 03:14:06 2010 +0100
@@ -163,6 +163,7 @@
     CONFIG_AUTOBROADCAST,
     CONFIG_ALLOW_TICKETS,
     CONFIG_DBC_ENFORCE_ITEM_ATTRIBUTES,
+    CONFIG_PRESERVE_CUSTOM_CHANNELS,
     BOOL_CONFIG_VALUE_COUNT
 };
 
@@ -308,6 +309,7 @@
     CONFIG_AUTOBROADCAST_INTERVAL,
     CONFIG_MAX_RESULTS_LOOKUP_COMMANDS,
     CONFIG_DB_PING_INTERVAL,
+    CONFIG_PRESERVE_CUSTOM_CHANNEL_DURATION,
     INT_CONFIG_VALUE_COUNT
 };
 
diff -r 9b294adafcde src/server/shared/Database/Implementation/CharacterDatabase.cpp
--- a/src/server/shared/Database/Implementation/CharacterDatabase.cpp   Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/shared/Database/Implementation/CharacterDatabase.cpp   Thu Dec 02 03:14:06 2010 +0100
@@ -215,5 +215,12 @@
     PrepareStatement(CHAR_DEL_CRESPAWNTIME, "DELETE FROM creature_respawn WHERE guid = ? AND instance = ?");
     PrepareStatement(CHAR_ADD_CRESPAWNTIME, "INSERT INTO creature_respawn VALUES (?, ?, ?)");
 
+    // Chat channel handling
+    PrepareStatement(CHAR_LOAD_CHANNEL, "SELECT m_announce, m_ownership, m_password, BannedList FROM channels WHERE m_name = ? AND m_team = ?");
+    PrepareStatement(CHAR_ADD_CHANNEL, "INSERT INTO channels (m_name, m_team, last_used) VALUES (? , ?, UNIX_TIMESTAMP())");
+    PrepareStatement(CHAR_SET_CHANNEL, "UPDATE channels SET m_announce = ?, m_ownership = ?, m_password = ?, BannedList = ?, last_used = UNIX_TIMESTAMP() WHERE m_name = ? AND m_team = ?");
+    PrepareStatement(CHAR_SET_CHANNEL_USAGE, "UPDATE channels SET last_used = UNIX_TIMESTAMP() WHERE m_name = ? AND m_team = ?");
+    PrepareStatement(CHAR_CLEAN_CHANNEL, "DELETE FROM channels WHERE m_ownership = 1 AND (last_used + ?) < UNIX_TIMESTAMP()");
+
     return true;
 }
diff -r 9b294adafcde src/server/shared/Database/Implementation/CharacterDatabase.h
--- a/src/server/shared/Database/Implementation/CharacterDatabase.h Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/shared/Database/Implementation/CharacterDatabase.h Thu Dec 02 03:14:06 2010 +0100
@@ -181,6 +181,12 @@
     CHAR_DEL_CRESPAWNTIME,
     CHAR_ADD_CRESPAWNTIME,
 
+    CHAR_LOAD_CHANNEL,
+    CHAR_ADD_CHANNEL,
+    CHAR_SET_CHANNEL,
+    CHAR_SET_CHANNEL_USAGE,
+    CHAR_CLEAN_CHANNEL,
+
     MAX_CHARACTERDATABASE_STATEMENTS,
 };
 
diff -r 9b294adafcde src/server/worldserver/worldserver.conf.dist
--- a/src/server/worldserver/worldserver.conf.dist  Wed Dec 01 21:20:28 2010 +0200
+++ b/src/server/worldserver/worldserver.conf.dist  Thu Dec 02 03:14:06 2010 +0100
@@ -1371,9 +1371,10 @@
 
 #
 #   DBC.EnforceItemAttributes
-#        Disallow overriding item attributes stored in DBC files with values from the database
-#        Default: 0 - Off, Use DB values
-#                 1 - On, Enforce DBC Values (default)
+#        Description: Disallow overriding item attributes stored in DBC files with values from the 
+#                     database.
+#        Default:     1 - (Enabled, Enforce DBC values)
+#                     0 - (Disabled, Use database values)
 
 DBC.EnforceItemAttributes = 1
 
@@ -1745,6 +1746,27 @@
 AllowPlayerCommands = 1
 
 #
+#    PreserveCustomChannels
+#        Description: Store custom chat channel settings like password, automatic ownership handout
+#                     or ban list in the database. Needs to be enabled to save custom 
+#                     world/trade/etc. channels that have automatic ownership handout disabled.
+#                     (.channel set ownership $channel off)
+#        Default:     0 - (Disabled, Blizzlike, Channel settings are lost if last person left)
+#                     1 - (Enabled)
+
+PreserveCustomChannels = 1
+
+#
+#    PreserveCustomChannelDuration
+#        Description: Time (in days) that needs to pass before the customs chat channels get
+#                     cleaned up from the database. Only channels with ownership handout enabled
+#                     (default behavior) will be cleaned.
+#        Default:     14 - (Enabled, Clean channels that haven't been used for 14 days)
+#                     0  - (Disabled, Infinite channel storage)
+
+PreserveCustomChannelDuration = 14
+
+#
 ###################################################################################################
 
 ###################################################################################################