Exemplo n.º 1
0
    public static void SavePlayerData(string name, string pass, bool isUpdate = false)
    {
        DateTime   dateNow = DateTime.UtcNow;
        PlayerData data    = new PlayerData();

        data.Store(name, pass, dateNow);
        players.Add(data);

        var db          = "GoC.sqlite";
        var playerSaver = new DataSaver().DataBase(db);

        var command1 = "PlayersData (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name TEXT NOT NULL,Password TEXT NOT NULL, `Date` TEXT NOT NULL, `LatestDate` TEXT,Kingdom TEXT, Score INTEGER DEFAULT 0);";
        var command2 = String.Format("PlayersData (Name, Password, Date, LatestDate, Kingdom) VALUES ('{0}', '{1}', '{2}', '{3}', 'Default');", data.Name, data.Password, data.playDate.ToString(), data.playDate.ToString());

        if (isUpdate)
        {
            command2 = String.Format("PlayersData SET LatestDate = '{0}' WHERE Name='{1}';", DateTime.UtcNow.ToString(), name);
        }

        playerSaver.Open();
        playerSaver.CreateTable(command1);
        if (isUpdate)
        {
            playerSaver.Update(command2);
        }
        else
        {
            playerSaver.Insert(command2);
        }
        playerSaver.Close();
    }
Exemplo n.º 2
0
    bool CheckIfNameExist()
    {
        var db          = "GoC.sqlite";
        var nameChecker = new DataSaver().DataBase(db);
        var command     = String.Format("* FROM PlayersData WHERE Name='{0}'", playerName);
        var command1    = "PlayersData (id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name TEXT NOT NULL,Password TEXT NOT NULL, `Date` TEXT NOT NULL, `LatestDate` TEXT,Kingdom TEXT, Score INTEGER DEFAULT 0);";

        nameChecker.Open();
        nameChecker.CreateTable(command1);
        var reader = nameChecker.Select(command);

        if (reader.Read())
        {
            nameChecker.Close();
            return(true);
        }
        nameChecker.Close();
        return(false);
    }