Exemple #1
0
 private void SendClientList()
 {
     DisplayInformation("Sending All Clients a list of currently available clients"); // This is not how we would normally do this
     foreach (string cid in clientList)
     {
         foreach (string cid2 in clientList)
         {
             byte[] d = ConvertStringToBytes("CList::" + cid);
             server.SendData(cid2, d);
         }
     }
 }
        /// <summary>
        /// Data Received from connected Clients
        /// </summary>
        /// <param name="Sender">
        /// String: The Sender's Unique ID
        /// </param>
        /// <param name="Recipient">
        /// String: The Recipient's Unique ID. If 0, then it is for the Server
        ///         Otherwise it is to be redirected to another Client
        /// </param>
        /// <param name="Data">
        /// String: The message to process or forward
        /// </param>
        void server_DataTransferred(string Sender, string Recipient, byte[] Data)
        {
            string message = ConvertBytesToString(Data);

            if (Recipient == "0") // The Server's ID
            {
                Log(Resources.ReceivedCommandFromClient + Sender + Resources.ForThisServer);


                if (message.StartsWith(CLOSINGCommand))
                {
                    DoClientClosing(Sender);
                }
                else if (message.StartsWith(REGISTRATIONCommand))
                {
                    DoRegistration(Sender, message);
                }
                else if (message.StartsWith(LOGINCommand))
                {
                    DoLogin(Sender, message);
                }
                else if (message.StartsWith(RELOGINCommand))
                {
                    DoRelogin(Sender, message);
                }
                else if (message.StartsWith(AddFriendCommand))
                {
                    DoAddFriend(Sender, message);
                }
                else if (message.StartsWith(GetFriendsList))
                {
                    // Get the list of friends from the database and Their Online Status and send to the calling client
                }
                else
                {
                    SendNotImplementedYet(Sender, message);
                    this.Log(Resources.ReceivedCommandFromClient + Sender + Resources.ForThisServer_ + message);
                }
            }
            else
            {
                server.SendData(Recipient, Data); // Just forward the message to the correct Recipient.
            }
        }
Exemple #3
0
        private void Server_DataReceived(string ID, byte[] Data)
        {
            //Console.WriteLine(ID + ": " + Network.ConvertBytesToString(Data));
            string received = Network.ConvertBytesToString(Data);

            if (received == "getAllCreatures")
            {
                string data = NetContainer.GetAllCreatures(ID);
                server.SendData(ID, Network.ConvertStringToBytes(data));
            }
            else
            {
                foreach (var player in connectedPlayers)
                {
                    if (player.playerId == ID)
                    {
                        player.ParceFromServer(Network.ConvertBytesToString(Data));
                        break;
                    }
                }
            }
        }
Exemple #4
0
        void Mandarcartaronda1(string clientID, int random, string pos)
        {
            switch (random)
            {
            case 1:
                Server.SendData(clientID, ConvertStringToBytes("*oro1" + pos));
                break;

            case 2:
                Server.SendData(clientID, ConvertStringToBytes("*esp2" + pos));
                break;

            case 3:
                Server.SendData(clientID, ConvertStringToBytes("*esp3" + pos));
                break;

            case 4:
                Server.SendData(clientID, ConvertStringToBytes("*oro4" + pos));
                break;

            case 5:
                Server.SendData(clientID, ConvertStringToBytes("*copa5" + pos));
                break;

            case 6:
                Server.SendData(clientID, ConvertStringToBytes("*copa6" + pos));
                break;

            case 7:
                Server.SendData(clientID, ConvertStringToBytes("*esp7" + pos));
                break;

            case 8:
                Server.SendData(clientID, ConvertStringToBytes("*esp8" + pos));
                break;

            case 9:
                Server.SendData(clientID, ConvertStringToBytes("*basto9" + pos));
                break;

            case 10:
                Server.SendData(clientID, ConvertStringToBytes("*copa10" + pos));
                break;

            case 11:
                Server.SendData(clientID, ConvertStringToBytes("*copa11" + pos));
                break;

            case 12:
                Server.SendData(clientID, ConvertStringToBytes("*basto12" + pos));
                break;
            }
        }
        private void Server_DataReceived(string iD, byte[] data)
        {
            string message = ConvertBytesToString(data);

            if (iD == "0")
            {
                DisplayInformation("Received Command From Client " + iD + " for this Server");


                if (message.StartsWith("CLOSING"))
                {
                    loggedInUsers.Remove(iD);
                    DisplayConnection(loggedInUsers.Count.ToString());
                    DisplayInformation("Client " + iD + " is Closing");
                }
                else if (message.StartsWith("REGISTRATION"))
                {
                    // Message = REGISTRATION:<USERNAME>:<PASSWORD>
                    if (registeredUsers.ContainsKey(message.Split(':')[1].ToString()))
                    {
                        server.SendData(iD, ConvertStringToBytes("ERROR:That email is already registered."));
                        DisplayInformation("Client " + iD + "ERROR:That email is already registered.");
                    }
                    else
                    {
                        registeredUsers.Add(message.Split(':')[1].ToString(), message.Split(':')[2].ToString());
                        loggedInUsers.Add(iD, DateTime.Now.ToString());
                        DisplayConnection(loggedInUsers.Count.ToString());
                        server.SendData(iD, ConvertStringToBytes("SUCCESS:Logged On"));
                        DisplayInformation("Client " + iD + "SUCCESS registered.");
                    }
                }
                else if (message.StartsWith("LOGIN"))
                {
                    // Message = LOGIN:<USERNAME>:<PASSWORD>
                    string[] parts = message.Split(':');
                    if (registeredUsers.ContainsKey(parts[1].ToString()))
                    {
                        string res = "";
                        if (registeredUsers.TryGetValue(parts[1].ToString(), out res))
                        {
                            if (res == parts[2])
                            {
                                // Successfully logged in
                                int newSenderId = (loggedInUsers.Count + 1);
                                server.SendData(iD, ConvertStringToBytes("ID:" + newSenderId.ToString()));
                                loggedInUsers.Add(newSenderId.ToString(), DateTime.Now.ToString());
                                DisplayConnection(loggedInUsers.Count.ToString());
                                DisplayInformation("Client " + parts[1].ToString() + " SUCCESS Logged in.");
                            }
                            else
                            {
                                server.SendData(iD, ConvertStringToBytes("ERROR:Login Details Not Recognized"));
                                DisplayInformation("Client " + iD + "ERROR:Login Details Not Recognized");
                            }
                        }
                    }
                    else
                    {
                        server.SendData(iD, ConvertStringToBytes("ERROR:Login Details Not Recognized"));
                        DisplayInformation("Client " + iD + "ERROR:Login Details Not Recognized");
                    }
                }
                else
                {
                    DisplayInformation("Received Command From Client " + iD + " for this Server: " + message);
                }
            }
            else
            {
                DisplayInformation("Received Command From Client " + iD + " for this Server: " + message);
            }
        }
        //FUNCTION:
        //PURPOSE: Send a single client a list of the other clients connected.
        private void SendClientList(string id)
        {
            DisplayInformation("Sending Client List To: " + id);
            string listOfClients = "CLIST::";

            foreach (string cid in clientList)
            {
                listOfClients += "::" + cid;
            }
            byte[] d = ConvertStringToBytes(listOfClients);
            server.SendData(id, d);
        }