2017-02-26 14:51:11 -05:00
/ *
2017-02-24 20:24:57 -05:00
* MIT License
*
* Copyright ( c ) 2017 Michael VanOverbeek and ShiftOS devs
*
* Permission is hereby granted , free of charge , to any person obtaining a copy
* of this software and associated documentation files ( the "Software" ) , to deal
* in the Software without restriction , including without limitation the rights
* to use , copy , modify , merge , publish , distribute , sublicense , and / or sell
* copies of the Software , and to permit persons to whom the Software is
* furnished to do so , subject to the following conditions :
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software .
*
* THE SOFTWARE IS PROVIDED "AS IS" , WITHOUT WARRANTY OF ANY KIND , EXPRESS OR
* IMPLIED , INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY ,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT . IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM , DAMAGES OR OTHER
* LIABILITY , WHETHER IN AN ACTION OF CONTRACT , TORT OR OTHERWISE , ARISING FROM ,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE .
* /
using System ;
2017-01-08 18:36:09 -05:00
using System.Collections.Generic ;
2017-02-02 09:47:23 -05:00
using System.Dynamic ;
2017-01-08 18:36:09 -05:00
using System.Linq ;
2017-06-03 11:29:21 -04:00
using System.Threading ;
2017-01-08 18:36:09 -05:00
namespace ShiftOS.Objects
{
//Better to store this stuff server-side so we can do some neat stuff with hacking...
public class Save
{
2017-06-02 11:38:38 -04:00
public bool MusicEnabled = true ;
public bool SoundEnabled = true ;
public int MusicVolume = 100 ;
2017-05-13 10:22:51 -04:00
2017-05-01 15:23:46 -04:00
[Obsolete("This save variable is no longer used in Beta 2.4 and above of ShiftOS. Please use ShiftOS.Engine.SaveSystem.CurrentUser.Username to access the current user's username.")]
2017-01-08 18:36:09 -05:00
public string Username { get ; set ; }
2017-05-01 15:23:46 -04:00
2017-06-03 11:29:21 -04:00
private List < Action > _setCpCallbacks = new List < Action > ( ) ; // everything in this list is called by Codepoints.set() and syncCp().
private ulong _cp = 0 ; // locally cached codepoints counter
private Object _cpLock = new Object ( ) ; // locked when modifying or reading the codepoints counter
private Object _webLock = new Object ( ) ; // locked when communicating with the server
private Timer _updTimer ; // timer to start a new sync thread every 5 minutes
// Sync local Codepoints count with the server.
public void syncCp ( )
{
new Thread ( ( ) = >
{
lock ( _cpLock )
{
lock ( _webLock )
{
var uc = new ShiftOS . Unite . UniteClient ( "" , UniteAuthToken ) ;
_cp = uc . GetCodepoints ( ) ;
}
}
foreach ( Action a in _setCpCallbacks )
a ( ) ;
} ) . Start ( ) ;
}
// we have to write these wrapper functions so we can keep _setCpCallbacks private,
// so that it doesn't get serialised
public void addSetCpCallback ( Action callback )
{
_setCpCallbacks . Add ( callback ) ;
}
public void removeSetCpCallback ( Action callback )
{
_setCpCallbacks . Remove ( callback ) ;
}
2017-05-21 08:31:48 -04:00
2017-06-10 10:17:10 -04:00
public bool IsSandbox = false ;
2017-05-29 20:08:30 -04:00
public ulong Codepoints
2017-05-21 08:31:48 -04:00
{
get
{
2017-06-10 10:17:10 -04:00
if ( IsSandbox = = true )
return 0 ;
2017-06-03 11:29:21 -04:00
if ( _updTimer = = null )
_updTimer = new Timer ( ( o ) = > syncCp ( ) , null , 0 , 300000 ) ;
lock ( _cpLock )
2017-05-29 12:41:49 -04:00
{
2017-05-21 08:31:48 -04:00
return _cp ;
2017-05-29 12:41:49 -04:00
}
2017-05-21 08:31:48 -04:00
}
set
{
2017-06-10 10:17:10 -04:00
if ( IsSandbox = = true )
return ;
2017-06-03 11:29:21 -04:00
lock ( _cpLock )
{
_cp = value ;
new Thread ( ( ) = >
2017-05-29 12:41:49 -04:00
{
2017-06-03 11:29:21 -04:00
lock ( _webLock )
{
try
{
var uc = new ShiftOS . Unite . UniteClient ( "" , UniteAuthToken ) ;
uc . SetCodepoints ( value ) ;
}
catch
{ }
}
} )
2017-05-29 12:41:49 -04:00
{
2017-06-03 11:29:21 -04:00
IsBackground = false
} . Start ( ) ;
}
foreach ( Action a in _setCpCallbacks )
a ( ) ;
2017-05-21 08:31:48 -04:00
}
}
2017-05-01 15:23:46 -04:00
2017-01-08 18:36:09 -05:00
public Dictionary < string , bool > Upgrades { get ; set ; }
public int StoryPosition { get ; set ; }
public string Language { get ; set ; }
2017-01-17 17:08:27 -05:00
public string MyShop { get ; set ; }
2017-01-08 18:36:09 -05:00
public List < string > CurrentLegions { get ; set ; }
public int MajorVersion { get ; set ; }
public int MinorVersion { get ; set ; }
public int Revision { get ; set ; }
2017-04-30 11:44:29 -04:00
public string UniteAuthToken { get ; set ; }
2017-03-06 12:01:16 -05:00
public bool IsPatreon { get ; set ; }
2017-04-09 10:00:16 -04:00
public UserClass Class { get ; set ; }
public double RawReputation { get ; set ; }
public Reputation Reputation
{
get
{
return ( Reputation ) ( ( int ) Math . Round ( RawReputation ) ) ;
}
}
2017-03-06 12:01:16 -05:00
2017-01-08 18:36:09 -05:00
public string Password { get ; set ; }
2017-02-04 19:11:53 -05:00
public bool PasswordHashed { get ; set ; }
2017-01-08 18:36:09 -05:00
public string SystemName { get ; set ; }
2017-02-02 09:47:23 -05:00
private dynamic _settings = new SettingsObject ( ) ;
2017-01-08 18:36:09 -05:00
2017-02-26 14:51:11 -05:00
public int ShiftnetSubscription { get ; set ; }
2017-02-12 18:35:15 -05:00
public Guid ID { get ; set ; }
public bool IsMUDAdmin { get ; set ; }
2017-02-02 09:47:23 -05:00
public dynamic Settings
{
get
{
return _settings ;
}
}
2017-01-08 18:36:09 -05:00
2017-03-05 14:36:12 -05:00
public int LastMonthPaid { get ; set ; }
2017-03-06 20:05:24 -05:00
public List < string > StoriesExperienced { get ; set ; }
2017-03-05 14:36:12 -05:00
2017-01-08 18:36:09 -05:00
public int CountUpgrades ( )
{
int count = 0 ;
foreach ( var upg in Upgrades )
{
if ( upg . Value = = true )
count + + ;
}
return count ;
}
2017-04-30 20:28:31 -04:00
2017-05-01 16:09:46 -04:00
public List < ClientSave > Users { get ; set ; }
2017-06-04 15:18:53 -04:00
/// <summary>
/// DO NOT MODIFY THIS. EVER. YOU WILL BREAK THE STORYLINE. Let the engine do it's job.
/// </summary>
public string PickupPoint { get ; set ; }
2017-01-08 18:36:09 -05:00
}
2017-02-02 09:47:23 -05:00
public class SettingsObject : DynamicObject
{
private Dictionary < string , object > _settings = null ;
public SettingsObject ( )
{
_settings = new Dictionary < string , object > ( ) ;
}
public override IEnumerable < string > GetDynamicMemberNames ( )
{
return _settings . Keys . ToArray ( ) ;
}
public override bool TryGetMember ( GetMemberBinder binder , out object result )
{
if ( _settings . ContainsKey ( binder . Name ) )
{
result = _settings [ binder . Name ] ;
return true ;
}
else
{
result = null ;
return false ;
}
}
public override bool TrySetMember ( SetMemberBinder binder , object value )
{
2017-02-08 18:01:13 -05:00
try
2017-02-02 09:47:23 -05:00
{
2017-02-08 18:01:13 -05:00
if ( _settings . ContainsKey ( binder . Name ) )
{
_settings [ binder . Name ] = value ;
}
else
{
_settings . Add ( binder . Name , value ) ;
}
2017-02-02 09:47:23 -05:00
}
2017-02-08 18:01:13 -05:00
catch
2017-02-02 09:47:23 -05:00
{
2017-02-08 18:01:13 -05:00
2017-02-02 09:47:23 -05:00
}
return true ;
}
}
2017-01-08 18:36:09 -05:00
}