本文整理汇总了C#中Server.SendPacket方法的典型用法代码示例。如果您正苦于以下问题:C# Server.SendPacket方法的具体用法?C# Server.SendPacket怎么用?C# Server.SendPacket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server
的用法示例。
在下文中一共展示了Server.SendPacket方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendChunk
public void SendChunk(Server server, int clientid, Vector3i globalpos, Vector3i chunkpos)
{
ClientOnServer c = server.clients[clientid];
ServerChunk chunk = server.d_Map.GetChunk(globalpos.x, globalpos.y, globalpos.z);
server.ClientSeenChunkSet(clientid, chunkpos.x, chunkpos.y, chunkpos.z, (int)server.simulationcurrentframe);
//sent++;
byte[] compressedchunk;
if (MapUtil.IsSolidChunk(chunk.data) && chunk.data[0] == 0)
{
//don't send empty chunk.
compressedchunk = null;
}
else
{
compressedchunk = server.CompressChunkNetwork(chunk.data);
//todo!
//commented because it was being sent too early, before full column was generated.
//if (!c.heightmapchunksseen.ContainsKey(new Vector2i(v.x, v.y)))
{
byte[] heightmapchunk = Misc.UshortArrayToByteArray(server.d_Map.GetHeightmapChunk(globalpos.x, globalpos.y));
byte[] compressedHeightmapChunk = server.d_NetworkCompression.Compress(heightmapchunk);
Packet_ServerHeightmapChunk p1 = new Packet_ServerHeightmapChunk()
{
X = globalpos.x,
Y = globalpos.y,
SizeX = Server.chunksize,
SizeY = Server.chunksize,
CompressedHeightmap = compressedHeightmapChunk,
};
server.SendPacket(clientid, server.Serialize(new Packet_Server() { Id = Packet_ServerIdEnum.HeightmapChunk, HeightmapChunk = p1 }));
c.heightmapchunksseen[new Vector2i(globalpos.x, globalpos.y)] = (int)server.simulationcurrentframe;
}
}
if (compressedchunk != null)
{
foreach (byte[] part in Server.Parts(compressedchunk, 1024))
{
Packet_ServerChunkPart p1 = new Packet_ServerChunkPart()
{
CompressedChunkPart = part,
};
server.SendPacket(clientid, server.Serialize(new Packet_Server() { Id = Packet_ServerIdEnum.ChunkPart, ChunkPart = p1 }));
}
}
Packet_ServerChunk p = new Packet_ServerChunk()
{
X = globalpos.x,
Y = globalpos.y,
Z = globalpos.z,
SizeX = Server.chunksize,
SizeY = Server.chunksize,
SizeZ = Server.chunksize,
};
server.SendPacket(clientid, server.Serialize(new Packet_Server() { Id = Packet_ServerIdEnum.Chunk_, Chunk_ = p }));
}
示例2: Ban
public bool Ban(Server server, int sourceClientId, int targetClientId, string reason)
{
if (!server.PlayerHasPrivilege(sourceClientId, ServerClientMisc.Privilege.ban))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandInsufficientPrivileges"), server.colorError));
return false;
}
if (!reason.Equals(""))
{
reason = server.language.Get("Server_CommandKickBanReason") + reason + ".";
}
ClientOnServer targetClient = server.GetClient(targetClientId);
if (targetClient != null)
{
if (targetClient.clientGroup.IsSuperior(server.GetClient(sourceClientId).clientGroup) || targetClient.clientGroup.EqualLevel(server.GetClient(sourceClientId).clientGroup))
{
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandTargetUserSuperior"), server.colorError));
return false;
}
string targetName = targetClient.playername;
string sourceName = server.GetClient(sourceClientId).playername;
string targetNameColored = targetClient.ColoredPlayername(server.colorImportant);
string sourceNameColored = server.GetClient(sourceClientId).ColoredPlayername(server.colorImportant);
server.banlist.BanPlayer(targetName, sourceName, reason);
SaveBanlist(server);
server.SendMessageToAll(string.Format(server.language.Get("Server_CommandBanMessage"), server.colorImportant, targetNameColored, sourceNameColored, reason));
server.ServerEventLog(string.Format("{0} bans {1}.{2}", sourceName, targetName, reason));
server.SendPacket(targetClientId, ServerPackets.DisconnectPlayer(string.Format(server.language.Get("Server_CommandBanNotification"), reason)));
server.KillPlayer(targetClientId);
return true;
}
server.SendMessage(sourceClientId, string.Format(server.language.Get("Server_CommandNonexistantID"), server.colorError, targetClientId));
return false;
}
示例3: Update
public override void Update(Server server, float dt)
{
pingtimer.Update(
delegate
{
if (server.exit.GetExit())
{
//Instantly return if server wants to exit
return;
}
List<int> keysToDelete = new List<int>();
foreach (var k in server.clients)
{
// Check if client is alive. Detect half-dropped connections.
if (!k.Value.Ping.Send(server.platform)/*&& k.Value.state == ClientStateOnServer.Playing*/)
{
if (k.Value.Ping.Timeout(server.platform))
{
Console.WriteLine(k.Key + ": ping timeout. Disconnecting...");
keysToDelete.Add(k.Key);
}
}
else
{
server.SendPacket(k.Key, ServerPackets.Ping());
}
}
foreach (int key in keysToDelete)
{
server.KillPlayer(key);
}
}
);
}
示例4: Update
public override void Update(Server server, float dt)
{
if (!loaded)
{
loaded = true;
LoadBanlist(server);
}
if (server.banlist.ClearTimeBans() > 0)
{
SaveBanlist(server);
}
foreach (KeyValuePair<int, ClientOnServer> k in server.clients)
{
int clientId = k.Key;
ClientOnServer c = k.Value;
IPEndPointCi iep1 = c.socket.RemoteEndPoint();
if (server.banlist.IsIPBanned(iep1.AddressToString()))
{
IPEntry entry = server.banlist.GetIPEntry(iep1.AddressToString());
string reason = entry.Reason;
if (string.IsNullOrEmpty(reason))
reason = "";
server.SendPacket(clientId, ServerPackets.DisconnectPlayer(string.Format(server.language.ServerIPBanned(), reason)));
Console.WriteLine(string.Format("Banned IP {0} tries to connect.", iep1.AddressToString()));
server.ServerEventLog(string.Format("Banned IP {0} tries to connect.", iep1.AddressToString()));
server.KillPlayer(clientId);
continue;
}
string username = c.playername;
if (server.banlist.IsUserBanned(username))
{
UserEntry entry = server.banlist.GetUserEntry(username);
string reason = entry.Reason;
if (string.IsNullOrEmpty(reason))
reason = "";
server.SendPacket(clientId, ServerPackets.DisconnectPlayer(string.Format(server.language.ServerUsernameBanned(), reason)));
Console.WriteLine(string.Format("{0} fails to join (banned username: {1}).", (c.socket.RemoteEndPoint()).AddressToString(), username));
server.ServerEventLog(string.Format("{0} fails to join (banned username: {1}).", (c.socket.RemoteEndPoint()).AddressToString(), username));
server.KillPlayer(clientId);
continue;
}
}
}
示例5: NotifyPlayers
void NotifyPlayers(Server server, int clientid)
{
ClientOnServer c = server.clients[clientid];
// EntitySpawn
foreach (var k in server.clients)
{
if (k.Value.state != ClientStateOnServer.Playing)
{
continue;
}
if (c.playersDirty[k.Key])
{
Packet_ServerEntity e = ToNetworkEntity(server.serverPlatform, k.Value.entity);
server.SendPacket(clientid, ServerPackets.EntitySpawn(k.Key, e));
c.playersDirty[k.Key] = false;
}
}
}
示例6: NotifyPlayerPositions
// EntityPositionAndOrientation
void NotifyPlayerPositions(Server server, int clientid, float dt)
{
ClientOnServer c = server.clients[clientid];
c.notifyPlayerPositionsAccum += dt;
if (c.notifyPlayerPositionsAccum < (one / PlayerPositionUpdatesPerSecond))
{
return;
}
c.notifyPlayerPositionsAccum = 0;
foreach (var k in server.clients)
{
if (k.Value.state != ClientStateOnServer.Playing)
{
continue;
}
if (!c.IsSpectator && k.Value.IsSpectator)
{
// Do not send position updates for spectating players if player is not spectator himself
continue;
}
if (k.Key == clientid)
{
if (k.Value.positionOverride == null)
{
continue;
}
else
{
k.Value.entity.position = k.Value.positionOverride;
k.Value.positionOverride = null;
}
}
else
{
if (server.DistanceSquared(server.PlayerBlockPosition(server.clients[k.Key]), server.PlayerBlockPosition(server.clients[clientid])) > server.config.PlayerDrawDistance * server.config.PlayerDrawDistance)
{
continue;
}
}
Packet_PositionAndOrientation position = ToNetworkEntityPosition(server.serverPlatform, server.clients[k.Key].entity.position);
server.SendPacket(clientid, ServerPackets.EntityPositionAndOrientation(k.Key, position));
}
}
示例7: NotifyEntities
void NotifyEntities(Server server, int clientid, float dt)
{
ClientOnServer c = server.clients[clientid];
c.notifyEntitiesAccum += dt;
if (c.notifyEntitiesAccum < (one / EntityPositionUpdatesPerSecond))
{
return;
}
c.notifyEntitiesAccum = 0;
// find nearest entities
int max = SpawnMaxEntities;
ServerEntityId[] nearestEntities = new ServerEntityId[max];
FindNearEntities(server, c, max, nearestEntities);
// update entities
for (int i = 0; i < max; i++)
{
ServerEntityId e = nearestEntities[i];
if (e == null) { continue; }
for (int k = 0; k < server.modEventHandlers.onupdateentity.Count; k++)
{
server.modEventHandlers.onupdateentity[k](e.chunkx, e.chunky, e.chunkz, e.id);
}
}
// despawn old entities
for (int i = 0; i < c.spawnedEntitiesCount; i++)
{
ServerEntityId e = c.spawnedEntities[i];
if (e == null) { continue; }
if (!Contains(nearestEntities, max, e))
{
int onClientId = i;
c.spawnedEntities[onClientId] = null;
server.SendPacket(clientid, ServerPackets.EntityDespawn(64 + onClientId));
}
}
// spawn new entities
for (int i = 0; i < max; i++)
{
ServerEntityId e = nearestEntities[i];
if (e == null) { continue; }
if (!Contains(c.spawnedEntities, max, e))
{
int onClientId = IndexOfNull(c.spawnedEntities, c.spawnedEntitiesCount);
c.spawnedEntities[onClientId] = e.Clone();
ServerChunk chunk = server.d_Map.GetChunk(e.chunkx * Server.chunksize, e.chunky * Server.chunksize, e.chunkz * Server.chunksize);
ServerEntity ee = chunk.Entities[e.id];
Packet_ServerEntity ne = ToNetworkEntity(server.serverPlatform, ee);
server.SendPacket(clientid, ServerPackets.EntitySpawn(64 + onClientId, ne));
}
}
for (int i = 0; i < max; i++)
{
if (c.updateEntity[i])
{
c.updateEntity[i] = false;
ServerEntityId e = c.spawnedEntities[i];
ServerChunk chunk = server.d_Map.GetChunk(e.chunkx * Server.chunksize, e.chunky * Server.chunksize, e.chunkz * Server.chunksize);
ServerEntity ee = chunk.Entities[e.id];
Packet_ServerEntity ne = ToNetworkEntity(server.serverPlatform, ee);
server.SendPacket(clientid, ServerPackets.EntitySpawn(64 + i, ne));
}
}
}