public void sendUpdateCommentToAll(CommentInfo c)
 {
     byte[] message = ServerMessages.UpdateCommentMessage(controller, c);
     foreach (User u in controller.usersViewing)
     {
         u.sendBinary(message);
     }
 }
 public void sendMoveThreadToTopToAll(ThreadInfo t)
 {
     byte[] message = ServerMessages.MoveToTopThreadMessage(controller, t);
     foreach (User u in controller.usersViewing)
     {
         u.sendBinary(message);
     }
 }
        public void sendAllChats(User u)
        { //Send only last 20
            int start = 0;

            // if (chats.length > 20) {
            //   start = chats.length - 20;
            // }
            for (int i = start; i < chats.Count; i++)
            {
                u.sendBinary(ServerMessages.ChatMessage(chats[i]));
            }
        }
 public void addChat(User u, String chat)
 {
     chat = $"{u.account.name}: " + chat;
     chats.Add(chat);
     //Send chat to all connected websockets
     byte[] chatMsg = ServerMessages.ChatMessage(chat);
     for (int i = 0; i < server.GetNetworking().users.Count; i++)
     {
         User u2 = server.GetNetworking().users[i];
         u2.sendBinary(chatMsg);
     }
 }
Ejemplo n.º 5
0
        public void onMessage(User u, Dictionary <string, object> message)
        {
            if ((string)message["Title"] == "Set Avatar" && u.account != null)
            {
                u.account.avatarURL = (string)message["AvatarURL"];
            }
            if ((string)message["Title"] == "Get Avatar" && u.account != null)
            {
                u.sendBinary(ServerMessages.GetAvatarMessage(u.account.avatarURL));
            }
            if ((string)message["Title"] == "Login" && u.account == null)
            {
                if (server.accountController.accountExists((string)message["Name"], (string)message["Password"]))
                {
                    u.account = server.accountController.getAccount((string)message["Name"], (string)message["Password"]);
                    u.sendBinary(ServerMessages.LoggedInMessage(u.account.name, u.account.password));

                    server.accountLoggedIn(u);
                }
                else
                {
                    //Send login failure
                    u.sendBinary(ServerMessages.LoginFailedMessage());
                }
            }
            if ((string)message["Title"] == "Logout" && u.account != null)
            {
                //Perhaps an account method can be called for saving or other logic
                u.account = null;
                //Send logout notification
                u.sendBinary(ServerMessages.LoggedOutMessage());
                server.accountLoggedOut(u);
            }
            if ((string)message["Title"] == "Register" && u.account == null)
            {
                if (server.accountController.accountNameExists((string)message["Name"]))
                {
                    u.sendBinary(ServerMessages.RegisterFailedMessage());
                }
                else
                {
                    u.account = server.accountController.createAccount((string)message["Name"], (string)message["Password"], (string)message["Email"]);
                    //Send login notification
                    u.sendBinary(ServerMessages.LoggedInMessage(u.account.name, u.account.password));
                    server.accountLoggedIn(u);
                }
            }
        }
        public void sendListUpdateToAll()
        {
            String list     = $"Online({users.Count}): ";
            int    guests   = 0;
            bool   addComma = false;

            foreach (User u in users)
            {
                if (u.account != null)
                {
                    if (addComma)
                    {
                        list += ", ";
                    }
                    else
                    {
                        addComma = true;
                    }
                    list += u.account.name;
                }
                else
                {
                    guests += 1;
                }
            }
            if (addComma)
            {
                list += $" and {guests} Guests";
            }
            else
            {
                list += $"{guests} Guests";
            }

            byte[] message = ServerMessages.ChatOnlineList(list);
            foreach (User u in users)
            {
                u.sendBinary(message);
            }
            Console.WriteLine(list);
        }
 public void sendAllThreadsToUser(User u)
 {
     u.sendBinary(ServerMessages.AllThreadsMessage(controller));
 }