Exemplo n.º 1
0
 public List <string> GetServerDatabaseList(ServerModel server)
 {
     try
     {
         string query  = "SELECT name FROM master.sys.databases";
         var    dblist = new List <string>();
         using (SqlCommand cmd = new SqlCommand(query, ConnectionManager.Connection(server)))
         {
             using (SqlDataReader dr = cmd.ExecuteReader())
             {
                 while (dr.Read())
                 {
                     dblist.Add(dr["name"].ToString());
                 }
                 return(dblist);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         ConnectionManager.Close();
     }
     return(null);
 }
        /// <summary>
        /// Insert a new record about a server.
        /// </summary>
        /// <param name="model">The server.</param>
        /// <returns>The server's identifier that has been inserted.</returns>
        public Int64 InsertServer(ServerModel model)
        {
            logger.WriteTrace("Inserting {0} into the database...", model);

            if (model.Id != 0)
            {
                throw new ArgumentException("Model's identifier should be 0. Now it is " + model.Id, "model");
            }

            logger.WriteTrace("Converting {0} into the entity...", model);
            ServerEntity entity = serverConverter.Convert(model);

            logger.WriteTrace("{0} has been converted. Generating sql command for {1}...", model, entity);

            string sqlCommand = string.Format(insertStatement, sqlSettings.WiseQueueDefaultSchema, serverTableName, entity.Name, entity.Description, entity.HeartbeatLifetime);

            logger.WriteTrace("The SqlCommand has been generated. Result: {0}", sqlCommand);

            logger.WriteTrace("Executing sql command...");
            using (IDbConnection connection = connectionFactory.CreateConnection())
            {
                using (IDbCommand command = connection.CreateCommand())
                {
                    command.CommandText = sqlCommand;
                    Int64 result = (Int64)command.ExecuteScalar();

                    logger.WriteTrace("The command has been executed. Entity identifier is {0}", result);
                    return(result);
                }
            }
        }
Exemplo n.º 3
0
        private void RefreshRooms()
        {
            if (!ServerModel.IsInited)
            {
                return;
            }

            using (var server = ServerModel.Get())
            {
                var roomsNames = server.Rooms.Keys.ToArray();

                foreach (string name in roomsNames)
                {
                    if (string.Equals(name, ServerModel.MainRoomName))
                    {
                        continue;
                    }

                    if (server.Rooms[name].Count == 0)
                    {
                        server.Rooms.Remove(name);
                    }
                }
            }
        }
Exemplo n.º 4
0
        // 서버메뉴리스트에서 서버를 컨넥팅 동작을 할 때 작동
        public void Refresh(ServerModel si)
        {
            this.EnableConnect = si;

            if (tabControl.SelectedIndex == 0)
            {
                EncryptTab.current.Refresh();
            }
            else if (tabControl.SelectedIndex == 1)
            {
                DecryptTab.current.Refresh();
            }
            else if (tabControl.SelectedIndex == 2)
            {
                DataBaseInfo.RefreshUi();
            }
            else if (tabControl.SelectedIndex == 3)
            {
                DataBaseInfo.RefreshUi();
            }

            if (this.EnableConnect?.SshManager?.IsConnected == true)
            {
                ConnectedServerName = this.EnableConnect?.Name;
            }
        }
Exemplo n.º 5
0
        public void Run(ServerCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentNullException("RoomName");
            }

            using (var server = ServerModel.Get())
            {
                if (server.Rooms.ContainsKey(receivedContent.RoomName))
                {
                    ServerModel.API.SendSystemMessage(args.ConnectionId, "Комната с таким именем уже создана, выберите другое имя.");
                    return;
                }

                var creatingRoom = receivedContent.Type == RoomType.Chat
          ? new Room(args.ConnectionId, receivedContent.RoomName)
          : new VoiceRoom(args.ConnectionId, receivedContent.RoomName);

                server.Rooms.Add(receivedContent.RoomName, creatingRoom);

                var sendingContent = new ClientRoomOpenedCommand.MessageContent
                {
                    Room  = creatingRoom,
                    Type  = receivedContent.Type,
                    Users = creatingRoom.Users.Select(nick => server.Users[nick]).ToList()
                };

                ServerModel.Server.SendMessage(args.ConnectionId, ClientRoomOpenedCommand.Id, sendingContent);
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Creates an instance of the chat room view model and resolves its dependencies
        /// </summary>
        /// <param name="eventAggregator"></param>
        /// <param name="networkConnectionController"></param>
        /// <param name="currentUser"></param>
        /// <param name="chatManager"></param>
        /// <param name="regionManager"></param>
        /// <param name="overlayService"></param>
        public ChatRoomViewModel(IEventAggregator eventAggregator, INetworkConnectionController networkConnectionController, ICurrentUser currentUser, IChatManager chatManager, IRegionManager regionManager, IOverlayService overlayService)
        {
            //assigns local variables
            _eventAggregator             = eventAggregator;
            _networkConnectionController = networkConnectionController;
            _currentUser    = currentUser;
            _chatManager    = chatManager;
            _regionManager  = regionManager;
            _overlayService = overlayService;

            _eventAggregator.GetEvent <UserLoginEvent>().Subscribe(UserLogin);
            _eventAggregator.GetEvent <OfflineUsersLoadedEvent>().Subscribe(() => IsConnectAllowed = true);
            _eventAggregator.GetEvent <UserEditedEvent>().Subscribe((user) => User = user);

            //Sets up the basic server settings
            ServerModel              = new ServerModel();
            ServerModel.IpAddress    = "192.168.1.97";
            ServerModel.Port         = 2500;
            ServerModel.ServerStatus = ServerStatus.Disconnected;

            //Sets up command executions
            ServerConnectCommand      = new DelegateCommand(Connect);
            ToggleBaseCommand         = new DelegateCommand <object>(ToggleBaseColor);
            CurrentUserClickedCommand = new DelegateCommand(CurrentUserClicked);
            LogoutCommand             = new DelegateCommand(Logout);
        }
Exemplo n.º 7
0
 private void FilePathSetting_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (IsCombBoxSelectionChanged)
     {
         ComboBox selectItem = (ComboBox)sender;
         if ((ServerModel)selectItem.SelectedItem == null)
         {
             return;
         }
         using (SqliteWrapper sqliteWrapper = new SqliteWrapper(true))
         {
             try
             {
                 ServerModel nowTarget = sqliteWrapper.ExecuteSelect <ServerModel>().FirstOrDefault(a => a.target == 1);
                 nowTarget.target = 0;
                 sqliteWrapper.ExecuteUpdata(nowTarget);
                 ServerModel selectTarget = sqliteWrapper.ExecuteSelectOne <ServerModel>(((ServerModel)selectItem.SelectedItem).id);
                 selectTarget.target = 1;
                 sqliteWrapper.ExecuteUpdata(selectTarget);
                 sqliteWrapper.Commit();
             }
             catch
             {
                 sqliteWrapper.RollBack();;
             }
         }
     }
     IsCombBoxSelectionChanged = true;
 }
Exemplo n.º 8
0
        protected override void OnRun(MessageContent content, ServerCommandArgs args)
        {
            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentNullException("RoomName");
            }

            using (var server = ServerModel.Get())
            {
                if (server.Rooms.ContainsKey(content.RoomName))
                {
                    ServerModel.Api.SendSystemMessage(args.ConnectionId, "Комната с таким именем уже создана, выберите другое имя.");
                    return;
                }

                var creatingRoom = content.Type == RoomType.Chat
          ? new Room(args.ConnectionId, content.RoomName)
          : new VoiceRoom(args.ConnectionId, content.RoomName);

                server.Rooms.Add(content.RoomName, creatingRoom);

                var sendingContent = new ClientRoomOpenedCommand.MessageContent
                {
                    Room  = creatingRoom,
                    Type  = content.Type,
                    Users = creatingRoom.Users.Select(nick => server.Users[nick]).ToList()
                };

                ServerModel.Server.SendMessage(args.ConnectionId, ClientRoomOpenedCommand.CommandId, sendingContent);
            }
        }
Exemplo n.º 9
0
        public void Run(ServerCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (string.IsNullOrEmpty(receivedContent.Message))
            {
                throw new ArgumentException("Message");
            }

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentException("RoomName");
            }

            if (!RoomExists(receivedContent.RoomName, args.ConnectionId))
            {
                return;
            }

            using (var server = ServerModel.Get())
            {
                var room = server.Rooms[receivedContent.RoomName];

                if (!room.Users.Contains(args.ConnectionId))
                {
                    ServerModel.API.SendSystemMessage(args.ConnectionId, "Вы не можете отправить сообщение, т.к. не входите в состав этой комнаты.");
                    return;
                }

                if (receivedContent.MessageId != null && !room.IsMessageBelongToUser(args.ConnectionId, receivedContent.MessageId.Value))
                {
                    ServerModel.API.SendSystemMessage(args.ConnectionId, "Вы не можете редактировать это сообщение.");
                    return;
                }

                Message message = null;
                if (receivedContent.MessageId == null)
                {
                    message = room.AddMessage(args.ConnectionId, receivedContent.Message);
                }
                else
                {
                    message      = room.GetMessage(receivedContent.MessageId.Value);
                    message.Text = receivedContent.Message;
                }

                var sendingContent = new ClientOutRoomMessageCommand.MessageContent
                {
                    Message   = message.Text,
                    RoomName  = receivedContent.RoomName,
                    Sender    = args.ConnectionId,
                    MessageId = message.Id
                };

                foreach (string user in room.Users.Where(u => u != null))
                {
                    ServerModel.Server.SendMessage(user, ClientOutRoomMessageCommand.Id, sendingContent);
                }
            }
        }
