//user requests broadcast about players void Packet17(NetIncomingMessage inmsg) { bool isSpectator; try { isSpectator = inmsg.ReadBoolean(); } catch { return; } CurrentUser user; if (isSpectator) { user = GetCurrentSpectator(inmsg.SenderConnection); if (user.sID == -1) { return; } } else { user = GetCurrentUser(inmsg.SenderConnection); if (user.sID == -1) { return; } } RoomData room = clientToMS.roomHandler.rooms[user.sID]; if (!isSpectator) { room.users[user.tID, user.pID].udpTrafficEnabled = true; } else { lock (room.spectatorData2) { try { room.spectatorData2[user.pID].udpTrafficEnabled = true; } catch { return; } } } room.BroadcastJoinerData("", inmsg.SenderConnection, 0); }
public void TryToAddUserToServer(int selectedServerUniqueID, NetConnection netConnection, int pID, int tID, int lockedTID, string username, string nation, bool isVip, byte admas, byte body, byte skin, byte hair, byte number /*, byte[] shoe*/) { //lets check, that room still exists RoomData roomData = roomHandler.FindRoomByUniqueID(selectedServerUniqueID); if (roomData == null) { serverForU.SendInfoMsg(netConnection, 3); return; } //check, that user is allowed to join this challenge if (roomData.roomType == RoomType.Challenge) { if (roomData.teams[0].tID != tID && roomData.teams[1].tID != tID) { return; } } if (roomData.officiallyStarted) { if (lockedTID > 0) { if (tID != lockedTID) { serverForU.SendInfoMsg(netConnection, 6); return; } } } //check, that room isnt full if (roomData.IsRoomFull(tID)) { serverForU.SendInfoMsg(netConnection, 5); return; } if (roomData.IsUserAlreadyInServer(username)) { Console.WriteLine("user already in server"); return; } int uniquePID; uniquePID = roomData.AddPlayerToServer(netConnection, tID, pID, nation, username, isVip, admas, body, skin, hair, number /*, shoe.ToArray()*/); bool statsWindowVisible = false; if (roomData.autoMoving == 2) { statsWindowVisible = true; } //send data to client NetOutgoingMessage outmsg = serverForU.server.CreateMessage(); outmsg.Write((byte)10); outmsg.Write(statsWindowVisible); outmsg.Write(roomData.botsEnabled); outmsg.Write(roomData.uniqueID); outmsg.Write(uniquePID); outmsg.Write((byte)roomData.roomState); outmsg.Write((byte)roomData.roomType); outmsg.Write(roomData.officiallyStarted); outmsg.Write(roomData.autostartTimeout); outmsg.Write(roomData.time); outmsg.Write(roomData.maxPlayers); outmsg.Write(roomData.homeSide); outmsg.Write(roomData.period); outmsg.Write(roomData.timerEnabled); //outmsg.Write(Proc.getSpectatorCount(sID)); for (int i = 0; i < 2; i++) { outmsg.Write(roomData.teams[i].score); outmsg.Write(roomData.teams[i].name); outmsg.Write(roomData.teams[i].shortName); outmsg.Write(roomData.teams[i].shirtStyle); } //kits colors for (int i = 0; i < 2; i++) { for (int j = 0; j < 4; j++) { for (int k = 0; k < 3; k++) { outmsg.Write(roomData.teams[i].shirtColors[j, k]); } } } serverForU.server.SendMessage(outmsg, netConnection, NetDeliveryMethod.ReliableOrdered, 0); roomData.BroadcastJoinerData(username, null, 1); }
//user clicks changeteam button void Packet13(NetIncomingMessage inmsg) { CurrentUser user = GetCurrentUser(inmsg.SenderConnection); if (user.sID == -1) { return; } RoomData room = clientToMS.roomHandler.rooms[user.sID]; if (room.autoMoving > 0) { return; } if (room.roomType != RoomType.Public) { return; } if (room.roomState == RoomState.ReadyScreen && room.users[user.tID, user.pID].ready) { return; } byte count = 0; int wantedTeam; if (user.tID == 0) { wantedTeam = 1; } else { wantedTeam = 0; } //lets check, if there is room in another team for (int i = 0; i < room.maxPlayers; i++) { if (room.IsPlayerOnline(wantedTeam, i)) { count++; } } if (count == room.maxPlayers) { return; //team is full } UserData u = room.users[user.tID, user.pID]; //find empty slot, and set player to there for (int i = 0; i < room.maxPlayers; i++) { if (!room.IsPlayerOnline(wantedTeam, i)) { room.users[wantedTeam, i] = u; room.users[wantedTeam, i].coords[0] = Field.BENCHX; room.users[wantedTeam, i].coords[1] = 0; room.users[wantedTeam, i].pos = room.GetAnyAvailablePos(wantedTeam, false); break; } } //reset previous slot room.users[user.tID, user.pID] = new UserData(room.roomType); //get position for bot if (room.botsEnabled) { room.users[user.tID, user.pID].pos = room.GetAnyAvailablePos(user.tID, true); } room.BroadcastJoinerData("", null, 0); }