本文整理汇总了C#中PeerBase.SendOperationResponse方法的典型用法代码示例。如果您正苦于以下问题:C# PeerBase.SendOperationResponse方法的具体用法?C# PeerBase.SendOperationResponse怎么用?C# PeerBase.SendOperationResponse使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PeerBase
的用法示例。
在下文中一共展示了PeerBase.SendOperationResponse方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OperationEnterWorld
/// <summary>
/// Expects operation EnterWorld and creates a new MmoActor with a new Item as avatar and a new MmoClientInterestArea.
/// </summary>
/// <remarks>
/// The MmoActor becomes the new Peer.CurrentOperationHandler.
/// If another MmoActor with the same name exists he is disconnected.
/// An OperationResponse with error code ReturnCode.Ok is published on success.
/// </remarks>
public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
{
var operation = new EnterWorld(peer.Protocol, request);
if (!operation.IsValid)
{
return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
}
World world;
if (WorldCache.Instance.TryGet(operation.WorldName, out world) == false)
{
return operation.GetOperationResponse((int)ReturnCode.WorldNotFound, "WorldNotFound");
}
var interestArea = new ClientInterestArea(peer, operation.InterestAreaId, world)
{
ViewDistanceEnter = operation.ViewDistanceEnter,
ViewDistanceExit = operation.ViewDistanceExit
};
var actor = new MmoActorOperationHandler(peer, world, interestArea);
var avatar = new Item(operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar, world);
while (world.ItemCache.AddItem(avatar) == false)
{
Item otherAvatarItem;
if (world.ItemCache.TryGetItem(avatar.Id, out otherAvatarItem))
{
avatar.Dispose();
actor.Dispose();
interestArea.Dispose();
(((Item)otherAvatarItem).Owner).DisconnectByOtherPeer(this.peer, request, sendParameters);
// request continued later, no response here
return null;
}
}
// init avatar
actor.AddItem(avatar);
actor.Avatar = avatar;
((Peer)peer).SetCurrentOperationHandler(actor);
// set return values
var responseObject = new EnterWorldResponse
{
BoundingBox = world.Area,
TileDimensions = world.TileDimensions,
WorldName = world.Name
};
// send response; use item channel to ensure that this event arrives before any move or subscribe events
var response = new OperationResponse(request.OperationCode, responseObject);
sendParameters.ChannelId = Settings.ItemEventChannel;
peer.SendOperationResponse(response, sendParameters);
lock (interestArea.SyncRoot)
{
interestArea.AttachToItem(avatar);
interestArea.UpdateInterestManagement();
}
avatar.Spawn(operation.Position);
world.Radar.AddItem(avatar, operation.Position);
// response already sent
return null;
}
示例2: OperationRadarSubscribe
/// <summary>
/// Expects operation RadarSubscribe and subscribes the peer to the Radar.
/// Publishes an OperationResponse with error code ReturnCode.Ok if successful.
/// </summary>
public static OperationResponse OperationRadarSubscribe(PeerBase peer, OperationRequest request, SendParameters sendParameters)
{
var mmoPeer = (MmoPeer)peer;
var operation = new RadarSubscribe(peer.Protocol, request);
if (!operation.IsValid)
{
return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
}
if (mmoPeer.RadarSubscription != null)
{
mmoPeer.RadarSubscription.Dispose();
mmoPeer.RadarSubscription = null;
}
World world;
if (WorldCache.Instance.TryGet(operation.WorldName, out world) == false)
{
return operation.GetOperationResponse((int)ReturnCode.WorldNotFound, "WorldNotFound");
}
mmoPeer.RadarSubscription = world.Radar.Channel.Subscribe(mmoPeer.RequestFiber, m => RadarChannel_OnItemEventMessage(peer, m));
// set return values
var responseObject = new RadarSubscribeResponse
{
BoundingBox = world.Area,
TileDimensions = world.TileDimensions,
WorldName = world.Name
};
// send response before sending radar content
var response = new OperationResponse(request.OperationCode, responseObject);
peer.SendOperationResponse(response, sendParameters);
// send complete radar content to client
world.Radar.SendContentToPeer(mmoPeer);
// response already sent
return null;
}
示例3: HandleSuccessHttpResponse
private void HandleSuccessHttpResponse(PeerBase peer, byte operationCode, WebRpcRequest rpcRequest, AsyncHttpRequest request)
{
try
{
var serializer = new JavaScriptSerializer();
var responseAsText = Encoding.UTF8.GetString(request.Response);
if (string.IsNullOrEmpty(responseAsText))
{
var msg = string.Format("WebRpc response for request to address {0} is empty", request.WebRequest.RequestUri);
if (Log.IsDebugEnabled)
{
Log.DebugFormat(msg);
}
this.SendErrorResponse(peer, operationCode, new SendParameters(), msg: msg);
return;
}
WebRpcResponse rpcResponse;
try
{
rpcResponse = serializer.Deserialize<WebRpcResponse>(responseAsText);
}
catch (Exception ex)
{
if (Log.IsDebugEnabled)
{
Log.DebugFormat("WebRpc failed to deserialize resonse. Uri={0} response={1} error={2}",
request.WebRequest.RequestUri, responseAsText, ex.Message);
}
var msg = string.Format("WebRpc failed to deserialize resonse. Uri={0} response={1} error={2}",
request.WebRequest.RequestUri, responseAsText.Substring(0, Math.Min(200, responseAsText.Length)), ex.Message);
this.SendErrorResponse(peer, operationCode, new SendParameters(), msg: msg);
return;
}
if (rpcResponse == null)
{
if (Log.IsDebugEnabled)
{
Log.DebugFormat("WebRpc response for request to address {0} has wrong format: {1}",
request.WebRequest.RequestUri, responseAsText);
}
var msg = string.Format("WebRpc response for request to address {0} has wrong format: {1}",
request.WebRequest.RequestUri, responseAsText.Substring(0, Math.Min(200, responseAsText.Length)));
this.SendErrorResponse(peer, operationCode, new SendParameters(), msg: msg);
return;
}
var data = rpcResponse.Data as IEnumerable;
var hasData = data != null && data.GetEnumerator().MoveNext();
if (Log.IsDebugEnabled)
{
Log.DebugFormat("WebRpc response {0} for request to address {1}: {2}", rpcResponse, request.WebRequest.RequestUri, responseAsText);
}
var path = rpcRequest.UriPath.Contains("?") ? rpcRequest.UriPath.Substring(0, rpcRequest.UriPath.IndexOf("?")) : rpcRequest.UriPath;
var response = new OperationResponse
{
OperationCode = operationCode,
ReturnCode = 0,
DebugMessage = hasData ? Newtonsoft.Json.JsonConvert.SerializeObject(rpcResponse.Data) : "",
Parameters =
hasData
?
new Dictionary<byte, object>
{
{ (byte)ParameterKey.RpcCallRetCode, rpcResponse.ResultCode },
{ (byte)ParameterKey.RpcCallRetMessage, rpcResponse.Message },
{ (byte)ParameterKey.UriPath, path },
{ (byte)ParameterKey.RpcCallParams, rpcResponse.Data },
}
:
new Dictionary<byte, object>
{
{ (byte)ParameterKey.RpcCallRetCode, rpcResponse.ResultCode },
{ (byte)ParameterKey.RpcCallRetMessage, rpcResponse.Message },
{ (byte)ParameterKey.UriPath, path },
}
};
peer.SendOperationResponse(response, new SendParameters());
}
catch (Exception e)
{
var msg = string.Format("Handling of successfull response failed with exception {0}", e);
this.SendErrorResponse(peer, operationCode, new SendParameters(), msg: msg);
Log.Error(msg);
}
}
示例4: SendErrorResponse
private void SendErrorResponse(PeerBase peer, byte opCode, SendParameters sp, short retCode = (short)ErrorCode.ExternalHttpCallFailed, string msg = "", Dictionary<byte, object> parameters = null)
{
var response = new OperationResponse(opCode)
{
DebugMessage = msg,
ReturnCode = retCode,
Parameters = parameters
};
peer.SendOperationResponse(response, sp);
}
示例5: OperationEnterWorld
public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
{
var operation = new EnterWorld(peer.Protocol, request);
if (!operation.IsValid)
{
return new OperationResponse(request.OperationCode) { ReturnCode = (int)ErrorCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
}
MmoWorld world = MmoWorld.Instance;
var actor = new MmoActor(peer, world, interestArea);
var avatar = new MmoItem(world, operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar);
while (world.ItemCache.AddItem(avatar) == false)
{
Item otherAvatarItem;
if (world.ItemCache.TryGetItem(avatar.Type, avatar.Id, out otherAvatarItem))
{
avatar.Dispose();
actor.Dispose();
interestArea.Dispose();
((Peer)((MmoItem)otherAvatarItem).Owner.Peer).DisconnectByOtherPeer(this, request, sendParameters);
// request continued later, no response here
return null;
}
}
// init avatar
actor.AddItem(avatar);
actor.Avatar = avatar;
((Peer)peer).SetCurrentOperationHandler(actor);
// set return values
var responseObject = new EnterWorldResponse
{
};
// send response; use item channel to ensure that this event arrives before any move or subscribe events
var response = new OperationResponse(request.OperationCode, responseObject);
sendParameters.ChannelId = Settings.ItemEventChannel;
peer.SendOperationResponse(response, sendParameters);
avatar.Spawn(operation.Position);
// response already sent
return null;
}
示例6: ExecuteGetStatsRequest
private void ExecuteGetStatsRequest(PeerBase peer, GetLobbyStatsRequest statsRequest, SendParameters sendParameter)
{
try
{
OperationResponse errorresponse;
if (this.ValidateRequest(statsRequest, out errorresponse) == false)
{
peer.SendOperationResponse(errorresponse, sendParameter);
return;
}
var response = new GetLobbyStatsResponse();
AppLobby[] lobbies;
short returnCode = 0;
string debugMessage = null;
if (statsRequest.LobbyNames == null)
{
lobbies = this.lobbyFactory.GetLobbies(this.maxLobbyStatsCount);
response = LobbyListToLobbyStatsData(lobbies);
}
else
{
// Check if lobby stats limit is exceeded.
// If Limit is exceeded the complete list will be returned anyway but with the response result code set to -4.
// This behaviour might change in future versions.
if (this.maxLobbyStatsCount > 0 && statsRequest.LobbyNames.Length > this.maxLobbyStatsCount)
{
returnCode = (short)ErrorCode.ArgumentOutOfRange;
debugMessage = string.Format("LobbyStats limit of {0} exceeded", this.maxLobbyStatsCount);
}
lobbies = this.lobbyFactory.GetLobbies(statsRequest.LobbyNames, statsRequest.LobbyTypes);
var count = lobbies.Length;
response.PeerCount = new int[count];
response.GameCount = new int[count];
for (int i = 0; i < lobbies.Length; i++)
{
if (lobbies[i] != null)
{
response.PeerCount[i] = lobbies[i].PeerCount + lobbies[i].PlayerCount;
response.GameCount[i] = lobbies[i].GameCount;
}
else
{
response.PeerCount[i] = 0;
response.GameCount[i] = 0;
}
}
}
var operationResponse = new OperationResponse((byte)OperationCode.LobbyStats, response)
{
ReturnCode = returnCode,
DebugMessage = debugMessage
};
peer.SendOperationResponse(operationResponse, sendParameter);
}
catch (Exception ex)
{
log.Error(ex);
}
}
示例7: OnOperationRequest
public void OnOperationRequest(PeerBase src, OperationRequest request, SendParameters sendParams)
{
// send ack to peer
src.SendOperationResponse(new OperationResponse(
(byte)AckOperationTypes.Ack), sendParams);
}
示例8: HandleFiendFriends
private void HandleFiendFriends(PeerBase peer, FindFriendsRequest request, SendParameters sendParameters)
{
try
{
var onlineList = new bool[request.UserList.Length];
var gameIds = new string[request.UserList.Length];
for (int i = 0; i < request.UserList.Length; i++)
{
PlayerState playerState;
if (this.playerDict.TryGetValue(request.UserList[i], out playerState))
{
onlineList[i] = true;
if (playerState.ActiveGame != null)
{
gameIds[i] = playerState.ActiveGame.Id;
}
else
{
gameIds[i] = string.Empty;
}
}
else
{
gameIds[i] = string.Empty;
}
}
var response = new FindFriendsResponse { IsOnline = onlineList, UserStates = gameIds };
var opResponse = new OperationResponse((byte)OperationCode.FindFriends, response);
peer.SendOperationResponse(opResponse, sendParameters);
}
catch (Exception ex)
{
log.Error(ex);
}
}
示例9: OperationEnterWorld
/// <summary>
/// Expects operation <see cref = "EnterWorld" /> and creates a new <see cref = "MmoActor" /> with a new <see cref = "MmoItem" /> as avatar and a new <see cref = "MmoClientInterestArea" />.
/// The <see cref = "MmoActor" /> becomes the new <see cref = "Peer.CurrentOperationHandler">operation handler</see>.
/// If another <see cref = "MmoActor" /> with the same name exists he is disconnected.
/// An <see cref = "OperationResponse" /> with error code <see cref = "ReturnCode.Ok" /> is published on success.
/// </summary>
/// <param name = "peer">
/// The client peer.
/// </param>
/// <param name = "request">
/// The request.
/// </param>
/// <param name = "sendParameters">
/// The send Parameters.
/// </param>
/// <returns>
/// Null or an <see cref = "OperationResponse" /> with error code <see cref = "ReturnCode.WorldNotFound" />.
/// </returns>
public OperationResponse OperationEnterWorld(PeerBase peer, OperationRequest request, SendParameters sendParameters)
{
var operation = new EnterWorld(peer.Protocol, request);
if (!operation.IsValid)
{
return new OperationResponse(request.OperationCode) { ReturnCode = (int)ReturnCode.InvalidOperationParameter, DebugMessage = operation.GetErrorMessage() };
}
MmoWorld world;
if (MmoWorldCache.Instance.TryGet(operation.WorldName, out world) == false)
{
return operation.GetOperationResponse((int)ReturnCode.WorldNotFound, "WorldNotFound");
}
var interestArea = new MmoClientInterestArea(peer, operation.InterestAreaId, world)
{
ViewDistanceEnter = operation.ViewDistanceEnter.ToVector(), ViewDistanceExit = operation.ViewDistanceExit.ToVector()
};
var actor = new MmoActor(peer, world, interestArea);
var avatar = new MmoItem(world, operation.Position, operation.Rotation, operation.Properties, actor, operation.Username, (byte)ItemType.Avatar);
while (world.ItemCache.AddItem(avatar) == false)
{
Item otherAvatarItem;
if (world.ItemCache.TryGetItem(avatar.Type, avatar.Id, out otherAvatarItem))
{
avatar.Dispose();
actor.Dispose();
interestArea.Dispose();
((Peer)((MmoItem)otherAvatarItem).Owner.Peer).DisconnectByOtherPeer(this, request, sendParameters);
// request continued later, no response here
return null;
}
}
#region PopBloop
avatar.AvatarName = operation.AvatarName;
log.InfoFormat("View Distance {0}, {1}", operation.ViewDistanceEnter[0], operation.ViewDistanceEnter[1]);
DbManager.Instance.RecordPlayerStats(avatar.Id, operation.WorldName);
DbManager.Instance.RecordRoomStats(avatar.Id, operation.WorldName);
DbManager.Instance.SetConcurrent(avatar.Id, operation.WorldName, false);
#endregion
// init avatar
actor.AddItem(avatar);
actor.Avatar = avatar;
((Peer)peer).SetCurrentOperationHandler(actor);
// set return values
var responseObject = new EnterWorldResponse
{
BottomRightCorner = world.Area.Max.ToFloatArray(2),
TopLeftCorner = world.Area.Min.ToFloatArray(2),
TileDimensions = world.TileDimensions.ToFloatArray(2),
WorldName = world.Name
};
// send response; use item channel to ensure that this event arrives before any move or subscribe events
var response = new OperationResponse(request.OperationCode, responseObject);
sendParameters.ChannelId = Settings.ItemEventChannel;
peer.SendOperationResponse(response, sendParameters);
lock (interestArea.SyncRoot)
{
interestArea.AttachToItem(avatar);
interestArea.UpdateInterestManagement();
}
avatar.Spawn(operation.Position);
world.Radar.AddItem(avatar, operation.Position);
PhotonCounter.SessionCount.Increment();
// response already sent
return null;
//.........这里部分代码省略.........