Ejemplo n.º 1
0
 private void startAuthentication(String jsonMessage, IWebSocketConnection socket)
 {
     Guid socketID = socket.ConnectionInfo.Id;
     Console.WriteLine("JSON: " + jsonMessage);
     this.user = JsonConvert.DeserializeObject<User>(jsonMessage);
     if (!isUserNameAlreadyInUse())
     {
         ludo.Users.Add(this.user);
         Console.WriteLine("Online Users:");
         for (int i = 0; i < ludo.Users.Count; i++)
         {
             Console.WriteLine("\t-" + ludo.Users[i].UserName);
         }
     }
     else
     {
         socket.Send("Username is already in use");
     }
 }
Ejemplo n.º 2
0
        private void startAuthentication(String jsonMessage, IWebSocketConnection socket)
        {
            this.user = JsonConvert.DeserializeObject<User>(jsonMessage); // Serialize from Json to Object
            this.user.SocketID = socket.ConnectionInfo.Id;
            this.user.Handshaked = true;

            if (isUserNameAvailable())
            {
                this.user.IsUserNameAvailable = true;
                //this.user.IP = socket.ConnectionInfo.ClientIpAddress;
                Main.ludo.Users.Add(this.user); // Add this User for the online user list
                setUserListID();

                socket.Send(JsonConvert.SerializeObject(this.user)); // Desiralize from Object to Json | Sending 1 user object
            }
            else
            {
                // Username isn't available
                this.user.IsUserNameAvailable = false;
                //this.user.UserListIndex = -1;
                socket.Send(JsonConvert.SerializeObject(this.user));
            }
        }