Esempio n. 1
0
 public void RegisterPacket(Packet packet)
 {
     var name = packet.GetType().Name;
     _packetCache[name] = packet.Copy();
     _mapping[name] = _nextType;
     _nextType++;
 }
 public override void ReceivePacket(Packet packet, Client client)
 {
     if (packet is AuthenticateUserPacket)
         HandleAuthenticatePacket(packet as AuthenticateUserPacket, client);
     else if (packet is UserDisconnectPacket)
         HandleDisconnectRequest(packet as UserDisconnectPacket, client);
     else if (packet is StartGamePacket)
         HandleStartRequest(packet as StartGamePacket);
     else if (packet is PlayCardRequestPacket)
         HandlePlayCardRequest(packet as PlayCardRequestPacket, client);
 }
Esempio n. 3
0
        public override void ReceivePacket(Packet packet, Client client)
        {
            if (!IsAuthenticated(client))
            {
                var authPacket = packet as AuthRequestPacket;
                if (authPacket == null) return;

                HandleAutheticatePacket(authPacket, client);
                return;
            }

            var chatPacket = packet as ChatPacket;
            var nick = nickTable[client];

            if (chatPacket == null) return;
            if (String.IsNullOrEmpty(chatPacket.Message)) return;

            SendPacket(MakePacket("{0}: {1}".format(nick, chatPacket.Message)));
        }
Esempio n. 4
0
 /// <summary>
 ///   <para> Writes a packet to the client. </para>
 ///   para>
 ///   <para> Messages are queued and a thread proccesses them in the order they were enqueued </para>
 /// </summary>
 public void WritePacket(Packet packet)
 {
     Write(packet.AsByteArray());
 }
Esempio n. 5
0
 /// <summary>
 ///   Called when we try to send a message to a client but that send fails.
 /// </summary>
 protected virtual void OnSendPacketException(Packet packet, string reason, Client client)
 {
     // Nothing to do if we didn't track the client
     if (!ClientTable.Contains(client))
     {
         Log.Debug(
             "Server:InvalidFunctionCall:OnSendPacketException:UnknownClient:Data:IP:<{0}>".format(
                 client.GetIP));
         return;
     }
     const bool success = false;
     var parameters = new Dictionary<string, string>
                          {
                              {"Exception:ServerException", "SendPacketFailedException"},
                              {"SendPacketFailedException:Data:Value", packet.ToString()},
                              {"SendPacketFailedException:Data:Reason", reason}
                          };
     var e = new ServerEventArgs(success, client, parameters);
     Console.WriteLine("OnSendPacketException");
     Disconnect(client, e);
 }
Esempio n. 6
0
 /// <summary>
 ///   See <see cref="IServer.SendPacket" />
 /// </summary>
 public virtual void SendPacket(Packet packet, params Client[] clients)
 {
     if (!IsRunning)
     {
         Log.Debug("Server:InvalidFunctionCall:SendPacket:Data:Packet:<{0}>".format(packet));
         return;
     }
     if (clients.Length == 0)
         clients = ClientTable.GetValuesType2().ToArray(); // Allows us to safely remove from the underlying structure
     Log.Debug("Server:SendPacket:Data:Packet:<{0}>".format(packet));
     foreach (var client in clients)
         try
         {
             client.WritePacket(packet);
         }
         catch
         {
             OnSendPacketException(packet, "Unknown", client);
         }
 }
Esempio n. 7
0
 /// <summary>
 ///   See <see cref="IServer.ReceivePacket" />
 /// </summary>
 public virtual void ReceivePacket(Packet packet, Client client)
 {
     if (!IsRunning)
         Log.Debug("Server:InvalidFunctionCall:ReceivePacket:Data:Packet:<{0}>".format(packet));
 }