本文整理汇总了C#中ZyGames.Framework.RPC.IO.MessageStructure.WriteBuffer方法的典型用法代码示例。如果您正苦于以下问题:C# MessageStructure.WriteBuffer方法的具体用法?C# MessageStructure.WriteBuffer怎么用?C# MessageStructure.WriteBuffer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ZyGames.Framework.RPC.IO.MessageStructure
的用法示例。
在下文中一共展示了MessageStructure.WriteBuffer方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnReceiveTimeout
public override void OnReceiveTimeout(string clientAddress, byte[] receiveData)
{
try
{
BufferReader reader = new BufferReader(receiveData);
string paramString = reader.ReadPacketString();
paramString = HttpUtility.UrlDecode(paramString, Encoding.UTF8);
int index = paramString.IndexOf("?d=");
if (index != -1)
{
index += 3;
paramString = paramString.Substring(index, paramString.Length - index);
}
PacketMessage receivePacket = ParsePacketMessage(clientAddress, paramString, ConnectType.Tcp);
var recHead = receivePacket.Head;
int errorCode = LanguageHelper.GetLang().ErrorCode;
string errorMsg = LanguageHelper.GetLang().RequestTimeout;
MessageHead head = new MessageHead(recHead.MsgId, recHead.ActionId, "st", errorCode, errorMsg);
head.HasGzip = true;
MessageStructure ds = new MessageStructure();
ds.WriteBuffer(head);
byte[] data = ds.ReadBuffer();
OnSendCompleted(clientAddress, data);
}
catch (Exception ex)
{
TraceLog.WriteError("Send to client {0} timeout error:{1}", clientAddress, ex);
}
}
示例2: ProcessRequest
/// <summary>
///
/// </summary>
/// <param name="package"></param>
/// <param name="param"></param>
/// <returns></returns>
public byte[] ProcessRequest(object package, object param) {
var httpresponse = new SocketGameResponse();
ActionGetter actionGetter = null;
try {
httpresponse.WriteErrorCallback += GameEnvironment.Setting.ActionDispatcher.ResponseError;
RequestPackage p = package as RequestPackage;
actionGetter = param as ActionGetter;
if (!string.IsNullOrEmpty(p.RouteName)) {
if (CheckRemote(p.RouteName, actionGetter)) {
MessageStructure response = new MessageStructure();
OnCallRemote(p.RouteName, actionGetter, response);
return response.PopBuffer();
}
httpresponse.WriteError(actionGetter, 10000, "No permission");
} else {
DoAction(actionGetter, httpresponse);
}
return httpresponse.ReadByte();
} catch (Exception ex) {
TraceLog.WriteError("Request error:{0}", ex);
MessageStructure response = new MessageStructure();
response.WriteBuffer(new MessageHead(0, 10000, "request error"));
return response.PopBuffer();
}
}
示例3: ResponseError
public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
{
MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), errorCode, errorInfo);
MessageStructure sb = new MessageStructure();
sb.WriteBuffer(head);
response.BinaryWrite(sb.PopBuffer());
}
示例4: CtorErrMsg
public static byte[] CtorErrMsg(int error, string msg, NameValueCollection requestParam)
{
int msgId = Convert.ToInt32(requestParam["msgid"]);
int actionid = Convert.ToInt32(requestParam["actionid"]);
var ms = new MessageStructure();
var head = new MessageHead(msgId, actionid, "st", error, msg);
ms.WriteBuffer(head);
return ms.PosGzipBuffer();
}
示例5: RequestTimeout
public void RequestTimeout(HttpConnection connection)
{
var param = connection.Param;
int msgId = param.Get("MsgId").ToInt();
int actionId = param.Get("ActionId").ToInt();
int errorCode = LanguageHelper.GetLang().ErrorCode;
string errorMsg = LanguageHelper.GetLang().RequestTimeout;
var head = new MessageHead(msgId, actionId, "st", errorCode, errorMsg);
head.HasGzip = true;
var ms = new MessageStructure();
ms.WriteBuffer(head);
byte[] data = ms.ReadBuffer();
string remoteAddress = connection.Context.Request.RemoteEndPoint.Address.ToString();
string successMsg = string.Format("{0}>>发送超时到{1} {2}字节!",
DateTime.Now.ToString("HH:mm:ss:ms"), remoteAddress, data.Length);
Console.WriteLine(successMsg);
OnResponseCompleted(connection, data);
}
示例6: OnCallRemote
private void OnCallRemote(string route, HttpGet httpGet, MessageStructure response)
{
try
{
string[] mapList = route.Split('.');
string funcName = "";
string routeName = "";
if (mapList.Length > 1)
{
funcName = mapList[mapList.Length - 1];
routeName = string.Join("/", mapList, 0, mapList.Length - 1);
}
string routeFile = "";
string typeName = string.Format("Game.Script.Remote.{0}", routeName);
int actionId = httpGet.ActionId;
MessageHead head = new MessageHead(actionId);
if (!ScriptEngines.DisablePython)
{
routeFile = string.Format("{0}/Remote/{1}.py", ScriptEngines.PythonDirName, routeName);
dynamic scope = ScriptEngines.Execute(routeFile, typeName);
if (scope != null)
{
var funcHandle = scope.GetVariable<RemoteHandle>(funcName);
if (funcHandle != null)
{
funcHandle(httpGet, head, response);
response.WriteBuffer(head);
return;
}
}
}
routeFile = string.Format("{0}/Remote/{1}.cs", ScriptEngines.CSharpDirName, routeName);
var instance = (object)ScriptEngines.Execute(routeFile, typeName);
if (instance != null)
{
var result = ObjectAccessor.Create(instance, true)[funcName];
}
}
catch (Exception ex)
{
TraceLog.WriteError("{0}", ex);
}
}
示例7: OnCallRemote
/// <summary>
/// Call remote method
/// </summary>
/// <param name="routePath"></param>
/// <param name="actionGetter"></param>
/// <param name="response"></param>
protected virtual void OnCallRemote(string routePath, ActionGetter actionGetter, MessageStructure response)
{
try
{
string[] mapList = routePath.Split('.');
string funcName = "";
string routeName = routePath;
if (mapList.Length > 1)
{
funcName = mapList[mapList.Length - 1];
routeName = string.Join("/", mapList, 0, mapList.Length - 1);
}
string routeFile = "";
int actionId = actionGetter.GetActionId();
MessageHead head = new MessageHead(actionId);
if (!ScriptEngines.SettupInfo.DisablePython)
{
routeFile = string.Format("Remote.{0}", routeName);
dynamic scope = ScriptEngines.ExecutePython(routeFile);
if (scope != null)
{
var funcHandle = scope.GetVariable<RemoteHandle>(funcName);
if (funcHandle != null)
{
funcHandle(actionGetter, head, response);
response.WriteBuffer(head);
return;
}
}
}
string typeName = string.Format(GameEnvironment.Setting.RemoteTypeName, routeName);
routeFile = string.Format("Remote.{0}", routeName);
var args = new object[] { actionGetter, response };
var instance = (object)ScriptEngines.Execute(routeFile, typeName, args);
if (instance is RemoteStruct)
{
var target = instance as RemoteStruct;
target.DoRemote();
}
}
catch (Exception ex)
{
TraceLog.WriteError("OnCallRemote error:{0}", ex);
}
}
示例8: ResponseHearbeat
/// <summary>
/// Response hearbeat stream.
/// </summary>
/// <param name="package"></param>
/// <param name="session"></param>
protected void ResponseHearbeat(RequestPackage package, GameSession session)
{
try
{
MessageStructure response = new MessageStructure();
response.WriteBuffer(new MessageHead(package.MsgId, package.ActionId, 0));
var data = response.PopBuffer();
if (session != null && data.Length > 0)
{
session.SendAsync(OpCode.Binary, data, 0, data.Length, OnSendCompleted).Wait();
}
}
catch (Exception ex)
{
TraceLog.WriteError("Post Heartbeat error:{0}", ex);
}
}
示例9: DoWriteError
private void DoWriteError(MessageStructure ms, MessageHead head)
{
head.ErrorCode = (int)MessageError.SystemError;
head.ClientVersion = 1;
string msg = string.Format("Request action:{0} wcfserver error:{1}-{2},MsgId:{3}",
head.Action, head.ErrorCode, head.ErrorInfo, head.MsgId);
TraceLog.WriteError(msg);
#if DEBUG
Console.WriteLine(msg);
#endif
ms.WriteBuffer(head);
}
示例10: OnCallRemoteComplated
protected byte[] OnCallRemoteComplated(ChannelContext context, string route, string param, string remoteAddress)
{
lock (context)
{
HttpGet httpGet = new HttpGet(param, remoteAddress);
MessageStructure structure = new MessageStructure();
MessageHead head = new MessageHead();
OnCallRemote(route, httpGet, head, structure);
structure.WriteBuffer(head);
return structure.ReadBuffer();
}
}
示例11: DoSerialize
private static byte[] DoSerialize(params BaseEntity[] entityList)
{
var rootWriter = new MessageStructure();
rootWriter.PushIntoStack(entityList.Length);
object fieldValue = null;
foreach (var entity in entityList)
{
var schema = entity.GetSchema();
if (schema == null)
{
continue;
}
var recordWriter = new MessageStructure();
recordWriter.PushIntoStack(schema.EntityName);
//write columns
var columns = schema.GetColumns();
foreach (var column in columns)
{
fieldValue = entity.GetPropertyValue(column.Name);
if (EntitySchemaSet.IsSupportType(column.ColumnType))
{
recordWriter.PushIntoStack(column.ColumnType, fieldValue);
}
else if (column.HasChild)
{
PushChildStack(recordWriter, column, fieldValue);
}
}
rootWriter.PushIntoStack(recordWriter);
}
var head = new MessageHead(SyncActionId);
rootWriter.WriteBuffer(head);
return rootWriter.PopBuffer();
}
示例12: ResponseError
/// <summary>
///
/// </summary>
/// <param name="response"></param>
/// <param name="actionGetter"></param>
/// <param name="errorCode"></param>
/// <param name="errorInfo"></param>
public virtual void ResponseError(BaseGameResponse response, ActionGetter actionGetter, int errorCode, string errorInfo)
{
string st = actionGetter.GetSt();
ProtocolVersion prtcl = actionGetter.GetPtcl();
MessageHead head = new MessageHead(actionGetter.GetMsgId(), actionGetter.GetActionId(), st, errorCode, errorInfo);
MessageStructure sb = new MessageStructure();
if (prtcl >= ProtocolVersion.ExtendHead)
{
sb.PushIntoStack(0); //不输出扩展头属性
}
sb.WriteBuffer(head);
response.BinaryWrite(sb.PopBuffer());
}
示例13: RequestError
/// <summary>
/// 出错处理
/// </summary>
/// <param name="response"></param>
/// <param name="actionID"></param>
/// <param name="errorCode"></param>
/// <param name="errorInfo"></param>
public static void RequestError(IGameResponse response, int actionID, int errorCode, string errorInfo)
{
MessageHead head = new MessageHead(actionID, errorCode, errorInfo);
MessageStructure sb = new MessageStructure();
sb.WriteBuffer(head);
response.BinaryWrite(sb.ReadBuffer());
}