public static GameInstance JoinGame(UdpClient client, IPEndPoint endPoint, NameValueCollection queryString) { lock (_gameDb) { GameInstance instance = ActiveGames[new Guid(queryString["game"])]; float latitude = 0, longitude = 0; float.TryParse(queryString["latitude"], out latitude); float.TryParse(queryString["longitude"], out longitude); Database.GameDevice device = new Database.GameDevice(); device.PkGameDevice = Guid.NewGuid(); device.Game = instance.Game; device.User = queryString["user"]; device.Latitude = latitude; device.Longitude = longitude; device.LocalAddress = queryString["address"]; device.LocalPort = int.Parse(queryString["port"]); device.Device = queryString["id"]; device.Date = DateTime.Now; device.Ready = false; device.Accepted = false; Trace.WriteLine("Joining Game: " + device.User); _gameDb.GameDevices.InsertOnSubmit(device); _gameDb.SubmitChanges(); instance.AddPlayer(device, client, endPoint); return(instance); } GamePlayer.SendUpdate(GameMessage.JoinResponse, client, endPoint, new byte[0], 1); }
public GameInstance(Database.Game game, Database.GameDevice device, UdpClient client, IPEndPoint endPoint) { _masterClient = new GamePlayer(device, client, endPoint); _masterClient.GotGameUpdate += new EventHandler <GameUpdateEventArgs>(_masterClient_GotGameUpdate); _masterClient.ClientDisconnected += new EventHandler(_masterClient_ClientDisconnected); _allPlayers.Add(_masterClient); _endPointMap.Add(endPoint.ToString().GetHashCode(), _masterClient); _game = game; }
public GamePlayer(string deviceName, UdpClient client, IPEndPoint endPoint) { using (Database.GameServer gameDb = new Database.GameServer("Data Source=(local);Initial Catalog=gameserver;Persist Security Info=True;User ID=sa;Password=ce-86944")) { var device = (from gameDevice in gameDb.GameDevices where gameDevice.Device == deviceName select gameDevice).First(); _device = device; _client = client; _endPoint = endPoint; } }
public void AddPlayer(Database.GameDevice gameDevice, UdpClient client, IPEndPoint endPoint) { lock (this) { GamePlayer addPlayer = new GamePlayer(gameDevice, client, endPoint); addPlayer.GotGameUpdate += new EventHandler <GameUpdateEventArgs>(_slaveClient_GotGameUpdate); addPlayer.ClientDisconnected += new EventHandler(addPlayer_ClientDisconnected); _endPointMap.Add(endPoint.ToString().GetHashCode(), addPlayer); _slaveClients.Add(addPlayer); _allPlayers.Add(addPlayer); } SendGameInfo(); }
public GamePlayer(string deviceName, UdpClient client, IPEndPoint endPoint) { using (Database.GameServer gameDb = new Database.GameServer("Data Source=(local);Initial Catalog=gameserver;Persist Security Info=True;User ID=sa;Password=ce-86944")) { var device = (from gameDevice in gameDb.GameDevices where gameDevice.Device == deviceName select gameDevice).First(); _device = device; _client = client; _endPoint = endPoint; } }
public GamePlayer(Database.GameDevice device, UdpClient client, IPEndPoint endPoint) { _device = device; _client = client; _endPoint = endPoint; }
public static GameInstance JoinGame(UdpClient client, IPEndPoint endPoint, NameValueCollection queryString) { lock (_gameDb) { GameInstance instance = ActiveGames[new Guid(queryString["game"])]; float latitude = 0, longitude = 0; float.TryParse(queryString["latitude"], out latitude); float.TryParse(queryString["longitude"], out longitude); Database.GameDevice device = new Database.GameDevice(); device.PkGameDevice = Guid.NewGuid(); device.Game = instance.Game; device.User = queryString["user"]; device.Latitude = latitude; device.Longitude = longitude; device.LocalAddress = queryString["address"]; device.LocalPort = int.Parse(queryString["port"]); device.Device = queryString["id"]; device.Date = DateTime.Now; device.Ready = false; device.Accepted = false; Trace.WriteLine("Joining Game: " + device.User); _gameDb.GameDevices.InsertOnSubmit(device); _gameDb.SubmitChanges(); instance.AddPlayer(device, client, endPoint); return instance; } GamePlayer.SendUpdate(GameMessage.JoinResponse, client, endPoint, new byte[0], 1); }
public static GameInstance CreateInstance(UdpClient client, IPEndPoint endPoint, NameValueCollection queryString, byte[] mapData) { lock (_gameDb) { var games = (from delGame in _gameDb.Games where delGame.User == queryString["user"] select delGame); foreach (Database.Game delGame in games) { delGame.Completed = true; //_gameDb.Games.DeleteOnSubmit(delGame); } Database.Game game = new Database.Game(); game.PkGame = Guid.NewGuid(); game.MapData = System.Text.Encoding.ASCII.GetString(mapData); game.User = queryString["user"]; if (string.IsNullOrEmpty(game.User)) { game.User = queryString["id"]; } game.Completed = false; game.Ready = false; game.Date = DateTime.Now; game.Width = Convert.ToInt32(queryString["width"]); game.Height = Convert.ToInt32(queryString["height"]); float latitude = 0, longitude = 0; float.TryParse(queryString["latitude"], out latitude); game.Latitude = latitude; float.TryParse(queryString["longitude"], out longitude); game.Longitude = longitude; game.GameId = Convert.ToInt32(queryString["gameId"]); // TODO: lookup here float version = 0; float.TryParse(queryString["gameversion"], out version); Database.GameDevice device = new Database.GameDevice(); device.PkGameDevice = Guid.NewGuid(); device.Game = game; device.User = queryString["user"]; if (string.IsNullOrEmpty(device.User)) { device.User = queryString["id"]; } device.Latitude = game.Latitude; device.Longitude = game.Longitude; device.LocalAddress = queryString["address"]; device.LocalPort = int.Parse(queryString["port"]); device.Device = queryString["id"]; device.Date = DateTime.Now; device.Ready = true; device.Accepted = true; _gameDb.Games.InsertOnSubmit(game); _gameDb.GameDevices.InsertOnSubmit(device); _gameDb.SubmitChanges(); Trace.WriteLine("Starting Game: " + game.User); GameInstance instance = new GameInstance(game, device, client, endPoint); GamePlayer.SendUpdate(GameMessage.CreateResponse, client, endPoint, Encoding.ASCII.GetBytes(game.PkGame.ToString()), 1); ActiveGames.Add(game.PkGame, instance); Thread gameThread = new Thread(new ParameterizedThreadStart(LaunchGame)); gameThread.IsBackground = true; gameThread.Start(instance); return instance; } }
public GamePlayer(Database.GameDevice device, UdpClient client, IPEndPoint endPoint) { _device = device; _client = client; _endPoint = endPoint; }
public static GameInstance CreateInstance(UdpClient client, IPEndPoint endPoint, NameValueCollection queryString, byte[] mapData) { lock (_gameDb) { var games = (from delGame in _gameDb.Games where delGame.User == queryString["user"] select delGame); foreach (Database.Game delGame in games) { delGame.Completed = true; //_gameDb.Games.DeleteOnSubmit(delGame); } Database.Game game = new Database.Game(); game.PkGame = Guid.NewGuid(); game.MapData = System.Text.Encoding.ASCII.GetString(mapData); game.User = queryString["user"]; if (string.IsNullOrEmpty(game.User)) { game.User = queryString["id"]; } game.Completed = false; game.Ready = false; game.Date = DateTime.Now; game.Width = Convert.ToInt32(queryString["width"]); game.Height = Convert.ToInt32(queryString["height"]); float latitude = 0, longitude = 0; float.TryParse(queryString["latitude"], out latitude); game.Latitude = latitude; float.TryParse(queryString["longitude"], out longitude); game.Longitude = longitude; game.GameId = Convert.ToInt32(queryString["gameId"]); // TODO: lookup here float version = 0; float.TryParse(queryString["gameversion"], out version); Database.GameDevice device = new Database.GameDevice(); device.PkGameDevice = Guid.NewGuid(); device.Game = game; device.User = queryString["user"]; if (string.IsNullOrEmpty(device.User)) { device.User = queryString["id"]; } device.Latitude = game.Latitude; device.Longitude = game.Longitude; device.LocalAddress = queryString["address"]; device.LocalPort = int.Parse(queryString["port"]); device.Device = queryString["id"]; device.Date = DateTime.Now; device.Ready = true; device.Accepted = true; _gameDb.Games.InsertOnSubmit(game); _gameDb.GameDevices.InsertOnSubmit(device); _gameDb.SubmitChanges(); Trace.WriteLine("Starting Game: " + game.User); GameInstance instance = new GameInstance(game, device, client, endPoint); GamePlayer.SendUpdate(GameMessage.CreateResponse, client, endPoint, Encoding.ASCII.GetBytes(game.PkGame.ToString()), 1); ActiveGames.Add(game.PkGame, instance); Thread gameThread = new Thread(new ParameterizedThreadStart(LaunchGame)); gameThread.IsBackground = true; gameThread.Start(instance); return(instance); } }