本文整理汇总了C#中IIPSocket.Send方法的典型用法代码示例。如果您正苦于以下问题:C# IIPSocket.Send方法的具体用法?C# IIPSocket.Send怎么用?C# IIPSocket.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IIPSocket
的用法示例。
在下文中一共展示了IIPSocket.Send方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnReceiveStatusChanged
/// <summary>
/// When overridden in the derived class, allows for handling when the status of an <see cref="IIPSocket"/> changes.
/// </summary>
/// <param name="sender">The <see cref="IIPSocket"/> who's status has changed.</param>
/// <param name="status">The new status.</param>
/// <param name="reason">The reason for the status change.</param>
protected override void OnReceiveStatusChanged(IIPSocket sender, NetConnectionStatus status, string reason)
{
base.OnReceiveStatusChanged(sender, status, reason);
switch (status)
{
case NetConnectionStatus.Disconnected:
// If there was an account on the socket, destroy it
var acc = World.GetUserAccount(sender, false);
if (acc != null)
acc.Dispose();
break;
case NetConnectionStatus.Connected:
// Send the server time to the client
using (var pw = ServerPacket.SetGameTime(DateTime.Now))
{
sender.Send(pw, ServerMessageType.GUI);
}
break;
}
}
示例2: RecvSynchronizeGameTime
void RecvSynchronizeGameTime(IIPSocket conn, BitStream r)
{
// Just reply immediately with the current game time
using (var pw = ServerPacket.SetGameTime(DateTime.Now))
{
conn.Send(pw, ServerMessageType.GUI);
}
}
示例3: RecvRequestMapEntityIndex
void RecvRequestMapEntityIndex(IIPSocket conn, BitStream r)
{
var index = r.ReadMapEntityIndex();
// Get the user and their map
User user;
if ((user = TryGetUser(conn)) == null)
return;
Map map;
if (!TryGetMap(user, out map))
return;
// Get the DynamicEntity
var de = map.GetDynamicEntity(index);
if (de == null)
{
// The DynamicEntity for the index was null, so tell the client to delete whatever is at that index
using (var pw = ServerPacket.RemoveDynamicEntity(index))
{
conn.Send(pw, ServerMessageType.Map);
}
}
else
{
// A DynamicEntity does exist at that index, so tell the client to create it
using (var pw = ServerPacket.CreateDynamicEntity(de))
{
conn.Send(pw, ServerMessageType.Map);
}
}
}
示例4: LoginAccount
/// <summary>
/// Handles the login attempt of an account.
/// </summary>
/// <param name="conn">Connection that the login request was made on.</param>
/// <param name="name">Name of the account.</param>
/// <param name="password">Entered password for this account.</param>
public void LoginAccount(IIPSocket conn, string name, string password)
{
if (!RequireServerRunning())
return;
ThreadAsserts.IsMainThread();
if (conn == null)
{
if (log.IsErrorEnabled)
log.Error("conn is null.");
return;
}
// Try to log in the account
IUserAccount userAccount;
var loginResult = UserAccountManager.Login(conn, name, password, out userAccount);
// Check that the login was successful
if (loginResult != AccountLoginResult.Successful)
{
HandleFailedLogin(conn, loginResult, name);
return;
}
// Check if banned
int banMins;
string banReason;
if (BanningManager.Instance.IsBanned(userAccount.ID, out banReason, out banMins))
{
userAccount.Dispose(GameMessage.AccountBanned, banMins, banReason);
if (log.IsInfoEnabled)
log.InfoFormat("Disconnected account `{0}` after successful login since they have been banned.", name);
return;
}
// Set the connection's tag to the account
conn.Tag = userAccount;
// Send the "Login Successful" message
using (var pw = ServerPacket.LoginSuccessful())
{
conn.Send(pw, ServerMessageType.System);
}
if (log.IsInfoEnabled)
log.InfoFormat("Login for account `{0}` successful.", name);
// Send the account characters
userAccount.SendAccountCharacterInfos();
}
示例5: CreateAccountCharacter
/// <summary>
/// Handles the request to create a new account.
/// </summary>
/// <param name="conn">Connection that the request was made on.</param>
/// <param name="name">The name of the character to create.</param>
public void CreateAccountCharacter(IIPSocket conn, string name)
{
if (!RequireServerRunning())
return;
ThreadAsserts.IsMainThread();
// Get the account
var account = conn.Tag as IUserAccount;
if (account == null)
return;
// Try to create the character
string errorMessage;
var success = UserAccountManager.TryAddCharacter(account.Name, name, out errorMessage);
// Send the result to the client (which we have to do both when successful and failed)
using (var pw = ServerPacket.CreateAccountCharacter(success, errorMessage))
{
conn.Send(pw, ServerMessageType.System);
}
// If we successfully created the character, reload and resync the character listing
if (success)
{
account.LoadCharacterIDs();
account.SendAccountCharacterInfos();
}
}
示例6: CreateAccount
/// <summary>
/// Handles the request to create a new account.
/// </summary>
/// <param name="conn">Connection that the request was made on.</param>
/// <param name="name">Name of the account.</param>
/// <param name="password">Entered password for this account.</param>
/// <param name="email">The email address.</param>
public void CreateAccount(IIPSocket conn, string name, string password, string email)
{
if (!RequireServerRunning())
return;
ThreadAsserts.IsMainThread();
if (conn == null)
{
if (log.IsErrorEnabled)
log.Error("conn is null.");
return;
}
// Create the account
GameMessage failReason;
var success = UserAccountManager.TryCreateAccount(conn, name, password, email, out failReason);
// Send the appropriate success message
using (var pw = ServerPacket.CreateAccount(success, failReason))
{
conn.Send(pw, ServerMessageType.System);
}
}