Exemplo n.º 1
0
 static void Main()
 {
     try
     {
         Server     = new ServerObj();
         ThreadList = new Thread(new ThreadStart(Server.Listen));
         ThreadList.Start();
     }
     catch (Exception ex)
     {
         Server.Disconnect();
         Console.WriteLine(ex.Message);
         Console.ReadLine();
     }
 }
Exemplo n.º 2
0
        internal void Close()
        {
            if (User is not null)
            {
                using (DB DB = new DB())
                {
                    User.Status          = Status.Offline;
                    DB.Entry(User).State = EntityState.Modified;
                    DB.SaveChanges();
                }

                GetUser(User);
            }
            ServerObj.RemoveConnection(this);

            if (Stream != null)
            {
                Stream.Close();
            }
            if (Client != null)
            {
                Client.Close();
            }
        }
Exemplo n.º 3
0
 internal ClientObject(TcpClient client, ServerObj serverObj)
 {
     Client    = client;
     ServerObj = serverObj;
 }
Exemplo n.º 4
0
        private void GetServer(Server server)
        {
            if (server is null)
            {
                throw new ArgumentNullException("server is null", nameof(server));
            }

            if (server.ActionOnServer == ActionOnServer.Connect)
            {
                using (DB db = new DB())
                {
                    var TC = db.TextChat
                             .Include(x => x.Message)
                             .Where(x => x.IDServer == server.ID)
                             .ToList();

                    foreach (var item in TC)
                    {
                        item.Message = db.Message
                                       .Include(x => x.ServerUser)
                                       .Where(x => x.IDTextChat == item.ID)
                                       .ToList();
                    }

                    SendObjectToClient(TC);

                    var SU = db.ServerUser
                             .Where(x => x.IDServer == server.ID)
                             .ToList();

                    foreach (var item in SU)
                    {
                        item.User = db.User.FirstOrDefault(x => x.ID == item.IDUser);
                        if (item.User is null)
                        {
                            Console.WriteLine("item.User is null");
                        }
                    }

                    SendObjectToClient(SU);

                    ServerUser = db.ServerUser
                                 .FirstOrDefault(x => x.IDUser == User.ID && x.IDServer == server.ID);
                }
                if (ServerUsers is not null)
                {
                    ServerObj.RemoveConnection(this);
                }

                ServerObj.AddConnection(this, server);

                return;
            }
            using DB DB = new DB();

            var obj = new Object();

            switch (server.ActionForServer)
            {
            case ActionForServer.None:
                break;

            case ActionForServer.Search:
                break;

            case ActionForServer.LoudTextChat:
                obj = DB.TextChat.Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.LoudOpinion:
                obj = DB.Opinion.Include(x => x.User).Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.LoudEventLog:
                obj = DB.EventLog.Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.LoudServerUsers:
                var a = DB.ServerUser.Include(x => x.User).Include(x => x.Role).Where(x => x.IDServer == server.ID).ToList();
                a.ForEach(x => x.User.Password = null);
                obj = a;
                break;

            case ActionForServer.LoudChat:
                obj = DB.Chat.Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.LoudRole:
                obj = DB.Role.Include(x => x.RightRole).Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.Loud:
                obj = DB.Server.Find(server.ID);
                break;

            case ActionForServer.Registration:
                break;

            case ActionForServer.Cheack:
                break;

            default:
                break;
            }
            SendObjectToClient(obj);
        }
Exemplo n.º 5
0
        private void GetServer(Server server)
        {
            if (server is null)
            {
                throw new ArgumentNullException("server is null", nameof(server));
            }

            if (server.ActionOnServer == ActionOnServer.Connect)
            {
                using (DB db = new DB())
                {
                    var s = db.GetServer(server.ID);
                    s.TextChat   = db.GetTextChatAndMessageFromServer(server.ID);
                    s.ServerUser = db.GetServerUserFromServer(server.ID);

                    SendObjectToClient(s.TextChat);
                    SendObjectToClient(s.ServerUser);

                    ServerUser = db.ServerUser
                                 .FirstOrDefault(x => x.IDUser == User.ID && x.IDServer == server.ID);
                }

                if (ServerUsers is not null)
                {
                    ServerObj.RemoveConnection(this);
                }

                ServerObj.AddConnection(this, server);

                return;
            }

            using DB DB = new DB();

            var obj = new Object();

            switch (server.ActionForServer)
            {
            case ActionForServer.Search:
                obj = DB.GetServerSerch(server.Name);
                break;

            case ActionForServer.LoudTextChat:
                obj = DB.GetTextChatFromServer(server.ID);
                break;

            case ActionForServer.LoudOpinion:
                obj = DB.GetOpinions(server.ID);
                break;

            case ActionForServer.LoudEventLog:
                obj = DB.EventLog.Where(x => x.IDServer == server.ID).ToList();
                break;

            case ActionForServer.LoudServerUsers:
                obj = DB.GetServerUserFromServer(server.ID);
                break;

            case ActionForServer.LoudRole:
                obj = DB.Role
                      .Include(x => x.RightRole)
                      .Where(x => x.IDServer == server.ID)
                      .ToList();
                break;

            case ActionForServer.Loud:
                obj = DB.GetServer(server.ID);
                break;

            case ActionForServer.Registration:
                obj = DB.CreateAndGetServerUser(server.ID, User.ID);
                break;

            default:
                break;
            }

            SendObjectToClient(obj);
        }