Ejemplo n.º 1
0
		public static void OnRoomEvent(this GameServer server, StoSMessage msg, RoomInfo info){
			using(PacketWriter writer = new PacketWriter(2)){
				writer.Write((ushort)msg);
				//length
				writer.Write((ushort)1);
				writer.WriteUnicode(info.Name, 20);
				writer.WriteUnicode(info.Pwd, 20);
				writer.Write((byte)info.Rule);
				writer.Write((byte)info.Mode);
				writer.Write(info.IsStart);
				writer.WriteUnicode(info.Lflist, 60);
				writer.Write(info.Warring);
				writer.Write(info.StartLP);
				writer.Write((ushort)info.players.Length);
				for(int i =0; i<info.players.Length;i++){
					writer.WriteUnicode(info.players[i], 20);
				}
				writer.Write((ushort)info.observers.Count);
				for(int i =0; i<info.observers.Count;i++){
					writer.WriteUnicode(info.observers[i], 20);
				}
				//string str = Tool.ToJson(info);
				//byte[] bs = Encoding.Unicode.GetBytes(str);
				//writer.Write(bs);
				writer.Use();
				//Send(server.LocalClient, writer.Content);
			}
		}
Ejemplo n.º 2
0
        private void DoShipList(Socket socket)
        {
            var writer = new PacketWriter();
            var entries = new List<ShipEntry>();

            for (var i = 1; i < 11; i++)
            {
                var entry = new ShipEntry
                {
                    order = (ushort)i,
                    number = (uint)i,
                    status = ShipStatus.Online,
                    name = String.Format("Ship{0:0#}", i),
                    ip = PolarisApp.BindAddress.GetAddressBytes()
                };
                entries.Add(entry);
            }
            writer.WriteStruct(new PacketHeader(Marshal.SizeOf(typeof(ShipEntry)) * entries.Count + 12, 0x11, 0x3D, 0x4,
                0x0));
            writer.WriteMagic((uint)entries.Count, 0xE418, 81);
            foreach (var entry in entries)
                writer.WriteStruct(entry);

            writer.Write((Int32)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
            writer.Write(1);

            socket.Send(writer.ToArray());
            socket.Close();
        }
Ejemplo n.º 3
0
		public static void OnRoomClose(GameRoom room){
            using (PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.RoomClose);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
		}
Ejemplo n.º 4
0
 public static void OnServerClose(this RoomServer roomServer, DuelServer server)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.ServerClose);
         writer.Write(server.Port);
         DuelServer srv = roomServer.GetMinServer();
         lock (srv.AsyncLock)
         {
             srv.Count = 0;
         }
         if (srv != null)
         {
             //特殊处理
             writer.Write(srv.Port);
             writer.Write(srv.NeedAuth);
             //session.ServerInfo = srv;
             lock (roomServer.Clients)
             {
                 foreach (Session client in roomServer.Clients.Values)
                 {
                     if (client.ServerInfo != null && client.ServerInfo.Port == server.Port)
                     {
                         client.ServerInfo = srv;
                         client.Send(writer.Content);
                     }
                 }
             }
         }
                      
     }
 }
Ejemplo n.º 5
0
        public override byte[] GenerateSpawnBlob()
        {
            PacketWriter writer = new PacketWriter();
            writer.WriteStruct(Header);
            writer.WritePosition(Position);
            writer.Write((UInt16)0);
            writer.WriteFixedLengthASCII(Name, 0x20);

            writer.Write(0); // Padding?
            writer.Write(new byte[0xC]); // Unknown, usually zero

            writer.Write((UInt16)0);
            writer.Write((UInt16)0);

            writer.Write((UInt32)0);
            writer.Write((UInt32)0);

            writer.Write((UInt32)1101004800); // Always this

            writer.Write((UInt32)0);
            writer.Write((UInt32)0);
            writer.Write((UInt32)0);

            writer.Write((UInt32)1);

            writer.WriteMagic(1, 0x9FCD, 0xE7);
            writer.Write((UInt32)0);

            return writer.ToArray();
        }
Ejemplo n.º 6
0
        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            var writer = new PacketWriter();
            writer.Write((uint) 0);

            context.SendPacket(0x11, 0x55, 0x0, writer.ToArray());
        }
