コード例 #1
0
    public void OnButtonSendEcho()
    {
        if (session == null)
        {
            return;
        }

        FunapiSession.Transport transport = session.GetTransport(info.protocol);
        if (transport == null)
        {
            FunDebug.LogWarning("sendEchoMessage - transport is null.");
            return;
        }

        if (transport.encoding == FunEncoding.kJson)
        {
            Dictionary <string, object> message = new Dictionary <string, object>();
            message["message"] = string.Format("[{0}] hello", transport.str_protocol);
            session.SendMessage("echo", message, info.protocol);
        }
        else if (transport.encoding == FunEncoding.kProtobuf)
        {
            PbufEchoMessage echo = new PbufEchoMessage();
            echo.msg = string.Format("[{0}] hello", transport.str_protocol);
            FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
            session.SendMessage("pbuf_echo", message, info.protocol);
        }
    }
コード例 #2
0
    void OnEventHandler(SNResultCode result)
    {
        FunDebug.DebugLog1("EVENT: Facebook ({0})", result);

        switch (result)
        {
        case SNResultCode.kLoggedIn:
        {
            var token = Facebook.Unity.AccessToken.CurrentAccessToken;
            if (encoding_ == FunEncoding.kJson)
            {
                Dictionary <string, object> message = new Dictionary <string, object>();
                message["facebook_uid"]          = token.UserId;
                message["facebook_access_token"] = token.TokenString;

                session_.SendMessage("login", message);
            }
            else if (encoding_ == FunEncoding.kProtobuf)
            {
                FacebookLoginMessage login = new FacebookLoginMessage();
                login.facebook_uid          = token.UserId;
                login.facebook_access_token = token.TokenString;

                FunMessage message = FunapiMessage.CreateFunMessage(login, MessageType.facebook_login);
                session_.SendMessage("facebook_login", message);
            }
        }
        break;

        case SNResultCode.kError:
            FunDebug.Assert(false);
            break;
        }
    }
コード例 #3
0
        public void sendEchoMessage(TransportProtocol protocol = TransportProtocol.kDefault)
        {
            if (!session_.Connected && !session_.ReliableSession)
            {
                FunDebug.Log("You should connect first.");
                return;
            }

            if (encoding_ == FunEncoding.kJson)
            {
                // In this example, we are using Dictionary<string, object>.
                // But you can use your preferred Json implementation (e.g., Json.net) instead of Dictionary,
                // by changing FunapiMessage.JsonHelper property.
                Dictionary <string, object> message = new Dictionary <string, object>();
                message["message"] = string.Format("[{0}] hello json", protocol.ToString().Substring(1).ToLower());
                session_.SendMessage("echo", message, protocol);
            }
            else if (encoding_ == FunEncoding.kProtobuf)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("[{0}] hello proto", protocol.ToString().Substring(1).ToLower());
                FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
                session_.SendMessage(MessageType.pbuf_echo, message, protocol);
            }
        }
コード例 #4
0
        void sendEchoMessage(TransportProtocol protocol)
        {
            FunapiSession.Transport transport = session_.GetTransport(protocol);
            if (transport == null)
            {
                FunDebug.LogWarning("sendEchoMessage - transport is null.");
                return;
            }

            ++echo_id_;

            if (transport.encoding == FunEncoding.kJson)
            {
                Dictionary <string, object> message = new Dictionary <string, object>();
                message["message"] = string.Format("[{0}] echo message ({1})", client_id_, echo_id_);
                session_.SendMessage("echo", message, protocol);
            }
            else if (transport.encoding == FunEncoding.kProtobuf)
            {
                PbufEchoMessage echo = new PbufEchoMessage();
                echo.msg = string.Format("[{0}] echo message ({1})", client_id_, echo_id_);
                FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
                session_.SendMessage("pbuf_echo", message, protocol);
            }
        }
コード例 #5
0
 public void SendMessage(TransportProtocol protocol, string message)
 {
     if (protocol == TransportProtocol.kTcp)
     {
         PbufEchoMessage echo = new PbufEchoMessage();
         echo.msg = message;
         FunMessage fmsg = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
         session_.SendMessage(MessageType.pbuf_echo, fmsg, protocol);
     }
     else
     {
         Dictionary <string, object> echo = new Dictionary <string, object>();
         echo["message"] = message;
         session_.SendMessage("echo", echo, protocol);
     }
 }
コード例 #6
0
    void sendEcho(TransportProtocol protocol)
    {
        FunapiSession.Transport transport = session.GetTransport(protocol);
        if (transport == null)
        {
            return;
        }

        if (transport.encoding == FunEncoding.kJson)
        {
            Dictionary <string, object> message = new Dictionary <string, object>();
            message["message"] = string.Format("[{0}] hello", transport.str_protocol);
            session.SendMessage("echo", message, protocol);
        }
        else if (transport.encoding == FunEncoding.kProtobuf)
        {
            PbufEchoMessage echo = new PbufEchoMessage();
            echo.msg = string.Format("[{0}] hello", transport.str_protocol);
            FunMessage message = FunapiMessage.CreateFunMessage(echo, MessageType.pbuf_echo);
            session.SendMessage("pbuf_echo", message, protocol);
        }
    }
コード例 #7
0
        public void sendMulticastMessage()
        {
            if (multicast_.encoding == FunEncoding.kJson)
            {
                Dictionary <string, object> mcast_msg = new Dictionary <string, object>();
                mcast_msg["_channel"] = kChannelName;
                mcast_msg["_bounce"]  = true;
                mcast_msg["_message"] = "multicast test message";

                multicast_.SendToChannel(mcast_msg);
            }
            else
            {
                PbufHelloMessage hello_msg = new PbufHelloMessage();
                hello_msg.message = "multicast test message";

                FunMulticastMessage mcast_msg = FunapiMessage.CreateFunMessage(hello_msg, MulticastMessageType.pbuf_hello);
                mcast_msg.channel = kChannelName;
                mcast_msg.bounce  = true;

                multicast_.SendToChannel(mcast_msg);
            }
        }
コード例 #8
0
ファイル: ServerNetwork.cs プロジェクト: ssorae/extichu_2017
 public override void SendMessage <TPacket>(MessageType packetType, TPacket packet)
 {
     _session.SendMessage(packetType, FunapiMessage.CreateFunMessage(packet, packetType));
 }