Exemple #1
0
        private static void Main(string[] args)
        {
            Settings.Init();
            client = new GameClient();

            MRandom = new Random();

            window.Closed += WindowOnClosed;
            window.MouseMoved += WindowOnMouseMoved;
            window.MouseButtonPressed += WindowOnMouseButtonPressed;
            window.KeyPressed += WindowOnKeyPressed;
            window.KeyReleased += WindowOnKeyReleased;
            window.MouseButtonReleased += WindowOnMouseButtonReleased;
            window.SetFramerateLimit(75);
            client.GameMode = new StandardMelee(client.InputHandler);

            var stopwatch = new Stopwatch();
            stopwatch.Restart();

            manager.SwitchState(new MainMenuState(), null);

            while (window.IsOpen())
            {
                window.DispatchEvents();
                window.Clear(new Color(100, 100, 200));

                var dt = (float) (stopwatch.Elapsed.TotalSeconds*1000);
                stopwatch.Restart();

                manager.Update(dt);
                manager.Render(window);
                window.Display();
            }
        }
Exemple #2
0
        private static readonly Logger Logger = LogManager.CreateLogger(); // logger instance.

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        private static void Main(string[] args)
        {
            #if !DEBUG
            AppDomain.CurrentDomain.UnhandledException += UnhandledExceptionHandler; // Watch for any unhandled exceptions.
            #endif

            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; // Use invariant culture - we have to set it explicitly for every thread we create to prevent any mpq-reading problems (mostly because of number formats).

            Console.ForegroundColor = ConsoleColor.Yellow;
            PrintBanner();
            PrintLicense();
            PrintDebugKeys();
            Console.ResetColor();

            InitLoggers(); // init logging facility.

            Logger.Info("voxeliq v{0} warming-up..", Assembly.GetAssembly(typeof (Player)).GetName().Version);
            Logger.Info(string.Format("Running over {0} {1}.", PlatformManager.DotNetFramework, PlatformManager.DotNetFrameworkVersion));
            Logger.Info(string.Format("Using game framework {0} {1}, over {2}.", PlatformManager.GameFramework, PlatformManager.GameFrameworkVersion, PlatformManager.GraphicsApi));            

            using (var game = new GameClient()) // startup the game.
            {
                Logger.Trace("Starting game loop..");
                PlatformManager.Startup(game);
            }
        }
Exemple #3
0
 void GameServer_OnClientConnect(ClientWrapper obj)
 {
     Client.GameClient client = new Client.GameClient(obj);
     client.Send(client.DHKeyExchange.CreateServerKeyPacket());
     obj.Connector = client;
     //ref to my server
     client.MyServer = this;
 }
Exemple #4
0
        void GameServer_OnClientReceive(byte[] buffer, int length, ClientWrapper obj)
        {
            if (obj.Connector == null)
            {
                obj.Disconnect();
                return;
            }
            Client.GameClient Client = obj.Connector as Client.GameClient;
            if (Client.Exchange)
            {
                Client.Exchange = false;
                Client.Action   = 1;
                var    crypto    = new Cryptography.GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey));
                byte[] otherData = new byte[length];
                Array.Copy(buffer, otherData, length);
                crypto.Decrypt(otherData, length);

                bool extra = false;
                int  pos   = 0;
                if (BitConverter.ToInt32(otherData, length - 140) == 128)//no extra packet
                {
                    pos = length - 140;
                    Client.Cryptography.Decrypt(buffer, length);
                }
                else if (BitConverter.ToInt32(otherData, length - 176) == 128)//extra packet
                {
                    pos   = length - 176;
                    extra = true;
                    Client.Cryptography.Decrypt(buffer, length - 36);
                }
                int len = BitConverter.ToInt32(buffer, pos); pos += 4;
                if (len != 128)
                {
                    Client.Disconnect();
                    return;
                }
                byte[] pubKey = new byte[128];
                for (int x = 0; x < len; x++, pos++)
                {
                    pubKey[x] = buffer[pos];
                }

                string PubKey = System.Text.Encoding.Default.GetString(pubKey);
                Client.Cryptography = Client.DHKeyExchange.HandleClientKeyPacket(PubKey, Client.Cryptography);

                if (extra)
                {
                    byte[] data = new byte[36];
                    Buffer.BlockCopy(buffer, length - 36, data, 0, 36);
                    processData(data, 36, Client);
                }
            }
            else
            {
                processData(buffer, length, Client);
            }
        }
