public void Read (TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.Struct) { Header = new ProtocolBase(); Header.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.I32) { Camp = iprot.ReadI32(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }
public static void Prot_Event_ErrorOccured(object sender, string ErrorMessage) { try { MessageCollector.AddMessage(MessageClass.InformationMsg, Language.strConnectionEventErrorOccured, true); ProtocolBase Prot = (ProtocolBase)sender; if (Prot.InterfaceControl.Info.Protocol == ProtocolType.RDP) { if (Convert.ToInt32(ErrorMessage) > -1) { MessageCollector.AddMessage(MessageClass.WarningMsg, string.Format(Language.strConnectionRdpErrorDetail, ErrorMessage, ProtocolRDP.FatalErrors.GetError(ErrorMessage))); } } } catch (Exception ex) { MessageCollector.AddMessage(MessageClass.ErrorMsg, Language.strConnectionEventConnectionFailed + Environment.NewLine + ex.Message, true); } }
//加入按钮回调 public void OnJoinBtnBack(ProtocolBase protocol) { //解析参数 ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); //EnterRoom int ret = proto.GetInt(start, ref start); //处理 if (ret == 0) { PanelMgr.instance.OpenPanel <TipPanel>("", "成功进入房间!"); PanelMgr.instance.OpenPanel <RoomPanel>(""); Close(); } else { PanelMgr.instance.OpenPanel <TipPanel>("", "进入房间失败"); } }
void OnLoginBack(ProtocolBase protoBase) { ProtocolBytes protocolRec = (ProtocolBytes)protoBase; int start = 0; string protoName = protocolRec.GetString(start, ref start); int result = protocolRec.GetInt(start, ref start); if (result == 0) { //Debug.Log ("[LoginPanel.OnLoginBack] Login success. "); PanelMgr.instance.OpenPanel <TipPanel>("", "Login success. "); PanelMgr.instance.OpenPanel <LobbyPanel> (""); Close(); } else { //Debug.Log ("[LoginPanel.OnLoginBack] Login fail. "); PanelMgr.instance.OpenPanel <TipPanel>("", "Login fail. Please check your username and password."); } }
public void OnLoginBack(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); if (ret == 0) { PanelMgr.instance.OpenPanel <TipPanel>("", "登录成功!"); //开始游戏 PanelMgr.instance.OpenPanel <RoomListPanel>(""); GameMgr.instance.id = idInput.text; Close(); } else { PanelMgr.instance.OpenPanel <TipPanel>("", "登录失败,请检查用户名密码!"); } }
//新建按钮返回 public void OnNewBack(ProtocolBase protocol) { //解析参数 ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); //处理 if (ret == 0) { PanelMgr.instance.OpenPanel <TipPanel>("", "创建成功!"); PanelMgr.instance.OpenPanel <RoomPanel>(""); Close(); } else { PanelMgr.instance.OpenPanel <TipPanel>("", "创建房间失败!"); } }
public void MsgUpdateInfo(Player player, ProtocolBase protoBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); float x = protocol.GetFloat(start, ref start); float y = protocol.GetFloat(start, ref start); float z = protocol.GetFloat(start, ref start); Scene.instance.UpdateInfo(player.id, x, y, z); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("UpdateInfo"); protocolRet.AddString("Player.id"); protocolRet.AddFloat(x); protocolRet.AddFloat(y); protocolRet.AddFloat(z); ServNet.instance.Broadcast(protocolRet); }
//更新列表 public void GetList(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; //获取头部数值 int start = 0; string protoName = proto.GetString(start, ref start); int count = proto.GetInt(start, ref start); //遍历 for (int i = 0; i < count; i++) { string id = proto.GetString(start, ref start); float x = proto.GetFloat(start, ref start); float y = proto.GetFloat(start, ref start); float z = proto.GetFloat(start, ref start); int score = proto.GetInt(start, ref start); Vector3 pos = new Vector3(x, y, z); UpdateInfo(id, pos, score); } }
public void MsgSpaceArriveEnd(Player player, ProtocolBase protoBase) { ProtocolBytes proto = (ProtocolBytes)protoBase; int start = 0; string name = proto.GetString(start, ref start); int num = proto.GetInt(start, ref start); Logger.Default.Info("MsgSpaceArriveEnd: num = " + num); ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("SpaceArriveEnd"); protocolRet.AddString(player.id); protocolRet.AddInt(num); Room room = player.tempData.room; room.Broadcast(protocolRet); room.isArrived += 1; room.UpdateWin(); }
public void OnPrepareBack(ProtocolBase protocol) { //获取数值 ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); isPrepare = proto.GetInt(start, ref start); //根据是否准备 设置不同的按钮文字 Text text = startOrPreBtn.transform.Find("Text").GetComponent <Text>(); if (isPrepare == 1) { text.text = "取消准备"; } else { text.text = "准备"; } }
//创建房间 public void MsgCreateRoom(Player player, ProtocolBase protoBase) { ProtocolBytes protocol = new ProtocolBytes(); protocol.AddString("CreateRoom"); //条件检测 if (player.tempData.status != PlayerTempData.Status.None) { Logger.Default.Info("MsgCreateRoom Fail " + player.id); protocol.AddInt(-1); player.Send(protocol); return; } RoomMgr.instance.CreateRoom(player); protocol.AddInt(0); protocol.AddInt(player.tempData.room.roomId); player.Send(protocol); Logger.Default.Info("MsgCreateRoom Ok " + player.id + " with roomId = " + player.tempData.room.roomId); }
public void GetAllItems(Conn conn, ProtocolBase protocol) { ProtocolBytes result; List <Item> itemList = dataMgr.GetAllItems(conn.player.ID); if (itemList != null) { result = new ProtocolBytes(requestCode, EActionCode.GetAllItems, EReturnCode.Success); result.AddInt(itemList.Count); foreach (Item i in itemList) { result.AddString(i.ToString()); } } else { result = new ProtocolBytes(requestCode, EActionCode.GetAllItems, EReturnCode.Failed); } Send(conn, result); }
public void OnLoginBack(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); Debug.Log("protoName:" + protoName); int ret = proto.GetInt(start, ref start); List <int> list = proto.GetIntList(start, ref start); List <int> battleList = proto.GetIntList(start, ref start); Debug.Log("MMMMMMMMMMMMMMMMMM:" + list.Count + "||||||||||||" + battleList.Count); string str = ""; foreach (int i in list) { str += i.ToString() + "||"; } Debug.Log(str); Debug.Log("Battle Cards"); str = ""; foreach (int i in battleList) { str += i.ToString() + "||"; } Debug.Log(str); if (ret == 0) { SinglePanelManger.Instance.PushTips(TextManager.Instance.GetString(TEXTS.Text_LoginSuccess)); Debug.Log("登录成功"); CloseUI(); MyPlayer.Instance.id = AccountText.text; MyPlayer.Instance.data = new PlayerData(list, battleList); UIManager.Instance.OpenUI(EUIName.HomeUI); } else { SinglePanelManger.Instance.PushTips(TextManager.Instance.GetString(TEXTS.Text_LoginFail)); Debug.Log("登录失败"); } }
public void MsgGrenade(Player player, ProtocolBase protoBase) { //获取数值 int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); //获取房间 if (player.tempData.status != PlayerTempData.Status.Fight) { return; } Room room = player.tempData.room; //广播 ProtocolBytes protocolRet = new ProtocolBytes(); protocolRet.AddString("Grenade"); protocolRet.AddString(player.id); room.Broadcast(protocolRet); }
private void RegisterReturn(ProtocolBase proto) { CustomProtocol protocol = (CustomProtocol)proto; int start = 0; string str = protocol.GetString(start, ref start); int ret = protocol.GetInt(start, ref start); int num = ret; if (num != 0) { MessageBox.Show(MultiLanguage.Hint21, MultiLanguage.Warn); } else { MessageBox.Show(MultiLanguage.Hint20, MultiLanguage.Warn); base.Dispatcher.Invoke(delegate { base.Close(); }); } }
protected override void OnMessage(MessageEventArgs e) { string msgBase = e.Data; Console.WriteLine("Receive " + ID + ":" + msgBase); //反序列化 ProtocolBase protocolBase = Utils.Js.Deserialize <ProtocolBase>(msgBase); //if (protocolBase.protocolName != "Ping_C_Protocol" && protocolBase.protocolName != "Pong_S_Protocol") //{ // SGS.Log.File = "log_" + ID; // SGS.Log.Info("Receive_" + ID + ":" + msgBase); //} //分发消息 MethodInfo mi = typeof(MsgHandler).GetMethod(protocolBase.protocolName); object[] o = { ID, msgBase }; if (mi != null) { mi.Invoke(null, o); } }
/// <summary> /// 登出消息处理,正常登出返回0 /// </summary> /// <param name="conn"></param> /// <param name="protoBase"></param> public void MsgLogout(Conn conn, ProtocolBase protoBase) { ProtocolBytes protoBytes = new ProtocolBytes(); protoBytes.AddString("Logout"); protoBytes.AddInt(0); //存在两种下线情况 if (conn.player == null) { conn.Send(protoBytes); conn.Close(); } else { //Logout方法调用Close,必须先Send conn.Send(protoBytes); conn.player.Logout(); } }
public void AddRoom(Conn conn, ProtocolBase protoBase) { ProtocolBytes proto = (ProtocolBytes)protoBase; int start = 0; string protoName = proto.GetString(start, ref start); string questid = proto.GetString(start, ref start); try { int quest = int.Parse(questid); if (ServerNet.instance.AddRoom(conn, quest)) { ServerNet.instance.SendID(conn); //此函数目前加入一个空房间也相当于创建房间 ServerNet.instance.SendRoomNum(conn); ServerNet.instance.HandleP2P(conn); } } catch { } }
public TcpPeer(Socket socket, ProtocolSelector protocolSelector, ILogger <TcpPeer> logger) { _socket = socket ?? throw new ArgumentNullException(nameof(socket)); _protocolSelector = protocolSelector ?? throw new ArgumentNullException(nameof(protocolSelector)); _logger = logger ?? throw new ArgumentNullException(nameof(logger)); _stream = new NetworkStream(socket, true); _protocol = protocolSelector.DefaultProtocol; // Extract address IPEndPoint ep = (IPEndPoint)(socket.IsBound ? socket.RemoteEndPoint : socket.LocalEndPoint); IPAddress = ep.Address; EndPoint = new EndPoint() { Protocol = Protocol.Tcp, Host = ep.Address.ToString(), Port = ep.Port }; SendMessages(_messageSenderTokenSource.Token); }
public void OnLoginBack(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); if (ret == 0) { Debug.Log("登录成功"); // 开始游戏 Walk.instance.StartGame(idInput.text); // 实际上这里不对。。。应该是PanelMgr.instance. // PanelMgr.instance.OpenPanel<TitlePanel>(""); Close(); } else { Debug.Log("登录失败!"); PanelMgr.instance.OpenPanel <TipPanel>(""); } }
/// <summary> /// 登陆协议的回调 /// </summary> /// <param name="proto"></param> private void OnLoginBack(ProtocolBase proto) { ProtocolBytes p = (ProtocolBytes)proto; int start = 0; string protoName = p.GetString(start, ref start); int ret = p.GetInt(start, ref start); if (ret == 0) { Debug.Log("登陆成功:" + idInput.text); //StartCoroutine(StartGameDelay(idInput.text)); PanelMgr.instance.OpenPanel <RoomListPanel>(""); GameMgr.instance.id = idInput.text; Close(); } else { Debug.Log("登陆失败"); PanelMgr.instance.OpenPanel <TipPanel>("", "警告", "用户名或密码错误"); } }
public static void SkillBoxTick(Room room) { Random ran = new Random(); int buffType = ran.Next(0, room.skillBoxTypeNum); int posIdx = ran.Next(0, room.posIdxNum); string boxID = RoomSystem.instance.GetGUID(); lock (room.boxSet) { room.boxSet.Add(boxID); } //广播 ProtocolBase protocol = ServNet.instance.proto.Decode(null, 0, 0); protocol.AddString("AddSkillBox"); protocol.AddString(boxID); protocol.AddInt(buffType); protocol.AddInt(posIdx); RoomSystem.instance.BroadcastInRoom(room, protocol); }
public void MsgResule(Player player, ProtocolBase protoBase) { int start = 0; ProtocolBytes protocol = (ProtocolBytes)protoBase; string protoName = protocol.GetString(start, ref start); int camp = protocol.GetInt(start, ref start); Room room = player.tempData.room; foreach (Player player1 in room.list.Values) { if (player1.tempData.team == camp) { player1.data.win += 1; } else { player1.data.fail += 1; } player1.data.achi = Ache(player1.data.win); } }
public void Register(Conn conn, ProtocolBase proto) { int start = sizeof(Int32) * 3; ProtocolBytes p = proto as ProtocolBytes; string username = p.GetString(start, ref start); ProtocolBytes result; if (dataMgr.CanGetUser(username)) { result = new ProtocolBytes(requestCode, EActionCode.Register, EReturnCode.RepeatName); } else { string password = p.GetString(start, ref start); bool createResult = dataMgr.CreateUser(username, password); // 有可能会创建失败,返回未知错误编号 EReturnCode returnCode = createResult ? EReturnCode.Success : EReturnCode.None; result = new ProtocolBytes(requestCode, EActionCode.Register, returnCode); } Send(conn, result); }
public void OnLoginBack(ProtocolBase protocol) { Debug.Log("OnLoginBack"); ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); if (ret == 0) { PanelMgr.instance.OpenPanel <TipPanel>("", "登录成功!"); //开始游戏 GameMgr.instance.id = idInput.text.Trim(); SceneManager.LoadScene("Room"); Close(); } else { PanelMgr.instance.OpenPanel <TipPanel>("", "登录失败,请检查用户名密码!"); } }
public void Send(Conn conn, ProtocolBase protocol) { int start = 0; string protoName = protocol.GetString(start, ref start); Console.WriteLine("发送消息:" + protoName + " 到:" + conn.GetAddress()); byte[] sendBuff = NetPackage.EncoderHeader(protocol); try { conn.socket.BeginSend(sendBuff, 0, sendBuff.Length, SocketFlags.None, null, null); } catch (Exception e) { Console.WriteLine("[发送消息]" + conn.GetAddress() + " : " + e.Message); } }
public void OnLoginBack(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; /*string protoName = */ proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); if (ret == 0) { Debug.Log("登陆成功"); Root.this_player.Name = name; Close(); PanelMrg.instance.OpenPanel <FirstPanelScript>(""); } else if (ret == 1) { UnityEditor.EditorUtility.DisplayDialog("alert", "This name has existed", "确认", "取消"); } }
public void DeleteRole(Conn conn, ProtocolBase protocol) { int start = sizeof(Int32) * 3; ProtocolBytes p = protocol as ProtocolBytes; int playerid = p.GetInt(start); Player player = dataMgr.GetPlayer(playerid); ProtocolBytes result; if (player.UserID != conn.user.ID) { Console.WriteLine($"【警告】Player[{player.UserID}]不属于User[{conn.user.ID}]"); result = new ProtocolBytes(requestCode, EActionCode.DeleteRole, EReturnCode.Failed); } else { bool isSucceed = dataMgr.DeleteRole(playerid); EReturnCode returnCode = isSucceed ? EReturnCode.Success : EReturnCode.Failed; result = new ProtocolBytes(requestCode, EActionCode.DeleteRole, returnCode); } Send(conn, result); }
public void OnRegisterBack(ProtocolBase protocol) { ProtocolBytes proto = (ProtocolBytes)protocol; int start = 0; string protoName = proto.GetString(start, ref start); int ret = proto.GetInt(start, ref start); if (ret == 0) { Debug.Log("注册成功"); UIManager.Instance.OpenUI(EUIName.ResigsterSucceesUI); ResigsterSucceesUI ui = (ResigsterSucceesUI)UIManager.Instance.GetUI(EUIName.ResigsterSucceesUI); ui.UpdateInfo("用户名:" + AccountText.text, "密码:" + PasswordText.text, "AAAAAAAAAAAAAAAAAAAAA"); CloseUI(); } else { SinglePanelManger.Instance.PushTips(TextManager.Instance.GetString(TEXTS.Text_RegistFail)); Debug.Log("注册失败"); } }
/// <summary> /// 解析帧信息 /// </summary> /// <param name="message">消息</param> public void ReceiveStep(ProtocolBase message) { frameKey.Parse(message); //Debug.Log(keyList[InputCenter.Instance.ServerStepIndex]); byte len = message.getByte(); for (byte i = 0; i < len; i++) { JoyStickKey joy = new JoyStickKey((KeyNum)(message.getByte()), message.getV2()); // Debug.LogError("rec+["+joy.key+"]"); if (joySticks.ContainsKey(joy.key)) { joySticks[joy.key] = joy; } else { joySticks.Add(joy.key, joy); } } }
static int _m_DefaltRequest(RealStatePtr L) { try { ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L); ProtocolBase gen_to_be_invoked = (ProtocolBase)translator.FastGetCSObj(L, 1); { gen_to_be_invoked.DefaltRequest( ); return(0); } } catch (System.Exception gen_e) { return(LuaAPI.luaL_error(L, "c# exception:" + gen_e)); } }
public void Read (TProtocol iprot) { TField field; iprot.ReadStructBegin(); while (true) { field = iprot.ReadFieldBegin(); if (field.Type == TType.Stop) { break; } switch (field.ID) { case 1: if (field.Type == TType.Struct) { Header = new ProtocolBase(); Header.Read(iprot); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 2: if (field.Type == TType.I64) { ServerTick = iprot.ReadI64(); } else { TProtocolUtil.Skip(iprot, field.Type); } break; case 3: if (field.Type == TType.List) { { CreatureStates = new List<CreatureState>(); TList _list0 = iprot.ReadListBegin(); for( int _i1 = 0; _i1 < _list0.Count; ++_i1) { CreatureState _elem2; _elem2 = new CreatureState(); _elem2.Read(iprot); CreatureStates.Add(_elem2); } iprot.ReadListEnd(); } } else { TProtocolUtil.Skip(iprot, field.Type); } break; default: TProtocolUtil.Skip(iprot, field.Type); break; } iprot.ReadFieldEnd(); } iprot.ReadStructEnd(); }