Ejemplo n.º 7
0
 public static void OnSendServerInfo(this RoomServer roomServer, Session session)
 {
     using (PacketWriter writer = new PacketWriter(2))
     {
         writer.Write((byte)RoomMessage.Info);
         writer.Write(roomServer.GetChatPort());
         DuelServer srv = roomServer.GetMinServer();
         lock (srv.AsyncLock)
         {
             srv.Count++;
         }
         if (srv != null)
         {
             session.ServerInfo = srv;
             writer.Write(srv.Port);
             writer.Write(srv.NeedAuth);
         }
         else
         {
             writer.Write(0);
             writer.Write((byte)0);
         }
         writer.WriteUnicode(session.Token, 32);
         session.Send(writer.Content);
     }
 }
Ejemplo n.º 8
0
        public RicePacket(ushort id)
        {
            Writer = new PacketWriter(new MemoryStream());
            ID = id;

            Writer.Write(id);
        }
Ejemplo n.º 9
0
		public static void LobbyError(this Session session, string message)
		{
			using (PacketWriter join = new PacketWriter(2))
			{
				join.Write((byte)RoomMessage.JoinGame);
				join.Write(0U);
				join.Write((byte)0);
				join.Write((byte)0);
				join.Write(0);
				join.Write(0);
				join.Write(0);
				// C++ padding: 5 bytes + 3 bytes = 8 bytes
				for (int i = 0; i < 3; i++)
					join.Write((byte)0);
				join.Write(0);
				join.Write((byte)0);
				join.Write((byte)0);
				join.Write((short)0);
				session.Send(join, false);
			}

			using (PacketWriter enter = new PacketWriter(2))
			{
				enter.Write((byte)RoomMessage.HsPlayerEnter);
				enter.WriteUnicode("[err]" + message, 20);
				enter.Write((byte)0);
				session.Send(enter);
			}
		}
Ejemplo n.º 10
0
 public SendRecvPacket(int id, string name)
 {
     Id = id;
     Name = name;
     Stream = PacketWriter.CreateInstance(Length);
     Stream.Write(id);
     Stream.Write((short) 0);
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Creates an instance of a packet
 /// </summary>
 /// <param name="id">the Id, or Command that identifies the packet</param>
 /// <param name="name">The name of the packet</param>
 public SendPacket(int id, string name)
 {
     m_Id = id;
     m_Name = name;
     Stream = PacketWriter.CreateInstance(m_Length);
     Stream.Write((byte)id);
     Stream.Write((short)0);
 }
Ejemplo n.º 12
0
		public static void OnPlayerLeave(GameSession player, GameRoom room){
            if (player.Name == null || player.Name.StartsWith("[AI]")) return;
            using (PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.PlayerLeave);
				writer.WriteUnicode(player.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
		}
Ejemplo n.º 13
0
		public static void OnServerInfo(GameServer server){
			ServerConfig Config = server.Config;
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.Info);
				writer.Write(Config.ServerPort);
				writer.Write(Config.isNeedAuth);
				Send(writer.Content);
			}
		}
Ejemplo n.º 14
0
        public SendRecvPacket(int id, string name, int length)
        {
            Id = id;
            Name = name;
            Length = length;

            Stream = PacketWriter.CreateInstance(length);
            Stream.Write((byte) id);
        }
