private void HandleReceived_Connection(MhfConnection connection, MhfPacket packet) { if (!_connectionHandlers.ContainsKey(packet.Id)) { // _logger.LogUnknownIncomingPacket(connection, packet); return; } IConnectionHandler connectionHandler = _connectionHandlers[packet.Id]; if (connectionHandler.ExpectedSize != NoExpectedSize && packet.Data.Size < connectionHandler.ExpectedSize) { _logger.Error(connection, $"Ignoring Packed (Id:{packet.Id}) is smaller ({packet.Data.Size}) than expected ({connectionHandler.ExpectedSize})"); return; } // _logger.LogIncomingPacket(connection, packet); packet.Data.SetPositionStart(); try { connectionHandler.Handle(connection, packet); } catch (Exception ex) { _logger.Exception(connection, ex); } }
private void HandleConnected(ITcpSocket socket) { MhfConnection connection = new MhfConnection(socket, new PacketFactory(_setting)); lock (_lock) { _connections.Add(socket, connection); _logger.Debug($"Clients Count: {_connections.Count}"); } Action <MhfConnection> onClientConnected = ClientConnected; if (onClientConnected != null) { try { onClientConnected.Invoke(connection); } catch (Exception ex) { _logger.Exception(connection, ex); } } _logger.Info(connection, $"Client connected"); }
public void Error(MhfConnection connection, string message, params object[] args) { MhfClient client = connection.Client; if (client != null) { Error(client, message, args); return; } Write(LogLevel.Error, null, $"{connection.Identity} {message}", args); }
public void Exception(MhfConnection connection, Exception exception) { MhfClient client = connection.Client; if (client != null) { Exception(client, exception); return; } Write(LogLevel.Error, null, $"{connection.Identity} {exception}"); }
public override void Handle(MhfConnection connection, MhfPacket packet) { string keySign = packet.Data.ReadCString(); string userId = packet.Data.ReadCString(); string sessionKey = packet.Data.ReadCString(); Logger.Info($"Auth Request: KeySign:{keySign} UserId:{userId} SessionKey:{sessionKey}"); MsgHeadResponse response = new MsgHeadResponse(); Router.Send(response, connection); }
public void LogOutgoingPacket(MhfConnection connection, MhfPacket packet) { MhfClient client = connection.Client; if (client != null) { LogOutgoingPacket(client, packet); return; } if (!_setting.LogIncomingPackets) { return; } MhfLogPacket logPacket = new MhfLogPacket(connection.Identity, packet, MhfLogType.PacketOut); WritePacket(logPacket); }
public abstract void Handle(MhfConnection client, MhfPacket packet);
private void LobbyClientDisconnected(MhfConnection client) { }
private void AuthClientDisconnected(MhfConnection client) { }