public bool Load() { if (!File.Exists(GetDataPath())) { return(false); } string s = File.ReadAllText(GetDataPath()); Account = JsonConvert.DeserializeObject <MUserAccount>(s); if (Account == null) { return(false); } if ((Account.HomePosition[0] == 0) && (Account.HomePosition[1] == 0) && (Account.HomePosition[2] == 0)) { Account.HomePosition = DefaultHome; } Change("Account"); return(true); }
public void ChangeDetails(MClient c, MNetMessage m) { MUserAccount mu = MUserAccount.Deserialize <MUserAccount>(m.Payload); // TODO: Validate account mu.CopyTo(c.Account); // c.Save(); c.Account.ClientIP = c.Address.ToString(); string UserID = _DataBase.UpdatePlayer(c.Account); MNetMessage mn = new MNetMessage(); mn.Command = MNetMessage.CHANGEDETAILS; mn.UserID = UserID; //TODO: VALIDATE USERACCOUNT MChangeDetailsResult res = new MChangeDetailsResult(); res.Success = true; res.Message = "Details Changed"; mn.Payload = res.Serialize(); Send(c, "Message", mn.Serialize()); }
public string UpdatePlayer(MUserAccount m) { string sQuery = string.Format( @"UPDATE users SET screenname = '{0}', avatarid = '{1}', email='{2}', password='******' WHERE `userid`='{4}';", m.UserName, m.AvatarID, m.Email, m.Password, m.UserID); Query(sQuery); return(m.UserID); }
public string UpdatePlayerIP(MUserAccount m) { if (m == null) { return(""); } string sQuery = string.Format( @"UPDATE users SET ip = '{0}' WHERE `userid`='{1}';", m.ClientIP, m.UserID); Query(sQuery); return(m.UserID); }
public void AddPlayer(MUserAccount m) { string sQuery = string.Format( @"INSERT IGNORE into users (userid, screenname, avatarid, email, password, ip) VALUES('{0}', '{1}', '{2}', '{3}', '{4}', '{5}');", m.UserID, m.UserName, m.AvatarID, m.Email, m.Password, m.ClientIP); Query(sQuery); /*sQuery = string.Format( * @"INSERT into `objects` (`instanceid`,`ownerid`,`templateid`,`name`,`persist`) * VALUES('{0}', '{1}', '{2}', '{3}', 0) * ON DUPLICATE KEY UPDATE `name`='{3}';", * m.UserID, m.UserID, m.AvatarID, m.UserName); * Query(sQuery);*/ }
public MUserAccount GetPlayerByUserID(string UserID) { MUserAccount mu = new MUserAccount(); string sQuery = string.Format("SELECT * from users where userid='{0}';", UserID); DataTable dt = QueryReader(sQuery); if (dt.Rows.Count == 0) { return(null); } //DataRow row = dt.Rows[0]["userid"]; //mu.UserID = row.ItemArray.GetValue("userid"].ToString(); mu.UserID = dt.Rows[0]["userid"].ToString(); return(mu); }
public void Load() { String sDetails = MFileSystem.GetFile("settings.json"); try { MUserAccount acc = MUserAccount.Deserialize <MUserAccount>(sDetails); if (acc != null) { Globals.UserAccount = acc; } } catch (Exception e) { Console.WriteLine(e.Message); } }
//log in registered player //player sends updatedetails message to register public void LoginRequest(MClient c, MNetMessage m) { if (MassiveConnections.Count >= MAXCONNECTIONS) { DisconnectClient(c.connection, "Maximum Connections exceded"); return; } MLoginMessageRequest mlir = MLoginMessageRequest.Deserialize <MLoginMessageRequest>(m.Payload); //check database //if password matches, continue //if not, send failed message IPEndPoint ipe = (IPEndPoint)c.connection.ConnectionInfo.RemoteEndPoint; string s = ipe.Address + ":" + ipe.Port; c.Account.ClientIP = s; if (c.Account.UserID == null) { c.Account.UserID = m.UserID; } _DataBase.UpdatePlayerIP(c.Account); _DataBase.UpdatePlayerUsage(c.Account); MUserAccount mu = _DataBase.GetPlayerByEmail(mlir.Email, mlir.Password); if (mu == null) { MNetMessage mli = new MNetMessage(); mli.Command = MNetMessage.ERROR; mli.Payload = "User not found. Building Disabled. Register User and Login again."; Send(c, "Message", mli.Serialize()); } else { MNetMessage mli = new MNetMessage(); mli.Command = MNetMessage.LOGIN; mli.UserID = mu.UserID; mli.Payload = mu.Serialize(); Send(c, "Message", mli.Serialize()); c.Account = mu; } ClientLoggedIn?.Invoke(this, new ServerEvent("Logged In:" + c.ToString())); }
public string UpdatePlayerUsage(MUserAccount m) { if (m == null) { return(""); } string sCountQuery = String.Format("SELECT COUNT(*) from `objects` where ownerid='{0}'", m.UserID); int ObjectsOwned = QueryScalar(sCountQuery); string DateMYSQL = DateTime.Now.ToString("yyyy-MM-dd HH:mm"); string sQuery = string.Format( @"UPDATE users SET date_accessed = '{0}',totalobjects='{1}' WHERE `userid`='{2}';", DateMYSQL, ObjectsOwned, m.UserID); Query(sQuery); return(m.UserID); }
public string RegisterUser(MUserAccount m) { MUserAccount mu = GetPlayerByEmail(m.Email, m.Password); if (mu != null) { return(mu.UserID); } string s = UidGen.GUID(); m.UserID = s; string sQuery = string.Format( @"INSERT into users (`screenname`,`avatarid`,`email`,`password`, `userid`, `ip`) VALUES('{0}','{1}','{2}','{3}','{4}','{5}');", m.UserName, m.AvatarID, m.Email, m.Password, m.UserID, m.ClientIP); Query(sQuery); return(m.UserID); }
public void RegisterUser(MClient c, MNetMessage m) { MUserAccount mu = MUserAccount.Deserialize <MUserAccount>(m.Payload); mu.CopyTo(c.Account); c.Account.ClientIP = c.Address.ToString(); string UserID = _DataBase.RegisterUser(c.Account); MNetMessage mn = new MNetMessage(); mn.Command = MNetMessage.REGISTERUSER; mn.UserID = UserID; MChangeDetailsResult res = new MChangeDetailsResult(); res.Success = true; res.Message = "User Registered"; mn.Payload = res.Serialize(); Send(c, "Message", mn.Serialize()); }
public MUserAccount GetPlayerByEmail(string Email, string Password) { MUserAccount mu = new MUserAccount(); mu.Email = Email; mu.Password = Password; string sQuery = string.Format("SELECT * from users where email='{0}' and password='******';", Email, Password); DataTable dt = QueryReader(sQuery); if (dt.Rows.Count == 0) { return(null); } //DataRow row = dt.Rows[0]["userid"]; //mu.UserID = row.ItemArray.GetValue("userid"].ToString(); mu.UserID = dt.Rows[0]["userid"].ToString(); mu.UserName = dt.Rows[0]["screenname"].ToString(); mu.AvatarID = dt.Rows[0]["avatarid"].ToString(); mu.TotalObjects = (int)dt.Rows[0]["totalobjects"]; mu.Credit = (int)dt.Rows[0]["wallet"]; return(mu); }
public MClient() { Account = new MUserAccount(); Account.HomePosition = DefaultHome; }