Пример #1
0
        public void LoginCLick()
        {
            var param = new Dictionary <byte, object>();

            param.Add(151, nameField_login.text);
            param.Add(152, pwdField_login.text);
            peer.OpCustom(101, param, true);
        }
Пример #2
0
 private void Login(string loginEmail, string loginPassword)
 {
     _state = GameManagerState.Sending;
     _photonPeer.OpCustom((byte)GameOperationCode.Login,
                          new Dictionary <byte, object>
     {
         { (byte)GameOperatorCodeParameter.Email, loginEmail },
         { (byte)GameOperatorCodeParameter.Password, loginPassword }
     }, true);
 }
Пример #3
0
    private void Login(string email, string password)
    {
        _state = GameManagerState.Sending;

        _photonPeer.OpCustom(
            (byte)RuneOperationCode.Login,
            new Dictionary <byte, object>()
        {
            { (byte)RuneOperationCodeParameter.Password, password },
            { (byte)RuneOperationCodeParameter.Email, email }
        },
            true);
    }
Пример #4
0
 void OnGui()
 {
     if (isConnected)
     {
         if (GUILayout.Button("Send a operation."))
         {
             Dictionary <byte, object> dict = new Dictionary <byte, object>();
             dict.Add(1, "username");
             dict.Add(2, "password");
             peer.OpCustom(1, dict, true);
         }
     }
 }
    void OnGUI()
    {
        if (!connected)
        {
            if (GUI.Button(new Rect(10, 10, Screen.width - 20, Screen.height * 0.3f), "Connect"))
            {
                CreateConnnect();
            }
        }

        if (connected)
        {
            inputText = GUI.TextArea(new Rect(10, 10, Screen.width - Screen.width * 0.7f - 20, Screen.height * 0.3f), inputText);
            if (GUI.Button(new Rect(Screen.width * 0.7f + 30, 10, Screen.width * 0.2f, Screen.height * 0.3f), "Send"))
            {
                // send to server
                var parameters = new Dictionary <byte, object> {
                    { (byte)ChatMsgParameterKey.Content, inputText }
                };

                peer.OpCustom((byte)ChatOp.Msg, parameters, true);
            }
        }

        GUI.TextArea(new Rect(10, Screen.height - Screen.height * 0.5f - 10, Screen.width - 20, Screen.height * 0.5f), outText);
    }
Пример #6
0
 public void SendLoginOperation(string name)
 {
     PhotonPeer.OpCustom((byte)OperationCode.Login,
                         new Dictionary <byte, object> {
         { (byte)ParameterCode.CharacterName, name }
     }, true);
 }
Пример #7
0
        static void Main(string[] args)
        {
            ChatServerListener listener = new ChatServerListener();
            PhotonPeer         peer     = new PhotonPeer(listener, ConnectionProtocol.Tcp);

            //连接服务器
            peer.Connect("127.0.0.1:4520", "ChatServer");

            Console.WriteLine("Connecting...");

            while (listener.isConnected == false)
            {
                peer.Service();
            }

            Dictionary <byte, object> dict = new Dictionary <byte, object>();

            dict.Add(1, "username");
            dict.Add(2, "password");

            peer.OpCustom(1, dict, true);

            while (true)
            {
                peer.Service();
            }

            Console.ReadKey();
        }
Пример #8
0
        static void Main(string[] args)
        {
            GameServerListener listener = new GameServerListener();

            PhotonPeer peer = new PhotonPeer(listener, ConnectionProtocol.Tcp);

            Console.WriteLine("connecting...");
            peer.Connect("127.0.0.1:4530", "GameServer");
            while (!listener.isConnected)
            {
                peer.Service();
            }

            Dictionary <byte, Object> dict = new Dictionary <byte, object>
            {
                { 1, "username" },
                { 2, "password" }
            };

            peer.OpCustom(1, dict, true);

            while (true)
            {
                peer.Service();
            }
        }