Exemplo n.º 10
0
        protected override void OnRun(MessageContent content, ServerCommandArgs args)
        {
            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentNullException("RoomName");
            }

            using (var server = ServerModel.Get())
            {
                if (server.Rooms.ContainsKey(content.RoomName))
                {
                    ServerModel.Api.SendSystemMessage(args.ConnectionId, SystemMessageId.RoomAlreadyExist);
                    return;
                }

                var creatingRoom = content.Type == RoomType.Chat
          ? new Room(args.ConnectionId, content.RoomName)
          : new VoiceRoom(args.ConnectionId, content.RoomName);

                server.Rooms.Add(content.RoomName, creatingRoom);

                var sendingContent = new ClientRoomOpenedCommand.MessageContent
                {
                    Room  = creatingRoom,
                    Type  = content.Type,
                    Users = ServerModel.Api.GetRoomUsers(server, creatingRoom)
                };

                ServerModel.Server.SendMessage(args.ConnectionId, ClientRoomOpenedCommand.CommandId, sendingContent);
            }
        }
Exemplo n.º 11
0
    private void InitServerList()
    {
        for (int i = 0; i < 30; i++)
        {
            string     ip         = "127.0.0.1";
            string     name       = string.Format("{0}区 马达加斯加", i + 1);
            int        count      = Random.Range(0, 100);
            GameObject serverItem = null;
            if (count > 50)
            {
                //red
                serverItem = NGUITools.AddChild(ServerGrid.gameObject, RedServerCellPrefab);
            }
            else
            {
                //green
                serverItem = NGUITools.AddChild(ServerGrid.gameObject, GreenServerCellPrefab);
            }

            ServerModel model = serverItem.GetComponent <ServerModel> ();
            model.Name  = name;
            model.IP    = ip;
            model.Count = count;
            ServerGrid.AddChild(serverItem.transform);
        }
    }
