Example #1
0
        private static void CreateSession(MessageData mdata, DWMessage packet)
        {
            Net_TcpDisconnected(mdata);
            var    seed = 0;
            string IP   = mdata.Get <string>("cid");

            string[] IPParts = IP.Split(':');
            seed = BitConverter.ToInt32(IPAddress.Parse(IPParts[0]).GetAddressBytes(), 0);
            TimeSpan ts = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0));

            seed += (int)ts.TotalSeconds;

            var rnd = new Random(seed);
            var sid = new byte[8];

            rnd.NextBytes(sid);

            var titleID            = DWRouter.GetTitleIDForData(mdata);
            bdMatchMakingInfo info = null;

            if (titleID == TitleID.T5)
            {
                info = new MatchMakingInfoT5();
            }
            else if (titleID == TitleID.IW5)
            {
                info = new MatchMakingInfoIW5();
            }

            info.Deserialize(packet);
            info.SessionID = sid;
            info.CID       = mdata.Get <string>("cid");
            info.User      = (DWRouter.CIDToUser.ContainsKey(info.CID)) ? DWRouter.CIDToUser[info.CID] : 0;
            info.Reachable = true;

            lock (_sessions)
            {
                _sessions.Add(BitConverter.ToUInt64(sid, 0), info);
            }

            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)1);
            reply.ByteBuffer.Write((uint)1);
            reply.ByteBuffer.Write((uint)1);
            reply.ByteBuffer.WriteBlob(info.SessionID);
            reply.Send(true);

            if (titleID == TitleID.T5)
            {
                var tInfo = (MatchMakingInfoT5)info;
                Log.Debug(tInfo.OnlineID.ToString("X16") + " registered session (map " + tInfo.MapName + ", gametype " + tInfo.GameTypeName + ")");
            }
            else if (titleID == TitleID.IW5)
            {
                Log.Debug("Registered session.");
            }
        }
Example #2
0
        private static void UpdateSession(MessageData mdata, DWMessage packet)
        {
            var sidBlob = packet.ByteBuffer.ReadBlob();
            var sid     = BitConverter.ToUInt64(sidBlob, 0);

            var titleID            = DWRouter.GetTitleIDForData(mdata);
            bdMatchMakingInfo info = null;

            if (titleID == TitleID.T5)
            {
                info = new MatchMakingInfoT5();
            }
            else if (titleID == TitleID.IW5)
            {
                info = new MatchMakingInfoIW5();
            }

            info.Deserialize(packet);
            info.SessionID = sidBlob;
            info.CID       = mdata.Get <string>("cid");
            info.User      = (DWRouter.CIDToUser.ContainsKey(info.CID)) ? DWRouter.CIDToUser[info.CID] : 0;
            info.Reachable = true;

            _sessions[sid] = info;

            if (titleID == TitleID.T5)
            {
                var tInfo = (MatchMakingInfoT5)info;
                Log.Debug(tInfo.OnlineID.ToString("X16") + " updated session (map " + tInfo.MapName + ", gametype " + tInfo.GameTypeName + ")");
            }
            else if (titleID == TitleID.IW5)
            {
                Log.Debug("Updated session.");
            }

            var reply = packet.MakeReply(1, false);

            reply.ByteBuffer.Write(0x8000000000000001);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((byte)1);
            reply.ByteBuffer.Write((uint)0);
            reply.ByteBuffer.Write((uint)0);
            reply.Send(true);
        }