Пример #9
0
        /// <summary>
        /// リクエスト送信
        /// </summary>
        /// <param name="SendPacket">送信パケット</param>
        /// <param name="ResponsePacketID">レスポンスパケットのID</param>
        /// <param name="ResponseHandler">リクエストに対応するレスポンスのハンドラ</param>
        public void SendRequest(IPacket SendPacket, EPacketID ResponsePacketID, Action <IDictionaryStream> ResponseHandler)
        {
            if (Peer == null)
            {
                Debug.LogError("Peer is null.");
                return;
            }
            byte ByteID = (byte)ResponsePacketID;

            ResponseHandlers.Add(ByteID, ResponseHandler);

            DictionaryStreamWriter Writer = new DictionaryStreamWriter();

            SendPacket.Serialize(Writer);
            Peer.OpCustom((byte)SendPacket.PacketID, Writer.Dest, false);
        }
Пример #10
0
        private void ExecuteCommand(string cmd)
        {
            if (!connected)
            {
                return;
            }

            switch (cmd.Trim().ToLower())
            {
            case "push":
            {
                Dictionary <byte, object> parameters = new Dictionary <byte, object> {
                    { (byte)ParameterCode.Type, (byte)ClientSettings.Default.PushType },
                    { (byte)ParameterCode.Body, ClientSettings.Default.Body },
                    { (byte)ParameterCode.Title, ClientSettings.Default.Title }
                };
                mPeer.OpCustom((byte)SelectCharacterOperationCode.SendPushToPlayers, parameters, true);
                Console.WriteLine("push sended");
            }
            break;

            case "exit":
            {
                mPeer.Disconnect();
                mLoopStarted = false;
            }
            break;
            }
        }
Пример #11
0
        private void LoginToServer()
        {
            Console.WriteLine("\n請輸入帳號:");
            string name = Console.ReadLine();

            Console.WriteLine("\n請輸入密碼:");
            string password = Console.ReadLine();

            var parameters = new Dictionary <byte, object>
            {
                { (byte)LoginParameterCode.Name, name },
                { (byte)LoginParameterCode.Password, password },
            };

            m_Peer.OpCustom((byte)OperationCode.Login, parameters, true);
        }
Пример #12
0
 public void SendChatMessage(string message)
 {
     PhotonPeer.OpCustom((byte)OperationCode.SendChatMessage,
                         new Dictionary <byte, object> {
         { (byte)ParameterCode.ChatMessage, message }
     }, true);
 }
Пример #13
0
    void userLogin(string uname, string pwd)
    {
        Dictionary <byte, object> param = new Dictionary <byte, object>();

        param.Add((byte)ScOpEnumCommon.OpKeyEnum.UserName, uname);
        param.Add((byte)ScOpEnumCommon.OpKeyEnum.PassWord, pwd);
        peer.OpCustom((byte)ScOpEnumCommon.OpCodeEnum.Login, param, true);
    }
Пример #14
0
 /// <summary>
 ///  Forwards the request to the peer which then sends the request to the server.
 /// </summary>
 internal static void ForwardRequest(OperationRequest operationRequest, bool sendReliable, byte channelId)
 {
     if (m_PhotonPeer == null)
     {
         Debug.LogError("Not connected");
         return;
     }
     m_PhotonPeer.OpCustom(operationRequest, sendReliable, channelId, m_Encrypt);
 }
Пример #15
0
        /// <summary>
        /// Creates a new character
        /// </summary>
        public static void CreateCharacter(PhotonPeer peer, CharacterStructure characterInfo)
        {
            var parameters = new Dictionary <byte, object>()
            {
                { (byte)1, (byte)GameOperationCode.CreateCharacter },
                { (byte)ParameterCode.Data, characterInfo },
            };

            peer.OpCustom((byte)ClientOperationCode.Character, parameters, true);
        }
Пример #16
0
 private void SendServer(string message)
 {
     _photonPeer.OpCustom(
         1,
         new Dictionary <byte, object>
     {
         { 0, message }
     },
         true);
 }
Пример #17
0
 public void MoveOperation(float x, float y, float z)
 {
     PhotonPeer.OpCustom((byte)OperationCode.Move,
                         new Dictionary <byte, object>
     {
         { (byte)ParameterCode.PosX, x },
         { (byte)ParameterCode.PosY, y },
         { (byte)ParameterCode.PosZ, z },
     }, false);
 }
