Beispiel #1
0
        public void LaunchTo(Vector3 point, IPEndPoint ignore = null)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.LaunchTo);
                ns.Write(point);
                NetServer.Send(ns, NetType.TCP, ignore);

                Main.LaunchTo(point);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.LaunchTo);
                nc.Write(point);
                NetClient.Send(nc);

                Main.LaunchTo(point);
                break;

            case Corsair.NetStatus.Null:
                Main.LaunchTo(point);
                break;
            }
        }
Beispiel #2
0
        public override void Hurt(AttackInfo a)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                ns.Write(a.Position);
                ns.Write(a.Rotation);
                ns.Write(a.Value);
                NetServer.Send(ns);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                nc.Write(a.Position);
                nc.Write(a.Rotation);
                nc.Write(a.Value);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            _Hurt(a);
        }
Beispiel #3
0
        public static void CreateGameObject(int id, Vector3 pos, Quaternion rota)
        {
            if (id > -1 && id < Prefabs.Count)
            {
                string name = id + "_" + Prefabs[id].name + "_" + index;
                switch (Net.Status)
                {
                case Corsair.NetStatus.Server:
                    NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.CreateGameObject);
                    n.Write(id);
                    n.Write(name);
                    n.Write(pos);
                    n.Write(rota);
                    NetServer.Send(n);

                    Instantiate(Prefabs[id], pos, rota).name = name;
                    break;

                case Corsair.NetStatus.Client:
                    Instantiate(Prefabs[id], pos, rota).name = name;
                    break;

                case Corsair.NetStatus.Null:
                    Instantiate(Prefabs[id], pos, rota).name = name;
                    break;
                }
                index++;
            }
        }
Beispiel #4
0
        public override void Hurt(Corsair.AttackInfo a)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                ns.Write(a.Position);
                ns.Write(a.Rotation);
                ns.Write(a.Value);
                NetServer.Send(ns);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                nc.Write(a.Position);
                nc.Write(a.Rotation);
                nc.Write(a.Value);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            base.Hurt(a);
            //animator.Play("Hurt");
            //attacks.prelude.gameObject.SetActive(false);
        }
Beispiel #5
0
        public void NetDataManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetStatus:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                n.Write(Heart);
                n.Write((byte)status);
                n.Write(index);
                NetServer.Send(n);
                break;

            case NetStatus.SetStatus:
                heart  = data.ReadInt();
                status = (RoleStatus)data.ReadByte();
                SetTarget(data.ReadInt(), data.RemoteIP);
                switch (status)
                {
                case RoleStatus.Death:
                    PlayDeath(data.RemoteIP);
                    break;

                case RoleStatus.Vectory:
                    PlayVictory(data.RemoteIP);
                    break;
                }
                break;

            case NetStatus.SetTarget:
                SetTarget(data.ReadInt(), data.RemoteIP);
                break;

            case NetStatus.Idle:
                PlayIdle(data.RemoteIP);
                break;

            case NetStatus.Attacking:
                PlayAttack(data.ReadInt(), data.RemoteIP);
                break;

            case NetStatus.Moving:
                break;

            case NetStatus.Hurt:
                Corsair.AttackInfo a = new Corsair.AttackInfo();
                a.Position = data.ReadVector3();
                a.Rotation = data.ReadQuaternion();
                a.Value    = data.ReadInt();
                base.Hurt(a);
                break;

            case NetStatus.Death:
                PlayDeath(data.RemoteIP);
                break;

            case NetStatus.Victory:
                PlayVictory(data.RemoteIP);
                break;
            }
        }
Beispiel #6
0
        private void Start()
        {
#if UNITY_EDITOR
            levelId = Manager.GetCurrentLevel();
#endif
            Manager.SetPlayerIndex(Manager.Info.ID);

            Manager.SetGameStatus(GameStatus.Playing);

            switch (Net.Status)
            {
            case NetStatus.Server:
                break;

            case NetStatus.Client:
                NetData n = Manager.CreateNetData(Manager.NetID, (byte)Manager.NetStatus.GetGameObjects);
                NetClient.Send(n);
                break;

            case NetStatus.Null:
                break;
            }

            Player.PlayerAllDeathEvent += Fail;
        }
