Beispiel #1
0
        private static void SendFriendRequest(string MessageString, IClientInfo Client)
        {
            string Sender   = AuxiliaryServerWorker.GetElement(MessageString, "-U ", " -Content");
            string Receiver = AuxiliaryServerWorker.GetElement(MessageString, "-Content ", ".");

            AuxiliaryServerWorker.WriteToConsole("[INFO] User " + Sender + " sent a friend request to " + Receiver);
            string ReceiverIpPort = null;
            bool   FoundOnline    = false;

            foreach (Session Sess in AuxiliaryServerWorker.Sessions)
            {
                if (Sess.Username == Receiver)
                {
                    ReceiverIpPort = Sess.IpPort;
                    FoundOnline    = true;
                }
            }
            if (FoundOnline == true)
            {
                AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientIDFromIPPort(ReceiverIpPort), AuxiliaryServerWorker.MessageByte(MessageString));
                AuxiliaryServerWorker.WriteToConsole("[INFO] Receiver " + Receiver + " received friend request successfully!");
                AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/FriendRequestSent -U " + Receiver));
            }
            else
            {
                AuxiliaryServerWorker.WriteToConsole("[WARN] Receiver " + Receiver + " was not online to receive their friend request");
                AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/FriendRequestOffline -U " + Receiver));
                //Send offline friend req method here?
            }
        }
Beispiel #2
0
        private static void SendStatus(string MessageString, IClientInfo Client)
        {
            string Sender        = AuxiliaryServerWorker.GetElement(MessageString, "-U ", ".");
            string CurrentStatus = AuxiliaryServerWorker.GetStatus(Sender);

            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/SendStatus -Content " + CurrentStatus + "."));//SendStatus -Content Status.
            AuxiliaryServerWorker.WriteToConsole("[INFO] Successully sent " + Sender + "'s status");
        }
Beispiel #3
0
        private static void DoAuthentication(string MessageString, IClientInfo Client) //NewConnection -U Username -P Password.
        {
            string UsernameC = AuxiliaryServerWorker.GetElement(MessageString, "-U ", " -P");
            string Password  = AuxiliaryServerWorker.GetElement(MessageString, "-P ", ".");

            if (AuxiliaryServerWorker.Usernames.Contains(UsernameC))
            {
                if (AuxiliaryServerWorker.Passwords[AuxiliaryServerWorker.Usernames.IndexOf(UsernameC)] == Password)//Client authenticated successfully
                {
                    Session NewSession = new Session()
                    {
                        IpPort         = Client.RemoteIPv4,
                        Username       = UsernameC,
                        Friends        = AuxiliaryServerWorker.GetFriendsList(UsernameC),
                        LoginTime      = DateTime.Now,
                        ProfilePicture = AuxiliaryServerWorker.GetProfilePicture(UsernameC),
                        Status         = AuxiliaryServerWorker.Statuses[AuxiliaryServerWorker.Usernames.IndexOf(UsernameC)]
                    };
                    AuxiliaryServerWorker.Sessions.Add(NewSession);
                    AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/AcceptConnection"));//AcceptConnection
                    AuxiliaryServerWorker.WriteToConsole("[INFO] Client " + UsernameC + " successfully authenticated! Creating new session file...");
                    foreach (Session Sess in AuxiliaryServerWorker.Sessions)
                    {
                        AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientIDFromIPPort(Sess.IpPort), AuxiliaryServerWorker.MessageByte("/UserConnected -U " + UsernameC + "."));
                    }
                    if (File.Exists(UserDirectories + UsernameC + "\\" + UsernameC + "_lastsession.AntSession"))
                    {
                        try
                        {
                            AuxiliaryServerWorker.WriteToConsole("[INFO] Previous session file located. Updating it now...");
                            File.Delete(UserDirectories + UsernameC + "\\" + UsernameC + "_lastsession.AntSession");
                        }
                        catch (Exception exc)
                        {
                            AuxiliaryServerWorker.WriteToConsole("[ERROR] Could not update session file for " + UsernameC + " due to " + exc);
                        }
                    }
                    try
                    {
                        File.WriteAllBytes(UserDirectories + UsernameC + "\\" + UsernameC + "_lastsession.AntSession", AuxiliaryServerWorker.GetSessionBytes(NewSession));
                        AuxiliaryServerWorker.WriteToConsole("[INFO] Successfully appended session file for " + UsernameC);
                    }
                    catch (Exception exc)
                    {
                        AuxiliaryServerWorker.WriteToConsole("[ERROR] Could not append session file for " + UsernameC + " due to " + exc);
                    }
                }
                else
                {
                    AuxiliaryServerWorker.WriteToConsole("[WARN] Client " + UsernameC + " tried to authenticate with a wrong password!");
                }
            }
            else
            {
                AuxiliaryServerWorker.WriteToConsole("[WARN] Address " + Client.RemoteIPv4 + " tried to authenticate with a non-existant username credential!");
            }
        }
