void OnRequestReceived(NetWork.Session session, BinaryRequestInfo requestInfo) { Console.WriteLine("OnRequestReceived success."); ByteBuffer buffer = new ByteBuffer(requestInfo.Body); if (buffer == null) { Console.WriteLine("----------Error data"); return; } try { //int length = buffer.ReadShort (); int length = 0; C2S_Proto_Type protoType = (C2S_Proto_Type)buffer.ReadShort(); Console.WriteLine("Receive proto size : {0}, name : {1}", length, protoType); switch (protoType) { case C2S_Proto_Type.Proto_Stuff_Login: { Stuff_Login login = ProtoUtil.Deserialize <Stuff_Login>(buffer); if (CheckAuthentication(login)) { Player player = new Player(login.PlayerId); player.SetSession(session); player.OnPlayerLogin(); } } break; case C2S_Proto_Type.Proto_Stuff_Account: { Stuff_Account account = ProtoUtil.Deserialize <Stuff_Account>(buffer); Console.WriteLine(account.UserName + account.PassWord); } break; default: break; } } catch (Exception ex) { Console.WriteLine("Deserialize exception : {0}", ex.Message); } }
public static C2S_Proto_Type GetProtoType(ProtoBuf.IExtensible proto) { PropertyInfo property = proto.GetType().GetProperty("type_t"); if (null == property) { Console.WriteLine("Protocol {0} does not have memeber 'type-t'", proto); return(C2S_Proto_Type.Proto_Stuff_Client_Begin); } String value = property.GetValue(proto, null).ToString(); C2S_Proto_Type type = C2S_Proto_Type.Proto_Stuff_Client_Begin; Enum.TryParse(value, out type); return(type); }