本文整理汇总了C#中Server.Network.Client.SendMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Client.SendMessage方法的具体用法?C# Client.SendMessage怎么用?C# Client.SendMessage使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Server.Network.Client
的用法示例。
在下文中一共展示了Client.SendMessage方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeliveryRequest
/// <summary>
/// Parses a Delivery Request command from a client.
/// </summary>
/// <param name="client">Client the command originated from.</param>
/// <param name="tokens">The network message.</param>
private void DeliveryRequest(Client client, string[] tokens)
{
try
{
int count = 1;
int originID = Convert.ToInt32(tokens[count++]);
int destinationID = Convert.ToInt32(tokens[count++]);
int weight = Convert.ToInt32(tokens[count++]);
int volume = Convert.ToInt32(tokens[count++]);
IDictionary<PathType, Delivery> options = deliveryService.GetBestRoutes(client.ID, originID, destinationID, weight, volume);
if (options.Count <= 0)
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_DELIVERY_PRICES, NetCodes.PATH_CANCEL));
else
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_DELIVERY_PRICES, PathTypeExtensions.BuildOptionsNetString(options)));
}
catch (FormatException e)
{
SendErrorMessage(client, "Malformed network message.");
}
catch (Exception e)
{
SendErrorMessage(client, e.Message);
}
}
示例2: PassMessage
public static void PassMessage(string message, Client sendingClient)
{
sendingClient.SendMessage("Hello!");
}
示例3: SyncState
/// <summary>
/// Parses a Sync State command from a client.
/// </summary>
/// <param name="client">Client the command originated from.</param>
/// <param name="tokens">The network message.</param>
private void SyncState(Client client, string[] tokens)
{
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_STATS_BEGIN, eventService.GetDateOfFirstEvent().ToString()));
DateTime clientTime = DateTime.Parse(tokens[1]);
var companies = companyService.GetAll();
foreach (Company c in companies)
SendUpdateForSync(client, NetCodes.OBJECT_COMPANY, c.ToNetString());
var countries = countryService.GetAll();
foreach (Country l in countries)
SendUpdateForSync(client, NetCodes.OBJECT_COUNTRY, l.ToNetString());
var routeNodes = locationService.GetAll();
foreach (RouteNode n in routeNodes)
SendUpdateForSync(client, NetCodes.OBJECT_ROUTENODE, n.ToNetString());
var domesticPrices = priceService.GetAllDomesticPrices();
foreach (DomesticPrice d in domesticPrices)
SendUpdateForSync(client, NetCodes.OBJECT_DOMESTIC_PRICE, d.ToNetString());
var prices = priceService.GetAll();
foreach (Price p in prices)
SendUpdateForSync(client, NetCodes.OBJECT_PRICE, p.ToNetString());
var routes = routeService.GetAll();
foreach (Route r in routes)
SendUpdateForSync(client, NetCodes.OBJECT_ROUTE, r.ToNetString());
client.SendMessage(NetCodes.SV_SYNC_DONE);
}
示例4: StatsRequest
/// <summary>
/// Parses a Stats Retrieval command from a client.
/// </summary>
/// <param name="client">Client the command originated from.</param>
/// <param name="tokens">The network message.</param>
private void StatsRequest(Client client, string[] tokens)
{
Statistics stats;
if (tokens[1] == NetCodes.STATS_NOW)
stats = statisticsService.GetStatisticsFromPoint(DateTime.UtcNow);
else
{
DateTime time = DateTime.Parse(tokens[1]);
stats = statisticsService.GetStatisticsFromPoint(time);
}
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_STATS_ANSWER, stats.ToNetString()));
}
示例5: SendUpdateForSync
private void SendUpdateForSync(Client client, string objectType, string objectDef)
{
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_SYNC_UPDATE, DateTime.UtcNow.ToString(), objectType, objectDef));
}
示例6: SendErrorMessage
private void SendErrorMessage(Client client, string error)
{
Logger.WriteLine("Error processing Client ({0}) request: {1}", client.ID, error);
client.SendMessage(NetCodes.BuildNetworkString(NetCodes.SV_ERROR, error));
}
示例7: DeliverySelect
/// <summary>
/// Parses a Delivery Select command from a client.
/// </summary>
/// <param name="client">Client the command originated from.</param>
/// <param name="tokens">The network message.</param>
private void DeliverySelect(Client client, string[] tokens)
{
int count = 1;
// TODO Implement the timeout stuff
if (tokens[count] == NetCodes.PATH_CANCEL)
return; // client cancelled request - TODO nicer handling
PathType type = PathTypeExtensions.ParseNetString(tokens[count]);
deliveryService.SelectDeliveryOption(client.ID, type);
client.SendMessage(NetCodes.SV_DELIVERY_CONFIRMED);
}