Exemple #5
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main(string[] args)
        {
            Console.WriteLine("Please Enter your Characters Name: ");
            string PlayerName = Console.ReadLine();

            using (GameClient game = new GameClient(PlayerName))
            {
                game.Run();
            }
        }
        public void Init()
        {
            _game = new GameClient();
            this._config = new EngineConfig();

            if(Engine.Core.Engine.Instance!=null) // if there exists already an engine instance, dispose it first.
                Engine.Core.Engine.Instance.Dispose(); 

            this._engine = new Engine.Core.Engine(this._game, this._config);
            this._chunkStorage = new ChunkStorage(_game);
            this._chunk = new Chunk(new Vector2Int(0, 0));
        }
Exemple #7
0
        public Lobby(GameClient client)
        {
            Name = "Lobby Name Not Set";
            Description = "Description Not Set";
            idSet = false;
            myId = 0;

            players = new Dictionary<byte, LobbyPlayer>();
            myclient = client;
            MaxSlots = 0;

            FLAG_IsSwitchedToGame = false;
            FLAG_IsSwitchedToGame = false;
        }
Exemple #8
0
        static void Main(string[] args)
        {
            GameClient gc = new GameClient();
            gc.localEp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7878);
            gc.remoteEp = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 10888);

            gc.client = new UdpClient(gc.localEp);
            gc.Establish();
            while (gc.ConnectionEstablished)
            {
                gc.servermessage = gc.ReceiveMsgFromServer();
                if (gc.servermessage == "RPLY") gc.SendMsgToServer(Console.ReadLine());
                else Console.WriteLine(gc.servermessage);
            }
        }
Exemple #9
0
        void processData(byte[] buffer, int length, Client.GameClient Client)
        {
            Client.Cryptography.Decrypt(buffer, length);
            Client.Queue.Enqueue(buffer, length);
            if (Client.Queue.CurrentLength > 1224)
            {
                Console.WriteLine("[Disconnect]Reason:The packet size is too big. " + Client.Queue.CurrentLength);
                Client.Disconnect();
                return;
            }
            while (Client.Queue.CanDequeue())
            {
                byte[] data = Client.Queue.Dequeue();

                //startHandling
                Packets.Handler.HandlePacket(data, Client);
            }
        }
        public void Init()
        {
            _game = new GameClient();
            this._config = new EngineConfig();
            this._engine = new Engine.Core.Engine(this._game, this._config);

            var cacheWidthInBlocks = ((_config.Cache.CacheRange * 2) + 1) * _config.Chunk.WidthInBlocks;
            var cacheLenghtInBlocks = ((_config.Cache.CacheRange*2) + 1) * _config.Chunk.LengthInBlocks;

            this._cacheXStartIndex = -cacheWidthInBlocks/2;
            this._cacheXEndIndex = cacheWidthInBlocks / 2;

            this._cacheZStartIndex = -cacheLenghtInBlocks / 2;
            this._cacheZEndIndex = cacheLenghtInBlocks / 2;

            this._directlyIndexedValidationDictionary = new Dictionary<int, BlockType>();

            // set the initial values.
            for (var x = this._cacheXStartIndex; x < this._cacheXEndIndex; x++)
            {
                for (var z = this._cacheZStartIndex; z < this._cacheZEndIndex; z++)
                {
                    var offset = BlockStorage.BlockIndexByWorldPosition(x, z);

                    for (var y = 0; y < _config.Chunk.HeightInBlocks; y++)
                    {
                        var index = offset + y;
                        var block = new Block().RandomizeType();

                        this._directlyIndexedValidationDictionary.Add(index, block.Type);

                        BlockStorage.Blocks[index] = block;
                    }
                }
            }

            // check if validationDictionaries item count is equal to CacheRange's volume.
            Assert.AreEqual(this._directlyIndexedValidationDictionary.Values.Count, _config.Cache.CacheRangeVolume);
        }