Пример #18
0
 public void SendOperation(IANTProtocol.OperationCode oprationCode, Dictionary <byte, object> parameter)
 {
     if (peer.IsEncryptionAvailable)
     {
         peer.OpCustom((byte)oprationCode, parameter, true, 0, true);
     }
     else
     {
         DebugReturn(DebugLevel.ERROR, "communication still not establish encryption");
     }
 }
Пример #19
0
    /// <summary>
    /// 向服务器发请求
    /// </summary>
    /// <param name="OpCode">操作码</param>
    /// <param name="SubCode">子操作码</param>
    /// <param name="parameters">参数</param>
    public void Request(byte OpCode, byte SubCode, params object[] parameters)
    {
        Dictionary <byte, object> dict = new Dictionary <byte, object>();

        dict[80] = SubCode;
        for (byte i = 0; i < parameters.Length; i++)
        {
            dict[(byte)i] = parameters[i];
        }
        bool ispeer = peer.OpCustom(OpCode, dict, true);
    }
Пример #20
0
        /// <summary>
        /// Logs in a user
        /// </summary>
        public static void Login(PhotonPeer peer, string username, string password)
        {
            var parameters = new Dictionary <byte, object>()
            {
                { (byte)1, (byte)GameOperationCode.LoginUser },
                { (byte)ParameterCode.Username, username },
                { (byte)ParameterCode.Password, password },
            };

            peer.OpCustom((byte)ClientOperationCode.Login, parameters, true, 0, true);
        }
Пример #21
0
 void OnGUI()
 {
     GUILayout.Label("Connected: " + connected.ToString());
     if (connected)
     {
         if (GUILayout.Button("Send Operation Request"))
         {
             // send a message to the server
             peer.OpCustom(0, new Dictionary <byte, object>(), true);
         }
     }
 }
Пример #22
0
    /// <summary>
    /// 向服务器发请求
    /// </summary>
    /// <param name="OpCode">操作码</param>
    /// <param name="SubCode">子操作码</param>
    /// <param name="parameters">传递参数</param>
    public void Request(byte OpCode, byte SubCode, params object[] parameters)
    {
        //创建参数字典
        Dictionary <byte, object> dict = new Dictionary <byte, object>();

        //指定子操作码
        dict[80] = SubCode;
        for (int i = 0; i < parameters.Length; i++)
        {
            dict[(byte)i] = parameters[i];
        }
        peer.OpCustom(OpCode, dict, true);
    }
Пример #23
0
 private void OnGUI()
 {
     if (GUILayout.Button("send"))
     {
         if (this.Status)
         {
             peer.OpCustom(1, new Dictionary <byte, object>()
             {
                 { 10, " hello world " }
             }, true);
         }
     }
 }
Пример #24
0
        public void SendEvent(Message req)
        {
            string json = JsonMapper.ToJson(req);
            Dictionary <byte, object> datas = new Dictionary <byte, object>();

            datas.Add(1, req.Code);
            datas.Add(2, json);
            if (peer == null)
            {
                GUIManager.Instance.OpenTipsView("链接服务器失败", "确定", () => { });
            }
            else
            {
                peer.OpCustom(1, datas, true);
            }
        }
        void INetChannel.Send(Message msg)
        {
            MemoryStream stream = new MemoryStream();
            BinaryWriter writer = new BinaryWriter(stream);

            msg.Serialize(writer);
            var arr = new byte[stream.Position];

            Array.Copy(stream.GetBuffer(), arr, stream.Position);

            var data = new Dictionary <byte, object>();

            data[0] = arr;
            bool isReliable = msg.Reliability == MessageReliability.Reliable || msg.Reliability == MessageReliability.ReliableOrdered;

            _photon.OpCustom(42, data, isReliable); //Photon does not allow to send raw messages so send dummy operation instead
        }
