本文整理汇总了C#中PacketWriter.WriteUTF8Null方法的典型用法代码示例。如果您正苦于以下问题:C# PacketWriter.WriteUTF8Null方法的具体用法?C# PacketWriter.WriteUTF8Null怎么用?C# PacketWriter.WriteUTF8Null使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketWriter
的用法示例。
在下文中一共展示了PacketWriter.WriteUTF8Null方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteSendPrivateMessageResult
public static DogBuffer WriteSendPrivateMessageResult(string userName, string message)
{
var writer = new PacketWriter();
writer.SetNetCode((ushort)OpCode.RecvPrivateMessage);
writer.WriteUTF8Null(userName);
writer.WriteUTF8Null(message);
return writer.GetBuffer();
}
示例2: OnSocketRecv
//.........这里部分代码省略.........
{
var dogBuffer = new DogBuffer();
session.RQ.Dequeue(dogBuffer.Bytes, 0, packetlen);
var reader = new PacketReader();
reader.SetBuffer(dogBuffer);
var pid = (OpCode)reader.GetPacketID();
switch (pid)
{
case OpCode.Login:
{
var userName = reader.ReadUTF8String();
var pwd = reader.ReadUTF8String();
if (string.IsNullOrEmpty(userName))
{
Logs.Error("连接的用户名是空");
session.Client.CloseSocket();
}
if (pwd != "123")
{
Logs.Error("用户名 {0} 速度的密码错误", userName);
var writer = new PacketWriter();
writer.SetNetCode((ushort) OpCode.LoginResult);
writer.Write(1); // 0表示登录成功 1表示密码错误
session.Client.SendPackage(writer.GetBuffer());
return;
}
// 如果玩家之前登录过,则把之前的客户端踢下线
var exists = sessions.FirstOrDefault(o => o.Name == userName);
if (exists != null)
{
exists.IsLogin = false;
sessions.Remove(exists);
exists.Client.CloseSocket();
}
// 登录完成
session.IsLogin = true;
nologinSessions.Remove(session);
sessions.Add(session);
session.Name = userName;
session.Pwd = pwd;
var writer2 = new PacketWriter();
writer2.SetNetCode((ushort) OpCode.LoginResult);
writer2.Write(0); // 0表示登录成功 1表示密码错误
session.Client.SendPackage(writer2.GetBuffer());
}
break;
case OpCode.SendMessage:
{
var message = reader.ReadUTF8String();
if (string.IsNullOrEmpty(message))
{
// 空消息
return;
}
// 广播给所有在线的用户
var writer = new PacketWriter();
writer.SetNetCode((ushort) OpCode.RecvMessage);
foreach (var ss in sessions)
{
ss.Client.SendPackage(writer.GetBuffer());
}
}
break;
case OpCode.SendPriviteMessage:
{
var userName = reader.ReadUTF8String();
var message = reader.ReadUTF8String();
if (message == null)
return;
var target = sessions.FirstOrDefault(o => o.Name == userName);
if (target == null)
return;
var writer = new PacketWriter();
writer.SetNetCode((ushort) OpCode.RecvPrivateMessage);
writer.WriteUTF8Null(session.Name);
writer.WriteUTF8Null(message);
target.Client.SendPackage(writer.GetBuffer());
}
break;
default:
Logs.Error("未知消息ID {0}", (int) pid);
break;
}
packetlen = session.RQ.GetPacketLength();
}
}
示例3: OnSendPrivateMessage
/// <summary>
/// 给聊天室里的某人单独发消息
/// </summary>
/// <param name="session"></param>
/// <param name="reader"></param>
static void OnSendPrivateMessage(Session session, PacketReader reader)
{
var userName = reader.ReadUTF8String();
var message = reader.ReadUTF8String();
if (message == null)
return;
var target = sessions.FirstOrDefault(o => o.Name == userName);
if (target == null)
return;
var writer = new PacketWriter();
writer.SetNetCode((ushort) OpCode.RecvPrivateMessage);
writer.WriteUTF8Null(session.Name);
writer.WriteUTF8Null(message);
target.Client.SendPackage(writer.GetBuffer());
}