Server object, used as reference when connecting to a server.
Exemplo n.º 1
0
 /// <summary>
 /// Initialize a new Minecraft client.
 /// </summary>
 /// <param name="server">The server to connect to.</param>
 /// <param name="player">The player who logged in with the client.</param>
 public Client(Server server, Player player)
 {
     _log = LogManager.GetLogger(this);
     _log.Debug("Minecraft Client created!");
     _server = server;
     _log.Debug("Loading Items from file...");
     try
     {
         using (var reader = new StreamReader(Constants.MinecraftItemFile))
             Items = new JsonSerializer().Deserialize<List<Item>>(new JsonTextReader(reader));
     }
     catch(IOException ex)
     {
         _log.Error("Failed to read item list from file!");
         _log.Error(ex.GetType() + ": " + ex.Message);
         _log.Error("Stack Trace:\n" + ex.StackTrace);
         throw new Exception("Sharpcraft.Library.Minecraft.Client failed to initialize! Could not read item list file!", ex);
     }
     _log.Debug("Creating communication protocol...");
     _protocol = new Protocol(_server.Address, _server.Port);
     _log.Info("Client initiated on " + _server.Address + ":" + _server.Port + "!");
     _player = player;
     _world = new World();
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of <c>GameSettings</c>.
 /// </summary>
 /// <param name="settingsFile">The settings file to use.</param>
 /// <param name="quickServer">The quickserver that the user last specified.</param>
 public GameSettings(string settingsFile, Server quickServer = null)
     : base(settingsFile)
 {
     QuickServer = quickServer;
     Servers = new List<Server>();
 }
Exemplo n.º 3
0
        /// <summary>
        /// Add a server to the server list.
        /// </summary>
        /// <param name="server">The server to add.</param>
        /// <returns><c>true</c> if the server was successfully added, <c>false</c> if not (server already in list).</returns>
        public bool AddServer(Server server)
        {
            if (Servers.Any(serv => serv.Name.ToLower() == server.Name.ToLower() || (serv.Address == server.Address && serv.Port == server.Port)))
                return false;

            Servers.Add(server);
            return true;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Removes a server from the list by reference.
 /// </summary>
 /// <param name="server"><see cref="Server"/> to remove.</param>
 /// <returns><c>true</c> if the server was removed, <c>false</c> if it was not found.</returns>
 public bool RemoveServer(Server server)
 {
     if (Servers.Contains(server))
     {
         Servers.Remove(server);
         return true;
     }
     return false;
 }
Exemplo n.º 5
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            _log.Debug("Initialize();");
            _log.Info("Sharpcraft is initializing!");

            base.Initialize();

            /* /!\ Steam hardcore loading action /!\ */
            _log.Info("Loading Steam components...");
            if (SteamManager.Init())
            {
                //SteamManager.FriendList.LoadFriends(); // Should load automatically now
                //Application.EnableVisualStyles();
                _log.Info("Creating Steam GUI.");
                // TODO: Find a way to set the start location of SteamGUI to be next to Game Window.
                var steamGUI = new SteamGUI();
                if (!steamGUI.Visible)
                    steamGUI.Show();
                _log.Info("Steam components loaded!");
            }
            else
            {
                _log.Info("Steam not installed or not running, Steam functionality will NOT be available.");
            }

            // /!\ WARNING /!\
            // Ugly debug code ahead!
            _log.Debug("Starting debug connection...");
            _server = new Server("F16Gaming Test", "localhost", 25565, "The test server", 0, 0, 0, true);
            Client = new Client(_server, new Player(0, "Sharpcraft"));
            Client.Connect();
            _log.Debug("Reached end of debug connection!");

            Exiting += (s, e) => Client.Exit();
        }