public static void Buffer_ReplyAskFrame(ReplyAskFrame replyAskFrame)
    {
        p_AllMsg.ReplyAskFrame.type = replyAskFrame.type;

        p_AllMsg.ReplyAskFrame.replyFrames = new Dictionary <int, List <p_AllMsg.p_Frame> >();
        foreach (KeyValuePair <int, List <Frame> > replyframe in replyAskFrame.replyFrames)
        {
            int frame_count = replyframe.Key;

            if (!p_AllMsg.ReplyAskFrame.replyFrames.ContainsKey(frame_count))
            {
                List <p_AllMsg.p_Frame> p_frame_list = new List <p_AllMsg.p_Frame>();

                foreach (Frame frame in replyframe.Value)
                {
                    SyncFrame syncFrame = frame.syncFrame;
                    List <p_AllMsg.p_CustomSyncMsg> p_msg_list = Buffer_SyncFrame_msg_list(syncFrame.msg_list);

                    p_AllMsg.p_SyncFrame p_syncFrame = new p_AllMsg.p_SyncFrame();
                    p_syncFrame.frame_count = syncFrame.frame_count;
                    p_syncFrame.msg_list    = p_msg_list;


                    p_AllMsg.p_Frame p_frame = new p_AllMsg.p_Frame();
                    p_frame.player_id = frame.player_id;

                    p_frame.syncFrame = new p_AllMsg.p_SyncFrame();
                    p_frame.syncFrame = p_syncFrame;

                    p_frame_list.Add(p_frame);
                }
                p_AllMsg.ReplyAskFrame.replyFrames.Add(frame_count, p_frame_list);
            }
        }
    }
Exemple #2
0
    public void OnAskedFrame(int clientID, List <int> areas, List <int> frames)
    {
        if (TheRoom != null)
        {
            List <int> Tareas = new List <int>();
            List <List <SyncFrame> > Tframes = new List <List <SyncFrame> >();


            for (int nLoop = 0; nLoop < areas.Count; ++nLoop)
            {
                int areaID     = areas[nLoop];
                int startFrame = frames[nLoop];
                List <SyncFrame> syncFrames = TheRoom.GetArea(areaID).GetNewFrames(startFrame);

                Tareas.Add(areaID);
                Tframes.Add(syncFrames);
            }

            NetworkMsg msg = new ReplyAskFrame(Tareas, Tframes);
            networkManager.SendDataTo(clientID, msg);
        }
        else
        {
            UnityEngine.Debug.Log("TheRoom != null");
        }
    }
Exemple #3
0
 public void BroadcastFrameUpdate(int startframe, int end)
 {
     for (int i = startframe; i < end; i++)
     {
         Dictionary <int, List <Frame> > updateFrames = new Dictionary <int, List <Frame> >();
         updateFrames.Add(i, TotalFrames[i]);
         ReplyAskFrame replyAskFrame = new ReplyAskFrame(updateFrames);
         roomBroadCast(replyAskFrame);
     }
 }
Exemple #4
0
    public void OnAskFrame(List <int> frames, int clientID)
    {
        if (frames.Count > 1)
        {
            Debug.Log("Error:AskFrame count>1");
        }
        if (frames.Count <= 0)
        {
            Debug.Log("Error:AskFrame count<=0");
            return;
        }

        int startFrame = frames[0];

        Dictionary <int, List <Frame> > replyFrames = room.GetFrame(startFrame);


        NetworkMsg msg = new ReplyAskFrame(replyFrames);

        networkManager.SendDataTo(clientID, msg);
    }
    public static byte[] SerializeData(BaseProtocol baseProtocol, NetworkMsg networkMsg, ReplyGetRooms replyGetRooms = null, ReplyJoin replyJoin = null,
                                       ReplyAskFrame replyAskFrame = null, ReplyID replyID = null, ReplyStart replyStart = null)
    {
        p_AllMsg = new p_AllMsg();
        if (baseProtocol != null)
        {
            Buffer_BaseProtocol(baseProtocol);
        }
        if (networkMsg != null)
        {
            Buffer_NetworkMsg(networkMsg);
        }
        if (networkMsg.type == (int)CmdType.REPLYGETROOMS)
        {
            replyGetRooms = networkMsg as ReplyGetRooms;
            Buffer_ReplyGetRooms(replyGetRooms);
        }
        else if (networkMsg.type == (int)CmdType.REPLYJOIN)
        {
            replyJoin = networkMsg as ReplyJoin;
            Buffer_ReplyJoin(replyJoin);
        }
        else if (networkMsg.type == (int)CmdType.REPLYASKFRAME)
        {
            replyAskFrame = networkMsg as ReplyAskFrame;
            Buffer_ReplyAskFrame(replyAskFrame);
        }
        else if (networkMsg.type == (int)CmdType.REPLYSTART)
        {
            replyStart = networkMsg as ReplyStart;
            BufferReplyStart(replyStart);
        }
        else if (networkMsg.type == (int)CmdType.REPLYID)
        {
            replyID = networkMsg as ReplyID;
            Buffer_ReplyID(replyID);
        }

        return(Serialize <p_AllMsg>(p_AllMsg));
    }
    public static byte[] SerializeDatareplyAskFrame(ReplyAskFrame replyAskFrame)
    {
        var ms = new MemoryStream();
        var br = new BinaryWriter(ms);

        var areas = replyAskFrame.areas;

        br.Write((char)areas.Count);
        for (int nLoop = 0; nLoop < areas.Count; nLoop++)
        {
            br.Write((char)areas[nLoop]);
            List <SyncFrame> list = replyAskFrame.frames[nLoop];
            br.Write((short)list.Count);
            for (int i = 0; i < list.Count; i++)
            {
                SyncFrame cur = list[i];

                if (i == 0)
                {
                    br.Write((short)cur.frame_count);
                }

                br.Write((char)cur.msg_list.Count);

                for (int msgLoop = 0; msgLoop < cur.msg_list.Count; msgLoop++)
                {
                    SerializeData(br, cur.msg_list[msgLoop]);
                }
            }
        }

        var t = ms.ToArray();

        br.Close();
        ms.Close();
        return(t);
    }