本文整理汇总了C#中Lidgren.Network.NetConnection.Disconnect方法的典型用法代码示例。如果您正苦于以下问题:C# NetConnection.Disconnect方法的具体用法?C# NetConnection.Disconnect怎么用?C# NetConnection.Disconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetConnection
的用法示例。
在下文中一共展示了NetConnection.Disconnect方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Dispatch
internal void Dispatch(int id, object msg, NetConnection conn)
{
try {
// 特殊处理认证消息
if (id == (int)RoomMessageDefine.Msg_CR_ShakeHands) {
Msg_CR_ShakeHands shakehandsMsg = msg as Msg_CR_ShakeHands;
if (shakehandsMsg == null) {
return;
}
bool ret = RoomPeerMgr.Instance.OnPeerShakeHands(shakehandsMsg.auth_key, conn);
Msg_RC_ShakeHands_Ret builder = new Msg_RC_ShakeHands_Ret();
if (ret) {
builder.auth_result = Msg_RC_ShakeHands_Ret.RetType.SUCCESS;
IOManager.Instance.SendMessage(conn, RoomMessageDefine.Msg_RC_ShakeHands_Ret, builder);
} else {
builder.auth_result = Msg_RC_ShakeHands_Ret.RetType.ERROR;
IOManager.Instance.SendUnconnectedMessage(conn, RoomMessageDefine.Msg_RC_ShakeHands_Ret, builder);
conn.Disconnect("disconnect");
}
return;
}
RoomPeer peer = RoomPeerMgr.Instance.GetPeerByConnection(conn);
// 没有认证连接的消息不进行处理
if (peer == null) {
Msg_RC_ShakeHands_Ret builder = new Msg_RC_ShakeHands_Ret();
builder.auth_result = Msg_RC_ShakeHands_Ret.RetType.ERROR;
IOManager.Instance.SendUnconnectedMessage(conn, RoomMessageDefine.Msg_RC_ShakeHands_Ret, builder);
conn.Disconnect("unauthed");
LogSys.Log(LOG_TYPE.DEBUG, "unauthed peer {0} got message {1}, can't deal it!", conn.RemoteEndPoint.ToString(), msg.ToString());
return;
}
// 直接转发消息(或进行其它处理)
MsgHandler msghandler;
if (m_DicHandler.TryGetValue(id, out msghandler)) {
msghandler(msg, peer);
}
if (msg is Msg_Ping)
return;
// 消息分发到peer
RoomPeerMgr.Instance.DispatchPeerMsg(peer, id, msg);
} catch (Exception ex) {
LogSys.Log(LOG_TYPE.ERROR, "Exception {0}\n{1}", ex.Message, ex.StackTrace);
}
}
示例2: DropClient
public void DropClient(NetConnection connection, string message, params object[] args)
{
message = string.Format(message, args);
Log(message);
connection.Disconnect(message);
}
示例3: HandleConnectionForciblyClosed
internal override void HandleConnectionForciblyClosed(NetConnection connection, SocketException sex)
{
if (connection != null)
connection.Disconnect("Connection forcibly closed", 0, false, false);
return;
}
示例4: HandlePlayerConnected
private void HandlePlayerConnected(NetConnection connection)
{
string name = connection.RemoteHailMessage.ReadString();
if (Players.ConnectedCount >= MaxNumConnectedClients)
{
connection.Disconnect("Server is full");
Log(string.Format("player connection attempt by {0}{1} rejected, server full", name, NetUtility.ToHexString(connection.RemoteUniqueIdentifier)));
return;
}
if(currentGameMode != null && currentGameMode.AllowJoinInProgress == false)
{
connection.Disconnect("Cannot connect to game already in progress");
Log(string.Format("player connection attempt by {0}{1} rejected, gamemode in progress", name, NetUtility.ToHexString(connection.RemoteUniqueIdentifier)));
return;
}
RemotePlayer player = new RemotePlayer(connection.RemoteUniqueIdentifier, name);
NetOutgoingMessage msg = CreateMessage(eServerToClientMessage.SessionInit);
msg.Write(Players.SlotsCount);
msg.Write(Players.ConnectedCount);
foreach (RemotePlayer connectedPlayer in Players.ConnectedPlayers)
{
msg.Write(connectedPlayer.UniqueID);
msg.Write(connectedPlayer.PlayerName);
msg.Write(connectedPlayer.PlayerSlot);
msg.Write((byte)connectedPlayer.Status);
}
server.SendMessage(msg, connection, NetDeliveryMethod.ReliableOrdered, 0);
// Add player and try to default assign a slot
Players.AddPlayer(player, true);
Log(string.Format("player ({0} {1}) joined, slot {2}", name, NetUtility.ToHexString(connection.RemoteUniqueIdentifier), player.PlayerSlot));
}
示例5: PlayerConnect
private void PlayerConnect(NetConnection sender)
{
Console.WriteLine("\"" + sender.RemoteEndpoint.Address + "\" has joined");
int tempid = FindOpenSlot();
if (tempid < 0)
sender.Disconnect("Server Full");
else
sender.Tag = tempid;
//msg.SenderConnection.Tag = TempCID;
//TODO: Realm Style: Client sends a temp password for AES using the servers RSA key Client sends password using AES etc
}
示例6: ProcessInboundMessage
protected override NetBuffer ProcessInboundMessage(NetConnection from, NetBuffer message)
{
CryptoHostConnection connection;
if (CryptoClients.ContainsKey(from))
connection = CryptoClients[from];
else
return message;
int code = -1;
switch (connection.state)
{
case CryptoHostState.Authenticated:
return DecryptMessage(connection, message);
case CryptoHostState.Invalid:
return null;
case CryptoHostState.InitalConnect:
{
// should be the response with a random key encoded with the shit
code = message.ReadInt32();
if (code == CRYPTO_SECRET_MESSAGE)
{
connection.state = CryptoHostState.GotSecret;
connection.SetSecret(RSA.Decrypt(message.ReadBytes(message.ReadInt32()),false));
connection.secretVerifyString = new Random().Next().ToString();
// crypto the random string with the secret and send it back
NetBuffer b = new NetBuffer();
b.Write(CRYPTO_SECRET_VERIFY);
byte[] cryptoBuffer = connection.EncryptBuffer(new UTF8Encoding().GetBytes(connection.secretVerifyString));
b.Write(cryptoBuffer.Length);
b.Write(cryptoBuffer);
server.SendMessage(b, from, NetChannel.ReliableInOrder1);
}
else
{
NetBuffer errorBuffer = new NetBuffer();
errorBuffer.Write(CRYPTO_DENY);
errorBuffer.Write("Invalid Secret");
server.SendMessage(errorBuffer, from, NetChannel.ReliableInOrder1);
from.Disconnect("CryptoError", 1);
connection.state = CryptoHostState.Invalid;
}
return null;
}
case CryptoHostState.GotSecret:
{
// should be the response with the properly encrypted sample
code = message.ReadInt32();
if (code == CRYPTO_SECRET_VERIFY)
{
// set em as real and let the base class call any events it needs to
string verify = new UTF8Encoding().GetString(connection.DecryptBuffer(message.ReadBytes(message.ReadInt32())));
if (verify == connection.secretVerifyString)
{
connection.state = CryptoHostState.Authenticated;
NetBuffer b = new NetBuffer();
b.Write(CRYPTO_ACCEPT);
server.SendMessage(b, from, NetChannel.ReliableInOrder1);
base.UserConnected(from);
return null;
}
}
NetBuffer errorBuffer = new NetBuffer();
errorBuffer.Write(CRYPTO_DENY);
errorBuffer.Write("Invalid Verify");
server.SendMessage(errorBuffer, from, NetChannel.ReliableInOrder1);
from.Disconnect("CryptoError", 1);
connection.state = CryptoHostState.Invalid;
return null;
}
}
return message;
}