Exemple #1
0
        public void UpdateItems()
        {
            Items    = new string[client.ServerInfo.Playerlist.Length * 2 + 2 + (client.LocalID == 0 ? 2 : 0)];
            Items[0] = "!" + client.ServerInfo.GameName + " hosted on " + client.ServerEp.Address.ToString();
            Items[1] = "!" + "".PadRight(41, '-');

            if (client.LocalID == 0)
            {
                Items[Items.Length - 2] = "!";
                Items[Items.Length - 1] = "START GAME";
            }

            for (int i = 0; i < client.ServerInfo.Playerlist.Length; i++)
            {
                ServersideClientInfo remotePlayer = client.ServerInfo.Playerlist[i];
                if (i == client.LocalID)
                {
                    remotePlayer = ServersideClientInfo.FromClient(client);
                }

                Items[2 * i + 2]  = "◘◘1" + (i + 1) + ". " + remotePlayer.PlayerName;
                Items[2 * i + 2]  = Items[2 * i + 2].PadRight(24 + 3);
                Items[2 * i + 2] += (!remotePlayer.Ready ? "◘c◘NOT " : "◘a◘    ") + "READY◘7◘";
                Items[2 * i + 2] += "".PadRight(2) + remotePlayer.Ping + " ms◘◘0 ";

                Items[2 * i + 3] = "! " + client.ServerInfo.Playerlist[i].CharacterToString;
            }
        }
        void Update(object o)
        {
            if (LoggedIn && Connected)
            {
                NetworkStream stream = tcpClient.GetStream();
                ClientRequest req    = new ClientRequest(this.LocalID);

                if (ServerInfo.GamePhase == GamePhase.Lobby)
                {
                    Stopwatch stopky = new Stopwatch();
                    stopky.Start();

                    req.Purpose = RequestPurpose.LobbyStatus;
                    req.Data    = new object[] { ServersideClientInfo.FromClient(this) };
                    req.SendTo(stream);

                    ServerResponse resp = ServerResponse.ReceiveFrom(stream);

                    if (resp.Purpose == ResponseType.LobbyInfo)
                    {
                        this.ServerInfo = (ClientsideServerInfo)resp.Data[0];
                        this.LobbyMenu.UpdateItems();
                        this.LobbyMenu.Draw();
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }

                    stopky.Stop();
                    this.Ping = (int)stopky.ElapsedMilliseconds;
                }
            }
        }
Exemple #3
0
 void Update()
 {
     for (int i = 0; i < Clients.Count; i++)
     {
         ServersideClientInfo client = Clients[i];
     }
 }
Exemple #4
0
        void OnConnect(TcpServerConnection connection)
        {
            NetworkStream stream = connection.Socket.GetStream();
            ClientRequest req    = null;

            try
            {
                req = ClientRequest.ReceiveFrom(stream);
            }
            catch
            {
                return;
            }

            if (req.Purpose == RequestPurpose.Login)
            {
                if (FreeSlots > 0 && CurrentGame.Phase == GamePhase.Lobby)
                {
                    ServersideClientInfo client = new ServersideClientInfo();
                    client.Connection        = connection;
                    client.PlayerName        = (string)req.Data[0];
                    client.CharacterToString = (string)req.Data[1];
                    client.ClientID          = Clients.Count;
                    Clients.Add(client);

                    ServerResponse toSend = new ServerResponse();
                    toSend.Purpose = ResponseType.LoginAccepted;
                    toSend.Data    = new object[] { client.ClientID, ClientsideServerInfo.FromServer(this) };
                    toSend.SendTo(stream);
                }
                else
                {
                    ServerResponse toSend = new ServerResponse();
                    toSend.Purpose = ResponseType.ActionDenied;
                    toSend.Data    = new object[] { "" };
                    if (FreeSlots == 0)
                    {
                        toSend.Data[0] = "Server full";
                    }
                    else
                    {
                        toSend.Data[0] = "Game in progress";
                    }

                    toSend.SendTo(stream);
                    server.Connections.Remove(connection);
                }
            }
        }
Exemple #5
0
        public void Show()
        {
            while (true)
            {
                this.Draw();
                buffer.SetCursorPosition(6, 3);
                UpdateItems();
                this.ReadMenu();

                if (Selected == Items.Length - 1 && client.LocalID == 0)
                {
                    ClientRequest req = new ClientRequest(client.LocalID);

                    req.Purpose = RequestPurpose.StartGame;
                    req.Data    = new object[] { ServersideClientInfo.FromClient(client) };

                    client.Send(req);
                }
            }
        }