public MyUdpServerForm() { InitializeComponent(); //serverSide = new ServerSide(new IPEndPoint(IPAddress.Parse("10.0.0.3"),1234)); serverSide = new ServerSide(1234); GameOptions gameOptions = new GameOptions("Poland","Niemcy", UDPClientServerCommons.Constants.GameTypeEnumeration.FragLimit,10); serverSide.StartLANServer(gameOptions,false,null); }
public override void AddPlayer(Player player) { World.Instance.AddPlayer(player); if (player == this.player) { GameOptions options = new GameOptions("Zabójcy", "Rycerze", UDPClientServerCommons.Constants.GameTypeEnumeration.TimeLimit, 10); UDPClientServerCommons.Usefull.PlayerMe pl; if (player.CharacterClass.GameTeam == GameTeam.Assassins) pl = new UDPClientServerCommons.Usefull.PlayerMe("Zabójcy", player.Name); else pl = new UDPClientServerCommons.Usefull.PlayerMe("Rycerze", player.Name); serverNetworkLayer.StartLANServer(options, false, pl); //ChangePlayerTeam(player, player.CharacterClass.GameTeam); } }
static void Main(string[] args) { //Console.WriteLine("How do you want to start Server?"); // Console.WriteLine("[1]\t by passing port number (ex. 1234)"); // Console.WriteLine("[2]\t by passing Ip Adress and port number (ex. 127.0.0.1:1234)"); // Console.WriteLine("[3]\t Default"); // string input = Console.ReadLine(); try { timer = new System.Threading.Timer(new System.Threading.TimerCallback(timerCallback), null, 1000, 1000); CS_Server = new ServerSide(1234); CS_Server.MessageWasReceivedEvent += new EventHandler(CS_Server_MessageWasReceivedEvent); GameOptions gameOptions = new GameOptions("Poland", "Niemcy", UDPClientServerCommons.Constants.GameTypeEnumeration.FragLimit, 10); //IPEndPoint adress = CS_Server.StartLANServer(gameOptions,true,null); IPEndPoint adress = CS_Server.StartLANServer(gameOptions, false, new UDPClientServerCommons.Usefull.PlayerMe("Poland", "ServerPlayer")); Console.WriteLine("Server started at adress : {0}", adress.ToString()); Console.WriteLine("Press [ENTER] to termiante..."); Console.Title = "Castle Strike Server - Press [ENTER] to termiante..."; while (true) { string input = Console.ReadLine(); if (input.ToLower() == "start") Console.WriteLine(" Trying to start game .... Started? {0}", CS_Server.StartGame()); if (input.ToLower() == "info") { if (CS_Server.Client.CurrentGameInfo != null) Console.WriteLine(CS_Server.Client.CurrentGameInfo.ToString()); } if (input.ToLower() == "pl") { List<UDPClientServerCommons.Interfaces.IOtherPlayerData> list = new List<UDPClientServerCommons.Interfaces.IOtherPlayerData>(CS_Server.Client.PlayerDataList); for (int i = 0; i < list.Count; i++) Console.WriteLine("\t {0}", list[i]); } if (input.ToLower() == "jump") { UDPClientServerCommons.Interfaces.IPlayerDataWrite pd = new UDPClientServerCommons.Usefull.PlayerData(); pd.Jump = true; pd.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.CrossBow; CS_Server.Client.UpdatePlayerData(pd); } if (input.ToLower() == "shoot") { UDPClientServerCommons.Interfaces.IPlayerDataWrite pd = new UDPClientServerCommons.Usefull.PlayerData(); pd.Shoot = true; pd.Weapon = UDPClientServerCommons.Constants.WeaponEnumeration.CrossBow; CS_Server.Client.UpdatePlayerData(pd); } if (input.ToLower() == "team") { List<UDPClientServerCommons.Usefull.TeamData> tdList = new List<UDPClientServerCommons.Usefull.TeamData>(); tdList.Add(new UDPClientServerCommons.Usefull.TeamData(13,null)); tdList[0].TeamScore= teamScore; teamScore++; CS_Server.UpdatePlayerHealthAndTeamScore(null, tdList); } if (input.Length == 0) break; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { if (CS_Server != null) CS_Server.Dispose(); } }
/// <summary> /// Starts local game, it also starts broadcasting game info all over network /// </summary> /// <param name="gameOptions"> game parameters</param> /// <param name="dedicatedServer">is server going to be dedicated</param> /// <param name="Me">if server is not dedicated - playerData is needed</param> /// <returns>Server Adress or null if error occured</returns> public IPEndPoint StartLANServer(GameOptions gameOptions,bool dedicatedServer,Interfaces.IPlayerMe Me) { try { if(lanBroadcast == null) lanBroadcast = new ServerLanBroadcast(); Usefull.PlayerMe me = (Usefull.PlayerMe)Me; PlayerStatus ps = new PlayerStatus(); lock (gameInfoPacketLock) { Random rand = new Random(gameOptions.GetHashCode()); gameInfoPacket.GameId = (ushort)rand.Next(1000, 9999); gameInfoPacket.GameType = gameOptions.GameType; gameInfoPacket.Limit = gameOptions.GameLimit; gameInfoPacket.PlayerStatusList = new List<PlayerStatus>(); gameInfoPacket.RoundNumber = 1; if (!dedicatedServer && me != null) { ps.PlayerId = (ushort)rand.Next(1000, 9999); ps.PlayerName = (string) me.PlayerName.Clone(); if (me.PlayerTeam == gameOptions.TeamOneName) ps.PlayerTeam = 13; else ps.PlayerTeam = 39; if (clientForServer == null) { clientForServer = new ClientForServer(); clientForServer.AddMessageToServer += new ClientForServer.AddMessageDelegate(clientForServer_AddMessageToServer); clientForServer.EndGameEvent += new EventHandler(clientForServer_EndGameEvent); } clientForServer.JoinGame(ps.PlayerId, gameInfoPacket.GameId, ps.PlayerName, ps.PlayerTeam); gameInfoPacket.PlayerStatusList.Add(ps); } gameInfoPacket.TeamScoreList = new List<TeamData>(); TeamData ts1 = new TeamData(13, gameOptions.TeamOneName); TeamData ts2 = new TeamData(39, gameOptions.TeamTwoName); gameInfoPacket.ServerAddress = base.ServerIpAdress; gameInfoPacket.TeamScoreList.Add(ts1); gameInfoPacket.TeamScoreList.Add(ts2); gameInfoPacketSendCounter = 0; } if (!dedicatedServer && me != null) { lock (serverPacketLock) { PlayerInfo pi = new PlayerInfo(); pi.PlayerId = ps.PlayerId; serverPacket.PlayerInfoList.Add(pi); } } timer.Change(0, _TimerTickPeriod); return base.Start(); } catch (Exception ex) { Diagnostic.NetworkingDiagnostics.Logging.Fatal("StartLanServer S", ex); } return null; }
/// <summary> /// Method not implemented !!! /// </summary> /// <param name="gameOptions"></param> /// <returns></returns> public IPEndPoint StartINTERNETServer(GameOptions gameOptions,bool dedicatedServer,Interfaces.IPlayerMe Me) { throw new NotImplementedException("Option for internet gaming has not been implemented"); }