本文整理汇总了C#中EventData.SendTo方法的典型用法代码示例。如果您正苦于以下问题:C# EventData.SendTo方法的具体用法?C# EventData.SendTo怎么用?C# EventData.SendTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EventData
的用法示例。
在下文中一共展示了EventData.SendTo方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TrySendAmountOfPlayer
public void TrySendAmountOfPlayer()
{
var eventAmountOfPlayer = new EventData((byte)EventCode.AmountOfPlayers);
int amountOfPlayers = AccountService.Instance.GetAllClient();
eventAmountOfPlayer.Parameters = new Dictionary<byte, object> { { (byte)ParameterCode.AmountOfPlayer, amountOfPlayers } };
eventAmountOfPlayer.SendTo(AccountService.Instance.Clients, SendParameters);
}
示例2: OnOperationRequest
protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters)
{
switch (operationRequest.OperationCode)
{
case (byte)OperationCode.Login:
var loginRequest = new Login(Protocol, operationRequest);
if (!loginRequest.IsValid)
{
SendOperationResponse(loginRequest.GetResponse(ErrorCode.InvalidParameters), sendParameters);
return;
}
CharacterName = loginRequest.CharacterName;
if (World.Instance.IsContain(CharacterName))
{
SendOperationResponse(loginRequest.GetResponse(ErrorCode.NameIsExist), sendParameters);
return;
}
World.Instance.AddClient(this);
var response = new OperationResponse(operationRequest.OperationCode);
SendOperationResponse(response, sendParameters);
Log.Info("user with name:" + CharacterName);
Log.Info("user id:" + ConnectionId);
break;
case (byte)OperationCode.SendChatMessage:
{
var chatRequest = new ChatMessage(Protocol, operationRequest);
if (!chatRequest.IsValid)
{
SendOperationResponse(chatRequest.GetResponse(ErrorCode.InvalidParameters), sendParameters);
return;
}
string message = chatRequest.Message;
string[] param = message.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
if (param.Length == 2)
{
string targetName = param[0];
message = param[1];
if (World.Instance.IsContain(targetName))
{
var targetClient = World.Instance.TryGetByName(targetName);
if (targetClient == null)
return;
message = CharacterName + "[PM]:" + message;
var personalEventData = new EventData((byte)EventCode.ChatMessage);
personalEventData.Parameters = new Dictionary<byte, object> { { (byte)ParameterCode.ChatMessage, message } };
personalEventData.SendTo(new UnityClient[] { this, targetClient }, sendParameters);
}
return;
}
message = CharacterName + ": " + message;
Chat.Instance.AddMessage(message);
var eventData = new EventData((byte)EventCode.ChatMessage);
eventData.Parameters = new Dictionary<byte, object> { { (byte)ParameterCode.ChatMessage, message } };
eventData.SendTo(World.Instance.Clients, sendParameters);
}
break;
case (byte)OperationCode.GetRecentChatMessages:
{
var messages = Chat.Instance.GetRecentMessages();
messages.Reverse();
if(messages.Count == 0)
break;
var message = messages.Aggregate((i, j) => i + "\r\n" + j);
var eventData = new EventData((byte)EventCode.ChatMessage);
eventData.Parameters = new Dictionary<byte, object> { { (byte)ParameterCode.ChatMessage, message } };
eventData.SendTo(new UnityClient[] {this}, sendParameters);
}
break;
case (byte)OperationCode.Move:
{
var moveRequest = new Move(Protocol, operationRequest);
if (!moveRequest.IsValid)
{
SendOperationResponse(moveRequest.GetResponse(ErrorCode.InvalidParameters), sendParameters);
return;
}
Position = new Vector3Net(moveRequest.X, moveRequest.Y, moveRequest.Z);
//.........这里部分代码省略.........
示例3: WorldExitHandler
private void WorldExitHandler(SendParameters sendParameters)
{
var eventData = new EventData((byte)EventCode.WorldExit);
eventData.Parameters = new Dictionary<byte, object>
{
{(byte)ParameterCode.CharacterName, CharacterName}
};
eventData.SendTo(World.Instance.Clients, sendParameters);
}
示例4: PublishGameChanges
public void PublishGameChanges()
{
if (this.removedGames.Count == 0 && this.changedGames.Count == 0)
{
return;
}
foreach (var entry in this.subscriptions)
{
Hashtable games;
if (entry.Key == 0)
{
games = this.GetChangedGames();
}
else
{
games = this.GetChangedGames(entry.Key);
}
if (games.Count > 0)
{
if (log.IsDebugEnabled)
{
log.DebugFormat("Publishing game changes: props={0}", this.propertyString);
}
var e = new GameListUpdateEvent { Data = games };
var eventData = new EventData((byte)EventCode.GameListUpdate, e);
eventData.SendTo(entry.Value, new SendParameters());
}
}
foreach (var gameId in this.removedGames)
{
this.gameDict.Remove(gameId);
}
this.changedGames.Clear();
this.removedGames.Clear();
}
示例5: PublishDiscussionEvent
public void PublishDiscussionEvent(byte eventCode, Dictionary<byte, object> data,
IEnumerable<Actor> actorList,
SendParameters sendParameters)
{
IEnumerable<PeerBase> peers = actorList.Select(actor => actor.Peer);
var eventData = new EventData(eventCode, data);
eventData.SendTo(peers, sendParameters);
}
示例6: PublishGameChanges
private void PublishGameChanges()
{
try
{
this.schedule = null;
if (this.GameList.ChangedGamesCount > 0)
{
Hashtable changedGames = this.GameList.GetChangedGames();
var e = new GameListUpdateEvent { Data = changedGames };
var eventData = new EventData((byte)EventCode.GameListUpdate, e);
eventData.SendTo(this.peers, new SendParameters());
}
}
catch (Exception ex)
{
log.Error(ex);
}
}
示例7: PublishEvent
/// <summary>
/// Publishes an event to a list of actors on a specified channel.
/// </summary>
/// <param name = "e">
/// The event to publish.
/// </param>
/// <param name = "actorList">
/// A list of <see cref = "Actor" /> who should receive the event.
/// </param>
/// <param name = "sendParameters">
/// The send Parameters.
/// </param>
protected void PublishEvent(LiteEventBase e, IEnumerable<Actor> actorList, SendParameters sendParameters)
{
IEnumerable<PeerBase> peers = actorList.Select(actor => actor.Peer);
var eventData = new EventData(e.Code, e);
eventData.SendTo(peers, sendParameters);
}
示例8: BroadcastReliableToRoom
public void BroadcastReliableToRoom(byte eventCode, Dictionary<byte, object> data)
{
var eventData = new EventData(eventCode, data);
var sendParams = new SendParameters();
eventData.SendTo(Actors.Select(actor => actor.Peer), sendParams);
}
示例9: TrySendRecentChatMessage
public void TrySendRecentChatMessage()
{
var eventDataMessages = new EventData((byte)EventCode.ChatMessage);
string lastMessages = ChatLobby.Instance.GetRecentMessages().Aggregate((i, j) => i + "\r\n" + j);
eventDataMessages.Parameters = new Dictionary<byte, object> { { (byte)ParameterCode.ChatMessage, lastMessages } };
eventDataMessages.SendTo(new UnityClient[] { UnityClient }, SendParameters);
}
示例10: TrySendChatMessage
public void TrySendChatMessage()
{
var chatRequest = new ChatMessage(UnityClient.Protocol, OperationRequest);
if (!chatRequest.IsValid) {
UnityClient.SendOperationResponse(chatRequest.GetResponse(ErrorCode.InvalidParameters), SendParameters);
return;
}
string message = chatRequest.Message;
message = UnityClient.CharacterName + ": " + message;
ChatLobby.Instance.AddMessage(message);
var eventData = new EventData((byte)EventCode.ChatMessage);
eventData.Parameters = new Dictionary<byte, object>() { { (byte)ParameterCode.ChatMessage, message } };
eventData.SendTo(AccountService.Instance.Clients, SendParameters);
}
示例11: TryEnter
/// <summary>
/// 类型:方法
/// 名称:TryEnter
/// 作者:taixihuase
/// 作用:通过角色数据尝试进入场景
/// 编写日期:2015/7/22
/// </summary>
/// <param name="operationRequest"></param>
/// <param name="sendParameters"></param>
/// <param name="peer"></param>
private static void TryEnter(OperationRequest operationRequest, SendParameters sendParameters, ServerPeer peer)
{
ServerPeer.Log.Debug("Entering");
int uniqueId = (int)
Serialization.Deserialize(operationRequest.Parameters[(byte) ParameterCode.WorldEnter]);
Character character;
if (peer.Server.Characters.CharacterEnter(uniqueId, out character))
{
peer.Server.Data.CharacterData.GetCharacterPosition(character);
}
// 返回数据给客户端
byte[] pos = Serialization.Serialize(character.Position);
OperationResponse reponseData = new OperationResponse((byte) OperationCode.WorldEnter,
new Dictionary<byte, object>
{
{(byte) ParameterCode.WorldEnter, pos}
})
{
ReturnCode = (short) ErrorCode.Ok,
DebugMessage = "进入场景成功"
};
peer.SendOperationResponse(reponseData, sendParameters);
byte[] data = Serialization.Serialize(character);
EventData eventData = new EventData((byte) EventCode.WorldEnter, new Dictionary<byte, object>
{
{(byte) ParameterCode.WorldEnter, data}
});
eventData.SendTo(peer.Server.Characters.GamingClientsToBroadcast, sendParameters);
}