Пример #1
0
 public void getBytesTest()
 {
     byte[] bytes = null; // TODO: Initialize to an appropriate value
     Packet target = new Packet(bytes); // TODO: Initialize to an appropriate value
     byte[] expected = null; // TODO: Initialize to an appropriate value
     byte[] actual;
     actual = target.getBytes();
     Assert.AreEqual(expected, actual);
     Assert.Inconclusive("Verify the correctness of this test method.");
 }
Пример #2
0
 public static void SendPosUpdate(string nPlayerId, Vector2 nPos)
 {
     PacketHeader header = new PacketHeader(32, 0x01);
     byte[] packet = new byte[32];
     Array.Copy(ArrayUtil.StringToBytes(nPlayerId), packet, 24);
     byte[] temp = BitConverter.GetBytes((int)nPos.X);
     temp.Reverse();
     Array.Copy(temp, 0, packet, 24, 4);
     temp = BitConverter.GetBytes((int)nPos.Y);
     temp.Reverse();
     Array.Copy(temp, 0, packet, 28, 4);
     Packet realpacket = new Packet(header, packet);
     mConnection.Write(realpacket.getBytes());
 }
Пример #3
0
 public void PacketConstructorTest()
 {
     PacketHeader header = new PacketHeader(32, 0x01);
     byte[] body = new byte[32] { 0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x00, 0x00, 0x00, 0x01,
                                  0x00, 0x00, 0x00, 0x01 };
     Packet target = new Packet(header, body);
     Assert.IsTrue(body.SequenceEqual(target.Body));
     Assert.IsTrue(header.Equals(target.Header));
 }
        private static void process()
        {
            // There needs to be at least a header to get
            while (Queue.Count > 9)
            {
                byte[] hak = Queue.GetRange(0, 3).ToArray();
                if (Encoding.ASCII.GetString(hak) == PacketHeader.TAG)
                {
                    PacketHeader ph = new PacketHeader(Queue.GetRange(0, 9).ToArray());
                    Packet pack = new Packet(ph, Queue.GetRange(9, ph.Length).ToArray());
                    // Remove the stuff we've gathered
                    Queue.RemoveRange(0, ph.Length + 9);

                    if (CommandDelegates.CommandInitialized(ph.Command))
                    {
                        switch (ph.Command)
                        {
                            case 0x01:      // Update position
                                CommandDelegates.UpdatePositionDelegate upd = (CommandDelegates.UpdatePositionDelegate)CommandDelegates.getInitializedDelegate(ph.Command);
                                upd.Invoke(CommandParamsParser.parseBytes(pack.Body, ph.Command));
                                break;
                            case 0x02:      // Spawn Monster
                                CommandDelegates.SpawnMonsterDelegate smd = (CommandDelegates.SpawnMonsterDelegate)CommandDelegates.getInitializedDelegate(ph.Command);
                                smd.Invoke(CommandParamsParser.parseBytes(pack.Body, ph.Command));
                                break;
                        }
                    }
                    else
                    {
                        // This means we're not supposed to act uppon the command
                    }

                }
                else
                {
                    // for now, throw away the first byte and try to look for the tag again
                    Queue.RemoveAt(0);
                    continue;
                }
            }
            // Pause the thread. It will be resumed when data is enqueued.
            runnerReset.WaitOne();
        }
Пример #5
0
 public void PacketConstructorTest1()
 {
     byte[] bytes = new byte[41] {0x48, 0x41, 0x4B,
                                  0x00, 0x00, 0x00, 0x20,
                                  0x00, 0x01,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x48, 0x41, 0x4B,
                                  0x00, 0x00, 0x00, 0x01,
                                  0x00, 0x00, 0x00, 0x01 };
     Packet target = new Packet(bytes);
     Assert.Inconclusive("TODO: Implement code to verify target");
 }