Ejemplo n.º 1
0
        public ClientState()
        {
            _client = new Client();
            respawnTimer = new Timer();
            respawnTimer.AutoReset = true;
            respawnTimer.Elapsed += new ElapsedEventHandler(timer_Elapsed);
            _client.OnMessage = new Client.Callback(MessageCallback);
            _client.OnError = new Client.ErrorCallback(ErrorCallback);
            _client.OnConnect = new Client.Callback(ConnectCallback);
            _client.OnDisconnect = new Client.Callback(DisconnectCallback);
            _messageStack = new MessageStack<GameMessage>(500);
            _infoStack = new MessageStack<string>(10);
            _errorStack = new MessageStack<string>(10);

            if (currentInstance == null)
                currentInstance = this;
            else
                throw new Exception("only one instance of client state allowed");
        }
Ejemplo n.º 2
0
 void DisconnectCallback(GameMessage message)
 {
     try
     {
         _infoStack.Push(String.Format("Disconnected from server: {0}", message.messageAsString()));
         _client.Dispose();
         _client = null;
     }
     catch (Exception e)
     {
         _errorStack.Push(e.Message);
     }
 }