Exemplo n.º 12
0
        public virtual void Add()
        {
            Trace.Call();

            var dialog = new ServerDialog(_Parent, null,
                                          Frontend.Session.GetSupportedProtocols(),
                                          _Controller.GetNetworks());

            try {
                int         res    = dialog.Run();
                ServerModel server = dialog.GetServer();
                if (res != (int)Gtk.ResponseType.Ok)
                {
                    return;
                }

                _Controller.AddServer(server);
                _Controller.Save();

                // refresh view
                Load();
            } finally {
                dialog.Destroy();
            }
        }
Exemplo n.º 13
0
        private ArrayList FillArrayListStudent(ServerModel.MdlStudent mdlStudentObj)
        {
            ArrayList userData = new ArrayList();

            userData.Add(mdlStudentObj.Id); //0
            userData.Add(mdlStudentObj.Email); //1
            //leave password null
            userData.Add(""); //2
            userData.Add(mdlStudentObj.Confirmed);//3
            userData.Add(mdlStudentObj.Student);//4
            userData.Add(mdlStudentObj.Score);//5
            userData.Add(mdlStudentObj.NumberOfChildren);//6
            userData.Add(mdlStudentObj.Pet);//7
            userData.Add(mdlStudentObj.NumberOfCohabiters);//8
            userData.Add(mdlStudentObj.Disabled);//9
            userData.Add(mdlStudentObj.DateOfCreation);//10
            userData.Add(mdlStudentObj.Name);//11
            userData.Add(mdlStudentObj.Surname);//12
            userData.Add(mdlStudentObj.Address);//13
            userData.Add(mdlStudentObj.PostCode);//14
            userData.Add(mdlStudentObj.City);//15
            userData.Add(mdlStudentObj.Country);//16
            userData.Add(mdlStudentObj.Phone);//17
            userData.Add("student");//18

            Console.WriteLine("Returning populated arraylist to the client.");
            return userData;
        }
