Ejemplo n.º 1
0
        public void Store(TalkyChannel channel, bool writeToDB)
        {
            lock (_lock)
            {
                _channels.Add(channel);


                string lobbyString  = (channel is LobbyChannel ? "true" : "false");
                string lockedString = (channel.Locked ? "true" : "false");

                if (true == writeToDB)
                {
                    MySqlConnection connection = MySqlConnector.GetConnection();
                    if (connection != null)
                    {
                        MySqlCommand command = new MySqlCommand("INSERT INTO `channels` VALUES(NULL, @channel_name, @lobby_type, @locked)", connection);
                        command.Prepare();
                        command.Parameters.AddWithValue("@channel_name", channel.Name);
                        command.Parameters.AddWithValue("@lobby_type", lobbyString);
                        command.Parameters.AddWithValue("@locked", lockedString);
                        try
                        {
                            command.ExecuteReader();
                        }
                        catch
                        {
                            Console.WriteLine("channels table: could not INSERT " + channel.Name);
                        }
                        connection.Close();
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public void Kick(ServerClient client, string reason = null)
        {
            if (!(this is LobbyChannel))
            {
                LobbyChannel lobby = ChannelRepository.Instance.GetLobby();
                if (lobby == null)
                {
                    return;
                }

                if (client.Channel.Equals(lobby))
                {
                    return;
                }

                TalkyChannel oldChannel = client.Channel;
                client.JoinChannel(lobby, false);

                if (reason != null)
                {
                    oldChannel.BroadcastMessage(client.Username + " was kicked from the channel (" + reason + ").");
                }
                oldChannel.BroadcastMessage(client.Username + " was kicked from the channel.");
            }
        }
Ejemplo n.º 3
0
        public void Remove(TalkyChannel channel)
        {
            lock (_lock)
            {
                // Remove gets called when there are 0 clients in the channel.
                // However, if the channel is just recently restored from recovery and clients have not reconnected yet,
                // don't delete the channel!  Btw, the InRecovery flag is set back to false as soon as the first client joins.
                if (false == (channel.InRecovery))
                {
                    _channels.Remove(channel);

                    MySqlConnection connection = MySqlConnector.GetConnection();
                    if (connection != null)
                    {
                        MySqlCommand command = new MySqlCommand("DELETE FROM `channels` WHERE channel_name = @channel_name", connection);
                        command.Prepare();
                        command.Parameters.AddWithValue("@channel_name", channel.Name);
                        command.ExecuteReader();
                        connection.Close();
                    }
                }
            }
        }