void OnNewMessages(object state) { Message msg; while (m_connection.TryGetMessage(out msg)) { InvokeMessageHandler((ClientMessage)msg); } m_onNewMessagesInvoked = false; while (m_connection.TryGetMessage(out msg)) { InvokeMessageHandler((ClientMessage)msg); } if (m_connection.IsConnected == false) { trace.TraceInformation("OnDisconnect"); m_world = null; m_state = ClientUserState.Disconnected; if (DisconnectEvent != null) { DisconnectEvent(); } DH.Dispose(ref m_connection); } }
public Client(Socket client) { _socket = client; // // Create a new room for the new connecting client. // var roomManager = RoomManager.GetInstance(); Room = roomManager.CreateNewRoom(this); // // Start the heartbeat timer. // _heartBeatTimer = new Timer(CheckHeartBeatTimer, null, 20000, TimerInterval); // // Set the client user state to default value. // _clientUserState = ClientUserState.InLobby; }
void HandleMessage(LogOnReplyBeginMessage msg) { m_state = ClientUserState.ReceivingLoginData; this.PlayerID = msg.PlayerID; this.IsSeeAll = msg.IsSeeAll; // XXX move to game engine or such this.GameMode = msg.GameMode; }
// XXX add cancellationtoken public async Task LogOn(string name, IProgress <string> prog) { if (m_state != ClientUserState.None) { throw new Exception(); } m_state = ClientUserState.LoggingIn; prog.Report("Logging in"); Send(new Messages.LogOnRequestMessage() { Name = name }); prog.Report("Waiting for logon reply"); bool ok = false; while (true) { var msg = await m_connection.GetMessageAsync(); if (msg == null) { break; } InvokeMessageHandler((ClientMessage)msg); if (msg is LogOnReplyEndMessage) { ok = true; break; } } if (m_connection.IsConnected == false) { throw new Exception("Disconnected"); } if (!ok) { throw new Exception("No LogOnReplyEnd"); } m_state = ClientUserState.LoggedIn; prog.Report("Logged in"); }
// XXX add cancellationtoken public async Task LogOn(string name, IProgress<string> prog) { if (m_state != ClientUserState.None) throw new Exception(); m_state = ClientUserState.LoggingIn; prog.Report("Logging in"); Send(new Messages.LogOnRequestMessage() { Name = name }); prog.Report("Waiting for logon reply"); bool ok = false; while (true) { var msg = await m_connection.GetMessageAsync(); if (msg == null) break; InvokeMessageHandler((ClientMessage)msg); if (msg is LogOnReplyEndMessage) { ok = true; break; } } if (m_connection.IsConnected == false) throw new Exception("Disconnected"); if (!ok) throw new Exception("No LogOnReplyEnd"); m_state = ClientUserState.LoggedIn; prog.Report("Logged in"); }
public void Read(System.IO.BinaryReader reader) { user.Read(reader); newUserState = (ClientUserState)reader.ReadByte(); }
public ClientUser(IConnection connection) { m_state = ClientUserState.None; m_connection = connection; }
void OnNewMessages(object state) { Message msg; while (m_connection.TryGetMessage(out msg)) InvokeMessageHandler((ClientMessage)msg); m_onNewMessagesInvoked = false; while (m_connection.TryGetMessage(out msg)) InvokeMessageHandler((ClientMessage)msg); if (m_connection.IsConnected == false) { trace.TraceInformation("OnDisconnect"); m_world = null; m_state = ClientUserState.Disconnected; if (DisconnectEvent != null) DisconnectEvent(); DH.Dispose(ref m_connection); } }