Beispiel #1
0
        // Get clients query result
        public static bool GetClientsQueryResult(Packets.ClientQueryPacket packet,
                                                 ClientStatus current,
                                                 ref List <Models.Client> result,
                                                 string query,
                                                 out string message)
        {
            try
            {
                if (CheckBasics(current, ClientStatus.Status.Disconnected, packet.Alea, out message))
                {
                    var db = new Models.ServerDatabase();

                    // Fill the lists with the requests
                    result = db.Clients
                             .Where(r => r.Username.Contains(query) ||
                                    r.FirstName.Contains(query) ||
                                    r.LastName.Contains(query))
                             .ToList();


                    message = "Cool!";
                    return(true);
                }
                else
                {
                    message = "Client query List Error: " + message;
                    return(false);
                }
            }
            catch (SqlException)
            {
                message = "Client query List Error: Database error.";
                return(false);
            }
        }
        public static void ClientsQuery(byte[] data, Server server, IPEndPoint ip)
        {
            string message = "";

            // Unpack the petition
            Packets.ClientQueryPacket cPacket = Packet.Unpack <ClientQueryPacket>(data);

            List <Models.Client> queryResult = null;

            server.DebugInfo("Client query  list requested by " + cPacket.Username);
            server.DebugInfo(cPacket.ToString());

            if (ClientsManagement.GetClientsQueryResult(cPacket, server.GetClient(cPacket.Username),
                                                        ref queryResult, cPacket.Query, out message))
            {
                // List filled correctly
                server.Udp.SendMessage(new ClientQueryPacket(PacketTypes.ClientsQueryAck,
                                                             cPacket.Alea,
                                                             queryResult).Pack(),
                                       ip);

                server.DebugInfo("Client list query requests sended correctly to + " + cPacket.Username);
            }
            else
            {
                server.DebugInfo("Client list query requests error: " + message);
                server.Udp.SendError(message, ip);
            }
        }