本文整理汇总了C#中System.IO.PacketReader类的典型用法代码示例。如果您正苦于以下问题:C# PacketReader类的具体用法?C# PacketReader怎么用?C# PacketReader使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PacketReader类属于System.IO命名空间,在下文中一共展示了PacketReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnCompressedGump
private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e)
{
p.MoveToData();
uint sender = p.ReadUInt32();
uint id = p.ReadUInt32();
if (id == responseID)
_responseSender = sender;
if (id != compressedID)
return;
p.Seek(19, SeekOrigin.Begin);
p.Seek(p.ReadInt32(), SeekOrigin.Current);
int lines = p.ReadInt32(), cLen = p.ReadInt32(), dLen = p.ReadInt32();
if (cLen < 5)
return;
byte[] buffer = new byte[dLen];
ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4);
string afk = string.Empty;
for (int i = 0, pos = 0; i < lines; i++)
{
int strLen = (buffer[pos++] << 8) | buffer[pos++];
string str = Encoding.BigEndianUnicode.GetString(buffer, pos, strLen * 2);
int index = str.IndexOf('>');
if (index != -1 && index < str.Length - 1)
afk += str[index + 1].ToString().ToUpper().Normalize(NormalizationForm.FormD)[0];
pos += strLen * 2;
}
afk = afk.Trim();
if (afk.Length == 5 && _responseSender != 0)
{
/*ClientCommunication.SendToClient(new CloseGump(responseID));
WorldEx.SendToServer(new GumpResponse(responseSender, responseID, 0x310, new int[0], new[] { new GumpTextEntry(0x310, afk) }));
responseSender = 0;*/
WorldEx.OverHeadMessage(afk);
}
}
示例2: HandlePacket
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
if (context.User == null || context.Character == null)
return;
// Looks/Jobs
if (size > 0)
{
var reader = new PacketReader(data);
reader.BaseStream.Seek(0x38, SeekOrigin.Begin);
context.Character.Looks = reader.ReadStruct<Character.LooksParam>();
context.Character.Jobs = reader.ReadStruct<Character.JobParam>();
using(var db = new PolarisEf())
db.ChangeTracker.DetectChanges();
}
Map lobbyMap = ZoneManager.Instance.MapFromInstance("lobby", "lobby");
lobbyMap.SpawnClient(context, lobbyMap.GetDefaultLocation(), "lobby");
// Unlock Controls
context.SendPacket(new NoPayloadPacket(0x03, 0x2B));
//context.SendPacket(File.ReadAllBytes("testbed/237.23-7.210.189.208.30.bin"));
// Give a blank palette
context.SendPacket(new PalettePacket());
// memset packet - Enables menus
// Also holds event items and likely other stuff too
var memSetPacket = File.ReadAllBytes("Resources/setMemoryPacket.bin");
context.SendPacket(memSetPacket);
}
示例3: GameClient
public GameClient(TcpClient selfClient, Guid onlineId, IClientKiller killer, ChatManager manager, GameLoop game)
{
_self = selfClient;
_self.NoDelay = true;
_self.Client.NoDelay = true;
_reader = new BinaryReader(_self.GetStream());
_writer = new BinaryWriter(_self.GetStream());
_clientKiller = killer;
_game = game;
ChatManager chatManager = manager;
chatManager.Join(this);
_auth = AuthorisationManager.Resolve();
_packetReader = PacketReader.Resolve<ServerPacketReader>();
_packetReader.InitialiseMapping();
OnlineId = onlineId;
_active = true;
_subs = new List<PacketSubscriber>
{
this,
_game,
chatManager
};
Task.Factory.StartNew(Receive);
}
示例4: HandlePacket
public override void HandlePacket(Client context, byte flags, byte[] data, uint position, uint size)
{
var reader = new PacketReader(data);
var id = reader.ReadInt32();
Logger.Write("[CHR] {0} is deleting character with ID {1}", context.User.Username, id);
// Delete Character
using (var db = new PolarisEf())
{
foreach (var character in db.Characters)
if (character.CharacterId == id)
{
db.Characters.Remove(character);
db.ChangeTracker.DetectChanges();
break;
}
// Detect the deletion and save the Database
if (db.ChangeTracker.HasChanges())
db.SaveChanges();
}
// Disconnect for now
// TODO: What do we do after a deletion?
context.Socket.Close();
}
示例5: RicePacket
public RicePacket(RiceClient sender, ushort id, byte[] buffer)
{
Sender = sender;
Buffer = buffer;
ID = id;
Reader = new PacketReader(new MemoryStream(Buffer));
}
示例6: Runtime
//private readonly ILog _logger = LogManager.GetLogger("Runtime");
/// <summary>
/// Create the Runtime object to combine all the various components of the livetiming.
/// </summary>
/// <param name="liveStream">A stream used to represent the incoming data of the live stream.</param>
/// <param name="authKeyService">Provider for authorization key requests.</param>
/// <param name="keyFrameService">Provider for keyframes.</param>
/// <param name="messageDispatch">A receiver for messages.</param>
public Runtime(Stream liveStream, IAuthKey authKeyService, IKeyFrame keyFrameService, IMessageDispatch messageDispatch)
{
_decryptor = new DataDecryptor();
_packetReader = new PacketReader(liveStream, new DecryptStreamDecorator(liveStream, _decryptor));
_messageDispatch = messageDispatch;
_authKeyService = authKeyService;
_keyFrameService = keyFrameService;
}
示例7: OnServerStop
private static void OnServerStop(Client client, PacketReader reader)
{
MessageBox.Show("服务器关闭");
try
{
client.Close(true);
}
catch { }
client.ServerStop();
}
示例8: Connection
private Connection(string server, int port)
{
_port = port;
_server = server;
_packetReader = PacketReader.Resolve<ClientPacketReader>();
_packetReader.InitialiseMapping();
_subs = new List<PacketSubscriber>();
AddSubscriber(this);
}
示例9: ProcessPacket
public static void ProcessPacket( byte[] data )
{
PacketHandler call = m_Table[data[0]] as PacketHandler;
if ( call != null )
{
PacketReader pvSrc = new PacketReader( data, RPVEditor.PacketInfo.IsDyn( data[0] ) );
pvSrc.MoveToData();
call( pvSrc );
}
}
示例10: HandlePacket
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);
}
}
}
示例11: OnServerInfo
private static void OnServerInfo(Client client, PacketReader reader){
//服务器信息
Program.Config.ChatPort = reader.ReadInt32();
Program.Config.DuelPort = reader.ReadInt32();
Program.Config.NeedAuth = reader.ReadBoolean();
client.Pwd = reader.ReadUnicode(32);
#if DEBUG
MessageBox.Show(Program.Config.ChatPort+":"+Program.Config.DuelPort+":"+Program.Config.NeedAuth + ":" + client.Pwd);
#endif
client.OnLoginOk();
}
示例12: OnError
private static void OnError(Client client, PacketReader reader){
//错误
string err = reader.ReadUnicode(256);
// int code = reader.ReadByte();
MessageBox.Show(err);
//if(!client.IsLogin){
try{
client.Close(client.IsLogin);
}catch{}
//}
}
示例13: ClientDoubleClick
private static void ClientDoubleClick(PacketReader p, PacketHandlerEventArgs args)
{
Serial serial = p.ReadUInt32();
if (items.ContainsKey(serial))
{
args.Block = true;
WorldEx.SendToServer(new DoubleClick(items[serial].List.Last()));
}
else
args.Block = PacketHandler.ProcessViewers(clientDoubleClick, p);
}
示例14: OnCompressedGump
private static void OnCompressedGump(PacketReader p, PacketHandlerEventArgs e)
{
p.Seek(7, SeekOrigin.Begin);
if (p.ReadUInt32() != 0x1105B263)
return;
p.Seek(19, SeekOrigin.Begin);
p.Seek(p.ReadInt32() + 4, SeekOrigin.Current);
int cLen = p.ReadInt32(), dLen = p.ReadInt32();
byte[] buffer = new byte[dLen];
ZLib.uncompress(buffer, ref dLen, p.CopyBytes(p.Position, cLen - 4), cLen - 4);
int strLen = (buffer[0] << 8) | buffer[1];
string[] str = Encoding.BigEndianUnicode.GetString(buffer, 2, strLen * 2).Split(',');
string[] lat = str[0].Split('°');
int yLat = int.Parse(lat[0]);
int yMins = int.Parse(lat[1].Split('\'')[0]);
bool ySouth = lat[1][lat[1].Length - 1] == 'S';
string[] lon = str[1].Split('°');
int xLong = int.Parse(lon[0]);
int xMins = int.Parse(lon[1].Split('\'')[0]);
bool xEast = lon[1][lon[1].Length - 1] == 'E';
const int xWidth = 5120;
const int yHeight = 4096;
const int xCenter = 1323;
const int yCenter = 1624;
double absLong = xLong + ((double)xMins / 60);
double absLat = yLat + ((double)yMins / 60);
if (!xEast)
absLong = 360.0 - absLong;
if (!ySouth)
absLat = 360.0 - absLat;
int x = xCenter + (int)((absLong * xWidth) / 360);
int y = yCenter + (int)((absLat * yHeight) / 360);
if (x < 0)
x += xWidth;
else if (x >= xWidth)
x -= xWidth;
if (y < 0)
y += yHeight;
else if (y >= yHeight)
y -= yHeight;
onGump(x, y);
}
示例15: OnRoomStart
private static void OnRoomStart(DuelServer server, PacketReader packet){
string name = packet.ReadUnicode(20);
Logger.Debug("OnRoomStart:"+server.Port+","+name);
lock(server.Rooms){
GameConfig cfg = null;
if(server.Rooms.TryGetValue(name, out cfg)){
cfg.IsStart = true;
}else{
Logger.Warn("no start room:"+name+" form "+server.Port);
}
}
if(server.Server!=null)
server.Server.server_OnRoomStart(server, name);
}