Beispiel #4
0
        private static void SendFriendsList(string MessageString, IClientInfo Client)
        {
            string Sender = AuxiliaryServerWorker.GetElement(MessageString, "-U ", ".");

            AuxiliaryServerWorker.WriteToConsole("[INFO] User " + Sender + " requested to update their friends list");
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/SendFriendsList"));
            Thread.Sleep(100);
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.FriendsListBytes(AuxiliaryServerWorker.GetFriendsList(Sender)));
            AuxiliaryServerWorker.WriteToConsole("[INFO Successfully updated friends list for user " + Sender);
        }
Beispiel #5
0
        private static void SendProfilePictures(string MessageString, IClientInfo Client)
        {
            string Sender = AuxiliaryServerWorker.GetElement(MessageString, "-U ", ".");

            AuxiliaryServerWorker.WriteToConsole("[INFO] User " + Sender + " requested to update their profile picture cache");
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/SendProfilePictures")); //SendProfilePictures
            Thread.Sleep(500);
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.ProfilePictureBytes(AuxiliaryServerWorker.ProfilePictures));
            AuxiliaryServerWorker.WriteToConsole("[INFO] Successfully sent profile picture cache to user " + Sender);
        }
Beispiel #6
0
        private static void SendUsers(string MessageString, IClientInfo Client)//SendUsers, byte[] UsersList
        {
            string Sender = AuxiliaryServerWorker.GetElement(MessageString, "-U ", ".");

            AuxiliaryServerWorker.WriteToConsole("[INFO] Sending users list to " + Sender);
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/SendUsernames"));
            Thread.Sleep(100);
            AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.ReturnByteArrayFromStringCollection(AuxiliaryServerWorker.Usernames));
            AuxiliaryServerWorker.WriteToConsole("[INFO] Successfully sent users list to " + Sender);
        }
Beispiel #7
0
        private static void Events_ClientDisconnected(IClientInfo Client, SimpleSockets.DisconnectReason e)
        {
            string Sender = null;

            foreach (Session Sess in AuxiliaryServerWorker.Sessions)
            {
                if (Sess.IpPort == Client.RemoteIPv4)
                {
                    Sender = Sess.Username;
                }
            }
            AuxiliaryServerWorker.WriteToConsole("[INFO] Client " + Client.RemoteIPv4 + " disconnected due to " + e);
            foreach (Session Sess in AuxiliaryServerWorker.Sessions)
            {
                if (Sess.IpPort != Client.RemoteIPv4)
                {
                    AntVaultServer.SendBytes(AuxiliaryServerWorker.GetClientID(Client), AuxiliaryServerWorker.MessageByte("/UserDisonnected -U " + Sender + "."));
                }
            }
            foreach (Session Sess in AuxiliaryServerWorker.Sessions)
            {
                if (Sess.IpPort == Client.RemoteIPv4)
                {
                    Sess.LogoutTime = DateTime.Now;
                    try
                    {
                        File.Delete(UserDirectories + Sess.Username + "\\" + Sess.Username + "_lastsession.AntSession");
                        AuxiliaryServerWorker.WriteToConsole("[INFO] Updating session entry for " + Sess.Username);
                        File.WriteAllBytes(UserDirectories + Sess.Username + "\\" + Sess.Username + "_lastsession.AntSession", AuxiliaryServerWorker.GetSessionBytes(Sess));
                        AuxiliaryServerWorker.WriteToConsole("[INFO] Updated session for " + Sess.Username + " successfully");
                        AuxiliaryServerWorker.Sessions.Remove(Sess);
                    }
                    catch (Exception exc)
                    {
                        AuxiliaryServerWorker.WriteToConsole("[ERROR] Could not update session entry for " + Sess.Username + " due to" + exc);
                    }
                    break; //No wasted resources
                }
            }
        }