protected override void ProBroadcast() { NetworkContent nc = new NetworkContent(); int id = sendThread.ManagedThreadId; long now = DateTime.Now.Ticks / 10000; long r = now % 30000; Int16 time = (Int16)r; while (GetBroadcast(ref nc)) { var dat = kcp.Pack(nc.dat, (byte)nc.MsgID, bid, time); BroadcastMsg msg = new BroadcastMsg(); msg.MsgID = bid; msg.data = dat; datas.Add(msg); for (int i = 0; i < tCount; i++) { linkBuff[i].Broadcast(id, bid); } bid++; if (bid >= MaxID) { bid = MinID; } } }
internal bool Get(ref NetworkContent content) { for (int i = 0; i < ncLength; i++) { if (ncs[i].State == 2) { content = ncs[i]; ncs[i].dat = null; ncs[i].MsgID = 0; ncs[i].State = 0; return(true); } } return(false); }
bool GetBroadcast(ref NetworkContent content) { for (int i = 0; i < 32; i++) { if (ncs[i].State == 2) { content = ncs[i]; ncs[i].dat = null; ncs[i].MsgID = 0; ncs[i].State = 0; return(true); } } return(false); }
public int SendMsg(KcpData link, Int16 time) { NetworkContent nc = new NetworkContent(); while (link.Get(ref nc)) { if (nc.dat == null) { if (nc.MsgID >= 60000)//这是一个广播消息 { var bm = kcpListener.FindBroadcastMsg(nc.MsgID); if (bm != null) { int c = bm.data.DataCount; for (int i = 0; i < c; i++) { MsgInfo info = new MsgInfo(); info.CurPart = (UInt16)i; unsafe { info.data = bm.data.Addr[i]; } info.MsgID = (UInt16)nc.MsgID; info.CreateTime = time; info.SendTime = time; link.Msgs.Add(info); } } } } else//这是一个私有消息 { link.MsgId++; if (link.MsgId >= MaxID) { link.MsgId = MinID; } PackAll(link, nc.dat, (byte)nc.MsgID, link.MsgId, time); } } ReSendTimeOut(link, time); return(link.Msgs.Count); }