Beispiel #7
0
        public static void Flush()
        {
            Servers.Clear();
            NetData n = new NetData(NetMessageType.GainServer);

            NetUdp.SendBroad(n);
        }
Beispiel #8
0
        public void NetDataManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetStatus:
                NetData ngs = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                ngs.Write(heart);
                ngs.Write((byte)Status);
                NetServer.SendTo(ngs, data.RemoteIP);
                break;

            case NetStatus.SetStatus:
                heart  = data.ReadInt();
                Status = (ShipStatus)data.ReadInt();
                break;

            case NetStatus.ShipStatus:
                Status = (ShipStatus)data.ReadByte();
                break;

            case NetStatus.Avatar:
                transform.position = data.ReadVector3();
                transform.rotation = data.ReadQuaternion();
                break;

            case NetStatus.Death:
                Death(data.RemoteIP);
                break;
            }
        }
Beispiel #9
0
        public void Hurt(AttackInfo a, IPEndPoint ignore)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                ns.Write(a.Position);
                ns.Write(a.Rotation);
                ns.Write(a.Value);
                NetServer.Send(ns, NetType.TCP, ignore);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                nc.Write(a.Position);
                nc.Write(a.Rotation);
                nc.Write(a.Value);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            _Hurt(a);
        }
Beispiel #10
0
        public static void SetLevel(int i)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.SetLevel);
                n.Write(i);
                NetServer.Send(n);
                if (i != Level)
                {
                    LoadLevel(i);
                }
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                if (i != Level)
                {
                    LoadLevel(i);
                }
                break;
            }
        }
Beispiel #11
0
        public void Select(int i, IPEndPoint ignore = null)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Select);
                ns.Write(i);
                NetServer.Send(ns, NetType.TCP, ignore);

                _Select(i);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Select);
                nc.Write(i);
                NetClient.Send(nc);

                _Select(i);
                break;

            case Corsair.NetStatus.Null:
                _Select(i);
                break;
            }
            index = i;
        }
Beispiel #12
0
 public void NetDataManager(NetData data)
 {
     switch ((NetStatus)data.ReadByte())
     {
     case NetStatus.Launch:
         break;
     }
 }
Beispiel #13
0
        public static NetData CreateNetData(string id, byte status)
        {
            NetData n = new NetData(NetMessageType.Data);

            n.Write(id);
            n.Write(status);
            return(n);
        }
Beispiel #14
0
        private NetData GetAvatar()
        {
            NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.Avatar);

            n.Write(Player_Vive.Main.Camera.transform.position);
            n.Write(Player_Vive.Main.Camera.transform.rotation);

            n.Write(Player_Vive.Main.Left.transform.position);
            n.Write(Player_Vive.Main.Left.transform.rotation);

            n.Write(Player_Vive.Main.Right.transform.position);
            n.Write(Player_Vive.Main.Right.transform.rotation);
            return(n);
        }
Beispiel #15
0
        public static void ConnectToServer(IPEndPoint ip, string password = null)
        {
            if (Status != NetStatus.Null)
            {
                Debug.LogError("请先退出Net状态:" + Status);
                return;
            }
            NetData n = new NetData(NetMessageType.Connecting);

            n.Write(PlayerName);
            if (password != null)
            {
                n.Write(password);
            }
            NetUdp.Send(n, ip);
        }
Beispiel #16
0
        public static NetData ReadBuffer(byte[] d)
        {
            int l = BitConverter.ToInt32(d, 0);

            if (l == d.Length)
            {
                int     t = BitConverter.ToInt32(d, 4);
                NetData n = new NetData((NetMessageType)t);
                n.data = new byte[d.Length - 8];
                Array.Copy(d, 8, n.data, 0, n.data.Length);
                return(n);
            }
            else
            {
                throw new Exception("data's length is error!");
            }
        }
Beispiel #17
0
        public void NetDataManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.Select:
                Select(data.ReadInt(), data.RemoteIP);
                break;

            case NetStatus.LookAt:
                LookAt(data.ReadVector3(), data.RemoteIP);
                break;

            case NetStatus.LaunchTo:
                LaunchTo(data.ReadVector3(), data.RemoteIP);
                break;
            }
        }
Beispiel #18
0
        public bool PlayAttack(int i, IPEndPoint ignore = null)
        {
            if (Time.time - attackLast[i] < attackCD[i])
            {
                return(false);
            }
            attackLast[i] = Time.time;
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Attacking);
                ns.Write(i);
                NetServer.Send(ns, NetType.TCP, ignore);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Attacking);
                nc.Write(i);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            switch (i)
            {
            case 0:
                isLookAt = true;
                animator.Play(attackClip[0]);
                transform.LookAt(target, Vector3.up);
                break;

            case 1:
                isLookAt = false;
                animator.Play(attackClip[1]);
                break;

            case 2:
                isLookAt = true;
                animator.Play(attackClip[2]);
                transform.LookAt(target, Vector3.up);
                break;
            }
            return(true);
        }
Beispiel #19
0
        protected void FixedUpdate()
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.Avatar);
                n.Write(transform.position);
                n.Write(transform.rotation);
                NetServer.Send(n, NetType.UDP);
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                break;
            }
        }
Beispiel #20
0
        public void NetDataManager(NetData data)
        {
            if (!isMain)
            {
                switch ((NetStatus)data.ReadByte())
                {
                case NetStatus.GetStatus:
                    NetData ngs = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                    ngs.Write(Heart);
                    ngs.Write((byte)status);
                    NetServer.SendTo(ngs, data.RemoteIP);
                    break;

                case NetStatus.SetStatus:
                    heart  = data.ReadInt();
                    status = (PlayerStatus)data.ReadByte();
                    break;

                case NetStatus.Avatar:
                    head.transform.position = data.ReadVector3();
                    head.transform.rotation = data.ReadQuaternion();

                    left.transform.position = data.ReadVector3();
                    left.transform.rotation = data.ReadQuaternion();

                    right.transform.position = data.ReadVector3();
                    right.transform.rotation = data.ReadQuaternion();
                    break;

                case NetStatus.Death:
                    Death(data.RemoteIP);
                    break;

                case NetStatus.Hurt:
                    AttackInfo a = new AttackInfo();
                    a.Position = data.ReadVector3();
                    a.Rotation = data.ReadQuaternion();
                    a.Value    = data.ReadInt();
                    Hurt(a, data.RemoteIP);
                    break;
                }
            }
        }
Beispiel #21
0
        public void Death(IPEndPoint ignore)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Death);
                NetServer.Send(ns, NetType.TCP, ignore);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Death);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            _Death();
        }
Beispiel #22
0
        public override void Death()
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData ns = Manager.CreateNetData(NetID, (byte)NetStatus.Death);
                NetServer.Send(ns);
                break;

            case Corsair.NetStatus.Client:
                NetData nc = Manager.CreateNetData(NetID, (byte)NetStatus.Death);
                NetClient.Send(nc);
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            _Death();
        }
Beispiel #23
0
        public static void SendTo(NetData data, IPEndPoint ip, NetType t = NetType.TCP)
        {
            if (clients.ContainsKey(ip))
            {
                switch (t)
                {
                case NetType.TCP:
                    clients[ip].Send(data.ToBuffer());
                    break;

                case NetType.UDP:
                    NetUdp.Send(data.ToBuffer(), ip);
                    break;
                }
            }
            else
            {
                Debug.LogError(ip + "未与本机建立连接");
            }
        }
Beispiel #24
0
        public void SetStatus(ShipStatus s)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.ShipStatus);
                n.Write((byte)s);
                NetServer.Send(n);

                Status = s;
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                Status = s;
                break;
            }
        }
Beispiel #25
0
        public void Remain(float y)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.Remain);
                n.Write(y);
                NetServer.Send(n);
                RemainEvent.Invoke(y);
                break;

            case Corsair.NetStatus.Client:
                RemainEvent.Invoke(y);
                break;

            case Corsair.NetStatus.Null:
                RemainEvent.Invoke(y);
                break;
            }
        }
Beispiel #26
0
        public void NetDataManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.Create:
                string     n = data.ReadString();
                Vector3    p = data.ReadVector3();
                Quaternion r = data.ReadQuaternion();
                Manager.CreateGameObject(prefabId, p, r);
                break;

            case NetStatus.Remain:
                Remain(data.ReadFloat());
                break;

            case NetStatus.End:
                End();
                break;
            }
        }
Beispiel #27
0
        public static void Send(NetData data, NetType t = NetType.TCP)
        {
            if (info != null)
            {
                switch (t)
                {
                case NetType.TCP:
                    info.Send(data.ToBuffer());
                    break;

                case NetType.UDP:
                    NetUdp.Send(data.ToBuffer(), info.ip);
                    break;
                }
            }
            else
            {
                Debug.LogWarning("未连接tcp服务器");
            }
        }
Beispiel #28
0
        public override void Death()
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.Death);
                NetServer.Send(n);

                base.Death();
                Ramparts.Remove(this);
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                base.Death();
                Ramparts.Remove(this);
                break;
            }
        }
Beispiel #29
0
        private static IEnumerator AutoNetCor()
        {
            NetClient.Flush();
            yield return(new WaitForSeconds(2f));

            if (NetClient.Servers.Count > 0)
            {
                while (Net.Status != Corsair.NetStatus.Client)
                {
                    NetClient.ConnectToServer(NetClient.Servers[0].IP);
                    yield return(new WaitForSeconds(2f));
                }
                NetData np = Manager.CreateNetData(NetID, (byte)NetStatus.GetPlayerIndex);
                NetClient.Send(np);
                NetData nl = Manager.CreateNetData(NetID, (byte)NetStatus.GetLevel);
                NetClient.Send(nl);
            }
            else
            {
                NetServer.Listen();
            }
        }
Beispiel #30
0
        //public static void Send(NetData data, NetType t = NetType.TCP)
        //{
        //    if (socket != null)
        //    {
        //        byte[] b = data.ToBuffer();
        //        if (LogEnable)
        //            Debug.Log("发送数据:" + b.Length);
        //        {
        //            switch (t)
        //            {
        //                case NetType.TCP:
        //                    foreach (var c in clients.Values)
        //                        c.Send(b);
        //                    break;
        //                case NetType.UDP:
        //                    foreach (var c in clients)
        //                        NetUdp.Send(b, c.Key);
        //                    break;
        //            }
        //        }
        //    }
        //    else
        //    {
        //        Debug.LogError("未开启tcp服务器");
        //    }
        //}
        public static void Send(NetData data, NetType t = NetType.TCP, IPEndPoint ignore = null)
        {
            if (socket != null)
            {
                byte[] b = data.ToBuffer();
                if (LogEnable)
                {
                    Debug.Log("发送数据:" + b.Length);
                }
                {
                    switch (t)
                    {
                    case NetType.TCP:
                        foreach (var c in clients)
                        {
                            if (ignore == null || c.Key.ToString() != ignore.ToString())
                            {
                                c.Value.Send(b);
                            }
                        }
                        break;

                    case NetType.UDP:
                        foreach (var c in clients)
                        {
                            if (ignore == null || c.Key.ToString() != ignore.ToString())
                            {
                                NetUdp.Send(b, c.Key);
                            }
                        }
                        break;
                    }
                }
            }
            else
            {
                Debug.LogError("未开启tcp服务器");
            }
        }