本文整理汇总了C#中Packet.AddString方法的典型用法代码示例。如果您正苦于以下问题:C# Packet.AddString方法的具体用法?C# Packet.AddString怎么用?C# Packet.AddString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Packet
的用法示例。
在下文中一共展示了Packet.AddString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindPlayer
public bool FindPlayer(string characterName)
{
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
Packet pkt = new Packet(PacketFamily.Players, PacketAction.Accept);
pkt.AddString(characterName);
return m_client.SendPacket(pkt);
}
示例2: HandleReport
public static void HandleReport(Packet packet, IClient client, bool fromQueue)
{
// TODO: Replace temporary talk code
string message = packet.GetEndString();
if (message[0] == '%')
{
string scriptFilename = message.Substring(1);
try
{
Program.Logger.LogDebug(String.Format("Loading {0}", scriptFilename));
Script script = Script.LoadFromFile(scriptFilename);
Program.Logger.LogDebug("Compiling");
client.Server.ScriptHost.Compile(script);
if (script.Compiled)
{
Program.Logger.LogDebug("Executing");
client.Server.ScriptHost.Execute(script, null, new Object[]{client.Character});
}
else
{
Program.Logger.LogError("Script compilation failed: ");
foreach (var error in script.results.Errors)
{
Console.WriteLine(error);
}
}
}
catch (Exception ex)
{
Program.Logger.LogError("Script execution failed", ex);
}
}
else if (message[0] == '$') // TODO: $ as command macro, = as eval
{
try
{
CommandParser.Parse(message.Substring(1), client.Character);
}
catch (Exception ex)
{
Packet warning = new Packet(PacketFamily.Message, PacketAction.Open);
warning.AddString(String.Format("{0}: {1}", ex.GetType().Name, ex.Message));
client.Send(warning);
}
}
client.Character.SendMsg((IMessageTarget)client.Character.Map, new MessageLocal(client.Character, message));
}
示例3: AccountCheckName
public bool AccountCheckName(string username, out AccountReply result)
{
result = AccountReply.THIS_IS_WRONG;
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
Packet builder = new Packet(PacketFamily.Account, PacketAction.Request);
builder.AddString(username);
if (!m_client.SendPacket(builder) || !m_account_responseEvent.WaitOne(Constants.ResponseTimeout))
return false;
result = m_account_reply;
return true;
}
示例4: HandleRequest
public static void HandleRequest(Packet packet, IClient client, bool fromQueue)
{
short count = (short)client.Server.Characters.Count;
// TODO: Don't list hidden admins
Packet reply = new Packet(PacketFamily.Init, PacketAction.Init);
reply.AddChar((byte)EO.InitReply.Players);
reply.AddShort(count);
reply.AddBreak();
foreach (Character character in client.Server.Characters)
{
reply.AddBreakString(character.Name);
reply.AddBreakString(character.Title ?? "");
reply.AddChar(0); // What's this?
reply.AddChar((byte)EO.PaperdollIcon.HGM);
reply.AddChar((byte)character.ClassId);
reply.AddString("TAG");
reply.AddBreak();
}
client.Send(reply);
}
示例5: Speak
public bool Speak(TalkType chatType, string message, string character = null)
{
if (!m_client.ConnectedAndInitialized || !Initialized)
return false;
Packet builder;
switch (chatType)
{
case TalkType.Local:
builder = new Packet(PacketFamily.Talk, PacketAction.Report);
break;
case TalkType.PM:
builder = new Packet(PacketFamily.Talk, PacketAction.Tell);
if (string.IsNullOrWhiteSpace(character))
throw new ArgumentException("Unable to send a PM to invalid character!", "character");
builder.AddBreakString(character);
break;
case TalkType.Global:
builder = new Packet(PacketFamily.Talk, PacketAction.Message);
break;
case TalkType.Guild:
builder = new Packet(PacketFamily.Talk, PacketAction.Request);
break;
case TalkType.Party:
builder = new Packet(PacketFamily.Talk, PacketAction.Open);
break;
case TalkType.Admin:
builder = new Packet(PacketFamily.Talk, PacketAction.Admin);
break;
case TalkType.Announce:
builder = new Packet(PacketFamily.Talk, PacketAction.Announce);
break;
default: throw new NotImplementedException();
}
builder.AddString(message);
return m_client.SendPacket(builder);
}
示例6: HandleRequest
public static void HandleRequest(Packet packet, IClient client, bool fromQueue)
{
int id = packet.GetInt();
if (id < 0 || id > client.Account.Characters.Count)
throw new ArgumentOutOfRangeException("Login character ID out of range");
client.SelectCharacter(client.Account.Characters[id]);
Packet reply = new Packet(PacketFamily.Welcome, PacketAction.Reply);
reply.AddShort((short)WelcomeReply.CharacterInfo);
reply.AddShort((short)client.Id);
reply.AddInt(id);
reply.AddShort((short)client.Character.Map.Data.Id);
reply.AddBytes(client.Character.Map.Data.RevisionID);
reply.AddThree((int)client.Character.Map.Data.PubFileLength);
reply.AddBytes(client.Server.ItemData.revisionId);
reply.AddShort((short)client.Server.ItemData.Count);
reply.AddBytes(client.Server.NpcData.revisionId);
reply.AddShort((short)client.Server.NpcData.Count);
reply.AddBytes(client.Server.SpellData.revisionId);
reply.AddShort((short)client.Server.SpellData.Count);
reply.AddBytes(client.Server.ClassData.revisionId);
reply.AddShort((short)client.Server.ClassData.Count);
reply.AddBreakString(client.Character.Name);
reply.AddBreakString(client.Character.Title ?? "");
reply.AddBreakString("Guild Name");
reply.AddBreakString("Guild Rank");
reply.AddChar(0); // Class
reply.AddString("TAG"); // Guild tag
reply.AddChar((byte)client.Character.Admin);
reply.AddChar(client.Character.Level); // Level
reply.AddInt(client.Character.Exp); // Exp
reply.AddInt(client.Character.Usage); // Usage
reply.AddShort(client.Character.Hp); // HP
reply.AddShort(client.Character.MaxHp); // MaxHP
reply.AddShort(client.Character.Tp); // TP
reply.AddShort(client.Character.MaxTp); // MaxTP
reply.AddShort(client.Character.MaxSp); // MaxSP
reply.AddShort(client.Character.StatPoints); // StatPts
reply.AddShort(client.Character.SkillPoints); // SkillPts
reply.AddShort(client.Character.Karma); // Karma
reply.AddShort(client.Character.MinDamage); // MinDam
reply.AddShort(client.Character.MaxDamage); // MaxDam
reply.AddShort(client.Character.Accuracy); // Accuracy
reply.AddShort(client.Character.Evade); // Evade
reply.AddShort(client.Character.Defence); // Armor
reply.AddShort(client.Character.Strength); // Str
reply.AddShort(client.Character.Wisdom); // Wis
reply.AddShort(client.Character.Intelligence); // Int
reply.AddShort(client.Character.Agility); // Agi
reply.AddShort(client.Character.Constitution); // Con
reply.AddShort(client.Character.Charisma); // Cha
// Inventory
reply.AddBreak();
reply.AddChar(1); // Guild Rank
reply.AddShort(2); // Jail map
reply.AddShort(4); // ?
reply.AddChar(24); // ?
reply.AddChar(24); // ?
reply.AddShort(10); // ?
reply.AddShort(10); // ?
reply.AddShort(0); // Admin command flood rate
reply.AddShort(2); // ?
reply.AddChar(0); // Login warning message
reply.AddBreak();
client.Send(reply);
}
示例7: Initialize
private bool Initialize(byte[] versionNumber, string hdSerialNum, out InitData data)
{
Initialized = false;
data = new InitData();
if (!m_client.ConnectedAndInitialized || versionNumber.Length != 3 || hdSerialNum.Length == 0)
{
return false;
}
Packet builder = new Packet(PacketFamily.Init, PacketAction.Init);
builder.AddThree(Hashes.stupid_hash(new Random().Next(6, 12)));
builder.AddChar(versionNumber[0]);
builder.AddChar(versionNumber[1]);
builder.AddChar(versionNumber[2]); //client version
builder.AddChar(112); //unknown
builder.AddChar((byte)hdSerialNum.Length);
builder.AddString(hdSerialNum);
if (!m_client.SendRaw(builder))
return false;
if (!m_init_responseEvent.WaitOne(Constants.ResponseTimeout))
return false;
data = m_init_initData;
return true;
}
示例8: HandleRequest
public static void HandleRequest(Packet packet, IClient client, bool fromQueue)
{
Packet reply = new Packet(PacketFamily.Character, PacketAction.Reply);
reply.AddShort(10); // Create session ID (10+)
reply.AddString("OK");
client.Send(reply);
}
示例9: UpdateClients
private void UpdateClients()
{
try
{
while (!this.ResetEvent.Wait(200))
{
try
{
var descriptors = this.ConnectedClients.ToArray();
if (descriptors.Length == 0) continue;
Packet p = new Packet();
List<TcpClient> sockets = new List<TcpClient>();
p.AddUInt16((ushort)descriptors.Length);
foreach (ClientDescriptor descriptor in descriptors)
{
sockets.Add(descriptor.TcpClient);
p.AddString(descriptor.PlayerName);
p.AddUInt32(descriptor.PlayerID);
p.AddUInt16(descriptor.PlayerLevel);
p.AddUInt16((ushort)descriptor.Location.X);
p.AddUInt16((ushort)descriptor.Location.Y);
p.AddByte((byte)descriptor.Location.Z);
}
p.AddLength();
foreach (TcpClient tc in sockets)
{
if (!tc.Connected) continue;
p.Send(tc);
}
}
catch { }
}
}
catch { }
}
示例10: Save
public void Save(string fileName)
{
Packet file = new Packet(PacketFamily.Internal, PacketAction.Server) {ReadPos = 0, WritePos = 0};
//map header
file.AddString("EMF");
file.AddBytes(Rid);
byte[] tmpName = _encodeMapString(Name);
byte[] rawName = new byte[24];
for (int i = rawName.Length - 1; i >= 0; --i) rawName[i] = 0xFF;
Array.Copy(tmpName, 0, rawName, rawName.Length - tmpName.Length, tmpName.Length);
file.AddBytes(rawName);
file.AddChar(pkByte);
file.AddChar((byte)Effect);
file.AddChar(Music);
file.AddChar(MusicExtra);
file.AddShort(AmbientNoise);
file.AddChar(Width);
file.AddChar(Height);
file.AddShort(FillTile);
file.AddChar(availByte);
file.AddChar(scrollByte);
file.AddChar(RelogX);
file.AddChar(RelogY);
file.AddChar(Unknown2);
//NPC Spawns
file.AddChar((byte)NPCSpawns.Count);
foreach (NPCSpawn spawn in NPCSpawns)
{
file.AddChar(spawn.x);
file.AddChar(spawn.y);
file.AddShort(spawn.id);
file.AddChar(spawn.spawnType);
file.AddShort(spawn.spawnTime);
file.AddChar(spawn.amount);
}
//unknowns
file.AddChar((byte)Unknowns.Count);
foreach(byte[] b in Unknowns)
file.AddBytes(b);
//chests
file.AddChar((byte)Chests.Count);
foreach (MapChest chest in Chests)
{
file.AddChar(chest.x);
file.AddChar(chest.y);
file.AddShort((short)chest.key);
file.AddChar(chest.slot);
file.AddShort(chest.item);
file.AddShort(chest.time);
file.AddThree(chest.amount);
}
//tile specs
file.AddChar((byte)TileRows.Count);
foreach (TileRow tr in TileRows)
{
file.AddChar(tr.y);
file.AddChar((byte)tr.tiles.Count);
foreach (Tile tt in tr.tiles)
{
file.AddChar(tt.x);
file.AddChar((byte)tt.spec);
}
}
//warps
file.AddChar((byte)WarpRows.Count);
foreach (WarpRow wr in WarpRows)
{
file.AddChar(wr.y);
file.AddChar((byte)wr.tiles.Count);
foreach (Warp ww in wr.tiles)
{
file.AddChar(ww.x);
file.AddShort(ww.warpMap);
file.AddChar(ww.warpX);
file.AddChar(ww.warpY);
file.AddChar(ww.levelRequirement);
file.AddShort((short)ww.door);
}
}
//gfx
for (int layer = 0; layer < (int) MapLayers.NUM_LAYERS; ++layer)
{
file.AddChar((byte)GfxRows[layer].Count);
foreach (GFXRow row in GfxRows[layer])
{
file.AddChar(row.y);
file.AddChar((byte)row.tiles.Count);
foreach (GFX gfx in row.tiles)
{
file.AddChar(gfx.x);
file.AddShort((short)gfx.tile);
//.........这里部分代码省略.........