Ejemplo n.º 15
0
        public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
        {
            if (context.Character == null)
                return;

            var reader = new PacketReader(data, position, size);
            reader.BaseStream.Seek(0xC, SeekOrigin.Begin);
            var channel = reader.ReadUInt32();
            var message = reader.ReadUtf16(0x9D3F, 0x44);

            if (message.StartsWith(PolarisApp.Config.CommandPrefix))
            {
                var valid = false;

                // Iterate commands
                foreach (var command in PolarisApp.ConsoleSystem.Commands)
                {
                    var full = message.Substring(1); // Strip the command chars
                    var args = full.Split(' ');

                    if (command.Names.Any(name => args[0].ToLower() == name.ToLower()))
                    {
                        command.Run(args, args.Length, full, context);
                        valid = true;
                        Logger.WriteCommand(null, "[CMD] {0} issued command {1}", context.User.Username, full);
                    }

                    if (valid)
                        break;
                }

                if (!valid)
                    Logger.WriteClient(context, "[CMD] {0} - Command not found", message.Split(' ')[0].Trim('\r'));
            }
            else
            {
                Logger.Write("[CHT] <{0}> <{1}>", context.Character.Name, message);

                var writer = new PacketWriter();
                writer.WritePlayerHeader((uint) context.User.PlayerId);
                writer.Write(channel);
                writer.WriteUtf16(message, 0x9D3F, 0x44);

                data = writer.ToArray();

                foreach (var c in Server.Instance.Clients)
                {
                    if (c.Character == null || c.CurrentZone != context.CurrentZone)
                        continue;

                    c.SendPacket(0x07, 0x00, 0x44, data);
                }
            }
        }
Ejemplo n.º 16
0
 /// <exception cref="System.IO.IOException" />
 internal NovacomSocketStream(TcpClient socket, string cmdUsedForStream)
 {
     this.socket = socket;
     ioStream = this.socket.GetStream();
     packetReader = new PacketReader(ioStream);
     packetWriter = new PacketWriter(ioStream);
     packetMode = true;
     outputClosed = false;
     inputClosed = false;
     this.cmdUsedForStream = cmdUsedForStream;
 }
Ejemplo n.º 17
0
		public static void OnPlayerEnter(GameSession player, GameRoom room){
            if (player.Name==null||player.Name.StartsWith("[AI]")) return;
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.PlayerEnter);
				writer.WriteUnicode(player.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				Send(writer.Content);
			}
			string tip = Messages.RandomMessage();
			if(!string.IsNullOrEmpty(tip))
				player.ServerMessage(Messages.RandomMessage());
		}
Ejemplo n.º 18
0
		public static void OnRoomCreate(GameRoom room){
			if(room==null||room.Config==null){
				return;
			}
			using(PacketWriter writer=new PacketWriter(2)){
				writer.Write((byte)RoomMessage.RoomCreate);
				writer.WriteUnicode(room.Name, 20);
				writer.WriteUnicode(room.Config.Name, 20);
				writer.WriteUnicode(room.Config.BanList);
				Send(writer.Content);
			}
		}
Ejemplo n.º 19
0
        private void DoBlockBalance(Socket socket)
        {
            var writer = new PacketWriter();
            writer.WriteStruct(new PacketHeader(0x90, 0x11, 0x2C, 0x0, 0x0));
            writer.Write(new byte[0x68 - 8]);
            writer.Write(PolarisApp.BindAddress.GetAddressBytes());
            writer.Write((UInt16)12205);
            writer.Write(new byte[0x90 - 0x6A]);

            socket.Send(writer.ToArray());
            socket.Close();
        }
Ejemplo n.º 20
0
        public virtual byte[] GenerateSpawnBlob()
        {
            PacketWriter writer = new PacketWriter();
            writer.WriteStruct(Header);
            writer.Write(Position);
            writer.Seek(2, SeekOrigin.Current); // Padding I guess...
            writer.WriteFixedLengthASCII(Name, 0x34);
            writer.Write(ThingFlag);
            writer.Write(Things.Length);
            foreach (PSOObjectThing thing in Things)
            {
                writer.WriteStruct(thing);
            }

            return writer.ToArray();
        }
Ejemplo n.º 21
0
 public void WritePacket(PacketWriter writer)
 {
     writer.WriteInt32((int)FailureReason);
     if (Fingerprint != null)
         writer.WriteString(Fingerprint.ToJson());
     else
         writer.WriteString(null);
     writer.WriteString(HostName);
     writer.WriteString(AssetsRootUrl);
     writer.WriteString(iTunesUrl);
     writer.WriteString(Unknown1);
     writer.WriteInt32(RemainingTime);
     writer.WriteByte(Unknown2);
     writer.WriteByteArray(CompressedFingerprintJson);
     writer.WriteString(Unknown3);
     writer.WriteString(Unknown4);
     File.WriteAllBytes("dump", ((MemoryStream)writer.BaseStream).ToArray());
 }