Exemplo n.º 14
0
        private ArrayList FillArrayListLandlord(ServerModel.MdlLandlord mdlLandlordObj)
        {
            ArrayList userData = new ArrayList();

            userData.Add(mdlLandlordObj.Id); //0
            userData.Add(mdlLandlordObj.Email); //1
            //leave password null
            userData.Add(""); //2
            userData.Add(mdlLandlordObj.Confirmed);//3
            userData.Add(null);//4
            userData.Add(null);//5
            userData.Add(null);//6
            userData.Add(null);//7
            userData.Add(null);//8
            userData.Add(null);//9
            userData.Add(mdlLandlordObj.DateOfCreation);//10
            userData.Add(mdlLandlordObj.Name);//11
            userData.Add(mdlLandlordObj.Surname);//12
            userData.Add(mdlLandlordObj.Address);//13
            userData.Add(mdlLandlordObj.PostCode);//14
            userData.Add(mdlLandlordObj.City);//15
            userData.Add(mdlLandlordObj.Country);//16
            userData.Add(mdlLandlordObj.Phone);//17
            userData.Add("landlord");//18

            Console.WriteLine("Returning populated arraylist to the client.");
            return userData;
        }
Exemplo n.º 15
0
        internal Face(ServerModel.Face face)
        {
            if (face != null)
            {
                Id = face.face_id;

                if (face.attribute != null)
                {
                    Age = new Age(face.attribute.age);
                    Gender = new UncertainValue(face.attribute.gender);
                    HasGlasses = new UncertainValue(face.attribute.glass);
                    Race = new UncertainValue(face.attribute.race);
                    Smiling = new UncertainValue(face.attribute.smiling);
                }

                if (face.position != null)
                {
                    Position = new Position(face.position.center);
                    Size = new Size { Width = face.position.width, Height = face.position.height };

                    EyeLeft = new Position(face.position.eye_left);
                    EyeRight = new Position(face.position.eye_right);
                    MouthLeft = new Position(face.position.mouth_left);
                    MouthRight = new Position(face.position.mouth_right);
                    Nose = new Position(face.position.nose);
                }
            }
        }
Exemplo n.º 16
0
        public void InfoReturnListIfHaveOnlyAdvertise()
        {
            var options = new DbContextOptionsBuilder()
                          .UseInMemoryDatabase("InfoAdvertise")
                          .Options;

            using (var context = new DatabaseContext(options))
            {
                var server = new ServerModel
                {
                    endpoint  = "167.42.23.32-1337",
                    name      = "] My P3rfect Server [",
                    gameModes = new List <GameModeModel>
                    {
                        new GameModeModel {
                            value = "DM"
                        },
                        new GameModeModel {
                            value = "TDM"
                        }
                    }
                };

                context.Servers.Add(server);
                context.SaveChanges();
            }

            using (var context = new DatabaseContext(options))
            {
                var controller = new ServersController(context);
                var result     = controller.Info();
                Assert.NotEmpty(result);
            }
        }
Exemplo n.º 17
0
    /// <summary>Sends the server info to the remote server.</summary>
    /// <param name="url">Url of the remote server.</param>
    /// <param name="server">Server information.</param>
    public IEnumerator Post(string url, ServerModel server)
    {
        string jsonData = JsonUtility.ToJson(server);

        using (UnityWebRequest www = UnityWebRequest.Post(url, jsonData))
        {
            www.SetRequestHeader("content-type", "application/json");
            www.uploadHandler.contentType = "application/json";
            www.uploadHandler             = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(jsonData));

            yield return(www.SendWebRequest());

            if (www.isNetworkError)
            {
                Debug.LogError("Server couldn't connect with master-server: \n[" + www.error + "]");
            }
            else
            {
                if (www.isDone)
                {
                    string jsonResult = System.Text.Encoding.UTF8.GetString(www.downloadHandler.data);
                    Debug.Log("Server added to master-server correctly");
                }
            }
        }
    }
