void OnReceivePack(stPkgHead head, MemoryStream data) { if (head.iSytle == 50) { RankInfo ri; string str; for (int i = 0; i < head.dataSize; i += 32) { str = ""; data.Read(rankBuffer, 0, 32); ri = (RankInfo)SocketMgr.BytesToStuct(rankBuffer, typeof(RankInfo)); for (int j = 0; ri.name[j] != '\0'; ++j) { str += ri.name[j]; } rankList.AddItem(ri.rank + " " + str + " " + ri.score); } } }
void OnReceivePack(stPkgHead head, byte[] data) { if (head.iSytle == 40) { head.iSytle = 40; } if (head.iSytle == 33) { //刷房间列表成功 string str; RoomInfo room; byte[] tmpData; roomList.Clear(); tmpData = new byte[head.dataSize]; for (int i = 0; i < head.dataSize; i += 36) { str = ""; //data.Read(roomBuffer, 0, 32); for (int k = 0; k < 36; ++k) { tmpData[k] = data[i + k]; } room = (RoomInfo)SocketMgr.BytesToStuct(tmpData, typeof(RoomInfo)); for (int j = 0; room.name[j] != '\0'; ++j) { str += room.name[j]; } roomList.AddItem(" " + str + " ( " + room.players + " / 2 )", room.id); } } else if (head.iSytle == 35) { //创建房间成功 bWaitEnter = false; headSend = new stPkgHead(); Stream = new MemoryStream(); headSend.dataSize = 0; headSend.iSytle = 33; SocketMgr.SendCommonPackge(headSend, Stream); Stream.Close(); bInRoom = true; headSend = new stPkgHead(); Stream = new MemoryStream(); headSend.dataSize = 0; headSend.iSytle = 34; SocketMgr.SendCommonPackge(headSend, Stream); Stream.Close(); } else if (head.iSytle == 36) { //创建房间失败 bWaitEnter = false; bInRoom = false; bIsHost = false; } else if (head.iSytle == 37) { //加入房间成功 bWaitEnter = false; headSend = new stPkgHead(); Stream = new MemoryStream(); headSend.dataSize = 0; headSend.iSytle = 33; SocketMgr.SendCommonPackge(headSend, Stream); Stream.Close(); bInRoom = true; headSend = new stPkgHead(); Stream = new MemoryStream(); headSend.dataSize = 0; headSend.iSytle = 34; SocketMgr.SendCommonPackge(headSend, Stream); Stream.Close(); } else if (head.iSytle == 38) { //加入房间失败 bWaitEnter = false; bInRoom = false; bIsHost = false; } else if (head.iSytle == 34) { //列举用户信息 string str; UserInfo player; byte[] tmpData; Monitor.Enter(heads); Monitor.Enter(ranks); Monitor.Enter(scores); heads.Clear(); ranks.Clear(); scores.Clear(); tmpData = new byte[head.dataSize]; bIsHost = false; string[] tmpNames = new string[6]; int playerNum = 0; for (int i = 0; i < head.dataSize; i += 56) { str = ""; //data.Read(roomBuffer, 0, 32); for (int k = 0; k < 56; ++k) { tmpData[k] = data[i + k]; } player = (UserInfo)SocketMgr.BytesToStuct(tmpData, typeof(UserInfo)); for (int j = 0; player.name[j] != '\0'; ++j) { str += player.name[j]; } if (str == myName && player.state == 1) { bIsHost = true; } tmpNames[playerNum] = str;//, Font font) ranks.Add(player.rank); scores.Add(player.score); Texture2D tex; if (devHeads.Contains(str)) { tex = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, str)); } else { tex = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "head")); } if (tex == null) { throw new Exception(""); } heads.Add(tex); playerNum++; //roomList.AddItem("room 1" + " ( " + room.players + " / 6 )", room.id); } playerCount = playerNum; userNames = new string[playerNum]; for (int i = 0; i < playerNum; i++) { userNames[i] = tmpNames[i]; } Monitor.Exit(scores); Monitor.Exit(ranks); Monitor.Exit(heads); headSend = new stPkgHead(); Stream = new MemoryStream(); headSend.dataSize = 0; headSend.iSytle = 33; SocketMgr.SendCommonPackge(headSend, Stream); Stream.Close(); } else if (head.iSytle == 70) { //开始游戏 bWaitEnter = false; if (bIsHost) { GameManager.AddGameScreen(new StarwarLogic(0, userNames)); } else { for (int i = 0; i < playerCount; i++) { if (userNames[i] == myName) { GameManager.AddGameScreen(new StarwarLogic(i, userNames)); } } } } else if (head.iSytle == 71) { bWaitEnter = false; } }
void OnReceivePack(stPkgHead head, byte[] data) { byte[] tmpData; tmpData = new Byte[head.dataSize]; if (head.iSytle == 50) { RankInfo ri; RankIF tmpItem; string str; rankItems.Clear(); for (int i = 0; i < head.dataSize; i += 32) { str = ""; for (int k = 0; k < 32; k++) { tmpData[k] = data[i + k]; } ri = (RankInfo)SocketMgr.BytesToStuct(tmpData, typeof(RankInfo)); for (int j = 0; ri.name[j] != '\0'; ++j) { str += ri.name[j]; } tmpItem.rank = ri.rank; tmpItem.score = ri.score; tmpItem.name = str; rankItems.Add(tmpItem); } } else if (head.iSytle == 40) { UserInfo player; string str; str = ""; //data.Read(roomBuffer, 0, 32); player = (UserInfo)SocketMgr.BytesToStuct(data, typeof(UserInfo)); for (int j = 0; player.name[j] != '\0'; ++j) { str += player.name[j]; } myInfo.name = str; myInfo.rank = player.rank; myInfo.score = player.score; if (devHeads.Contains(myInfo.name)) { hdTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, myInfo.name)); } else { hdTexture = BaseGame.ContentMgr.Load <Texture2D>(Path.Combine(Directories.UIContent, "head")); } bLoaded = true; } }