private void OnClientMessage(byte[] message) { // Read RCON message PacketModel packet = PacketModel.ReadData(message); // Check if packet is server response (0) or invalid // RCON auth response (-1) if (packet.Id != 0 && packet.Id != -1) { return; } switch (packet.Type) { case PacketTypeModel.AUTH_RESPONSE: { // Read packet as AuthResponse var authPacket = packet as AuthReponsePacketModel; if (!authPacket.WasSuccessful()) { _outputFunction.Invoke("Failed to connect: incorrect password."); break; } _outputFunction("Successfully authenticated!"); break; } case PacketTypeModel.RESPONSE_VALUE: { if (string.IsNullOrEmpty(packet.Body)) { break; } _outputFunction(packet.Body); break; } case PacketTypeModel.DATA: { if (string.IsNullOrEmpty(packet.Body)) { break; } _outputFunction(packet.Body); break; } default: { _outputFunction($"Received uncaught packet of type {packet.Type}"); break; } } packet.Dispose(); }
private void OnMessage(object sender, MessageEventArgs e) { PacketModel packet = PacketModel.ReadData(e.Data); if (string.IsNullOrEmpty(packet.Message)) { return; } if (packet.Type == "Chat") { ChatPacketModel chat = packet as ChatPacketModel; _outputFunction($"[CHAT] | {chat.Username} [{chat.UserID}]: {chat.ChatMessage}"); return; } if (packet.Type == "Generic") { _outputFunction(packet.Message); return; } _outputFunction($"Error! Uncaught packet type: {packet.Type}"); }