Exemplo n.º 18
0
        protected override void OnRun(MessageContent content, ServerCommandArgs args)
        {
            if (string.IsNullOrEmpty(content.RoomName))
            {
                throw new ArgumentException("RoomName");
            }

            if (string.Equals(content.RoomName, ServerModel.MainRoomName))
            {
                return;
            }

            if (!RoomExists(content.RoomName, args.ConnectionId))
            {
                return;
            }

            using (var server = ServerModel.Get())
            {
                var room = server.Rooms[content.RoomName];

                if (!room.Users.Contains(args.ConnectionId))
                {
                    ServerModel.Api.SendSystemMessage(args.ConnectionId, MessageId.RoomAccessDenied);
                    return;
                }

                var roomRefreshedContent = new ClientRoomRefreshedCommand.MessageContent
                {
                    Room  = room,
                    Users = room.Users.Select(nick => server.Users[nick]).ToList()
                };
                ServerModel.Server.SendMessage(args.ConnectionId, ClientRoomRefreshedCommand.CommandId, roomRefreshedContent);
            }
        }
Exemplo n.º 19
0
        private void WindowClosed(object sender, EventArgs e)
        {
            if (ClientModel.IsInited)
            {
                try
                {
                    if (ClientModel.Api != null)
                    {
                        ClientModel.Api.Perform(new ClientUnregisterAction());
                    }
                }
                catch (Exception)
                {
                    // program will be closed and the exception will not affect it.
                }

                ClientModel.Reset();
            }

            if (ServerModel.IsInited)
            {
                ServerModel.Reset();
            }

            Settings.SaveSettings();
        }
Exemplo n.º 20
0
        protected void OnAddServerActionActivated(object sender, EventArgs e)
        {
            Trace.Call(sender, e);

            ServerDialog dialog = null;

            try {
                var controller = new ServerListController(Frontend.UserConfig);
                dialog = new ServerDialog(Parent, null,
                                          Frontend.Session.GetSupportedProtocols(),
                                          controller.GetNetworks());
                int         res    = dialog.Run();
                ServerModel server = dialog.GetServer();
                if (res != (int)Gtk.ResponseType.Ok)
                {
                    return;
                }

                controller.AddServer(server);
                controller.Save();

                // reload server list in join bar
                JoinWidget.InitNetworks(controller.GetNetworks());
            } catch (InvalidOperationException ex) {
                Frontend.ShowError(Parent, _("Unable to add server: "), ex);
            } catch (Exception ex) {
                Frontend.ShowException(Parent, ex);
            } finally {
                if (dialog != null)
                {
                    dialog.Destroy();
                }
            }
        }
Exemplo n.º 21
0
        public virtual void Remove(ServerModel server)
        {
            Trace.Call(server);

            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            Gtk.MessageDialog md = new Gtk.MessageDialog(null,
                                                         Gtk.DialogFlags.Modal,
                                                         Gtk.MessageType.Warning,
                                                         Gtk.ButtonsType.YesNo,
                                                         _("Are you sure you want to delete the selected server?"));
            int result = md.Run();

            md.Destroy();
            if (result != (int)Gtk.ResponseType.Yes)
            {
                return;
            }

            _Controller.RemoveServer(server.Protocol, server.ServerID);
            _Controller.Save();

            // refresh the view
            Load();
        }
