本文整理汇总了C#中IIPSocket类的典型用法代码示例。如果您正苦于以下问题:C# IIPSocket类的具体用法?C# IIPSocket怎么用?C# IIPSocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IIPSocket类属于命名空间,在下文中一共展示了IIPSocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RecvMoveStopHorizontal
void RecvMoveStopHorizontal(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && (user.IsMovingLeft || user.IsMovingRight))
{
if (user.IsPeerTrading)
return;
user.StopMovingHorizontal();
}
}
示例2: RecvMoveUp
void RecvMoveUp(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && !user.IsMovingUp)
{
if (user.IsPeerTrading)
return;
user.MoveUp();
}
}
示例3: RecvMoveStopVertical
void RecvMoveStopVertical(IIPSocket conn, BitStream r)
{
User user;
if ((user = TryGetUser(conn)) != null && (user.IsMovingUp || user.IsMovingDown))
{
if (user.IsPeerTrading)
return;
user.StopMovingVertical();
}
}
示例4: RecvJump
void RecvJump(IIPSocket conn, BitStream r)
{
User user;
if (((user = TryGetUser(conn)) != null) && user.CanJump)
{
if (user.IsPeerTrading)
return;
user.Jump();
}
}
示例5: InvokeProcessor
/// <summary>
/// Invokes the <see cref="IMessageProcessor"/> for handle processing a message block.
/// </summary>
/// <param name="socket">The <see cref="IIPSocket"/> that the data came from.</param>
/// <param name="processor">The <see cref="IMessageProcessor"/> to invoke.</param>
/// <param name="reader">The <see cref="BitStream"/> containing the data to process.</param>
protected override void InvokeProcessor(IIPSocket socket, IMessageProcessor processor, BitStream reader)
{
// Invoke the processor as normal, but keeping track of the bit position before and after invoking
var startBits = reader.PositionBits;
base.InvokeProcessor(socket, processor, reader);
var endBits = reader.PositionBits;
// Update the stats
_stats.HandleProcessorInvoked(processor.MsgID, endBits - startBits);
}
示例6: OnReceiveData
/// <summary>
/// When overridden in the derived class, allows for handling received data from an <see cref="IIPSocket"/>.
/// </summary>
/// <param name="sender">The <see cref="IIPSocket"/> that the data came from.</param>
/// <param name="data">The data that was received.</param>
protected override void OnReceiveData(IIPSocket sender, BitStream data)
{
base.OnReceiveData(sender, data);
try
{
// Process the data
_messageProcessorManager.Process(sender, data);
}
catch (Exception ex)
{
const string errmsg = "Failed to process received data from `{0}`. Exception: {1}";
if (log.IsWarnEnabled)
log.WarnFormat(errmsg, sender, ex);
Debug.Fail(string.Format(errmsg, sender, ex));
}
}
示例7: OnReceiveData
/// <summary>
/// When overridden in the derived class, allows for handling received data from an <see cref="IIPSocket"/>.
/// </summary>
/// <param name="sender">The <see cref="IIPSocket"/> that the data came from.</param>
/// <param name="data">The data that was received. This <see cref="BitStream"/> instance is reused internally, so it
/// is vital that you do NOT hold a reference to it when this method returns. This should be no problem since you should
/// not be holding onto raw received data anyways, but if you must, you can always make a deep copy.</param>
protected virtual void OnReceiveData(IIPSocket sender, BitStream data)
{
}
示例8: TryGetAccount
static IUserAccount TryGetAccount(IIPSocket conn)
{
// Check for a valid conn
if (conn == null)
{
const string errmsg = "conn is null.";
if (log.IsErrorEnabled)
log.Error(errmsg);
Debug.Fail(errmsg);
return null;
}
return conn.Tag as IUserAccount;
}
示例9: RecvSendPrivateMessage
void RecvSendPrivateMessage(IIPSocket conn, BitStream r)
{
string TargetName = r.ReadString();
string Text = r.ReadString();
// Get the user to send the message to
User TargetChar = World.FindUser(TargetName);
string PrivateMessage = TargetName + " Says: " + Text;
using (var pw = ServerPacket.ReceivePrivateMessage(PrivateMessage))
{
TargetChar.Send(pw, ServerMessageType.GUIChat);
}
}
示例10: RecvAcceptOrTurnInQuest
void RecvAcceptOrTurnInQuest(IIPSocket conn, BitStream r)
{
var providerIndex = r.ReadMapEntityIndex();
var questID = r.ReadQuestID();
// Get the user
User user;
if ((user = TryGetUser(conn)) == null || user.Map == null)
return;
if (user.IsPeerTrading)
return;
// Get the provider
var npc = user.Map.GetDynamicEntity<Character>(providerIndex);
var provider = npc as IQuestProvider<User>;
if (provider == null)
return;
// Check the distance and state
if (user.Map != npc.Map || user.Map == null || !npc.IsAlive || npc.IsDisposed ||
user.GetDistance(npc) > GameData.MaxNPCChatDistance)
return;
// Get the quest
var quest = _questManager.GetQuest(questID);
if (quest == null)
return;
// Ensure this provider even provides this quest
if (!provider.Quests.Contains(quest))
return;
// If the user already has the quest, try to turn it in
if (user.ActiveQuests.Contains(quest))
{
// Quest already started, try to turn in
var success = user.TryFinishQuest(quest);
using (var pw = ServerPacket.AcceptOrTurnInQuestReply(questID, success, false))
{
user.Send(pw, ServerMessageType.GUI);
}
}
else
{
// Quest not started yet, try to add it
var success = user.TryAddQuest(quest);
using (var pw = ServerPacket.AcceptOrTurnInQuestReply(questID, success, true))
{
user.Send(pw, ServerMessageType.GUI);
}
}
}
示例11: RecvUseWorld
void RecvUseWorld(IIPSocket conn, BitStream r)
{
var useEntityIndex = r.ReadMapEntityIndex();
// Get the map and user
User user;
Map map;
if (!TryGetMap(conn, out user, out map))
return;
if (user.IsPeerTrading)
return;
if (!user.IsAlive)
{
const string errmsg = "User `{0}` tried to use world entity while dead.";
if (log.IsInfoEnabled)
log.InfoFormat(errmsg, user);
return;
}
// Grab the DynamicEntity to use
var useEntity = map.GetDynamicEntity(useEntityIndex);
if (useEntity == null)
{
const string errmsg = "UseEntity received but usedEntityIndex `{0}` is not a valid DynamicEntity.";
Debug.Fail(string.Format(errmsg, useEntityIndex));
if (log.IsErrorEnabled)
log.ErrorFormat(errmsg, useEntityIndex);
return;
}
// Ensure the used DynamicEntity is even usable
var asUsable = useEntity as IUsableEntity;
if (asUsable == null)
{
const string errmsg =
"UseEntity received but useByIndex `{0}` refers to DynamicEntity `{1}` which does " +
"not implement IUsableEntity.";
Debug.Fail(string.Format(errmsg, useEntityIndex, useEntity));
if (log.IsErrorEnabled)
log.WarnFormat(errmsg, useEntityIndex, useEntity);
return;
}
// Use it
if (asUsable.Use(user))
{
// Notify everyone in the map it was used
if (asUsable.NotifyClientsOfUsage)
{
using (var pw = ServerPacket.UseEntity(useEntity.MapEntityIndex, user.MapEntityIndex))
{
map.Send(pw, ServerMessageType.Map);
}
}
}
}
示例12: RecvSelectAccountCharacter
void RecvSelectAccountCharacter(IIPSocket conn, BitStream r)
{
ThreadAsserts.IsMainThread();
var index = r.ReadByte();
// Ensure the client is in a valid state to select an account character
var userAccount = World.GetUserAccount(conn);
if (userAccount == null)
return;
if (userAccount.User != null)
{
const string errmsg = "Account `{0}` tried to change characters while a character was already selected.";
if (log.IsInfoEnabled)
log.InfoFormat(errmsg, userAccount);
return;
}
// Get the CharacterID
CharacterID characterID;
if (!userAccount.TryGetCharacterID(index, out characterID))
{
const string errmsg = "Invalid account character index `{0}` given.";
if (log.IsInfoEnabled)
log.InfoFormat(errmsg, characterID);
return;
}
// Load the user
userAccount.SetUser(World, characterID);
var user = userAccount.User;
if (user != null)
{
// Send the MOTD
if (!string.IsNullOrEmpty(ServerSettings.Default.MOTD))
{
using (var pw = ServerPacket.Chat(ServerSettings.Default.MOTD))
{
user.Send(pw, ServerMessageType.GUIChat);
}
}
// Send a notification to the world that the user joined
var param = new object[] {user.Name};
World.Send(GameMessage.UserJoinedWorld, ServerMessageType.GUIChat, param);
}
}
示例13: RecvSay
void RecvSay(IIPSocket conn, BitStream r)
{
var text = r.ReadString(GameData.MaxClientSayLength);
User user;
if ((user = TryGetUser(conn)) == null)
return;
_sayHandler.Process(user, text);
}
示例14: 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);
}
}
}
示例15: RecvRaiseStat
void RecvRaiseStat(IIPSocket conn, BitStream r)
{
StatType statType;
// Get the StatType
try
{
statType = r.ReadEnum<StatType>();
}
catch (InvalidCastException)
{
const string errorMsg = "Received invaild StatType on connection `{0}`.";
Debug.Fail(string.Format(errorMsg, conn));
if (log.IsWarnEnabled)
log.WarnFormat(errorMsg, conn);
return;
}
// Get the User
User user;
if ((user = TryGetUser(conn)) == null)
return;
// Raise the user's stat
user.RaiseStat(statType);
}