Exemple #1
0
 public void ClientRequestPacket(ServerClient client, short packetId)
 {
     if (packetId == (short)Messages.GETUSERS)
     {
         client.Send(new Packet(Messages.GETUSERS, SerializeUsers()));
     }
     else if (packetId == (short)Messages.CONNECTED)
     {
         Console.WriteLine("Ressending CONNECT packet! ----------------------------");
         client.Send(new SignedPacket(Messages.CONNECTED, client.Id));
     }
 }
Exemple #2
0
 public void Join(ServerClient client)
 {
     if ((clients.Count >= channelLimit || channelLimit == 0) && client.joinPower > this.joinPower)
     {
         clients.Add(client);
         client.Send(new Packet(Messages.JOINCHANNEL, BitConverter.GetBytes(this.channelId)));
         if (ClientJoinedChannel != null)
         {
             ClientJoinedChannel(this, client);
         }
     }
 }
Exemple #3
0
        protected void HandleConnectPacket(Packet packet)
        {
            string name = Data.MakeSafe(Encoding.ASCII.GetString(packet.Data));

            ServerClient newClient = new ServerClient(packet.Sender, name, ++CLIENT_NEXTID);

            newClient.ClientDisconnected  += ClientDisconnect;
            newClient.ClientRequestPacket += ClientRequestPacket;
            newClient.SwitchChannel(FindChannel(defaultChannel));
            newClient.Send(new Packet(Messages.GETUSERS, SerializeUsers()));
            SignedPacket newPacket = new SignedPacket(Messages.CONNECTCHANNEL, newClient.Id, BitConverter.GetBytes(defaultChannel).Concat(Encoding.ASCII.GetBytes(newClient.name)).ToArray());

            SendToClients(0, newPacket, newClient.Id);

            Console.WriteLine(newClient.name + " Has Connected.");
        }
Exemple #4
0
        protected void HandleServerMessagePacket(Packet packet)
        {
            ServerClient user = FindClient(BitConverter.ToInt16(packet.Data, 0));

            if (user != null)
            {
                string message = Encoding.ASCII.GetString(packet.Data.Skip(2).ToArray());
                if (user.IsAdmin)
                {
                    Console.WriteLine(user.name + ": " + message);
                    SendToClients(0, packet);
                }
                else
                {
                    user.Send(new Packet(Messages.SERVERMESSAGE, BitConverter.GetBytes(0).Concat(Encoding.ASCII.GetBytes("Insuffciant Permissions.")).ToArray()));
                }
            }
        }