Exemplo n.º 1
0
        public void Execute(Entity p_Entity, int p_Index, ref C_NetworkConnection p_ServerConnection)
        {
            DataStreamReader stream;

            if (!p_ServerConnection.Connection.IsCreated)
            {
                Assert.IsTrue(true);
            }

            NetworkEvent.Type cmd;
            while ((cmd = RW_Driver.PopEventForConnection(p_ServerConnection.Connection, out stream)) !=
                   NetworkEvent.Type.Empty)
            {
                if (cmd == NetworkEvent.Type.Data)
                {
                    DataStreamReader.Context t_ReaderCtx = default(DataStreamReader.Context);
                    MessageFromClientTypes   e_MsgType   = (MessageFromClientTypes)stream.ReadInt(ref t_ReaderCtx);
                    Debug.Log($"Got {e_MsgType} from the Client.");

                    switch (e_MsgType)
                    {
                    case MessageFromClientTypes.PingConnection:
                        Debug.Log($"Connection is still established on Client {p_ServerConnection.ConnectionId}.");
                        break;

                    case MessageFromClientTypes.MovePlayer:
                        HandleAttemptMoveMessage(in p_Index, in p_ServerConnection, ref stream, ref t_ReaderCtx);
                        break;

                    case MessageFromClientTypes.BreakWall:
                        HandleAttemptBreakWall(in p_Index, in p_ServerConnection, ref stream, ref t_ReaderCtx);
                        break;

                    case MessageFromClientTypes.RepairWall:
                        HandleAttemptRepairWall(in p_Index, in p_ServerConnection, ref stream, ref t_ReaderCtx);
                        break;

                    case MessageFromClientTypes.ShootPlayer:
                        HandleAttemptShootDirection(in p_Index, in p_ServerConnection, ref stream, ref t_ReaderCtx);
                        break;

                    default:
                        break;
                    }
                }
                else if (cmd == NetworkEvent.Type.Disconnect)
                {
                    Debug.Log("Client disconnected from server");
                    p_ServerConnection.Connection = default(NetworkConnection);
                }
            }
        }
Exemplo n.º 2
0
    private string OnMessageSentCallback(string p_TypedText)
    {
        string[] s_CommandStrings = p_TypedText.Split();

        if (s_CommandStrings.Length > 2)
        {
            return("Do not speak in long sentences. I.M.P's vocalization is dissapointing in long stretches.");
        }

        if (s_CommandStrings.Length < 2)
        {
            return("Leave it to this &#!!@#!&#! I.M.P to not complete the command.");
        }

        string s_Command   = s_CommandStrings[0];
        string s_Direction = s_CommandStrings[1];

        string s_ReturnText = p_TypedText;

        MessageFromClientTypes e_MessageType = MessageFromClientTypes.PingConnection;

        switch (s_Command.ToLower())
        {
        case "break":
            e_MessageType = MessageFromClientTypes.BreakWall;
            break;

        case "move":
            e_MessageType = MessageFromClientTypes.MovePlayer;
            break;

        case "build":
            e_MessageType = MessageFromClientTypes.RepairWall;
            break;

        case "shoot":
            e_MessageType = MessageFromClientTypes.ShootPlayer;
            break;

        default:
            s_ReturnText = "Invalid Command - I.M.P (Ignorant Moving Personality)";
            break;
        }

        switch (s_Direction.ToLower())
        {
        case "up":
            m_ClientWorld.EntityManager.GetBuffer <NMBF_RequestServer>(s_ManageClientConnections.ClientEntity)
            .Add(new NMBF_RequestServer
            {
                Index = WallIndexes.Up,
                Type  = e_MessageType
            });
            break;

        case "down":
            m_ClientWorld.EntityManager.GetBuffer <NMBF_RequestServer>(s_ManageClientConnections.ClientEntity)
            .Add(new NMBF_RequestServer
            {
                Index = WallIndexes.Down,
                Type  = e_MessageType
            });
            break;

        case "left":
            m_ClientWorld.EntityManager.GetBuffer <NMBF_RequestServer>(s_ManageClientConnections.ClientEntity)
            .Add(new NMBF_RequestServer
            {
                Index = WallIndexes.Left,
                Type  = e_MessageType
            });
            break;

        case "right":
            m_ClientWorld.EntityManager.GetBuffer <NMBF_RequestServer>(s_ManageClientConnections.ClientEntity)
            .Add(new NMBF_RequestServer {
                Index = WallIndexes.Right,
                Type  = e_MessageType
            });
            break;

        default:
            s_ReturnText = "Invalid Direction -- I only know Up, Down, Left or Right";
            break;
        }

        return(s_ReturnText);
    }