Skip to content

Commit

Permalink
Version 0.1.408-1
Browse files Browse the repository at this point in the history
  • Loading branch information
KithM committed Apr 12, 2018
1 parent 42c47be commit 12577bb
Show file tree
Hide file tree
Showing 7 changed files with 127 additions and 32 deletions.
Binary file modified 0.1.408/ruthenium_01408.zip
Binary file not shown.
102 changes: 78 additions & 24 deletions files/Abstract/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Game : IXmlSerializable {
public int userID { get; protected set; } // Our userID is only used for saving the default XML
public string bio { get; protected set; } // The Biography of the user, or whatever the user sets it to
public string userGroup { get; protected set; } // TODO: Our user group. Can only be User or Admin
public List<string> permissions { get; protected set; } // TODO: Our user privelages. Will hold all of our special permissions we can do when we are logged in
public List<string> permissions { get; protected set; } // Our user privelages. Will hold all of our special permissions we can do when we are logged in

// Our database is filled in every time we start the game using the XML file. It holds our username and our associated password, and
// anything else we need for our user
Expand Down Expand Up @@ -113,41 +113,65 @@ public void WriteXml(XmlWriter writer){
} else {
// DEFAULT (NO FILE)
User user1 = new User ("default", "password");

List<string> adminperms = new List<string> ();
adminperms.Add ("permissions.add.self");
adminperms.Add ("permissions.remove.self");
adminperms.Add ("permissions.add.others");
adminperms.Add ("permissions.remove.others");

User user2 = new User ("admin", "password", "This user does not have a bio.", "Admin", adminperms);
dataBase.Add (user1);
dataBase.Add (user2);

// User Start
writer.WriteStartElement("User");
foreach (User user in dataBase) {
string username = user.Username;
string password = user.Password;
string bio = user.Bio;
string usergroup = user.UserGroup;

// Username
writer.WriteStartElement("Username");
writer.WriteString (user1.Username);
writer.WriteEndElement ();
// User Start
writer.WriteStartElement ("User");

// Password
writer.WriteStartElement("Password");
writer.WriteString (user1.Password);
writer.WriteEndElement ();
// Username
writer.WriteStartElement ("Username");
writer.WriteString (username);
writer.WriteEndElement ();

// Bio
writer.WriteStartElement("Bio");
writer.WriteString (user1.Bio);
writer.WriteEndElement ();
// Password
writer.WriteStartElement ("Password");
writer.WriteString (password);
writer.WriteEndElement ();

// Privelages
writer.WriteStartElement("UserGroup");
writer.WriteString (user1.UserGroup);
writer.WriteEndElement ();
// Bio
writer.WriteStartElement ("Bio");
writer.WriteString (bio);
writer.WriteEndElement ();

// Permissions
writer.WriteStartElement("Permissions");
writer.WriteEndElement ();
// Privelages
writer.WriteStartElement ("UserGroup");
writer.WriteString (usergroup);
writer.WriteEndElement ();

// User End
writer.WriteEndElement();
// Permissions
writer.WriteStartElement ("Permissions");
if (user.Permissions != null && user.Permissions.Count > 0) {
foreach (string perm in user.Permissions) {
writer.WriteStartElement ("Permission");
writer.WriteString (perm);
writer.WriteEndElement ();
}
}
writer.WriteEndElement ();

// User End
writer.WriteEndElement ();
}
}
}
public void ReadXml(XmlReader reader){
// TODO: EVERYTHING!!!!!
bool doSaveAfterLoad = false;

Debug.Log ("Game::ReadXml");
reader.Read ();
Expand Down Expand Up @@ -178,12 +202,36 @@ public void ReadXml(XmlReader reader){

if (reader.ReadToDescendant ("Username")) {
xmlusername = reader.ReadString ();
//TODO:
if(xmlusername.Length > 25){
Debug.LogError ("Game::ReadXml: The specified username \'<b>" + xmlusername + "</b>\' is too long (" + xmlusername.Length + " char).");
Logger.WriteLog ("Game::ReadXml: The specified username \'" + xmlusername + "\' is too long (" + xmlusername.Length + " char).");
xmlusername = xmlusername.Substring (0, 25);

doSaveAfterLoad = true;
}
}
if (reader.ReadToNextSibling ("Password")) {
xmlpassword = reader.ReadString ();
//TODO:
if(xmlpassword.Length > 50){
Debug.LogError ("Game::ReadXml: The specified password for user \'<b>" + xmlusername + "</b>\' is too long (" + xmlpassword.Length + " char).");
Logger.WriteLog ("Game::ReadXml: The specified password for user \'" + xmlusername + "\' is too long (" + xmlpassword.Length + " char).");
xmlpassword = xmlpassword.Substring (0, 50);

doSaveAfterLoad = true;
}
}
if (reader.ReadToNextSibling ("Bio")) {
xmlbio = reader.ReadString ();
//TODO:
if(xmlbio.Length > 300){
Debug.LogError ("Game::ReadXml: The specified bio for user \'<b>" + xmlusername + "</b>\' is too long (" + xmlbio.Length + " char).");
Logger.WriteLog ("Game::ReadXml: The specified bio for user \'" + xmlusername + "\' is too long (" + xmlbio.Length + " char).");
xmlbio = xmlbio.Substring (0, 300);

doSaveAfterLoad = true;
}
}
if (reader.ReadToNextSibling ("UserGroup")) {
xmlprivelages = reader.ReadString ();
Expand Down Expand Up @@ -214,6 +262,12 @@ public void ReadXml(XmlReader reader){
}

reader.Close ();

if (doSaveAfterLoad == true) {
// TODO: May need to move this?
GameController.sl.StartSave ();
}

Debug.Log ("Game::ReadXml: Successfully loaded the data file \'<b>data.ruth</b>\' with " + dataBase.Count + " users.");

string log1 = "Game::ReadXml: Successfully loaded the data file \'data.ruth\' with " + dataBase.Count + " users.";
Expand Down
12 changes: 10 additions & 2 deletions files/Managers/LoginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,16 @@ public void Register(){
return;
}

//User user = new User (u, p);
//GameController.current.dataBase.Contains(user)
if(u.Length > 25){
// TODO
warningText.text = "Username is too long (" + u.Length + " char).";
return;
}
if(p.Length > 50){
// TODO
warningText.text = "Password is too long (" + p.Length + " char).";
return;
}

int count = 0;

Expand Down
4 changes: 4 additions & 0 deletions files/Managers/PermissionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void ViewUserPermissions(){
// Display our currently selected user's permissions
foreach (User user in GameController.current.dataBase) {
if (user == GameController.current.dataBase [dd.value]) {
if(user.Permissions == null){
// TODO
user.Permissions = new List<string>();
}
foreach (string perm in user.Permissions) {
GameObject pGO = Instantiate (permissionPrefab, bodyPanel.transform);

Expand Down
11 changes: 11 additions & 0 deletions files/UI/Manage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,17 @@ public void SaveChanges(){
return;
}

if(u.Length > 25){
// TODO
warningText.text = "Username is too long (" + u.Length + " char).";
return;
}
if(p.Length > 50){
// TODO
warningText.text = "Password is too long (" + p.Length + " char).";
return;
}

for (int i = 0; i < GameController.current.dataBase.Count; i++) {
if (GameController.current.dataBase [i].Username == GameController.current.GetUsername ()) {
GameController.current.dataBase [i].Username = u;
Expand Down
26 changes: 20 additions & 6 deletions files/UI/Profile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void ShowProfile(){
//TODO:
string filePath = System.IO.Path.Combine ( SaveLoad.ImagesBasePath(), GameController.current.GetUsername() + ".png" );

Texture2D ppT = LoadPNG (filePath);
Texture2D ppT = LoadTextureFromFile (filePath);
if (ppT != null) {
Rect ppR = new Rect (0, 0, ppT.width, ppT.height);
Sprite ppS = Sprite.Create (ppT, ppR, profilePicture.rectTransform.pivot);
Expand Down Expand Up @@ -87,21 +87,35 @@ public void SaveEditProfile(){
ShowProfile ();
}

public Texture2D LoadPNG(string filePath) {
public Texture2D LoadTextureFromFile(string filePath) {

Texture2D tex = null;
byte[] fileData;

// default blank texture used for saving, if loading it will just be overrided
tex = new Texture2D(100, 100, TextureFormat.ARGB32, false);

if (File.Exists(filePath)) {
fileData = File.ReadAllBytes(filePath);

tex = new Texture2D(2, 2, TextureFormat.ARGB32, false);

tex.LoadImage(fileData); //..this will auto-resize the texture dimensions
Debug.Log ("Profile::LoadPNG: Loaded file \'<b>" + filePath + "</b>\'.");
Debug.Log ("Profile::LoadTextureFromFile: Loaded file \'<b>" + filePath + "</b>\'.");
} else {
Debug.LogError ("Profile::LoadPNG: Failed to load file \'<b>" + filePath + "</b>\'.");
Debug.Log ("Profile::LoadTextureFromFile: Failed to load file \'<b>" + filePath + "</b>\'.");
SaveTextureToFile (tex, filePath);
}
return tex;
}

public void SaveTextureToFile(Texture2D tex, string filePath){
var bytes = tex.EncodeToPNG();

FileStream file = File.Create (filePath);
BinaryWriter binary = new BinaryWriter (file);

binary.Write(bytes);
file.Close();

Debug.Log ("Profile::SaveTextureToFile: Created file \'<b>" + filePath + "</b>\'.");
}
}
4 changes: 4 additions & 0 deletions files/UI/Users.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ public void ShowMenu () {
int n = 0;

foreach (User user in GameController.current.dataBase) {
if(user.Permissions == null){
// TODO
user.Permissions = new List<string>();
}
if(user.Permissions.Contains("user.type.hidden") && !GameController.current.permissions.Contains("settings.see.hidden")){
continue;
}
Expand Down

0 comments on commit 12577bb

Please sign in to comment.