@@ -144,34 +144,23 @@ void GuildPlayer::HandleReadyState() {
144144}
145145
146146GuildPlayer* GuildPlayer::Get (const dpp::snowflake &guild_id) {
147- /* Try to get the guild in the array */
148- for (unsigned int i = 0 ; i < _players_count; i++ )
149- if (_players[i] ->guild_id == guild_id) return _players[i] ;
147+ /* Try to get the guild in the list */
148+ for (GuildPlayer* player: _players )
149+ if (player ->guild_id == guild_id) return player ;
150150
151- /* If there is not a such guild we need to add it to the array */
151+ /* If there is not a such guild player we need to add it to the array */
152152 return Add (guild_id);
153153}
154154
155155bool GuildPlayer::IsPlayerReady () { return _voiceconn != nullptr && _voiceconn->voiceclient != nullptr && _voiceconn->voiceclient ->is_ready (); }
156156
157157GuildPlayer* GuildPlayer::Add (const dpp::snowflake &guild_id) {
158- /* Increase the number of guilds */
159- _players_count++;
160-
161- /* Try to get the empty place for the pointer */
162- for (unsigned int i = _max_players_count - PLAYERS_DELTA; i < _max_players_count; i++) {
163- if (_players[i] != nullptr ) continue ;
164- _players[i] = new GuildPlayer (guild_id);
165- return _players[i];
166- }
158+ /* Create a new guild player */
159+ GuildPlayer* player = new GuildPlayer (guild_id);
167160
168- /* If the array with pointer is full we need to increase it */
169- auto ** new_guilds = new GuildPlayer* [_max_players_count + PLAYERS_DELTA];
170- for (unsigned int i = 0 ; i < _max_players_count; i++) new_guilds[i] = _players[i];
171- delete[] _players;
172- _players = new_guilds;
161+ /* Add it to the list */
162+ _players.Append (player);
173163
174- /* Add the new guild to the array */
175- _players[_max_players_count] = new GuildPlayer (guild_id);
176- return _players[_max_players_count += PLAYERS_DELTA];
164+ /* Return a new player */
165+ return player;
177166}
0 commit comments