// alinan root minionlardan sadece player'in science type'ina uygun olanlari true olacak. Diger minionlar unlocked bile olsalar, science type uygun degilse bu listede false olacaklar. //Upgrade edileni true yap, upgrade olani da false yap ki yapilabilecek minionlar listesinden parent olan cikmis olsun. public Player(User user, Game game) { readyInQueue = false; loadedTheGame = false; this.user = user; this.game = game; this.board = (Board)Activator.CreateInstance(TypeIdGenerator.getBoardType(user.selectedBoardTypeId)); board.player = this; cash = 20000; income = 1200; healthPoints = 10; // 5000000; playerState = PlayerState.ALIVE; initializeAvailableMinions(); }
private void destroyGame(User guiltyUser) { Science_Wars_Server.Game gameToBeDestroyed = guiltyUser.player.game; foreach (Player player in guiltyUser.player.game.players) { if (player.user == guiltyUser || player.user.Destroyable == true) { player.user.setState(User.UserState.LOBBY); } else if (player.user != guiltyUser && player.user.Destroyable == false) { Runner.queue.addUser(player.user); LReturnQueue.sendMessage(player.user); } } gameToBeDestroyed.destroy(); }
public override void processMessage(RawMessage message, User user) { if (message.getBool("r")) { if (user.userState == User.UserState.GAME) { OutgoingMessages.Game.GReadyStateResult.sendMessage(user.player.game.players, message.getBool("r")); user.player.readyInQueue = true; bool anyoneDisconnected = false; bool flagAllReady = true; User disconnectedUser = null; foreach (Player p in user.player.game.players) if (p.user.Destroyable) { anyoneDisconnected = true; disconnectedUser = p.user; break; } else if (!p.readyInQueue) { flagAllReady = false; break; } if (anyoneDisconnected) destroyGame(disconnectedUser); else if (flagAllReady) user.player.game.setState(Science_Wars_Server.Game.GameState.LOADING); } } else { destroyGame(user); } }
private void loginProcess() { string username; string password; string certPassword = "******"; X509Certificate certificate = new X509Certificate2("ScienceWars_SSL_certificate.pfx", certPassword); SslStreamObject sslStream = session.client.createSslStreamObject(true); try { sslStream.AuthenticateAsServer(certificate); } catch (Exception e) { return; } while (true) { RawMessage message = sslStream.ReadSingleMessage(); if (message == null) return; username = message.getUTF8String("username"); // TODO exception check password = message.getUTF8String("password"); int userId = 0; if (dal.credentialCheck(username,password,out userId)) //username, password, out userId)) { Database.Models.UserDataModel userData = new Database.Models.UserDataModel(); if (dal.getUserData(userId, TypeIdGenerator.getScienceNodeCount(), out userData)) { //TODO unlocked Science Nodes bize dbId olarak geliyor ancak biz o id yi sanki isimden uretilen typeId si gibi kullaniyoruz. burada bir convert yapmak lazim // aldigin unlockedScienceNodes arrayindeki her bir indexi dbId olarak tutan scienceNode u bul, o nodun typeId sini al, o typeId yi index olarak kullanarak yeni bir bool[] doldur. // yeni olusturdugun bool array i User konstraktirina gonder. sendLoginResponse(sslStream, true, "successful"); //sslStream.Close(); // DUE TO A BUG -kardeslerim- WE CANNOT CLOSE THE STREAM. // Cunku close yaparsak, nereden geldigi belirsiz 37 byte, client'a ait messageListenera dusuyor. // sadece unity'de oluyor, .net'te duzgun calisiyor. Muhtemelen Mono kaynakli bir sorun. session.client.ListenForMessages(); User user = new User(session, username , userData.physPoints, userData.chemPoints, userData.chemPoints, userData.unlockedScienceNodes); runner.userLoggedIn(user); return; } else sendLoginResponse(sslStream, false, "cannot retrieve user data"); } else sendLoginResponse(sslStream, false, "wrong username or password"); } }
private void AddUser(User user) { lock (userdictionary) { if (userdictionary.ContainsKey(user.session.client) == false) { userdictionary.Add(user.session.client, user); users.AddLast(user); Console.WriteLine("User Added: " + user.username); } } }
public void userLoggedIn(User user) { AddUser(user); }