本文整理汇总了C#中Lidgren.Network.NetConnection.Approve方法的典型用法代码示例。如果您正苦于以下问题:C# NetConnection.Approve方法的具体用法?C# NetConnection.Approve怎么用?C# NetConnection.Approve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetConnection
的用法示例。
在下文中一共展示了NetConnection.Approve方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddPlayer
public void AddPlayer(NetConnection connection, PlayerInformation playerInfo)
{
String denyReason;
Byte slot = AllocateSlot(playerInfo, out denyReason);
// could not allocate the player if AllocateSlot returns DummySlot
if (slot == ProtocolInformation.DummySlot)
{
Log.InfoFormat("Player \"{0}\" from {1} tried to join, but was rejected ({2}).",
playerInfo.Callsign, connection, denyReason);
connection.Deny(denyReason);
return;
}
// we can now approve the player if we get here
connection.Approve();
// add player to our list
players[slot] = new Player(this, slot, connection, playerInfo);
// and tell everyone else about this awesome new player
Log.DebugFormat("Sending MsgAddPlayer to everyone else about player #{0}", slot);
NetOutgoingMessage packet = Server.CreateMessage();
MsgAddPlayerPacket message = new MsgAddPlayerPacket(players[slot].PlayerInfo, false);
packet.Write((Byte)message.MsgType);
message.Write(packet);
Log.DebugFormat("MsgAddPlayer Compiled ({0} bytes) and being sent to {1} recipients",
packet.LengthBytes, players.Count - 1);
// send to everyone except our new player, we let Player itself decide when to send the state to the new guy
Server.SendToAll(packet, connection, NetDeliveryMethod.ReliableOrdered, 0);
}
示例2: Start
public void Start()
{
NetIncomingMessage packetin;
while (true)
{
while ((packetin = _netserver.ReadMessage()) != null)
{
_msgSender = packetin.SenderConnection;
switch (packetin.MessageType)
{
case NetIncomingMessageType.StatusChanged:
{
NetConnectionStatus status = (NetConnectionStatus)packetin.ReadByte();
//Player doesnt want to play anymore
if (status == NetConnectionStatus.Disconnected || status == NetConnectionStatus.Disconnecting)
{
_mineserver.Console.ConsoleWrite(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Name + " Disconnected");
_mineserver.ServerSender.SendPlayerLeft(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.PlayerManager.RemovePlayer(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
}
break;
}
case NetIncomingMessageType.DiscoveryRequest:
{
_mineserver.ServerSender.SendDiscoverResponse(packetin.SenderEndpoint);
break;
}
case NetIncomingMessageType.ConnectionApproval:
{
//If the server is full then deny
if (_netserver.ConnectionsCount == _netserver.Configuration.MaximumConnections)
{
_msgSender.Deny("serverfull");
break;
}
int version = packetin.ReadInt32();
string name = packetin.ReadString();
//If the version is any other then the server deny
if(_mineserver.VersionMatch(version) == false)
{
_msgSender.Deny("versionmismatch");
break;
}
ServerPlayer dummy = new ServerPlayer(_msgSender);
if (_mineserver.PlayerManager.NameExists(name))
{
name += dummy.Id;
}
dummy.Name = name;
_mineserver.PlayerManager.AddPlayer(dummy);
_msgSender.Approve();
Thread.Sleep(4000);
_mineserver.GameWorld.GenerateSpawnPosition(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.ServerSender.SendCurrentWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.ServerSender.SendInitialUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.ServerSender.SendPlayerJoined(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.ServerSender.SendOtherPlayersInWorld(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
_mineserver.Console.ConsoleWrite(name + " Connected");
break;
}
case NetIncomingMessageType.Data:
{
PacketType dataType = (PacketType)packetin.ReadByte();
switch (dataType)
{
case PacketType.PlayerMovementUpdate:
{
_mineserver.PlayerManager.GetPlayerByConnection(_msgSender).Position = packetin.ReadVector3();
_mineserver.ServerSender.SendMovementUpdate(_mineserver.PlayerManager.GetPlayerByConnection(_msgSender));
break;
}
case PacketType.PlayerBlockSet:
{
Vector3 pos = packetin.ReadVector3();
_mineserver.MapManager.WorldMap[(int)pos.X, (int)pos.Y, (int)pos.Z] = (BlockTypes)packetin.ReadByte();
break;
}
}
break;
}
}
}
}
}
示例3: approveClient
private void approveClient(NetConnection connection, string name)
{
var p = new Player(this.idMan.GetNext<Player>(), name);
this.players.Add(p);
this.connections.Add(p.ID, connection);
var message = this.server.CreateMessage(4);
message.Write(p.ID.Simple);
connection.Approve(message);
}