private void readIP(string textInField)
    {
        IPAddress serverIP;

        try
        {
            serverIP = IPAddress.Parse(textInField);
        }
        catch
        {
            output.text = prefixMessage + "Please enter a valid IP";
            return;
        }
        ConnectionClient client_ = new ConnectionClient(new DummyGraphics(), serverIP);

        try
        {
            client_.Connect();
        }
        catch
        {
            output.text = prefixMessage + "Sorry, couldn't connect to server, is the address you chose correct?";
            return;
        }

        Variables.client = client_;

        UnityEngine.SceneManagement.SceneManager.LoadScene("SampleScene");
    }
예제 #2
0
        public MainScene(Location Size) : base(Size)
        {
            ConnectionClient Connection = new ConnectionClient();

            Connection.Connect((Port) =>
            {
                if (Port != 0)
                {
                    Logger.Log("Connecting on Port " + Port);
                    Client = new Client(Port);
                }
                else
                {
                    Logger.Log("Failed to connect to remote host");
                }
                Connection.Dispose();
            });

            Player       = new Player();
            Player.Scale = 10;
            Player.Layer = 10;
            AddChild(Player);
            Players.Add(Player);

            Tiles       = new TileManager(2048, 2048, ClansGame.TestTileTexture, 8);
            Tiles.Scale = 5;

            for (int Y = 0; Y < Tiles.Height; Y++)
            {
                for (int X = 0; X < Tiles.Width; X++)
                {
                    Tiles.Set(X, Y, 3 + JRandom.Next(3), 0, 1, 0);
                }
            }

            Tiles.Layer = -1;
            AddChild(Tiles);

            Camera.Target = Player;

            Snow           = new SnowEffect(2);
            Snow.Intensity = 0;
            UI.AddChild(Snow);

            Info               = new LabelNode(Font.Default, "WASD to move + and - to change the bleeding", 20);
            Info.Position      = new Location(Size.X / 2, Size.Y * 0.3);
            Info.AnchorPoint.X = 0.5;
            Info.Color         = new Color(128, 128, 130);
            UI.AddChild(Info);

            Input.ListenForKey(Keys.I, this);
            Input.ListenForKey(Keys.O, this);
            Input.ListenForKey(Keys.P, this);
        }
예제 #3
0
        /// <summary>
        /// General method for sending messages. Sends single message to server and waits for any responses.
        /// </summary>
        /// <param name="message">XmlMessage to be sent.</param>
        /// <returns>All received messages as XMLDocuments.</returns>
        protected List<MessagePackage> SendMessage(IClusterMessage message)
        {
            var tcpClient = new ConnectionClient(ServerInfo);

            tcpClient.Connect();

            var responses = tcpClient.SendAndWaitForResponses(message);

            tcpClient.Close();

            return responses;
        }
        private void VerifyStateTransitionsUntilConnected(bool bExchangeWorldData)
        {
            m_WorldData.Setup(d => d.RequiresInitialWorldData).Returns(bExchangeWorldData);

            // Init
            Assert.Equal(EConnectionState.Disconnected, m_Connection.State);
            m_Connection.Connect();

            // Expect client hello
            m_NetworkConnection.Verify(
                c => c.SendRaw(It.IsAny <ArraySegment <byte> >(), It.IsAny <EDeliveryMethod>()),
                Times.Once);
            ArraySegment <byte> expectedSentData = TestUtils.MakeRaw(
                EPacket.Client_Hello,
                new Client_Hello(Version.Number).Serialize());

            Assert.Equal(expectedSentData, m_SendRawParam);
            Assert.Equal(EConnectionState.ClientJoinRequesting, m_Connection.State);

            // Ack client hello
            ArraySegment <byte> response = TestUtils.MakeRaw(
                EPacket.Server_RequestClientInfo,
                new Server_RequestClientInfo().Serialize());

            m_Connection.Receive(response);
            Assert.Equal(EConnectionState.ClientJoinRequesting, m_Connection.State);

            // Expect client info
            expectedSentData = TestUtils.MakeRaw(
                EPacket.Client_Info,
                new Client_Info(new Player("Unknown")).Serialize());
            Assert.Equal(expectedSentData, m_SendRawParam);
            Assert.Equal(EConnectionState.ClientJoinRequesting, m_Connection.State);

            // Ack client info
            response = TestUtils.MakeRaw(
                EPacket.Server_JoinRequestAccepted,
                new Server_JoinRequestAccepted().Serialize());
            m_Connection.Receive(response);

            if (bExchangeWorldData)
            {
                expectedSentData = TestUtils.MakeRaw(
                    EPacket.Client_RequestWorldData,
                    new Client_RequestWorldData().Serialize());
                Assert.Equal(expectedSentData, m_SendRawParam);
                Assert.Equal(EConnectionState.ClientAwaitingWorldData, m_Connection.State);

                // Send world data to client
                response = TestUtils.MakeRaw(
                    EPacket.Server_WorldData,
                    m_WorldData.Object.SerializeInitialWorldState());
                m_Connection.Receive(response);
                Assert.Equal(EConnectionState.ClientPlaying, m_Connection.State);
            }

            // Expect client joined
            expectedSentData = TestUtils.MakeRaw(
                EPacket.Client_Joined,
                new Client_Joined().Serialize());
            Assert.Equal(expectedSentData, m_SendRawParam);
            Assert.Equal(EConnectionState.ClientPlaying, m_Connection.State);

            // Send keep alive
            ArraySegment <byte> keepAliveFromServer = TestUtils.MakeKeepAlive(42);

            m_Connection.Receive(keepAliveFromServer);
            Assert.Equal(EConnectionState.ClientPlaying, m_Connection.State);

            // Expect client keep alive response
            expectedSentData = keepAliveFromServer;
            Assert.Equal(expectedSentData, m_SendRawParam);
        }