Ejemplo n.º 22
0
        public Client(Server server, SocketClient socket)
        {
            IsClosed = false;
            _server = server;
            Socket = socket;

            socket.DataReceived += HandleDataReceived;
            socket.ConnectionLost += HandleConnectionLost;

            _readBuffer = new byte[1024 * 64];
            _readBufferSize = 0;

            InputArc4 = null;
            OutputArc4 = null;

            var welcome = new PacketWriter();
            welcome.Write((ushort)3);
            welcome.Write((ushort)201);
            welcome.Write((ushort)0);
            welcome.Write((ushort)0);
            SendPacket(0x03, 0x08, 0, welcome.ToArray());
        }
        public void WritePacket(PacketWriter writer)
        {

        }
Ejemplo n.º 24
0
 public void EnsureCapacity(int length)
 {
     Stream = PacketWriter.CreateInstance(length);
     Stream.Write((byte) Id);
     Stream.Write((short) length);
 }
Ejemplo n.º 25
0
        public override void Serialize(PacketWriter writer, bool prefix)
        {
            if (prefix) {
                writer.BlockCopy(SteamPacket.Prefix);
            }

            writer.WriteStringNoZero(Request);
        }
Ejemplo n.º 26
0
        public override void Serialize(PacketWriter writer, bool prefix)
        {
            PacketWriter pw = new PacketWriter();

            base.Serialize(pw, prefix);

            int lengthPosition = pw.Position;
            pw.WriteInt(0); // length

            pw.WriteInt(RequestId);
            pw.WriteInt(Header);
            pw.WriteStringNoZero(RconData);

            pw.Position = lengthPosition;

            pw.WriteInt(pw.Length);
        }
Ejemplo n.º 27
0
        public override void Serialize(PacketWriter writer, bool prefix)
        {
            base.Serialize(writer, prefix);

            writer.WriteStringNoZero(Response);
        }
Ejemplo n.º 28
0
 /*
  * EVENTS
  */
 internal int EnableEvent(EventType etype, SuspendPolicy suspend_policy, List<Modifier> mods)
 {
     var w = new PacketWriter ().WriteByte ((byte)etype).WriteByte ((byte)suspend_policy);
     if (mods != null) {
         if (mods.Count > 255)
             throw new NotImplementedException ();
         w.WriteByte ((byte)mods.Count);
         foreach (Modifier mod in mods) {
             if (mod is CountModifier) {
                 w.WriteByte ((byte)ModifierKind.COUNT);
                 w.WriteInt ((mod as CountModifier).Count);
             } else if (mod is LocationModifier) {
                 w.WriteByte ((byte)ModifierKind.LOCATION_ONLY);
                 w.WriteId ((mod as LocationModifier).Method);
                 w.WriteLong ((mod as LocationModifier).Location);
             } else if (mod is StepModifier) {
                 w.WriteByte ((byte)ModifierKind.STEP);
                 w.WriteId ((mod as StepModifier).Thread);
                 w.WriteInt ((mod as StepModifier).Size);
                 w.WriteInt ((mod as StepModifier).Depth);
                 if (Version.AtLeast (2, 16))
                     w.WriteInt ((mod as StepModifier).Filter);
             } else if (mod is ThreadModifier) {
                 w.WriteByte ((byte)ModifierKind.THREAD_ONLY);
                 w.WriteId ((mod as ThreadModifier).Thread);
             } else if (mod is ExceptionModifier) {
                 var em = mod as ExceptionModifier;
                 w.WriteByte ((byte)ModifierKind.EXCEPTION_ONLY);
                 w.WriteId (em.Type);
                 if (Version.MajorVersion > 2 || Version.MinorVersion > 0) {
                     /* This is only supported in protocol version 2.1 */
                     w.WriteBool (em.Caught);
                     w.WriteBool (em.Uncaught);
                 } else if (!em.Caught || !em.Uncaught) {
                     throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
                 }
                 if (Version.MajorVersion > 2 || Version.MinorVersion > 24) {
                     w.WriteBool (em.Subclasses);
                 } else if (!em.Subclasses) {
                     throw new NotSupportedException ("This request is not supported by the protocol version implemented by the debuggee.");
                 }
             } else if (mod is AssemblyModifier) {
                 w.WriteByte ((byte)ModifierKind.ASSEMBLY_ONLY);
                 var amod = (mod as AssemblyModifier);
                 w.WriteInt (amod.Assemblies.Length);
                 foreach (var id in amod.Assemblies)
                     w.WriteId (id);
             } else if (mod is SourceFileModifier) {
                 w.WriteByte ((byte)ModifierKind.SOURCE_FILE_ONLY);
                 var smod = (mod as SourceFileModifier);
                 w.WriteInt (smod.SourceFiles.Length);
                 foreach (var s in smod.SourceFiles)
                     w.WriteString (s);
             } else if (mod is TypeNameModifier) {
                 w.WriteByte ((byte)ModifierKind.TYPE_NAME_ONLY);
                 var tmod = (mod as TypeNameModifier);
                 w.WriteInt (tmod.TypeNames.Length);
                 foreach (var s in tmod.TypeNames)
                     w.WriteString (s);
             } else {
                 throw new NotImplementedException ();
             }
         }
     } else {
         w.WriteByte (0);
     }
     return SendReceive (CommandSet.EVENT_REQUEST, (int)CmdEventRequest.SET, w).ReadInt ();
 }