Exemple #11
0
        static void Main(string[] args)
        {
            var gClient = new GameClient("luckygeck.dyndns-home.com");

            gClient.Client.ResponseEvent += (o, e) => Console.WriteLine("server answer is " + e.Message());
            gClient.Client.ResponseErrorEvent += (o, e) => Console.WriteLine("Response error occuried: " + e.Error);
            gClient.NetErrorEvent += (o, e) => Console.WriteLine("Net error occuried: " + e.Error);
            gClient.LoginEvent += (o, e) => { if (e.Ok) Console.WriteLine("Login ok"); else Console.WriteLine("Login not ok: " + e.Error); };

            gClient.Start();

            gClient.Login("s***n", "megapassword");
            Thread.Sleep(1000);
            gClient.GameSessionList();
            Thread.Sleep(1000);
            gClient.GameSessionJoin(1);
            Thread.Sleep(1000);
            gClient.GameHit(27);
            Thread.Sleep(1000);
            gClient.GameLeave();

            Console.ReadLine();
            gClient.Stop();
        }
Exemple #12
0
 public InputHandler(GameClient _client)
 {
     client = _client;
 }
        public void TestDefaultValidConfig()
        {
            var game = new GameClient();
            var config = new EngineConfig();
            var engine = new Engine.Core.Engine(game, config);

            Assert.IsTrue(config.Validate()); // expect config validation to succeed.

            Assert.IsNotNull(config.Chunk); // chunk configuration should exist.
            Assert.IsNotNull(config.Cache); // cache configuratio should exists.

            #region validate chunk configuration 

            // make sure default dimensions are valid.
            Assert.Greater(config.Chunk.WidthInBlocks, 0);
            Assert.Greater(config.Chunk.HeightInBlocks, 0);
            Assert.Greater(config.Chunk.LengthInBlocks, 0);

            // calculate expected chunk volume in blocks
            var expectedChunkVolumeInBlocks = config.Chunk.WidthInBlocks*
                                              config.Chunk.HeightInBlocks*
                                              config.Chunk.LengthInBlocks;
            Assert.AreEqual(config.Chunk.Volume, expectedChunkVolumeInBlocks);

            // make sure max-width-index is valid.
            Assert.AreEqual(config.Chunk.MaxWidthInBlocks,
                            config.Chunk.WidthInBlocks - 1);

            // make sure max-height-index is valid.
            Assert.AreEqual(config.Chunk.MaxHeightInBlocks,
                            config.Chunk.HeightInBlocks - 1);

            // make sure max-lenght-index is valid.
            Assert.AreEqual(config.Chunk.MaxLengthInBlocks,
                            config.Chunk.LengthInBlocks - 1);

            #endregion

            #region validate cache configuration

            // make sure default dimensions are valid.
            Assert.Greater(config.Cache.ViewRange, 0);
            Assert.Greater(config.Cache.CacheRange, 0);

            // make sure cache-dimension in blocks are calculated correctly.
            var expectedCacheWidthInBlocks = (config.Cache.CacheRange * 2 + 1) *
                                             config.Chunk.WidthInBlocks;

            var expectedCacheHeightInBlocks = config.Chunk.HeightInBlocks;

            var expectedCacheLenghtInBlocks = (config.Cache.CacheRange * 2 + 1) *
                                              config.Chunk.LengthInBlocks;

            Assert.AreEqual(config.Cache.CacheRangeWidthInBlocks, expectedCacheWidthInBlocks);
            Assert.AreEqual(config.Cache.CacheRangeHeightInBlocks, expectedCacheHeightInBlocks);
            Assert.AreEqual(config.Cache.CacheRangeLenghtInBlocks, expectedCacheLenghtInBlocks);

            // if by default, cache-extra-chunks option is set to true, make sure that default cache-range > default view-range.
            if (config.Cache.CacheExtraChunks)
                Assert.Greater(config.Cache.CacheRange, config.Cache.ViewRange,
                    "Cache range must be greater view range when CacheExtraChunk option is set to true.");
            else // if by default, cache-extra-chunks option is set to false, make sure that default cache-range = default view-range.
                Assert.AreEqual(config.Cache.ViewRange, config.Cache.CacheRange,
                    "Cache range can not be different than view range when CacheExtraChunk option is set to false.");

            #endregion
        }
Exemple #14
0
 static GameClient()
 {
     Instance = new GameClient("192.168.33.55");
     //Instance = new GameClient("luckygeck.dyndns-home.com");
 }