void CheckGroups() { //Server.Log("Chk Grp", LogTypesEnum.Debug); if (!DatabaseController.TableExists("groups")) { Server.Log("Table No Exists", LogTypesEnum.Debug); DatabaseController.CreateNewTable("groups", new[] { DataTypes.Name, DataTypes.Message, DataTypes.Name, DataTypes.Byte, DataTypes.Bool, DataTypes.Bool, DataTypes.Bool, DataTypes.Int}); } if (!DatabaseController.TableExists("groups")) { throw new NullReferenceException("Table GROUPS creation FAILED!"); } groups = DatabaseController.FindTable("groups"); if(groups.RowCount == 0) { InitializeBaseGroups(); } for (int i = 0; i < groups.RowCount; ++i) { //Server.Log("Loading GDB #" + i, LogTypesEnum.Debug); new PreLoader.GDB(i, groups.GetData(i)); } }
void CheckUsers() { //Server.Log("Chk Usr", LogTypesEnum.Debug); if (!DatabaseController.TableExists("users")) { Server.Log("Table No Exists", LogTypesEnum.Debug); DatabaseController.CreateNewTable("users", new[] { DataTypes.Name, DataTypes.Message, DataTypes.Name, DataTypes.Byte, DataTypes.Int, DataTypes.Bool, DataTypes.Bool }); } if (!DatabaseController.TableExists("users")) { throw new NullReferenceException("Table USERS creation FAILED!"); } users = DatabaseController.FindTable("users"); for (int i = 0; i < users.RowCount; ++i) { //Server.Log("Loading PDB #" + i, LogTypesEnum.Debug); new PreLoader.PDB(i, users.GetData(i)); } }
public void CreateNewTable(string name, DataTypes[] dataTypes) { if(_keyFileStream == null) { _keyFileStream = new FileStream(KeyfilePath, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None); } try { _keyFileStream.Position = _keyFileStream.Length; name = name.Trim(); if (name.Length > 16) { throw (new ArgumentException("Table name must be no longer than 16 characters!")); } //_keyFileStream = File.Open(KeyfilePath, FileMode.Append); var toWrite = Encode.GetBytes(name.PadRight(16)); _keyFileStream.Write(toWrite, 0, 16); _keyFileStream.WriteByte((byte)dataTypes.Length); for (int i = 0; i < dataTypes.Length; i++) _keyFileStream.WriteByte((byte)dataTypes[i]); _keyFileStream.Flush(); //_keyFileStream.Close(); var table = new Table(this, name, DatabaseFilesPrePath + name, dataTypes, GetTotalSize(dataTypes)); LoadedTables.Add(name.ToLower(), table); } catch(Exception e) { //if (_keyFileStream != null) _keyFileStream.Close(); Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } }