Example #1
0
        private void OnApplicationQuit()
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetServer.ShutDown();
                break;

            case Corsair.NetStatus.Client:
                NetClient.ShutDown();
                break;

            case Corsair.NetStatus.Null:
                break;
            }
            NetUdp.ShutDown();
            Net.NetDataMgr.Enable = false;
        }
Example #2
0
        public void End()
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetServer.Send(Manager.CreateNetData(NetID, (byte)NetStatus.End));
                EndEvent.Invoke();
                break;

            case Corsair.NetStatus.Client:
                EndEvent.Invoke();
                break;

            case Corsair.NetStatus.Null:
                EndEvent.Invoke();
                break;
            }
        }
Example #3
0
        public static void ResetLevel(int i)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.ResetLevel);
                n.Write(Level);
                NetServer.Send(n);
                LoadLevel(i);
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                LoadLevel(i);
                break;
            }
        }
Example #4
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;
            }
        }
Example #5
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;
            }
        }
Example #6
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();
            }
        }
Example #7
0
        public void NetManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetStatus:
                NetData ngs = Manager.CreateNetData(NetID, (byte)NetStatus.SetStatus);
                ngs.Write(heart);
                NetServer.Send(ngs);
                break;

            case NetStatus.SetStatus:
                heart = data.ReadInt();
                if (heart > 0)
                {
                    LifeEvent.Invoke(heart / (float)max);
                }
                else
                {
                    base.Death();
                    Ramparts.Remove(this);
                }
                break;

            case NetStatus.Hurt:
                AttackInfo a = new AttackInfo();
                a.Position = data.ReadVector3();
                a.Rotation = data.ReadQuaternion();
                a.Value    = data.ReadInt();
                base.Hurt(a);
                LifeEvent.Invoke(heart / (float)max);
                break;

            case NetStatus.Death:
                base.Death();
                Ramparts.Remove(this);
                break;
            }
        }
Example #8
0
        public override void Hurt(AttackInfo a)
        {
            switch (Net.Status)
            {
            case Corsair.NetStatus.Server:
                NetData n = Manager.CreateNetData(NetID, (byte)NetStatus.Hurt);
                n.Write(a.Position);
                n.Write(a.Rotation);
                n.Write(a.Value);
                NetServer.Send(n);

                base.Hurt(a);
                LifeEvent.Invoke(heart / (float)max);
                break;

            case Corsair.NetStatus.Client:
                break;

            case Corsair.NetStatus.Null:
                base.Hurt(a);
                LifeEvent.Invoke(heart / (float)max);
                break;
            }
        }
Example #9
0
        private static void NetManager(NetData data)
        {
            switch ((NetStatus)data.ReadByte())
            {
            case NetStatus.GetLevel:
                NetData ngl = Manager.CreateNetData(NetID, (byte)NetStatus.SetLevel);
                ngl.Write(Level);
                NetServer.SendTo(ngl, data.RemoteIP);
                break;

            case NetStatus.SetLevel:
                int level = data.ReadInt();
                if (Level != level)
                {
                    LoadLevel(level);
                }
                break;

            case NetStatus.ResetLevel:
                LoadLevel(data.ReadInt());
                break;

            case NetStatus.GetPlayerIndex:
                NetData ngp = Manager.CreateNetData(NetID, (byte)NetStatus.SetPlayerIndex);
                ngp.Write(1);
                NetServer.SendTo(ngp, data.RemoteIP);
                break;

            case NetStatus.SetPlayerIndex:
                SetPlayerIndex(data.ReadInt());
                break;

            case NetStatus.GetGameStatus:
                NetData ngg = Manager.CreateNetData(NetID, (byte)NetStatus.SetGameStatus);
                ngg.Write((byte)GameStatus);
                NetServer.SendTo(ngg, data.RemoteIP);
                break;

            case NetStatus.SetGameStatus:
                SetGameStatus((GameStatus)data.ReadByte());
                break;

            case NetStatus.CreateGameObject:
                int        id = data.ReadInt();
                string     na = data.ReadString();
                Vector3    po = data.ReadVector3();
                Quaternion ro = data.ReadQuaternion();
                Instantiate(Prefabs[id], po, ro).name = na;
                break;

            case NetStatus.GetGameObjects:
                for (int i = 0; i < GameObjects.Count; i++)
                {
                    NetData    ng = Manager.CreateNetData(NetID, (byte)NetStatus.CreateGameObject);
                    GameObject g  = GameObjects[i];
                    ng.Write(int.Parse(g.name.Substring(0, g.name.IndexOf('_'))));
                    ng.Write(g.name);
                    ng.Write(g.transform.position);
                    ng.Write(g.transform.rotation);
                    NetServer.SendTo(ng, data.RemoteIP);
                }
                break;
            }
        }