Пример #26
0
        protected void SendToServer(INetworkMessage message, bool reliable, byte channel)
        {
            var baseMessage = message as NetworkMessageBase;

            if (baseMessage != null)
            {
                baseMessage.PlayerName = playerName;
            }

            if (selfPeer != null)
            {
                var messageData = serializer.ToMessageData(message);

                if (messageData.Value != null)
                {
                    selfPeer.OpCustom(messageData.Key, messageData.Value, reliable, channel);
                }
            }
        }
Пример #27
0
        //private static

        /// <summary>
        /// Creates the client.
        /// </summary>
        /// <param name="localhost">Localhost.</param>
        /// <param name="seerverName">Seerver name.</param>
        public static void CreateClient(string localhost, string seerverName)
        {
            if (instance != null)
            {
                Debug.Log("客户端已经创建");
                return;
            }

            localhost   = "127.0.0.1:4530";
            seerverName = "ChatServer";
            //参数检查


            GameClient listener = new GameClient();

            listener.clientState = ClientState.DisConnect;
            photonPeer           = new PhotonPeer(listener, ConnectionProtocol.Tcp);
            photonPeer.Connect(localhost, seerverName);     //链接服务器
            Debug.Log("连接服务器中......");


            //启动异步客户端服务

            while (listener.clientState == ClientState.DisConnect)
            {
                photonPeer.Service();
            }
            Dictionary <byte, object> dict = new Dictionary <byte, object>();

            dict.Add(1, "username");
            dict.Add(2, "password");
            //向服务端发送请求
            photonPeer.OpCustom(1, dict, true);
            while (true)
            {
                photonPeer.Service();
            }
        }
Пример #28
0
        private static void toTestPhoton()
        {
            PeerListener listener = new PeerListener();
            var          peer     = new PhotonPeer(listener, ConnectionProtocol.Tcp);

            peer.Connect("127.0.0.1:4530", "ChatServer");
            while (!listener.Status)
            {
                peer.Service();
            }

            peer.OpCustom(1, new Dictionary <byte, object>()
            {
                { 10, " hello world " }
            }, true);

            while (true)
            {
                peer.Service();
            }

            Console.WriteLine("end");
        }
Пример #29
0
    public static void Main()
    {
        var client = new ChatClient();
        var peer = new PhotonPeer(client, ConnectionProtocol.Tcp);

        // connect
        client.connected = false;
        peer.Connect("127.0.0.1:4530", "ChatServer");
        while (!client.connected)
        {
            peer.Service();
        }

        var buffer = new StringBuilder();
        while (true)
        {
            peer.Service();

            // read input
            if (Console.KeyAvailable)
            {
                ConsoleKeyInfo key = Console.ReadKey();
                if (key.Key != ConsoleKey.Enter)
                {
                    // store input
                    buffer.Append(key.KeyChar);
                }
                else
                {
                    // send to server
                    var parameters = new Dictionary<byte, object> { { 1, buffer.ToString() } };
                    peer.OpCustom(1, parameters, true);
                    buffer.Length = 0;
                }
            }
        }
    }
Пример #30
0
    public void Request(byte OpCode, byte SubCode, params object[] parameters)
    {
        OperationRequest request = new OperationRequest();

        request.OperationCode  = OpCode;
        request.Parameters     = new Dictionary <byte, object>();
        request.Parameters[80] = SubCode;
        for (int i = 0; i < parameters.Length; i++)
        {
            request.Parameters[(byte)i] = parameters[i];
        }
        peer.OpCustom(OpCode, request.Parameters, true);
        ////创建参数字典
        //Dictionary<byte, object> OpParameters = new Dictionary<byte, object>();
        ////指定子操作码
        //OpParameters[80] = SubCode;
        ////赋值参数
        //for (int i = 0; i < parameters.Length; i++)
        //{
        //    OpParameters[(byte)i] = parameters[i];
        //}
        ////发送
        //peer.OpCustom(OpCode, OpParameters, true);
    }
Пример #31
0
 public void SendRequest(OperationCode opCode, Dictionary <byte, object> parameters)
 {
     Debug.Log("sendrequest to server , opcode : " + opCode);
     peer.OpCustom((byte)opCode, parameters, true);
 }