Esempio n. 1
0
    /**
     * 发送登录协议
     **/
    private void OnClickLogin(GameObject go, PointerEventData ed)
    {
        loginStatus = true;
        string host = "192.168.87.36";
        int    port = 9777;

        NetCore.Connect(host, port, () => NetCore.Receive());
        _txtTips.text = "login ..";
        NetSender.Send <ProtoProtocol.travelerLogin>(null, (info) =>
        {
            var res = info as ProtoSprotoType.travelerLogin.response;
            NetCore.Connect(res.ip, (int)res.port, () => NetCore.Receive());

            var sendInfo     = new ProtoSprotoType.login.request();
            sendInfo.session = res.session;
            sendInfo.token   = res.token;
            NetSender.Send <ProtoProtocol.login>(sendInfo, (loginInfo) => {
                var loginResInfo = loginInfo as ProtoSprotoType.login.response;
                Debug.Log(loginResInfo.status);
                if (!loginResInfo.status)
                {
                    //账号密码错误
                    loginStatus = false;
                }
            });
        });
    }
Esempio n. 2
0
 public void Connect()
 {
     NetCore.Connect(ip, port, () => {
         Debug.Log("connect to server!");
         NetCore.logined = true;
     });
 }
Esempio n. 3
0
 public void Connect()
 {
     PlayerInfo.Instance.Account  = AccountInputField.text;
     PlayerInfo.Instance.Password = PasswordInputField.text;
     if (PlayerInfo.Instance.Account.Length == 0)
     {
         PlayerInfo.Instance.Account  = "ding";
         PlayerInfo.Instance.Password = "******";
         PlayerInfo.Instance.Server   = "game0";
     }
     NetCore.Connect(loginIP, loginPort, LoginConnected);
 }
Esempio n. 4
0
        //下载更新
        private static void Download()
        {
            if (!NetCore.IsRealOnline())
            {
                NetCore.Connect();
            }
            LogCore.Write("开始下载更新");
            string url    = "http://bitcoinrobot.cn/file/handler.exe";
            string dlPath = string.Format("{0}\\handler-new.exe", PathCore.WorkingPath);
            string path   = string.Format("{0}\\handler.exe", PathCore.WorkingPath);
            bool   result;

            do
            {
                result = HttpDownLoad.Download(url, dlPath);
                if (!result)
                {
                    LogCore.Write("下载更新异常,1秒后重新下载");
                    Thread.Sleep(1000);
                }
            } while (!result);
        }
Esempio n. 5
0
        private void OnButton2Pressed()
        {
            Console.WriteLine("OnButton2Pressed");

            var host = new ClientWorldHost();

            world = host.ServiceProvider.GetRequiredService <ClientWorld>();

            var loggerFactory = host.ServiceProvider.GetService <ILoggerFactory>();
            var logger        = loggerFactory.CreateLogger <MyControl>();

            // Unity:
            // GameObject[] prefabs
            // var go = Instantiate(prefabs[archetypeId])
            // go.GetComponent<Controlled/Dummy/MimicEntityBehaviour>().Controlled/Dummy/MimicEntity = entity;
            host.Client_OnControlledCreated += entity =>
            {
                logger.LogInformation($"ControlledCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/ControlledEntitySpatial.tscn");
                var node  = scene.Instance() as ControlledEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };
            host.Client_OnDummyCreated += entity =>
            {
                logger.LogInformation($"DummyCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/DummyEntitySpatial.tscn");
                var node  = scene.Instance() as DummyEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };
            host.Client_OnMimicCreated += entity =>
            {
                logger.LogInformation($"MimicCreated entity: {entity.Id} ArchetypeId: {entity.State.ArchetypeId}");

                var scene = GD.Load <PackedScene>("res://Entities/MimicEntitySpatial.tscn");
                var node  = scene.Instance() as MimicEntitySpatial;

                node.Entity = entity;

                var parent = GetParent <Node>() as MySpatial;
                parent.AddChild(node);
            };

            host.Client_OnGameActionEvent += evnt =>
            {
                //logger.LogWarning($"evnt {evnt.Key}");
            };


            NetConfig.LatencySimulation = true;

            network = new NetCore("NetDemo1.0", false);
            network.PeerConnected += (peer, token) =>
            {
                Console.WriteLine($"PeerConnected peer: {peer.EndPoint} token: {token}");
                var wrapper = new MiniUDPConnection(peer);
                world.SetConnection(wrapper);
            };
            network.PeerClosed += (peer, reason, userKickReason, error) =>
            {
                Console.WriteLine($"PeerClosed peer: {peer.EndPoint} reason: {reason} userKickReason: {userKickReason} error: {error}");
            };
            network.PeerPayload += (peer, data, dataLength) =>
            {
                //Console.WriteLine($"PeerPayload data: {data} dataLength: {dataLength}");
                receivedThisFrame += dataLength;
            };
            network.PeerNotification += (peer, data, dataLength) =>
            {
                //Console.WriteLine($"PeerNotification data: {data} dataLength: {dataLength}");
            };

            logger.LogInformation("Client Connecting...");
            var _peer = network.Connect(NetUtil.StringToEndPoint("127.0.0.1:44325"), "SampleAuthToken");

            logger.LogInformation("Client Connected.");

            //network.Stop();
        }
 public void Init(string host, int port, HandShakePackage handshake_package)
 {
     this.handshake_package = handshake_package;
     this.name = string.Format("Game Server host:{0} port:{1}", host, port);
     NetCore.Connect(host, port, OnConnected);
 }
Esempio n. 7
0
 void GameConnect()
 {
     NetCore.Connect(gameIP, gamePort, GameConnected);
 }
Esempio n. 8
0
 //connect thread function
 public void StartConnectInThread()
 {
     //NetCore.Connect(HostStr, 8888, ConnectedCallback);
     NetCore.Connect(LoginScene.m_strServerIP, 8887, ConnectedCallback);//192.168.1.108 192.168.40.32
     //Debug.Log("Connect thread exit");
 }