//服务器端直接向客户端发送请求 public void OnEvent(EventData eventData) { EventCode code = (EventCode)eventData.Code; BaseEvent e = DicTool.GetValue <EventCode, BaseEvent>(EventDict, code); e.OnEvent(eventData); }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { //将客户端的动作传到服务器端 List <Actions> act = new List <Actions>(); Actions a; string actString = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.ActQueue) as string; //if (act.Count != 0) //{ // MyGameServer.log.Info(peer.username + "用户的动作为:" + actString); //} using (StringReader reader = new StringReader(actString)) { //利用XML得到响应字符串链表 XmlSerializer serializer = new XmlSerializer(typeof(List <Actions>)); act = (List <Actions>)serializer.Deserialize(reader); } for (int i = 0; i < act.Count; i++) { a = act[i]; peer.ActionQueue.Enqueue(a); peer.ActionQueueCopy.Enqueue(a); } }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { string username = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.UserName) as string; string password = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.PassWord) as string; UserManage userManage = new UserManage(); Runoob_tbl user = userManage.GetByUserName(username); OperationResponse response = new OperationResponse(operationRequest.OperationCode); if (user == null) //没有用户才注册 { user = new Runoob_tbl() { Username = username, Password = password, RegisterDate = DateTime.Now }; userManage.Add(user); response.ReturnCode = (short)ReturnCode.Success; } else { response.ReturnCode = (short)ReturnCode.Failed; } peer.SendOperationResponse(response, sendParameters); }
public void VerityUser(string username, string userpassword) { if (Username.Equals("111") && Password.Equals("222")) { DicTool.SwitchPanel(UIPanelType.StartPanel); } }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { string username = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username) as string; string password = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password) as string; //连数据库查询 UserManager manager = new UserManager(); User user = manager.GetByUserName(username); //响应,直接用请求时的OperationCode作为响应的OperationCode OperationResponse response = new OperationResponse(operationRequest.OperationCode); if (user == null) { user = new User() { Username = username, Password = password }; manager.Add(user); //注册成功并用ReturnCode作为数据返回 response.ReturnCode = (short)ReturnCode.Success; } else { response.ReturnCode = (short)ReturnCode.Failed; } peer.SendOperationResponse(response, sendParameters); }
public override void OnEvent(EventData data) { if (DicTool.GetValue(data.Parameters, (byte)ParaType.BFOther) != null) { var dataCode = (ParaCode)DicTool.GetValue(data.Parameters, (byte)ParaType.BFOther); if (dataCode == ParaCode.BF_Join) { var allPlayer = (string)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Join); BattleFieldManager.Instance.AddPlayer(allPlayer); } else if (dataCode == ParaCode.BF_DestoryOnline) { var playerindex = (int)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_DestoryOnline); BattleFieldManager.Instance.DestoryEntity(playerindex); } else if (dataCode == ParaCode.BF_Ending) { var para = (int)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Ending); BattleFieldManager.Instance.CheckResult(para); } } else if (DicTool.GetValue(data.Parameters, (byte)ParaType.BFSendEvent) != null) { var dataCode = (ParaCode)DicTool.GetValue(data.Parameters, (byte)ParaType.BFSendEvent); if (dataCode == ParaCode.BF_Move) { var para = (string)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Move); var list = para.Split(','); BattleFieldManager.Instance.MoveEntity(Convert.ToInt32(list[0]), float.Parse(list[1]), float.Parse(list[2]), float.Parse(list[3]), float.Parse(list[4]), float.Parse(list[5])); } else if (dataCode == ParaCode.BF_Test_Pos) { var para = (string)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Test_Pos); var list = para.Split(','); BattleFieldManager.Instance.TestEntityPos(Convert.ToInt32(list[0]), float.Parse(list[1]), float.Parse(list[2]), float.Parse(list[3])); } else if (dataCode == ParaCode.BF_Attack) { var para = (string)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Attack); var list = para.Split(','); BattleFieldManager.Instance.AttackPlayer(int.Parse(list[0]), int.Parse(list[1]), (AttackType)int.Parse(list[2])); } else if (dataCode == ParaCode.BF_Hurt) { var para = (string)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Hurt); var list = para.Split(','); Debug.Log(int.Parse(list[0]) + ""); BattleFieldManager.Instance.HurtTarget(int.Parse(list[0]), int.Parse(list[1])); } else if (dataCode == ParaCode.BF_Destory) { var para = (int)DicTool.GetValue(data.Parameters, (byte)ParaCode.BF_Destory); BattleFieldManager.Instance.DestoryEntity(para); } } }
public void SwitchToStartPanel() { if (id == 0) { DicTool.SwitchPanel(UIPanelType.StartPanel); } else { DicTool.SwitchPanel(UIPanelType.MainScreenPanel); } }
//当服务器发送事件时执行↓这个函数 public void OnEvent(EventData eventData) { try { DicTool.GetValue(RequestDic, (OperationCode)eventData.Code) .OnEvent(eventData); } catch (Exception e) { Debug.Log(e); } }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { string roomID = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.RoomID) as string; peer.roomID = roomID; //取得所有已登录用户信息 List <string> usernameList = new List <string>(); foreach (ClientPeer tempPeer in MyGameServer.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer.roomID == roomID) { usernameList.Add(tempPeer.username); } } if (usernameList.Count == 0) { OperationResponse response = new OperationResponse(operationRequest.OperationCode); response.ReturnCode = (short)ReturnCode.Failed; peer.SendOperationResponse(response, sendParameters); } else { //利用XML将已登录用户信息转化为字符串,便于发送 StringWriter stringWriter = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(List <string>)); serializer.Serialize(stringWriter, usernameList); stringWriter.Close(); string usernameListString = stringWriter.ToString(); //将字符串装载到响应中 Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add((byte)ParameterCode.UsernameList, usernameListString); OperationResponse response = new OperationResponse(operationRequest.OperationCode); response.Parameters = data; peer.SendOperationResponse(response, sendParameters); //告诉房间内的所有客户端 foreach (ClientPeer tempPeer in MyGameServer.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer.roomID == roomID && tempPeer.username != peer.username) { EventData ed = new EventData((byte)EventCode.Room); Dictionary <byte, object> data2 = new Dictionary <byte, object>(); data2.Add((byte)ParameterCode.UsernameList, peer.username); ed.Parameters = data2; tempPeer.SendEvent(ed, new SendParameters()); } } } }
public override void OnEvent(EventData eventData) { List <string> usernameList = new List <string>(); List <List <Actions> > ActionList = new List <List <Actions> >(); List <Queue <Actions> > ActionQueueList = new List <Queue <Actions> >(); string usernameListString = (string)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.UsernameList); Debug.Log("GetName:" + usernameListString); using (StringReader reader1 = new StringReader(usernameListString)) { XmlSerializer serializer1 = new XmlSerializer(typeof(List <string>)); usernameList = (List <string>)serializer1.Deserialize(reader1); } string actionListString = (string)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.ActionData); using (StringReader reader2 = new StringReader(actionListString)) { XmlSerializer serializer2 = new XmlSerializer(typeof(List <List <Actions> >)); ActionList = (List <List <Actions> >)serializer2.Deserialize(reader2); } Debug.Log("GetAction:" + actionListString); List <Actions> al = new List <Actions>(); //Queue<Actions> aq = new Queue<Actions>(); Actions a; for (int i = 0; i < ActionList.Count; i++) { al = ActionList[i]; Queue <Actions> aq = new Queue <Actions>(); for (int j = 0; j < al.Count; j++) { a = al[j]; aq.Enqueue(a); } ActionQueueList.Add(aq); // aq.Clear(); } Dictionary <string, Queue <Actions> > actionDictionary = new Dictionary <string, Queue <Actions> >(); for (int i = 0; i < ActionQueueList.Count; i++) { actionDictionary.Add(usernameList[i], ActionQueueList[i]); } //处理事件 playerManager.OnSyncActionEvent(actionDictionary); }
//根据用户名,同步动作 public void OnMove(string name, Queue <Actions> actions) { //查找到username对应的物体 GameObject go = DicTool.GetValue <string, GameObject>(playerDict, name); // go.GetComponent<Enemy_player>.queue if (go == default(GameObject)) { return; } while (actions.Count != 0) { string s = ""; // Debug.Log(go.name+"???"); Actions a = (Actions)actions.Dequeue(); /* * if(a==Actions.Recover) * { * //重新初始化 * * } */ if (a == Actions.Upward) { s = "u"; } else if (a == Actions.Downward) { s = "d"; } else if (a == Actions.Toleft) { s = "l"; } else if (a == Actions.Toright) { s = "r"; } else if (a == Actions.Fire) { s = "a"; } //go.GetComponent<Enemy_player>.queue=new Queue(); if (s != "") { go.GetComponent <Enemy_player>().queue.Enqueue(s); } } }
public override void OnOperationRespionse(OperationResponse operationResponse) { //解析数据 if (operationResponse.ReturnCode == (byte)ReturnCode.Success) { var playerIndex = (int)DicTool.GetValue(operationResponse.Parameters, (byte)ParaCode.BF_Join); Debug.Log("我的玩家序列号:" + playerIndex); BattleFieldManager.Instance.MyPlayerIndex = playerIndex; } else { Debug.Log("请求失败"); } }
public override void OnEvent(EventData eventData) { float x = (float)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.X); float y = (float)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.Y); float z = (float)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.Z); DirectiontCode direction = (DirectiontCode)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.Direction); string username = (string)DicTool.GetValue <byte, object>(eventData.Parameters, (byte)ParameterCode.Username); Vector3Data vector3Data = new Vector3Data() { x = x, y = y, z = z, direction = direction }; //处理事件: playerManager.OnRecoverEvent(username, vector3Data); }
private IEnumerator LoudHero(int Playerindex, HeroType heroType) { yield return(new WaitForEndOfFrame()); var BF = (BattleFieldRequest)DicTool.GetValue(RequestDic, OperationCode.BattleField); Debug.Log("加载英雄ID" + Playerindex); ClientIndex = Playerindex; yield return(new WaitForEndOfFrame()); yield return(new WaitForFixedUpdate()); BF.JoinRequest(heroType); yield return(null); }
//操作客户端请求 TODO OnOperationRequest...... protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { BaseHandler handler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDic, (OperationCode)operationRequest.OperationCode); if (handler != null) { handler.OnOperationRequest(operationRequest, sendParameters, this); } else { BaseHandler deflaut = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.handlerDic, OperationCode.Unknow); deflaut.OnOperationRequest(operationRequest, sendParameters, this); } /*switch (operationRequest.OperationCode) * { * case 1: * MyGameServer.log.Info("收到了一个客户端请求"); * Dictionary<byte, object> data = operationRequest.Parameters; //客户端传回的数据参数; * * object IntValue; * data.TryGetValue(1, out IntValue); * object StringValue; * data.TryGetValue(2, out StringValue); * MyGameServer.log.Info("得到的参数: " + IntValue.ToString() + "," + StringValue.ToString()); * * OperationResponse opResponse = new OperationResponse(operationRequest.OperationCode); * * Dictionary<byte, object> data2 = new Dictionary<byte, object>(); //所要传递的数据 * data2.Add(1, 100); * data2.Add(2, "Server"); * opResponse.SetParameters(data2); //向客户端传递数据; * SendOperationResponse(opResponse, sendParameters); //给客户端一个响应 必须有请求,才能有响应; * * EventData ed = new EventData(1); //1代表事件代码; * ed.SetParameters(data2); * SendEvent(ed, new SendParameters()); //向客户端发送数据和SendOperationResponse有区别,可以不必有响应; * * break; * case 2: * * break; * * default: * break; * }*/ }
//处理客户端的请求 protected override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters) { //MyGameServer.log.Info("收到了一个客户端的请求!!!"); //根据OperationCode在Handler字典中查找响应的Handler BaseHandler handler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode); if (handler != null) { //调用Handler处理请求 handler.OnOperationRequest(operationRequest, sendParameters, this); } else { //未在Handler字典中查找到相应响应的Handler,默认调用defaultHandler BaseHandler defaultHandler = DicTool.GetValue <OperationCode, BaseHandler>(MyGameServer.Instance.HandlerDict, (OperationCode)operationRequest.OperationCode); defaultHandler.OnOperationRequest(operationRequest, sendParameters, this); } }
public override void OnOperationResponse(OperationResponse operationResponse) { List <List <Actions> > ActionList = new List <List <Actions> >(); List <PlayerData> PlayerDataList = new List <PlayerData>(); List <Queue <Actions> > ActionQueueList = new List <Queue <Actions> >(); //提取响应的数据 string playerDataListString = DicTool.GetValue <byte, object>(operationResponse.Parameters, (byte)ParameterCode.PlayerDataList) as string; using (StringReader reader = new StringReader(playerDataListString)) { //利用XML得到响应字符串链表 XmlSerializer serializer = new XmlSerializer(typeof(List <PlayerData>)); PlayerDataList = (List <PlayerData>)serializer.Deserialize(reader); } string actionListString = (string)DicTool.GetValue <byte, object>(operationResponse.Parameters, (byte)ParameterCode.ActionData); using (StringReader reader2 = new StringReader(actionListString)) { XmlSerializer serializer2 = new XmlSerializer(typeof(List <List <Actions> >)); ActionList = (List <List <Actions> >)serializer2.Deserialize(reader2); } List <Actions> al = new List <Actions>(); Queue <Actions> aq = new Queue <Actions>(); Actions a; for (int i = 0; i < ActionList.Count; i++) { al = ActionList[i]; for (int j = 0; j < al.Count; j++) { a = al[j]; aq.Enqueue(a); } ActionQueueList.Add(aq); } //处理响应 playerManager.OnGetinResponse(PlayerDataList, ActionQueueList); }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { string username = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.UserName) as string; string password = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.PassWord) as string; UserManage userManage = new UserManage(); bool isSuccess = userManage.VerifiyUserAndPassword(username, password); OperationResponse response = new OperationResponse(operationRequest.OperationCode); if (isSuccess) { response.ReturnCode = (short)ReturnCode.Success; } else { response.ReturnCode = (short)ReturnCode.Failed; } peer.SendOperationResponse(response, sendParameters); }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { MyGameServer.log.Info("进入了RecoverHandler"); //记录登入信息 float x = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.X); float y = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Y); float z = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Z); DirectiontCode direction = (DirectiontCode)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Direction); string username = (string)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username); while (peer.ActionQueue.Count != 0) { peer.ActionQueue.Dequeue(); } while (peer.ActionQueueCopy.Count != 0) { peer.ActionQueueCopy.Dequeue(); } Thread.Sleep(1000); //告诉其他客户端有客户端复活,并传输其方位和用户名 foreach (ClientPeer tempPeer in MyGameServer.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer.username != peer.username) { EventData ed = new EventData((byte)EventCode.Recover); Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add((byte)ParameterCode.X, x); data.Add((byte)ParameterCode.Y, y); data.Add((byte)ParameterCode.Z, z); data.Add((byte)ParameterCode.Direction, direction); data.Add((byte)ParameterCode.Username, peer.username); ed.Parameters = data; tempPeer.SendEvent(ed, sendParameters); } } }
public override void OnEvent(EventData data) { if (DicTool.GetValue(data.Parameters, (byte)ParaType.BFOther) != null) { var dataCode = (ParaCode)DicTool.GetValue(data.Parameters, (byte)ParaType.BFOther); if (dataCode == ParaCode.MC_Confirm) { var PlayerIndex = (int)DicTool.GetValue(data.Parameters, (byte)ParaCode.MC_Confirm); Debug.Log("匹配成功!" + PlayerIndex); LoginScene = GameObject.Find("LoginScene"); Main_camera = GameObject.Find("Main Camera"); camera2 = GameObject.Find("Camera2"); MyplayerIndex = PlayerIndex; camera2.GetComponent <Camera>().targetDisplay = 0; camera2.GetComponent <Camera2>().StartChooseHeroAnimation(); Camera.main.targetDisplay = 1; //Main_camera.SetActive(false); LoginScene.SetActive(false); LoudBFScene(); } if (dataCode == ParaCode.MC_Prepare) { JoinTheGame(); } if (dataCode == ParaCode.MC_DestoryOnline) { async.allowSceneActivation = true; SceneManager.LoadSceneAsync(0); GC.Collect(); } } else if (DicTool.GetValue(data.Parameters, (byte)ParaType.BFSendEvent) != null) { var dataCode = (ParaCode)DicTool.GetValue(data.Parameters, (byte)ParaType.BFSendEvent); } }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { string username = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username) as string; string password = DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Password) as string; //连数据库查询 UserManager manager = new UserManager(); bool isSuccess = manager.VerifyUser(username, password); //响应,直接用请求时的OperationCode作为响应的OperationCode OperationResponse response = new OperationResponse(operationRequest.OperationCode); if (isSuccess) { //登录成功并用ReturnCode作为数据返回 response.ReturnCode = (short)ReturnCode.Success; peer.username = username; } else { response.ReturnCode = (short)ReturnCode.Failed; } peer.SendOperationResponse(response, sendParameters); }
public Request GetRequest(OperationCode code) { return(DicTool.GetValue(RequestDic, code)); }
//当客户端发送事件后服务器返回时执行↓这个函数 public void OnOperationResponse(OperationResponse operationResponse) { DicTool.GetValue(RequestDic, (OperationCode)operationResponse.OperationCode) .OnOperationRespionse(operationResponse); return; }
public void SwitchToStartPanel() { DicTool.SwitchPanel(UIPanelType.StartPanel); }
public void SwitchToTitlePanel() { UIManager.getInstance().PushPanel(UIPanelType.TitlePanel); DicTool.SwitchPanel(UIPanelType.TitlePanel); }
public void SwitchToCharacter() { DicTool.SwitchPanel(UIPanelType.CharactePanel); }
public void SwitchToSetting() { SettingPanel.id = 1; DicTool.SwitchPanel(UIPanelType.SettingPanel); }
public void SwitchToMain() { DicTool.SwitchPanel(UIPanelType.MainScreenPanel); }
public void SwitchToLevelPanel() { DicTool.SwitchPanel(UIPanelType.LevelPanel); }
public override void OnOperationRequest(OperationRequest operationRequest, SendParameters sendParameters, ClientPeer peer) { MyGameServer.log.Info("进入了GetinHandler"); //记录登入信息 float x = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.X); float y = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Y); float z = (float)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Z); DirectiontCode direction = (DirectiontCode)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Direction); string username = (string)DicTool.GetValue <byte, object>(operationRequest.Parameters, (byte)ParameterCode.Username); peer.x = x; peer.y = y; peer.z = z; peer.direction = direction; peer.username = username; MyGameServer.log.Info("用户名为:" + username); //取得所有已登录用户信息 List <PlayerData> PlayerDataList = new List <PlayerData>(); List <List <Actions> > ActionList = new List <List <Actions> >(); foreach (ClientPeer tempPeer in MyGameServer.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer.username != peer.username) { Vector3Data Pos = new Vector3Data() { x = tempPeer.x, y = tempPeer.y, z = tempPeer.z, direction = tempPeer.direction }; PlayerData playerData = new PlayerData() { Pos = Pos, Username = tempPeer.username }; PlayerDataList.Add(playerData); List <Actions> AL = new List <Actions>(); Queue <Actions> AQ = new Queue <Actions>(tempPeer.ActionQueueCopy); if (AQ.Count == 0) { AL.Add(Actions.stay); } else { while (AQ.Count != 0) { AL.Add(AQ.Dequeue()); } } ActionList.Add(AL); } } //利用XML将已登录用户信息转化为字符串,便于发送 StringWriter stringWriter = new StringWriter(); XmlSerializer serializer = new XmlSerializer(typeof(List <PlayerData>)); serializer.Serialize(stringWriter, PlayerDataList); stringWriter.Close(); string playerDataListString = stringWriter.ToString(); //将字符串装载到响应中,响应新加入客户端,告诉新加入的客户端其他客户端的用户名 Dictionary <byte, object> data = new Dictionary <byte, object>(); data.Add((byte)ParameterCode.PlayerDataList, playerDataListString); StringWriter stringWriter2 = new StringWriter(); XmlSerializer serializer2 = new XmlSerializer(typeof(List <List <Actions> >)); serializer2.Serialize(stringWriter2, ActionList); stringWriter2.Close(); string actionListString = stringWriter2.ToString(); //将字符串装载到响应中 data.Add((byte)ParameterCode.ActionData, actionListString); OperationResponse response = new OperationResponse(operationRequest.OperationCode); response.Parameters = data; peer.SendOperationResponse(response, sendParameters); //告诉其他客户端有新的客户端加入,并传输其方位和用户名 foreach (ClientPeer tempPeer in MyGameServer.Instance.peerList) { if (string.IsNullOrEmpty(tempPeer.username) == false && tempPeer.username != peer.username) { EventData ed = new EventData((byte)EventCode.NewPlayer); Dictionary <byte, object> data2 = new Dictionary <byte, object>(); data2.Add((byte)ParameterCode.X, x); data2.Add((byte)ParameterCode.Y, y); data2.Add((byte)ParameterCode.Z, z); data2.Add((byte)ParameterCode.Direction, direction); data2.Add((byte)ParameterCode.Username, username); ed.Parameters = data2; tempPeer.SendEvent(ed, sendParameters); } } }