Exemple #1
0
    public void SendCommand(NetRequest request, ServerCallbackDelegate callback)
    {
        if (!isOfflinePlay)
        {
            Debug.Log("[SEND MSG]" + request.GetType().Name + "=>");
            _client.SendCommand(request, delegate(NetResponse msg) {
                callback(msg);
                Debug.Log("[RECIVE MSG]" + request.GetType().Name + "<=" + msg.ToString());
            });
            return;
        }

        Regex    regex   = new Regex("Request");
        string   cmdname = regex.Split(request.GetType().Name)[0];
        FileInfo info    = new FileInfo(Application.streamingAssetsPath + "/command/" + cmdname + ".txt");

        if (!info.Exists)
        {
            Debug.Log("[NOT RUN MSG]" + cmdname + "");
            return;
        }

        NetResponse response = Activator.CreateInstance(
            Assembly.GetAssembly(request.GetType())
            .GetType(cmdname + "Response")
            ) as FaustComm.NetResponse;
        FileStream fs = info.OpenRead();

        fs.Position = 0;
        BinaryReader br = new BinaryReader(fs);

        response.Decode(br);
        callback(response);
        fs.Close();
        fs.Dispose();
        Debug.Log("[RUN MSG]" + cmdname + "");
    }