//commandsTable private void Join(byte[] data, EndPoint sender) { Console.WriteLine("Join"); foreach (ServerRoom serverRoom in serverRooms.Values) { if (clientsTable.ContainsKey(sender)) { GameClient badClient = clientsTable[sender]; badClient.UpdateMalus(); Console.WriteLine("Error! Client already logged in; client endpoint IP {0} malus updated: {1}", badClient.ToString(), badClient.Malus); return; } } GameClient newClient = new GameClient(sender, this); ServerRoom room = GetEmptyRoom(); clientsTable[sender] = newClient; room.AddGameClient(newClient); Console.WriteLine(newClient.TeamTag); Packet welcomePacket = new Packet(1, newClient.ClientID, room.RoomID, newClient.TeamTag); welcomePacket.NeedAck = true; newClient.Enqueue(welcomePacket); }
public void SpawnHeroes(ServerRoom room) { if (!room.SpawnTeam) { Dictionary <uint, GameObject> gameObjectTable = room.GetGameObjectTable(); foreach (GameObject obj in gameObjectTable.Values) { if (obj is RPGHero) { RPGHero hero = (RPGHero)obj; Packet spawnPacket = new Packet(2, hero.ClassID, hero.ID, hero.GetOwner().ClientID, hero.X, hero.Y, hero.Z); spawnPacket.NeedAck = true; Send(spawnPacket, room.Player1.GetEndPoint()); Send(spawnPacket, room.Player2.GetEndPoint()); } else { continue; } } room.TeamSpawned(); } }
private ServerRoom GetEmptyRoom() { if (serverRooms != null) { //find a empty room for a client to join for (uint i = 0; i < serverRooms.Count; i++) { if (!serverRooms[i].IsOccupy) { Console.WriteLine("Selected room ID: " + serverRooms[i].RoomID); return(serverRooms[i]); } } //if there isn't create a new ServerRoom newRoom = new ServerRoom(roomID, this); serverRooms.Add(roomID, newRoom); Console.WriteLine("Create new room ID: " + newRoom.RoomID); roomID++; return(newRoom); } else { return(null); } }
private void TurnCreation(byte[] data, EndPoint sender) { uint clientId = BitConverter.ToUInt32(data, 1); GameClient client = GetClientFromID(clientId); uint roomId = BitConverter.ToUInt32(data, 5); ServerRoom room = GetRoomFromID(roomId); if (!room.GetClientTable().Contains(client)) { client.UpdateMalus(); return; } uint heroId = BitConverter.ToUInt32(data, 9); if (!room.GetGameObjectTable().ContainsKey(heroId)) { client.UpdateMalus(); return; } RPGHero hero = (RPGHero)room.GetGameObjectFromId(heroId); room.AddNewTurn(hero); }
public void ProcessingTurn(ServerRoom room, uint attackerId, int skillId, uint targetId) { Packet processingTurnPacket = new Packet(9, attackerId, skillId, targetId); processingTurnPacket.NeedAck = true; Send(processingTurnPacket, room.Player1.GetEndPoint()); Send(processingTurnPacket, room.Player2.GetEndPoint()); }
public void SpawnNewTurn(ServerRoom room, uint heroID) { Packet addTurnPacket = new Packet(7, heroID); addTurnPacket.NeedAck = true; Send(addTurnPacket, room.Player1.GetEndPoint()); Send(addTurnPacket, room.Player2.GetEndPoint()); }
public void SendToAllClientsInARoom(Packet packet, ServerRoom room) { //room.Player1.Enqueue(packet); //room.Player2.Enqueue(packet); foreach (GameClient client in room.GetClientTable()) { client.Enqueue(packet); Console.WriteLine("Send"); } }
public bool RegisterGameObject(uint roomId, GameObject gameObject) { ServerRoom room = GetRoomFromID(roomId); if (room == null) { return(false); } GetRoomFromID(roomId).RegisterGameObject(gameObject); return(true); }
public void GameStart(ServerRoom room) { if (!room.GameStarted) { Console.WriteLine("Game start in room " + room.RoomID); Packet startGamePacket = new Packet(5); startGamePacket.NeedAck = true; Send(startGamePacket, room.Player1.GetEndPoint()); Send(startGamePacket, room.Player2.GetEndPoint()); room.StartGame(); } }
private void Ready(byte[] data, EndPoint sender) { uint clientId = BitConverter.ToUInt32(data, 1); GameClient client = GetClientFromID(clientId); uint roomId = BitConverter.ToUInt32(data, 5); bool isClientReady = BitConverter.ToBoolean(data, 9); Console.WriteLine(isClientReady); ServerRoom room = GetRoomFromID(roomId); if (room != null && room.GetClientTable().Contains(client)) { room.SetPlayersReady(client, isClientReady); } }
public void RoomTurnEnd(ServerRoom room) { if (room.GameLogicProcessTurn) { Console.WriteLine("Turn ended in room " + room.RoomID); Packet endTurnPacket = new Packet(10); endTurnPacket.NeedAck = true; Send(endTurnPacket, room.Player1.GetEndPoint()); Send(endTurnPacket, room.Player2.GetEndPoint()); room.EndTurn(); } }
private void EndTurn(byte[] data, EndPoint sender) { uint clientId = BitConverter.ToUInt32(data, 1); GameClient client = GetClientFromID(clientId); uint roomId = BitConverter.ToUInt32(data, 5); ServerRoom room = GetRoomFromID(roomId); if (!room.GetClientTable().Contains(client)) { client.UpdateMalus(); return; } room.SetPlayerEndTurn(client); }
public void SendToOtherClientsInARoom(Packet packet, ServerRoom room, GameClient sender = null) { /* * if (sender != room.Player1 && room.Player1 != null) * room.Player1.Enqueue(packet); * else if (sender != room.Player2 && room.Player2 != null) * room.Player2.Enqueue(packet); */ foreach (GameClient client in room.GetClientTable()) { if (client != null && client != sender) { client.Enqueue(packet); Console.WriteLine("Send"); } } }
public GameObject GetGameObject(uint roomId, uint objId) { ServerRoom room = GetRoomFromID(roomId); if (room == null) { return(null); } if (room.GetGameObjectTable().ContainsKey(objId)) { return(room.GetGameObjectFromId(objId)); } else { return(null); } }
private void Spawn(byte[] data, EndPoint sender) { //2[0], myIdOnServer[1], serverRoomId[5], classIndex[9], x[13], y[17], z[21] uint clientId = BitConverter.ToUInt32(data, 1); GameClient client = GetClientFromID(clientId); uint roomId = BitConverter.ToUInt32(data, 5); ServerRoom room = GetRoomFromID(roomId); if (!room.GetClientTable().Contains(client)) { client.UpdateMalus(); return; } RPGHero newHero = SpawnHero(roomId); newHero.SetOwner(client); uint classId = BitConverter.ToUInt32(data, 9); newHero.SetInGameValues(classId, ""); float x = BitConverter.ToSingle(data, 13); float y = BitConverter.ToSingle(data, 17); float z = BitConverter.ToSingle(data, 21); newHero.SetPosition(x, y, z); //byte[] name = new byte[12]; //for (int i = 0; i < name.Length; i++) //{ // name[i] = data[25 + i]; //} //string heroName = System.Text.Encoding.UTF8.GetString(name); //Console.WriteLine(heroName); Console.WriteLine("Spaned Object {0}", room.GetGameObjectTable().Count); }
private void SetTurnParameter(byte[] data, EndPoint sender) { uint clientId = BitConverter.ToUInt32(data, 1); GameClient client = GetClientFromID(clientId); uint roomId = BitConverter.ToUInt32(data, 5); ServerRoom room = GetRoomFromID(roomId); if (!room.GetClientTable().Contains(client)) { client.UpdateMalus(); return; } uint heroId = BitConverter.ToUInt32(data, 9); if (!room.GetGameObjectTable().ContainsKey(heroId)) { client.UpdateMalus(); return; } RPGHero hero = (RPGHero)room.GetGameObjectFromId(heroId); int skillId = BitConverter.ToInt32(data, 13); uint targetId = BitConverter.ToUInt32(data, 17); RPGHero target = null; if (targetId != 172) { target = (RPGHero)room.GetGameObjectFromId(targetId); } Console.WriteLine("Attacker : {0}, skill: {1}, Target: {2}", hero.ID, skillId, targetId); room.SetTurnParameters(hero, skillId, target); }
public void EnterInARoom(ServerRoom serverRoom, string tag) { room = serverRoom; teamTag = tag; }
public GameLogicFST(uint objectType, GameServer server, ServerRoom room) : base(1, server) { TurnOrder = new List <Turn>(); owner = room; }