コード例 #1
0
 protected override void OnMessage(MessageEventArgs e)
 {
     if (e.Type == Opcode.Binary)
     {
         IEwkProtocol ewk = EwkProtoSerilazer.DeserializeForProtobuf(e.RawData);
         if (ewk.Protocol_Enum == ProtocolEnum.Req_Change_Scene)
         {
             SendToSelf(EwkProtoFactory.CreateIEwkProtocol <SceneListEnum>(ProtocolEnum.Res_Change_Scene, ewk.GetData <SceneListEnum>()).GetBytes);
         }
     }
     //else
     //{
     //    log_.Debug("e.Data = {0}", e.Data);
     //}
 }
コード例 #2
0
 protected override void OnMessage(MessageEventArgs e)
 {
     //Send( "echo response = " + e.Data );
     if (e.Type == Opcode.Binary)
     {
         IEwkProtocol protocol = EwkProtoSerilazer.DeserializeForProtobuf(e.RawData);
         log_.Debug(protocol.ToString());
         if (protocol.Protocol_Enum == ProtocolEnum.RightAnswer)
         {
             int answer_index = protocol.GetData <int>();
             log_.Debug("ansewr_index = {0}", answer_index);
             room_.Game_Logic.RequestRightAnswer(user_info_.Guest_Id, answer_index);
         }
         //if ( protocol.Protocol_Enum == ProtocolEnum.None )
         //{
         //    stream.Position = 0;
         //    Person person = ProtoBuf.Serializer.Deserialize<Person>( stream );
         //    log_.Debug( "person.name = {0}", person.name );
         //}
     }
 }
コード例 #3
0
        protected override void OnMessage(MessageEventArgs e)
        {
            if (e.Type == Opcode.Binary)
            {
                IEwkProtocol protocol = EwkProtoSerilazer.DeserializeForProtobuf(e.RawData);
                if (protocol.Protocol_Enum == ProtocolEnum.Req_Notify_Game_Ready)
                {
                    BroadcastMessage(string.Format(Resources.Chat_Game_Ready_Notification, _name));

                    // TODO : 이 코드는 굉장히 불안전(해킹에 취약)하고 불안정하다.
                    // 나중에 다시 GameLogic 으로 다시 되돌려야함.
                    if (room_.IsGamePlayReady() && !is_started)
                    {
                        is_started = true;
                        BroadcastMessage(Resources.Chat_Game_Start_Notification);
                        room_.Game_Logic.StartGameLogic();
                    }
                }
            }
            else if (e.Type == Opcode.Text)
            {
                string message = String.Format(Resources.Chat_Chatting_Color, _name, e.Data);

                BroadcastMessage(message);
                //Sessions.Broadcast( message );

                // Example [Terdong : 2014-08-14]
                //Person person = new Person();
                //person.id = 100;
                //person.name = "terdong";
                //MemoryStream serialize = new MemoryStream();
                //ProtoBuf.Serializer.Serialize<Person>(serialize, person);
                //byte[] byteData = serialize.ToArray();
                //Sessions.SendTo(ID, byteData);
                //Sessions.SendTo( ID, ID + " = hey!" );

                log_.Info(message);
            }
        }
コード例 #4
0
        void TestProtobuf()
        {
            // var model = new EwkProtocol<Person>();
            //Object obj = new Object();
            IDictionary <string, Object> dic_ = new Dictionary <string, Object>();

            dic_["aaa"] = 7777 as Object;
            dic_["bbb"] = 9999 as Object;
            dic_["ccc"] = new List <int> {
                1, 2, 3
            } as Object;
            //dic_["ccc"] = 9999;
            //dic_["ddd"] = 9999;
            //dic_["eee"] = 9999;
            //dic_["fff"] = 9999;
            //dic_["ggg"] = 9999;

            Hashtable htable_ = new Hashtable();

            dic_["aaa"] = 9999;
            dic_["bbb"] = 9999;
            dic_["ccc"] = 9999;
            dic_["ddd"] = 9999;
            dic_["eee"] = 9999;
            dic_["fff"] = 9999;
            dic_["ggg"] = 9999;

            IList <string> list_ = new List <string>();

            list_.Add("hello");
            list_.Add("asdf");
            list_.Add("asdf111");
            list_.Add("asdf222");
            list_.Add("asdf333");

            QuizInfo quiz_info = QuizInfo.CreateUserInfo(100);


            //AvatarInfo ai = AvatarInfo.CreateAvatarInfo(9999,9999,9999,9999,9999,9999);
            //EwkProtocol ewk_ = EwkProtocol.CreateEwkProtocol( ProtocolEnum.Res_Game_Change_Game_Mode, ai );
            // string base64_ = ewk_.Input_Parameters_Base64;
            // byte[] string_bytes = Encoding.UTF8.GetBytes( base64_ );
            //byte[] bytes = ProtocolUtility.SerializeForProtobuf<AvatarInfo>( ai );
            //byte[] bytes = ProtocolUtility.SerializeForProtobuf<EwkProtocol>(
            //EwkProtocol.CreateEwkProtocol( ProtocolEnum.Res_Game_Change_Game_Mode, dic_ ) );
            //ewk_ );

            //IEwkProtocol ewkp = ProtocolUtility.DeserializeForProtobuf<EwkProtocol>( bytes );

            // 비 generic collection은 직렬화안됨.
            //IEwkProtocol gewk = EwkProtocolFactory.CreateEwkProtocol<Hashtable>( ProtocolEnum.Avatar_Direction_Left, htable_ );

            //IEwkProtocol gewk = EwkProtoFactory.CreateEwkProtocol<IList<string>>( ProtocolEnum.Ready, list_ );
            IEwkProtocol gewk = EwkProtoFactory.CreateIEwkProtocol <QuizInfo>(ProtocolEnum.QuizInfo, quiz_info);

            //IEwkProtocol gewk = EwkProtoFactory.CreateEwkProtocol<IList<string>>( ProtocolEnum.Avatar_Direction_Left, list_ );
            //IEwkProtocol ewk = EwkProtoFactory.CreateEwkProtocol( ProtocolEnum.Avatar_Direction_Left );

            byte[] bytes = gewk.GetBytes;
            gewk = EwkProtoSerilazer.DeserializeForProtobuf(bytes);
            //EwkProtocol<QuizInfo> gewkp = gewk as EwkProtocol<QuizInfo>;
            //QuizInfo gewkpp = gewkp.Data;

            QuizInfo gewkpp = gewk.GetData <QuizInfo>();
            //QuizInfo gewkpp = EwkProtoSerilazer.DeserializeForData<QuizInfo>( bytes );

            //QuizInfo quiz_info = QuizInfo.CreateUserInfo(null, null, 100, 10);
            //Person p = new Person();
            ////p.Protocol_Enum = ProtocolEnum.QuizInfo;

            //byte[] bytes = ProtocolUtility.SerializeForProtobuf<Person>(p);
            //EwkProtocol ewk = ProtocolUtility.DeserializeForProtobuf<EwkProtocol>(bytes);

            ////quiz_info = BinarySerializationExtension.DeserializeForProtobuf<QuizInfo>(bytes);
            //p = ProtocolUtility.DeserializeForProtobuf<Person>(bytes);
        }