예제 #1
0
        private void PreparePlayer(PlayerConnection playerConnection)
        {
            var task = new Task(() =>
            {
                playerConnection.Send("Bem vindo ao jogo, digite seu nome:");

                var playerName = playerConnection.Receive();

                Console.WriteLine("Nome jogador: {0}", playerName);

                if (players.Count == Arena.MAX_PLAYERS_IN_THE_GAME)
                {
                    playerConnection.Send("The game is already full");
                    playerConnection.Dispose();
                }
                else
                {
                    var player = new PlayerProcessor(playerName, arena, playerConnection);

                    player.OnStop  = () => players.Remove(player);
                    player.OnStart = () => StartPlayers();
                    players.Add(player);
                }
            });

            task.Start();
            task.ContinueWith(t => Console.WriteLine("The player was prepared!"));
        }
예제 #2
0
파일: Bot.cs 프로젝트: sertsch1/TS3AudioBot
        public void Dispose()
        {
            BotManager.RemoveBot(this);

            lock (SyncRoot)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;
                }
                else
                {
                    return;
                }
                Log.Info("Bot disconnecting.");

                PluginManager.StopPlugins(this);

                PlayManager.Stop();
                PlayManager = null;

                PlayerConnection.Dispose();                 // before: logStream,
                PlayerConnection = null;

                QueryConnection.Dispose();                 // before: logStream,
                QueryConnection = null;
            }
        }
예제 #3
0
        public void Dispose()
        {
            BotManager.RemoveBot(this);

            lock (SyncRoot)
            {
                if (!IsDisposed)
                {
                    IsDisposed = true;
                }
                else
                {
                    return;
                }
                Log.Info("Bot ({0}) disconnecting.", Id);

                PluginManager.StopPlugins(this);

                PlayManager.Stop();
                PlayManager = null;

                PlayerConnection.Dispose();
                PlayerConnection = null;

                ClientConnection.Dispose();
                ClientConnection = null;
            }
        }
            private async Task StartCycle()
            {
                var task = new Task(() =>
                {
                    var command       = "";
                    var parsedCommand = command.Trim().ToLower();

                    while (!parsedCommand.StartsWith("exit") || !parsedCommand.StartsWith("stop") || !connection.IsConnected)
                    {
                        try
                        {
                            command = ReceiveAndProcessClientMessage();
                        }
                        catch (SocketException ex)
                        {
                            Console.WriteLine("Stack: ");
                            Console.WriteLine(ex);
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine("Stack: ");
                            Console.WriteLine(ex);
                        }
                    }

                    connection.Send("goodbye");
                    connection.Dispose();
                });

                task.Start();
                await task;
            }
예제 #5
0
            private async Task DoConnectionThrash()
            {
                var connection = new PlayerConnection(API.BaseURL.ToString(), this.World);

                for (int i = 0; i < 1000; i++)
                {
                    Console.WriteLine($"Spawn #: {i + 1}");

                    await connection.ConnectAsync();

                    await connection.SpawnAsync("Testing", "ship_red", "red");

                    connection.Dispose();
                }
            }
예제 #6
0
파일: Program.cs 프로젝트: hymersm/Fortrex
        private static void DisconnectUser(PlayerConnection connection)
        {
            lock (locker)
            {
                if (connection != null)
                {
                    if (connection.ConnectionSocket != null)
                    {
                        connection.ConnectionSocket.Close();
                    }

                    if (EntityConnections.Contains(connection))
                    {
                        EntityConnections.Remove(connection);

                        connection.Dispose();
                    }
                }
            }
        }