Exemplo n.º 22
0
        public ActionResult CreateServer(ServerModel model)
        {
            var serverModel = new Operation <ServerModel>();

            if (ModelState.IsValid)
            {
                try
                {
                    model.CreatedBy = User.Identity.GetUserName();
                    var result = _servMgr.CreateServer(model);
                    serverModel.Succeeded = true;

                    if (serverModel.Succeeded == true)
                    {
                        TempData["message"] = $"Server was successful added";
                        return(RedirectToAction("Index"));
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
            return(View(model));
        }
Exemplo n.º 23
0
        public void Run(ServerCommandArgs args)
        {
            var receivedContent = Serializer.Deserialize <MessageContent>(args.Message);

            if (string.IsNullOrEmpty(receivedContent.RoomName))
            {
                throw new ArgumentException("RoomName");
            }

            if (receivedContent.Users == null)
            {
                throw new ArgumentNullException("Users");
            }

            if (string.Equals(receivedContent.RoomName, ServerModel.MainRoomName))
            {
                ServerModel.API.SendSystemMessage(args.ConnectionId, "Невозможно удалить пользователей из основной комнаты.");
                return;
            }

            if (!RoomExists(receivedContent.RoomName, args.ConnectionId))
            {
                return;
            }

            using (var server = ServerModel.Get())
            {
                Room room = server.Rooms[receivedContent.RoomName];

                if (!room.Admin.Equals(args.ConnectionId))
                {
                    ServerModel.API.SendSystemMessage(args.ConnectionId, "Вы не являетесь администратором комнаты. Операция отменена.");
                    return;
                }

                var sendingContent = new ClientRoomClosedCommand.MessageContent {
                    Room = room
                };

                foreach (var user in receivedContent.Users)
                {
                    if (!room.Users.Contains(user.Nick))
                    {
                        continue;
                    }

                    if (user.Equals(room.Admin))
                    {
                        ServerModel.API.SendSystemMessage(args.ConnectionId, "Невозможно удалить из комнаты администратора.");
                        continue;
                    }

                    room.RemoveUser(user.Nick);

                    ServerModel.Server.SendMessage(user.Nick, ClientRoomClosedCommand.Id, sendingContent);
                }

                RefreshRoom(server, room);
            }
        }
Exemplo n.º 24
0
        public void LoadDatabases()
        {
            tscomserver.SelectedIndexChanged -= tscomserver_SelectedIndexChanged;

            EntityBusiness entityBusiness = new EntityBusiness();
            var            dbs            = entityBusiness.GetServerList();

            tscomserver.ComboBox.DisplayMember = "DbAlias";
            tscomserver.ComboBox.ValueMember   = "ServerID";
            tscomserver.ComboBox.DataSource    = dbs;
            string mainserver = new ConfigurationHelper().GetConfigurationValue("mainserver");

            if (mainserver != "0" && mainserver != "")
            {
                tscomserver.ComboBox.SelectedValue = Convert.ToInt32(mainserver);
                maindb = dbs.Where(x => x.ServerID == Convert.ToInt32(mainserver)).FirstOrDefault();
                //LoadOtherDBs(dbs, Convert.ToInt32(mainserver));
            }

            else
            {
                tscomserver.ComboBox.SelectedIndex = -1;
                //LoadOtherDBs(dbs, 0);
            }


            tscomserver.SelectedIndexChanged += tscomserver_SelectedIndexChanged;
        }
Exemplo n.º 25
0
        public ActionResult UploadServers()
        {
            DropDown();
            var model = new ServerModel();

            return(View(model));
        }
Exemplo n.º 26
0
        private XElement CreateServerXmlElement(ServerModel server)
        {
            var xelem = new XElement("ServerItem",
                                     new XElement("id", server.ServerId),
                                     new XElement("name", server.ServerName),
                                     new XElement("alias", server.ServerAlias),
                                     new XElement("description", server.ServerDescription),
                                     new XElement("emu", server.EMU),
                                     new XElement("connect_string", server.ServerIpAndPort),
                                     new XElement("DiscordUrl", server.DiscordUrl),
                                     new XElement("GameApiUrlKey", server.GameApiUrl),
                                     new XElement("LoginServerUrlKey", server.LoginServerUrl),
                                     new XElement("enable_login", "true"),
                                     new XElement("custom_credentials", "true"),
                                     new XElement("emu", server.EMU),
                                     new XElement("default_rodat", server.RodatSetting),
                                     new XElement("default_secure", server.SecureSetting),
                                     new XElement("visibility", server.VisibilitySetting),
                                     new XElement("default_username", "username"),
                                     new XElement("default_password", "password"),
                                     new XElement("allow_dual_log", "true")
                                     );

            return(xelem);
        }
Exemplo n.º 27
0
 public bool CheckTable(ServerModel server, string tablename)
 {
     try
     {
         string query     = @"IF EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES 
                WHERE TABLE_NAME='" + tablename + "') SELECT 1 ELSE SELECT 0";
         var    tablelist = new List <TableModel>();
         using (SqlCommand cmd = new SqlCommand(query, ConnectionManager.Connection(server)))
         {
             int res = Convert.ToInt32(cmd.ExecuteScalar());
             if (res == 1)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         ConnectionManager.Close();
     }
 }
Exemplo n.º 28
0
        private void SetServer()
        {
            if (!Directory.Exists(Path.GetDirectoryName(Settings.PathToSkympClientSettings)))
            {
                Directory.CreateDirectory(Path.GetDirectoryName(Settings.PathToSkympClientSettings));
            }

            SkympClientSettingsModel oldServer;

            if (File.Exists(Settings.PathToSkympClientSettings))
            {
                oldServer = JsonConvert.DeserializeObject <SkympClientSettingsModel>(File.ReadAllText(Settings.PathToSkympClientSettings));
            }
            else
            {
                oldServer = new SkympClientSettingsModel();
                oldServer.IsEnableConsole = false;
                oldServer.IsShowMe        = false;
            }

            ServerModel newServer = (ServerModel)serverList.SelectedItem;

            if (newServer.IsSameServer(oldServer))
            {
                return;
            }
            File.WriteAllText(Settings.PathToSkympClientSettings, JsonConvert.SerializeObject(newServer.ToSkympClientSettings(oldServer), Formatting.Indented));
            Settings.Save();
        }
Exemplo n.º 29
0
        public void Load(ServerModel server)
        {
            Trace.Call(server);

            // protocol is part of the PKEY, not allowed to change
            f_ProtocolComboBox.Sensitive = false;

            Protocol             = server.Protocol;
            ServerID             = server.ServerID;
            f_HostnameEntry.Text = server.Hostname;
            f_NetworkComboBoxEntry.Entry.Text = server.Network;
            if (String.IsNullOrEmpty(server.Nickname))
            {
                var defaultNicknames = (string[])Frontend.UserConfig["Connection/Nicknames"];
                f_NicknameEntry.Text = String.Join(" ", defaultNicknames);
            }
            else
            {
                f_NicknameEntry.Text = server.Nickname;
            }
            if (String.IsNullOrEmpty(server.Realname))
            {
                var defaultRealname = (string)Frontend.UserConfig["Connection/Realname"];
                f_RealnameEntry.Text = defaultRealname;
            }
            else
            {
                f_RealnameEntry.Text = server.Realname;
            }
            f_UsernameEntry.Text = server.Username;
            // HACK: Twitter username is part of the PKEY, not allowed to change
            if (server.Protocol == "Twitter")
            {
                f_UsernameEntry.Sensitive = false;
            }
            else
            {
                f_UsernameEntry.Sensitive = true;
            }
            f_PasswordEntry.Text = server.Password;
            f_UseEncryptionCheckButton.Active             = server.UseEncryption;
            f_ValidateServerCertificateCheckButton.Active =
                server.ValidateServerCertificate;
            f_PortSpinButton.Value             = server.Port;
            OnStartupConnectCheckButton.Active = server.OnStartupConnect;
            if (server.OnConnectCommands == null ||
                server.OnConnectCommands.Count == 0)
            {
                f_OnConnectCommandsTextView.Buffer.Text = String.Empty;
            }
            else
            {
                // LAME: replace me when we have .NET 3.0
                string[] commands = new string[server.OnConnectCommands.Count];
                server.OnConnectCommands.CopyTo(commands, 0);
                f_OnConnectCommandsTextView.Buffer.Text = String.Join(
                    "\n", commands
                    );
            }
        }
Exemplo n.º 30
0
        public virtual void Edit(ServerModel server)
        {
            Trace.Call(server);

            if (server == null)
            {
                throw new ArgumentNullException("server");
            }

            var dialog = new ServerDialog(_Parent, server,
                                          Frontend.Session.GetSupportedProtocols(),
                                          _Controller.GetNetworks());
            int res = dialog.Run();

            server = dialog.GetServer();
            dialog.Destroy();
            if (res != (int)Gtk.ResponseType.Ok)
            {
                return;
            }

            _Controller.SetServer(server);
            _Controller.Save();

            // refresh the view
            Load();
        }
Exemplo n.º 31
0
        private void SaveButton_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(NameBox.Text))
            {
                MessageBox.Show("You must enter a server name.");
                return;
            }

            if (string.IsNullOrEmpty(AddressBox.Text) || !IPAddress.TryParse(AddressBox.Text, out IPAddress ipAddress))
            {
                MessageBox.Show("You must enter a (valid) IP address.");
                return;
            }

            if (string.IsNullOrEmpty(PasswordBox.Text))
            {
                MessageBox.Show("You must enter a password.");
                return;
            }

            var serverItem = new ServerModel(NameBox.Text, ipAddress.ToString(),
                                             (int)ServerPort.Value, (int)RCONPort.Value, PasswordBox.Text, ConnectOnStartupCheck.Checked,
                                             LegacyServer.Checked);
            var search = DataFileManager.Data.AllServers.Where(x => x.Name == serverItem.Name);

            if (search.Any())
            {
                DataFileManager.Data.AllServers.Remove(search.First());
            }

            DataFileManager.Data.AllServers.Add(serverItem);
            DataFileManager.SaveData();

            RefreshServerList();
        }
Exemplo n.º 32
0
        public ServerModel GetServer()
        {
            ServerModel server = new ServerModel();

            server.Protocol = f_ProtocolComboBox.ActiveText;
            server.Hostname = f_HostnameEntry.Text.Trim();
            server.Network  = f_NetworkComboBoxEntry.Entry.Text.Trim();
            server.Port     = f_PortSpinButton.ValueAsInt;
            server.Username = f_UsernameEntry.Text.Trim();
            // HACK: use Twitter username as hostname for multi-account support
            if (f_ProtocolComboBox.ActiveText == "Twitter")
            {
                server.Hostname = server.Username;
            }
            server.Password                  = f_PasswordEntry.Text;
            server.UseEncryption             = f_UseEncryptionCheckButton.Active;
            server.ValidateServerCertificate =
                f_ValidateServerCertificateCheckButton.Active;
            server.OnStartupConnect = f_OnStartupConnectCheckButton.Active;
            if (f_OnConnectCommandsTextView.Sensitive)
            {
                server.OnConnectCommands =
                    f_OnConnectCommandsTextView.Buffer.Text.Split('\n');
            }

            return(server);
        }
Exemplo n.º 33
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Host,Username,Password")] ServerModel Server)
        {
            if (id != Server.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(Server);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!ServerModelExists(Server.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(Server));
        }
Exemplo n.º 34
0
 internal UncertainValue(ServerModel.Smiling smiling)
 {
     if (smiling != null)
     {
         Value = smiling.value < 50 ? "is not" : "is";
         Certainty = 100 * Math.Abs(smiling.value - 50.0)/50.0;
     }
 }
Exemplo n.º 35
0
 internal UncertainValue(ServerModel.Glass glass)
 {
     if (glass != null)
     {
         Certainty = glass.confidence;
         Value = glass.value;
     }
 }
Exemplo n.º 36
0
 internal UncertainValue(ServerModel.Race race)
 {
     if (race != null)
     {
         Certainty = race.confidence;
         Value = race.value;
     }
 }
Exemplo n.º 37
0
 internal Position(ServerModel.PositionedObject positionedObject)
 {
     if (positionedObject != null)
     {
         X = positionedObject.x;
         Y = positionedObject.y;
     }
 }
Exemplo n.º 38
0
 internal UncertainValue(ServerModel.Gender gender)
 {
     if (gender != null)
     {
         Certainty = gender.confidence;
         Value = gender.value;
     }
 }
Exemplo n.º 39
0
 internal Age(ServerModel.Age age)
 {
     if (age != null)
     {
         Value = age.value;
         Range = age.range;
     }
 }
Exemplo n.º 40
0
 internal FaceRecognition(ServerModel.Faces faces)
 {
     if (faces != null)
     {
         if (faces.face != null)
         {
             Faces = faces.face.Select(f => new Face(f)).ToArray();
         }
         ImageSize = new Size { Width = faces.img_width, Height = faces.img_height };
     }
 }
Exemplo n.º 41
0
 public ServerPlugin()
 {
     _control = new ServerControl();
     _model = new ServerModel();
     _view = new ServerView();
 }
Exemplo n.º 42
0
        public JsonResult JsonAddServer(ServerModel model, string returnUrl)
        {
            this.rememberService.Add(DefaultNames.ServerCookieName, model);

            return Json(new { success = true, redirect = Url.Action("List") });
        }