예제 #1
0
        public void Connect()
        {
            if (m_protocol == null)
            {
                m_settings = Dependencies.Settings;

                m_wasConnected = false;

                m_protocol              = new LowProtocol <Socket>(ServerUrl, Time.realtimeSinceStartup);
                m_protocol.Enabled     += OnEnabled;
                m_protocol.Disabled    += OnDisabled;
                m_protocol.SocketError += OnSocketError;
                m_protocol.Message     += OnMessage;
            }

            m_wasConnected = IsConnected;

            IsConnectionStateChanging = true;

            if (ConnectionStateChanging != null)
            {
                ConnectionStateChanging(new Error(StatusCode.OK));
            }
            m_protocol.Enable();
        }
        public void IsAlive(ServerEventHandler callback)
        {
            if (m_protocol != null)
            {
                throw new InvalidOperationException();
            }

            LowProtocol <ClientSocket> protocol = new LowProtocol <ClientSocket>(m_url, m_time.Time);

            m_protocol              = protocol;
            m_protocol.Enabled     += OnEnabled;
            m_protocol.SocketError += OnError;
            m_protocol.Disabled    += OnDisabled;

            m_response = externalError =>
            {
                callback(externalError);
            };

            m_call = () =>
            {
                RemoteCall rpc = new RemoteCall(RemoteCall.Proc.IsAliveCheck, ServerContainer.ServerIdentity);

                Call(rpc, (error, remoteResult) =>
                {
                    m_response = externalError =>
                    {
                        if (externalError != null)
                        {
                            callback(externalError);
                        }
                        else
                        {
                            callback(error);
                        }
                    };

                    m_protocol.Disable();
                });
            };

            m_protocol.Enable();
        }
        public void CreateMatch(Guid creatorClientId, Room room, Guid[] clientIds, Player[] players, ReplayData replay, ServerEventHandler callback)
        {
            if (m_protocol != null)
            {
                throw new InvalidOperationException();
            }

            LowProtocol <ClientSocket> protocol = new LowProtocol <ClientSocket>(m_url + "create", m_time.Time);

            m_protocol              = protocol;
            m_protocol.Enabled     += OnEnabled;
            m_protocol.SocketError += OnError;
            m_protocol.Disabled    += OnDisabled;

            m_response = externalError =>
            {
                callback(externalError);
            };

            m_call = () =>
            {
                RemoteCall rpc = new RemoteCall(RemoteCall.Proc.CreateMatch, ServerContainer.ServerIdentity, RemoteArg.Create(creatorClientId), RemoteArg.Create(room), RemoteArg.Create(clientIds), RemoteArg.Create(players), RemoteArg.Create(replay));

                Call(rpc, (error, remoteResult) =>
                {
                    m_response = externalError =>
                    {
                        if (externalError != null)
                        {
                            callback(externalError);
                        }
                        else
                        {
                            callback(error);
                        }
                    };

                    m_protocol.Disable();
                });
            };

            m_protocol.Enable();
        }