/// <summary> /// 请求好友列表 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqFriendList msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("game", (int)msg.game); sendMsg(pID, jsonMsg, action); }
/////////////////////////////////////LOBBY///////////////////////////////////// /// <summary> /// 请求登陆 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgLogin msg, Action <Message> action) { //填写相应字段 JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("userID", msg.userID); jsonMsg.Add("area", msg.area); jsonMsg.Add("loginType", (int)msg.loginType); jsonMsg.Add("openID", msg.openID); jsonMsg.Add("password", msg.password); jsonMsg.Add("deviceID", msg.deviceID); jsonMsg.Add("nickName", msg.nickName); jsonMsg.Add("osVersion", msg.osVersion); jsonMsg.Add("ipAddr", msg.ipAddr); jsonMsg.Add("channelID", msg.channelID); jsonMsg.Add("appVersion", msg.appVersion); jsonMsg.Add("netWorkType", msg.netWorkType); jsonMsg.Add("token", msg.token); jsonMsg.Add("head", msg.head); jsonMsg.Add("sex", msg.sex); jsonMsg.Add("expireTime", msg.expireTime); sendMsg(pID, jsonMsg, action); }
private void Start() { if (state == NETWORK_STATE.LOCAL_HOST) { this.serverIP = "127.0.0.1"; } else { this.serverIP = "10.211.55.3"; } if (!Network.Instance.IsConnected) { Network.Instance.Initialize(); ProtocolManager.Instance.Initialize(); Network.Instance.Connect(this.serverIP, Defines.SERVER_PORT); } this.loginProtocol = transform.Find("Login Protocol").GetComponent <LoginProtocol>(); this.lobbyProtocol = transform.Find("Lobby Protocol").GetComponent <LobbyProtocol>(); this.roomProtocol = transform.Find("Room Protocol").GetComponent <RoomProtocol>(); this.testProtocol = transform.Find("Test Protocol").GetComponent <TestProtocol>(); this.gameProtocol = transform.Find("Game Protocol").GetComponent <GameProtocol>(); this.loginProtocol.InitializeProtocol(); this.lobbyProtocol.InitializeProtocol(); this.roomProtocol.InitializeProtocol(); this.testProtocol.InitializeProtocol(); this.gameProtocol.InitializeProtocol(); //Network.Instance.Connect(this.serverIP, Defines.SERVER_PORT); }
/// <summary> /// Sends the message. /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqOpenTalentslot msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("game", (int)msg.game); jsonMsg.Add("openBy", (int)msg.openBy); sendMsg(pID, jsonMsg, action); }
/// <summary> /// Sends the message. /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqFeedback msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("type", (int)msg.type); jsonMsg.Add("content", msg.content); sendMsg(pID, jsonMsg, action); }
/// <summary> /// 请求更新邮件信息 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqUpdateEmail msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("type", (int)msg.type); jsonMsg.Add("awardEmailId", msg.awardEmailId); sendMsg(pID, jsonMsg, action); }
/// <summary> /// 请求抽奖 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqLuckDraw msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("game", (int)msg.game); jsonMsg.Add("areaID", msg.areaID); jsonMsg.Add("deviceID", msg.deviceID); sendMsg(pID, jsonMsg, action); }
/// <summary> /// 请求个人邮件信息 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqPrivateMsgList msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("game", (int)msg.game); jsonMsg.Add("cnt", msg.cnt); jsonMsg.Add("begin", msg.begin); sendMsg(pID, jsonMsg, action); }
public void removePushMsgEventListener(LobbyProtocol pID) { System.Object route; if (ROUTE_MAP.TryGetValue("P" + (int)pID, out route)) { _connection.removeEventListeners(route.ToString()); } }
//需要手动调用添加服务器push给客户端的消息,不同的界面请添加不同的消息回调 public void addPushMsgEventListener(LobbyProtocol pID, Action <Message> action) { System.Object route; if (ROUTE_MAP.TryGetValue("P" + (int)pID, out route)) { _connection.on(route.ToString(), action); } }
/// <summary> /// 请求排行榜 /// </summary> /// <param name="pID">P I.</param> /// <param name="msg">Message.</param> /// <param name="action">Action.</param> public void sendMsg(LobbyProtocol pID, msgReqRankList msg, Action <Message> action) { JsonObject jsonMsg = new JsonObject(); jsonMsg.Add("game", (int)msg.game); jsonMsg.Add("type", (int)msg.type); jsonMsg.Add("scope", (int)msg.scope); jsonMsg.Add("area", msg.areaID); jsonMsg.Add("rankNum", msg.rankNum); sendMsg(pID, jsonMsg, action); }
public void ParseProtocol(LobbyProtocol protocol, MemoryStream memory, NetConnection connection) { var reader = new BinaryReader(memory); var LobbyPlayer = (LobbyPlayer) connection.Tag; switch (protocol) { case LobbyProtocol.SetTeam: { var team = reader.ReadByte(); LobbyPlayer.Team = team; UpdatePlayer(LobbyPlayer); } break; case LobbyProtocol.IsReady: { LobbyPlayer.IsReady = reader.ReadBoolean(); UpdatePlayer(LobbyPlayer); } break; case LobbyProtocol.StartGame: break; case LobbyProtocol.SetHost: break; case LobbyProtocol.ChangeName: { LobbyPlayer.Name = reader.ReadString(); UpdatePlayer(LobbyPlayer); } break; case LobbyProtocol.LoadedGameState: { LobbyPlayer.HasLoadedGame = true; } break; } }
public void SendData(byte[] data, LobbyProtocol protocol, bool direct = false) { var memory = new MemoryStream(); var writer = new BinaryWriter(memory); writer.Write((byte) protocol); writer.Write(data); myServer.SendLobbyData(memory.ToArray(), direct); }
///////////////////////////////GAME END////////////////////////////////// #endregion #region 私有接口,发送消息,外部禁止访问 private void sendMsg(LobbyProtocol pID, JsonObject msg, Action <Message> action) { sendMsg((uint)pID, msg, action); }
public void SendData(byte[] data, LobbyProtocol protocol) { var memory = new MemoryStream(); var writer = new BinaryWriter(memory); writer.Write((byte)protocol); writer.Write(data); myclient.SendData(memory.ToArray()); }