示例#1
0
        private void IncommingBytesToPackets(byte[] bytes, int numBytes)
        {
            byte[] cheatArray = new byte[numBytes];// this is a terrible temp solution
            Buffer.BlockCopy(bytes, 0, cheatArray, 0, numBytes);
#if DEBUG_NETWORK_PACKETS
            Console.WriteLine("Received: " + BitConverter.ToString(cheatArray));
#endif
            int bytesParsed          = 0;
            List <BasePacket> dataIn = IntrepidSerialize.Deserialize(cheatArray, numBytes, ref bytesParsed);
            lock (packetsReceived)
            {
                int num = packetsReceived.Count;
                dataIn.ForEach((bp) => { packetsReceived.Enqueue(bp); });
                totalPacketsReceived = packetsReceived.Count - num;
            }
            if (packetAnalyzer != null)
            {
                dataIn.ForEach((bp) => { packetAnalyzer.Send(bp); });
            }
#if DEBUG_NETWORK_PACKETS
            Console.WriteLine("totalCount of packets received {0}", totalPacketsReceived);
#endif

            if (bytesParsed < numBytes)
            {
                int numBytesUnParsed = numBytes - bytesParsed;
                Buffer.BlockCopy(cheatArray, bytesParsed, readBuffer, 0, numBytesUnParsed);
                readBufferOffset = numBytesUnParsed;
            }
            else
            {
                readBufferOffset = 0;
            }
        }
示例#2
0
        private void SendKeepAlive()
        {
            if (IsAwaitingKeepAlive == true)
            {
                return;
            }

            IsAwaitingKeepAlive = true;
            timestampOfLastKeepAlive.Restart();
            KeepAlive ka = (KeepAlive)IntrepidSerialize.TakeFromPool(PacketType.KeepAlive);

            Send(ka);
        }
示例#3
0
        void ManageDebuggingPackets(BasePacket packet)
        {
#if DEBUG_NETWORK_PACKETS
            if (IntrepidSerialize.DebugLogPacket(packet))
            {
                Console.WriteLine("Attempting to send {0}", packet);
            }

            /*    if (packet is ServerPingHopperPacket)
             *  {
             *      ServerPingHopperPacket hopper = packet as ServerPingHopperPacket;
             *      string name = Assembly.GetCallingAssembly().GetName().Name;
             *      hopper.Stamp(name + " gateway send to client");
             *     // Send(packet);
             * } */
#endif
        }
示例#4
0
        private void Send()
        {
            BasePacket[] packetList = PrepPacketsToSend();
            if (packetList == null)
            {
                return;
            }

            memoryStream.Seek(0, SeekOrigin.Begin);

            for (int i = 0; i < packetList.Length; i++)
            {
                BasePacket packet = packetList[i];

                ManageDebuggingPackets(packet);

                int pos = Network.Utils.SetupWrite(binaryWriter);
                packet.Write(binaryWriter);
                Network.Utils.FinishWrite(binaryWriter, pos);

                IntrepidSerialize.ReturnToPool(packet);
            }
            SendRecursive(packetList);
        }
示例#5
0
        public bool ProcessIdPackets()// TODO: only process id packets
        {
            List <BasePacket> packets = RetrieveData();

            if (packets.Count == 0)
            {
                // We're still waiting for their packet
                return(true);
            }
            else if (packets.Count == 1)
            {
                BasePacket     packet = packets[0];
                ServerIdPacket id     = packet as ServerIdPacket;
                if (id != null)
                {
                    gameId     = id.Id;
                    serverType = id.Type;
                    int mapId = id.MapId;
                    versionAndHandshakeComplete = true;
                    IntrepidSerialize.ReturnToPool(packet);
                    return(true);
                }

                /*     if (packet is ServerPingHopperPacket)
                 *   {
                 *       HandleServerHopping(packet as ServerPingHopperPacket);
                 *       return true;
                 *   }*/
                IntrepidSerialize.ReturnToPool(packet);
            }

            // If we're here, it means we either received more than one packet
            // or it wasn't a ServerIdPacket, which means the server isn't behaving
            // properly
            return(false);
        }