Пример #1
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.");
        }
Пример #2
0
        protected void HandleJoinChannelPacket(Packet packet)
        {
            short senderId  = BitConverter.ToInt16(packet.Data, 0);
            short channelId = BitConverter.ToInt16(packet.Data, 2);

            Channel channel = FindChannel(channelId);

            if (channel == null)
            {
                return;
            }

            ServerClient client = FindClient(senderId);

            if (client == null)
            {
                return;
            }

            client.SwitchChannel(channel);
            SignedPacket sendingPacket = new SignedPacket(Messages.SWAPCHANNEL, client.Id, BitConverter.GetBytes(channel.channelId).ToArray());

            SendToClients(0, sendingPacket, senderId);
        }