Ejemplo n.º 29
0
        PacketReader SendReceive(CommandSet command_set, int command, PacketWriter packet)
        {
            int packetId = IdGenerator;
            Stopwatch watch = null;

            if (disconnected)
                throw new VMDisconnectedException ();

            if (EnableConnectionLogging)
                watch = Stopwatch.StartNew ();

            byte[] encoded_packet;

            if (packet == null)
                encoded_packet = EncodePacket (packetId, (int)command_set, command, null, 0);
            else
                encoded_packet = EncodePacket (packetId, (int)command_set, command, packet.Data, packet.Offset);

            WritePacket (encoded_packet);
            if (EnableConnectionLogging) {
                LogPacket ("Send", packetId, command_set, command, encoded_packet);
            }

            /* Wait for the reply packet */
            while (true) {
                lock (reply_packets_monitor) {
                    if (reply_packets.ContainsKey (packetId)) {
                        byte[] reply = reply_packets [packetId];
                        reply_packets.Remove (packetId);
                        PacketReader r = new PacketReader (reply);

                        if (EnableConnectionLogging) {
                            LogPacket ("Recv", packetId, command_set, command, reply);
                        }

                        if (r.ErrorCode != 0) {
                            if (ErrorHandler != null)
                                ErrorHandler (this, new ErrorHandlerEventArgs () { ErrorCode = (ErrorCode)r.ErrorCode });
                            throw new NotImplementedException ("No error handler set.");
                        } else {
                            return r;
                        }
                    } else {
                        if (disconnected)
                            throw new VMDisconnectedException ();
                        Monitor.Wait (reply_packets_monitor);
                    }
                }
            }
        }
Ejemplo n.º 30
0
        /* Send a request and call cb when a result is received */
        int Send(CommandSet command_set, int command, PacketWriter packet, Action<PacketReader> cb, int count)
        {
            int id = IdGenerator;

            byte[] encoded_packet;
            if (packet == null)
                encoded_packet = EncodePacket (id, (int)command_set, command, null, 0);
            else
                encoded_packet = EncodePacket (id, (int)command_set, command, packet.Data, packet.Offset);

            if (cb != null) {
                lock (reply_packets_monitor) {
                    reply_cbs [id] = delegate (int packet_id, byte[] p) {
                        if (EnableConnectionLogging) {
                            LogPacket ("Recv", packet_id, command_set, command, encoded_packet);
                        }
                        /* Run the callback on a tp thread to avoid blocking the receive thread */
                        PacketReader r = new PacketReader (p);
                        cb.BeginInvoke (r, null, null);
                    };
                    reply_cb_counts [id] = count;
                }
            }

            if (buffer_packets) {
                buffered_packets.Add (encoded_packet);
            } else {
                WritePacket (encoded_packet);
            }
            if (EnableConnectionLogging) {
                LogPacket ("Send", id, command_set, command, encoded_packet);
            }

            return id;
        }