gamechanlist.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. //
  19. // Filename: gamechanlist.cpp
  20. // Project: Network.lib, for Commando
  21. // Author: Tom Spencer-Smith
  22. // Date: Dec 1998
  23. // Description:
  24. //
  25. #include "gamedata.h"
  26. #include "gamechannel.h"
  27. #include "gamechanlist.h"
  28. #include "wwdebug.h"
  29. #include <WWOnline\WOLChannel.h>
  30. //
  31. // Class statics
  32. //
  33. SList<cGameChannel> cGameChannelList::ChanList;
  34. //-----------------------------------------------------------------------------
  35. void cGameChannelList::Add_Channel(cGameData * p_game_data, const RefPtr<WWOnline::ChannelData>& p_channel)
  36. {
  37. WWASSERT(p_game_data != NULL);
  38. cGameChannel * p_game_channel = Find_Channel(p_game_data->Get_Owner());
  39. if (p_game_channel == NULL) {
  40. cGameChannel * p_game_channel = new cGameChannel(p_game_data, p_channel);
  41. WWASSERT(p_game_channel != NULL);
  42. ChanList.Add_Tail(p_game_channel);
  43. } else {
  44. //
  45. // Update any dynamic data
  46. //
  47. p_game_channel->Get_Game_Data()->Set_Current_Players(
  48. p_game_data->Get_Current_Players());
  49. p_game_channel->Get_Game_Data()->Set_Map_Name(
  50. p_game_data->Get_Map_Name());
  51. p_game_channel->WolChannel = p_channel;
  52. delete p_game_data;
  53. }
  54. }
  55. //-----------------------------------------------------------------------------
  56. cGameChannel * cGameChannelList::Find_Channel(const WideStringClass & owner)
  57. {
  58. for (
  59. SLNode<cGameChannel> * objnode = ChanList.Head();
  60. objnode;
  61. objnode = objnode->Next()) {
  62. cGameChannel * p_channel = objnode->Data();
  63. WWASSERT(p_channel != NULL);
  64. if (p_channel->Get_Game_Data()->Get_Owner() == owner) {
  65. return p_channel;
  66. }
  67. }
  68. return NULL;
  69. }
  70. //-----------------------------------------------------------------------------
  71. void cGameChannelList::Remove_Channel(const WideStringClass & owner)
  72. {
  73. cGameChannel * p_channel = Find_Channel(owner);
  74. if (p_channel != NULL) {
  75. ChanList.Remove(p_channel);
  76. p_channel->Release_Ref ();
  77. //delete p_channel;
  78. }
  79. }
  80. //-----------------------------------------------------------------------------
  81. void cGameChannelList::Remove_All(void)
  82. {
  83. WWDEBUG_SAY(("cGameChannelList::Remove_All\n"));
  84. for (
  85. SLNode<cGameChannel> * objnode = ChanList.Head();
  86. objnode;
  87. objnode = objnode->Next()) {
  88. cGameChannel * p_channel = objnode->Data();
  89. WWASSERT(p_channel != NULL);
  90. p_channel->Release_Ref ();
  91. }
  92. ChanList.Remove_All();
  93. }