├── README
├── reference
└── System.Data.SQLite.dll
└── source
├── Account.cs
├── AccountBanner.cs
├── D3Sharp.db
├── D3SharpDatabase.csproj
├── D3SharpDatabase.sln
├── D3SharpDatabase.suo
├── Database.cs
├── ExperienceLevels.cs
├── Hero.cs
├── HeroClasses.cs
├── HeroDetails.cs
├── HeroGender.cs
├── HeroTitles.cs
├── Program.cs
├── Properties
└── AssemblyInfo.cs
├── app.config
├── bin
└── Debug
│ ├── D3Database.vshost.exe.config
│ ├── D3Sharp.db
│ ├── D3SharpDatabase.exe
│ ├── D3SharpDatabase.exe.config
│ ├── D3SharpDatabase.pdb
│ ├── D3SharpDatabase.vshost.exe
│ ├── D3SharpDatabase.vshost.exe.config
│ ├── D3SharpDatabase.vshost.exe.manifest
│ ├── d3db_fixed.db
│ ├── d3sharp.sqlite
│ └── d3sharp_fixed20110918_2.sqlite
└── obj
└── x86
└── Debug
├── D3Database.csproj.FileListAbsolute.txt
├── D3SharpDatabase.csproj.FileListAbsolute.txt
├── D3SharpDatabase.exe
├── D3SharpDatabase.pdb
├── DesignTimeResolveAssemblyReferencesInput.cache
└── ResolveAssemblyReference.cache
/README:
--------------------------------------------------------------------------------
1 | Requires http://sqlite.phxsoftware.com/
--------------------------------------------------------------------------------
/reference/System.Data.SQLite.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/reference/System.Data.SQLite.dll
--------------------------------------------------------------------------------
/source/Account.cs:
--------------------------------------------------------------------------------
1 | // ///////////////////////////////////////////////////////////////////////////////////////////////
2 | // @File: Account.cs
3 | //
4 | // @Project: D3SharpDatabase
5 | // @Version: 1.0
6 | // @Created: 21.09.2011
7 | // @Author: D3Sharp Database Team
8 | //
9 | // @Environment: Windows
10 | // @References: SQLite
11 | //
12 | // @Description: This file provides all account related database communication functions.
13 | //
14 | // @Usage: Database communication.
15 | // @Notes: You need SQLite installed to get this working.
16 | //
17 | // @Modifications: - 21-September-2010 (TeTuBe)
18 | //
19 | // ///////////////////////////////////////////////////////////////////////////////////////////////
20 | using System;
21 | using System.Collections.Generic;
22 | using System.Data.SQLite;
23 |
24 | namespace D3Database
25 | {
26 | public class Account
27 | {
28 | #region Properties
29 |
30 | ///
31 | /// The database ID for this account.
32 | ///
33 | public int Id { get; private set; }
34 |
35 | ///
36 | /// The name of this account.
37 | ///
38 | public string Name { get; private set; }
39 |
40 | ///
41 | /// The amount of gold associated with this account.
42 | ///
43 | public int Gold { get; set; }
44 |
45 | ///
46 | /// The gender of this account (1 = male, 2 = female)
47 | ///
48 | public int Gender { get; private set; }
49 |
50 | #endregion
51 |
52 | ///
53 | /// Constructor.
54 | ///
55 | /// Name of the account.
56 | /// Amount of gold.
57 | /// Account gender.
58 | public Account(string name, int gold, int gender)
59 | {
60 | Id = -1;
61 | Name = name;
62 | Gold = gold;
63 | Gender = gender;
64 | }
65 |
66 | ///
67 | /// Updates account information in the database.
68 | ///
69 | /// False on failure, otherwise true.
70 | public bool Save()
71 | {
72 | try
73 | {
74 | // initialize SQL statement
75 | SQLiteCommand command = new SQLiteCommand(string.Format("UPDATE account SET gold='{1}' WHERE account_id='{0}'", Id, Gold), Database.Instance.Connection);
76 | // execute SQL (update appropriate account row with new data)
77 | command.ExecuteNonQuery();
78 | return true;
79 | }
80 | catch (Exception e)
81 | {
82 | // red for errors
83 | Console.ForegroundColor = ConsoleColor.Red;
84 | Console.WriteLine("Failed to save hero to database:");
85 | // reset colour
86 | Console.ResetColor();
87 | // output exception detail
88 | Console.WriteLine(e.Message);
89 | return false;
90 | }
91 | }
92 |
93 | ///
94 | /// Inserts account information in the database.
95 | ///
96 | /// Account password.
97 | /// False if the account already exists, otherwise true.
98 | public bool Create(string password)
99 | {
100 | // false if default ID
101 | if (Id != -1)
102 | {
103 | return false;
104 | }
105 | // false if account exists in the database
106 | if (CheckIfAccountExists(Name))
107 | {
108 | return false;
109 | }
110 |
111 | // MD5 hash of account password
112 | string md5Password = GetMD5Hash(password);
113 |
114 | // initialize SQL statement
115 | SQLiteCommand command = new SQLiteCommand(string.Format("INSERT INTO account (account_name, password, gold, gender) VALUES('{0}','{1}','{2}','{3}')", Name, md5Password, Gold, Gender), Database.Instance.Connection);
116 |
117 | // execute SQL (insert account data into the database), return false if insertion failed
118 | if (command.ExecuteNonQuery() == 0)
119 | {
120 | return false;
121 | }
122 |
123 | // set instance ID to that of the inserted row
124 | Id = Database.Instance.GetLastInsertId();
125 | return true;
126 | }
127 |
128 | ///
129 | /// Checks if an account already exists in the database.
130 | ///
131 | /// Name of the account to check.
132 | /// True if the account already exists, otherwise false.
133 | public static bool CheckIfAccountExists(string account_name)
134 | {
135 | // initialize SQL statement
136 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_id FROM account WHERE account_name='{0}'", account_name), Database.Instance.Connection);
137 | // execute SQL (select row where account_name matches input)
138 | SQLiteDataReader reader = command.ExecuteReader();
139 | return reader.HasRows;
140 | }
141 |
142 | ///
143 | /// Checks if an account already exists in the database.
144 | ///
145 | /// ID of account to check.
146 | /// True if the account already exists, otherwise false.
147 | public static bool CheckIfAccountExists(int account_id)
148 | {
149 | // initialize SQL statement
150 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_id FROM account WHERE account_id='{0}'", account_id), Database.Instance.Connection);
151 | // execute SQL (select row where account_id matches input)
152 | SQLiteDataReader reader = command.ExecuteReader();
153 | return reader.HasRows;
154 | }
155 |
156 | ///
157 | /// Loads an account from the database.
158 | ///
159 | /// ID of the account to load.
160 | /// Account data.
161 | /// True on success, otherwise false.
162 | public static bool Load(int id, out Account account)
163 | {
164 | account = null;
165 |
166 | // initialize SQL statement
167 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_id, account_name, gold, gender FROM account WHERE account_id='{0}'", id), Database.Instance.Connection);
168 | // execute SQL (retrieve account data where account_id matches input)
169 | SQLiteDataReader reader = command.ExecuteReader();
170 |
171 | // continue if a row was returned
172 | if (reader.HasRows)
173 | {
174 | while (reader.Read())
175 | {
176 | account = new Account(reader.GetString(1), reader.GetInt32(2), reader.GetInt32(3));
177 | account.Id = reader.GetInt32(0);
178 | return true;
179 | }
180 | }
181 |
182 | return false;
183 | }
184 |
185 | ///
186 | /// Validates account credentials with those stored in the database.
187 | ///
188 | /// Account name.
189 | /// Account password.
190 | /// Reference to the account instance.
191 | /// False if account name and password hash don't match anything in the database, otherwise true.
192 | public static bool Authorize(string account_name, string password, out Account account)
193 | {
194 | account = null;
195 |
196 | // MD5 hash of account password
197 | string md5Password = GetMD5Hash(password);
198 |
199 | // initialize SQL statement
200 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_id FROM account WHERE account_name='{0}' AND password='{1}'", account_name, md5Password), Database.Instance.Connection);
201 | // execute SQL (retrieve row with account name and hashed password that match input)
202 | SQLiteDataReader reader = command.ExecuteReader();
203 |
204 | // false if no rows were returned
205 | if (!reader.HasRows)
206 | {
207 | return false;
208 | }
209 |
210 | reader.Read();
211 | int account_id = reader.GetInt32(0);
212 | return Load(account_id, out account);
213 | }
214 |
215 | ///
216 | /// Returns a collection of heroes associated with this account from the database.
217 | ///
218 | /// List of heroes associated with this account.
219 | public List GetHeroes()
220 | {
221 | // initialize collection
222 | List heroList = new List();
223 |
224 | // initialize SQL statement
225 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT hero_id FROM hero WHERE account_id='{0}'", Id), Database.Instance.Connection);
226 | // execute SQL (get hero ids from database where account_id matches if of this instance)
227 | SQLiteDataReader reader = command.ExecuteReader();
228 |
229 | if (reader.HasRows)
230 | {
231 | while (reader.Read())
232 | {
233 | int hero_id = reader.GetInt32(0);
234 | Hero hero;
235 | if (!Hero.Load(hero_id, out hero))
236 | {
237 | // red for errors
238 | Console.ForegroundColor = ConsoleColor.Red;
239 | Console.WriteLine("Failed to load hero with id: {0}", hero_id);
240 | // reset colour
241 | Console.ResetColor();
242 | }
243 | else
244 | {
245 | // add hero data to collection
246 | heroList.Add(hero);
247 | }
248 | }
249 | }
250 |
251 | return heroList;
252 | }
253 |
254 | ///
255 | /// Returns a collection of banners associated with this account from the database.
256 | ///
257 | /// List of banners associated with this account
258 | public List GetBanners()
259 | {
260 | // initialize collection
261 | List accountBannerList = new List();
262 |
263 | // initialize SQL statement
264 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_banner_id FROM account_banner WHERE account_id='{0}'", Id), Database.Instance.Connection);
265 | // execute SQL (retrieve banner id from database where account_id matches id of this instance)
266 | SQLiteDataReader reader = command.ExecuteReader();
267 |
268 | if (reader.HasRows)
269 | {
270 | while (reader.Read())
271 | {
272 | int account_banner_id = reader.GetInt32(0);
273 | AccountBanner accountBanner;
274 | if (!AccountBanner.Load(account_banner_id, out accountBanner))
275 | {
276 | // red for errors
277 | Console.ForegroundColor = ConsoleColor.Red;
278 | Console.WriteLine("Failed to load account banner with id: {0}", account_banner_id);
279 | // reset colour
280 | Console.ResetColor();
281 | }
282 | else
283 | {
284 | // add banner to collection
285 | accountBannerList.Add(accountBanner);
286 | }
287 |
288 | }
289 | }
290 |
291 | return accountBannerList;
292 | }
293 |
294 | ///
295 | /// Returns a string that represents the current object.
296 | ///
297 | /// A string that represents the current object.
298 | public override string ToString()
299 | {
300 | return String.Format("{0}\t{1}\t{2}\t{3}", Id, Name, Gold, Gender);
301 | }
302 |
303 | ///
304 | /// Creates an MD5 hash of a string.
305 | ///
306 | /// The string to hash.
307 | /// A cryptographic hash of the input string
308 | private static string GetMD5Hash(string input)
309 | {
310 | System.Security.Cryptography.MD5CryptoServiceProvider x = new System.Security.Cryptography.MD5CryptoServiceProvider();
311 | byte[] bs = System.Text.Encoding.UTF8.GetBytes(input);
312 | bs = x.ComputeHash(bs);
313 | System.Text.StringBuilder s = new System.Text.StringBuilder();
314 | foreach (byte b in bs)
315 | s.Append(b.ToString("x2").ToLower());
316 | string password = s.ToString();
317 | return password;
318 | }
319 |
320 | }
321 | }
322 |
--------------------------------------------------------------------------------
/source/AccountBanner.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | public class AccountBanner
10 | {
11 | public int Id {get; private set;}
12 | public int AccountId { get; private set; }
13 | public int BackgroundColor { get; private set; }
14 | public int Banner { get; private set; }
15 | public int Pattern { get; private set; }
16 | public int PatternColor { get; private set; }
17 | public int Placement { get; private set; }
18 | public int SigilAccent { get; private set; }
19 | public int SigilMain { get; private set; }
20 | public int SigilColor { get; private set; }
21 | public bool UseSigilVariant { get; private set; }
22 |
23 | public AccountBanner(int AccountId, int BackgroundColor, int Banner, int Pattern, int PatternColor, int Placement, int SigilAccent, int SigilMain, int SigilColor, bool UsesigilVariant)
24 | {
25 | this.Id = -1;
26 | this.AccountId = AccountId;
27 | this.BackgroundColor = BackgroundColor;
28 | this.Banner = Banner;
29 | this.Pattern = Pattern;
30 | this.Placement = Placement;
31 | this.SigilAccent = SigilAccent;
32 | this.SigilColor = SigilColor;
33 | this.SigilMain = SigilMain;
34 | this.UseSigilVariant = UseSigilVariant;
35 |
36 | }
37 |
38 | public bool Save()
39 | {
40 | try
41 | {
42 | SQLiteCommand command = new SQLiteCommand(string.Format("UPDATE account_banner SET background_color='{1}', banner='{2}', pattern='{3}', pattern_color='{4}', placement='{5}', sigil_accent='{6}', sigil_main='{7}', sigil_color='{8}', use_sigil_variant='{9}' WHERE account_id='{0}'", AccountId,BackgroundColor,Banner,Pattern,PatternColor,Placement,SigilAccent,SigilMain,SigilColor,UseSigilVariant), Database.Instance.Connection);
43 | command.ExecuteNonQuery();
44 | return true;
45 | }
46 | catch (Exception e)
47 | {
48 | Console.WriteLine("Failed to save Account Banner exception: {0}", e.Message);
49 | return false;
50 | }
51 | }
52 |
53 | public bool Create()
54 | {
55 | if (Id != -1)
56 | return false;
57 | if (!Account.CheckIfAccountExists(AccountId))
58 | return false;
59 | SQLiteCommand command = new SQLiteCommand(string.Format("INSERT INTO account_banner (account_id, background_color, banner, pattern, pattern_color, placement, sigil_accent, sigil_main, sigil_color, use_sigil_variant) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}')", AccountId, BackgroundColor, Banner, Pattern, PatternColor, Placement, SigilAccent, SigilMain, SigilColor, UseSigilVariant ? 1 : 0), Database.Instance.Connection);
60 | int affectedRows = command.ExecuteNonQuery();
61 | if (affectedRows == 0)
62 | return false;
63 | Id = Database.Instance.GetLastInsertId();
64 | return true;
65 | }
66 |
67 |
68 | public static bool Load(int id, out AccountBanner accountbanner)
69 | {
70 | accountbanner = null;
71 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_banner_id, account_id, background_color, banner, pattern, pattern_color, placement, sigil_accent, sigil_main, sigil_color, use_sigil_variant FROM account_banner WHERE account_banner_id='{0}'", id), Database.Instance.Connection);
72 | SQLiteDataReader reader = command.ExecuteReader();
73 | if (reader.HasRows)
74 | {
75 | while (reader.Read())
76 | {
77 | var account_banner_id = reader.GetInt32(0);
78 | var account_id = reader.GetInt32(1);
79 | var background_color = reader.GetInt32(2);
80 | var banner = reader.GetInt32(3);
81 | var pattern = reader.GetInt32(4);
82 | var pattern_color = reader.GetInt32(5);
83 | var placement = reader.GetInt32(6);
84 | var sigil_accent = reader.GetInt32(7);
85 | var sigil_main = reader.GetInt32(8);
86 | var sigil_color = reader.GetInt32(9);
87 | var use_sigil_variant = reader.GetBoolean(10);
88 | accountbanner = new AccountBanner(account_id, background_color, banner, pattern, pattern_color, placement, sigil_accent, sigil_main, sigil_color, use_sigil_variant);
89 | accountbanner.Id = account_banner_id;
90 | return true;
91 | }
92 | }
93 | return false;
94 | }
95 |
96 |
97 |
98 | public override string ToString()
99 | {
100 | return String.Format("BannerId: {0}, AccId: {1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}", Id, AccountId, BackgroundColor,Banner,Pattern,PatternColor,Placement,SigilAccent,SigilMain,SigilColor,UseSigilVariant);
101 | }
102 |
103 |
104 | }
105 | }
106 |
--------------------------------------------------------------------------------
/source/D3Sharp.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/D3Sharp.db
--------------------------------------------------------------------------------
/source/D3SharpDatabase.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Debug
5 | x86
6 | 8.0.30703
7 | 2.0
8 | {97446941-EB80-485B-89F6-6CB18073E505}
9 | Exe
10 | Properties
11 | D3SharpDatabase
12 | D3SharpDatabase
13 | v3.5
14 | Client
15 | 512
16 |
17 |
18 | x86
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | x86
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 | False
41 | ..\reference\System.Data.SQLite.dll
42 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
65 |
72 |
--------------------------------------------------------------------------------
/source/D3SharpDatabase.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 11.00
3 | # Visual Studio 2010
4 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "D3SharpDatabase", "D3SharpDatabase.csproj", "{97446941-EB80-485B-89F6-6CB18073E505}"
5 | EndProject
6 | Global
7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
8 | Debug|x86 = Debug|x86
9 | Release|x86 = Release|x86
10 | EndGlobalSection
11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
12 | {97446941-EB80-485B-89F6-6CB18073E505}.Debug|x86.ActiveCfg = Debug|x86
13 | {97446941-EB80-485B-89F6-6CB18073E505}.Debug|x86.Build.0 = Debug|x86
14 | {97446941-EB80-485B-89F6-6CB18073E505}.Release|x86.ActiveCfg = Release|x86
15 | {97446941-EB80-485B-89F6-6CB18073E505}.Release|x86.Build.0 = Release|x86
16 | EndGlobalSection
17 | GlobalSection(SolutionProperties) = preSolution
18 | HideSolutionNode = FALSE
19 | EndGlobalSection
20 | EndGlobal
21 |
--------------------------------------------------------------------------------
/source/D3SharpDatabase.suo:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/D3SharpDatabase.suo
--------------------------------------------------------------------------------
/source/Database.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | public class Database
10 | {
11 | #region Singleton
12 | private static volatile Database instance;
13 | private static object syncRoot = new Object();
14 |
15 | private Database() { }
16 |
17 | public static Database Instance
18 | {
19 | get
20 | {
21 | if (instance == null)
22 | {
23 | lock (syncRoot)
24 | {
25 | if (instance == null)
26 | instance = new Database();
27 | }
28 | }
29 |
30 | return instance;
31 | }
32 | }
33 | #endregion
34 |
35 | public SQLiteConnection Connection{get; private set;}
36 |
37 | public void Connect(string databaseFile)
38 | {
39 | Connection = new SQLiteConnection(string.Format("Data Source={0}", databaseFile));
40 | Connection.Open();
41 | }
42 |
43 | public int GetLastInsertId()
44 | {
45 | var command = new SQLiteCommand("SELECT last_insert_rowid()", Database.Instance.Connection);
46 | return Convert.ToInt32(command.ExecuteScalar());
47 | }
48 |
49 | public int Update(string table, List insertParameters, string whereSQL, List whereParameters)
50 | {
51 | string sql = "UPDATE {0} SET {1} WHERE {2}";
52 |
53 | var sbInsert = new StringBuilder();
54 | foreach(var parameter in insertParameters)
55 | sbInsert.AppendFormat("`{0}`={1},", parameter.ParameterName.Replace("@",""), parameter.ParameterName);
56 | sbInsert.Length -= 1;
57 |
58 | sql = string.Format(sql, table, sbInsert, whereSQL);
59 |
60 | var command = new SQLiteCommand(sql, Database.Instance.Connection);
61 | command.Parameters.AddRange(insertParameters.ToArray());
62 | command.Parameters.AddRange(whereParameters.ToArray());
63 | return command.ExecuteNonQuery();
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/source/ExperienceLevels.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | public static class ExperienceLevels
10 | {
11 | public static bool Load(int level, out int experience)
12 | {
13 | experience = -1;
14 | try {
15 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT experience FROM experience_levels WHERE level='{0}'", level), Database.Instance.Connection);
16 | SQLiteDataReader reader = command.ExecuteReader();
17 | if (reader.HasRows)
18 | {
19 | while (reader.Read())
20 | {
21 | experience = reader.GetInt32(0);
22 | return true;
23 | }
24 | }
25 | }
26 |
27 | catch (Exception e)
28 | {
29 | Console.WriteLine("ExperienceLevels: Failed to load experience levels! Exception: {0}", e.Message);
30 | return false;
31 | }
32 | return false;
33 | }
34 |
35 |
36 |
37 |
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/source/Hero.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | public class Hero
10 | {
11 | #region Properties
12 |
13 | ///
14 | /// The database id of this hero.
15 | ///
16 | public int Id { get; private set; }
17 |
18 | ///
19 | /// The database id of the account that this hero is associated with.
20 | ///
21 | public int AccountId { get; private set; }
22 |
23 | ///
24 | /// The name of this hero
25 | ///
26 | public string Name { get; private set; }
27 |
28 | ///
29 | /// The class of this hero (1 = Wizard, 2 = Witch Doctor, 3 = Demon Hunter, 4 = Monk, 5 = Barbarian)
30 | ///
31 | public int HeroClass { get; private set; }
32 |
33 | ///
34 | /// The gender for this hero (1 = male, 2 = female).
35 | ///
36 | public int Gender { get; set; }
37 |
38 | ///
39 | /// The current total experience points for this hero.
40 | ///
41 | public int Experience { get; set; }
42 |
43 | ///
44 | /// The current level of this hero.
45 | ///
46 | public int Level { get; set; }
47 |
48 | #endregion
49 |
50 | ///
51 | /// Constructor.
52 | ///
53 | /// Hero name
54 | /// Hero class (1 = Wizard, 2 = Witch Doctor, 3 = Demon Hunter, 4 = Monk, 5 = Barbarian)
55 | /// Gender (1 = male, 2 = female)
56 | /// Experience points
57 | /// Hero level
58 | public Hero(int accountId, string name, int heroClass, int gender, int experience, int level)
59 | {
60 | Id = -1;
61 | AccountId = accountId;
62 | Name = name;
63 | HeroClass = heroClass;
64 | Gender = gender;
65 | Experience = experience;
66 | Level = level;
67 | }
68 |
69 | public bool Save()
70 | {
71 | try
72 | {
73 | // initialize SQL statement
74 | SQLiteCommand command = new SQLiteCommand(string.Format("UPDATE hero SET experience='{0}', level='{1}' WHERE hero_id='{2}'", Experience, Level, Id), Database.Instance.Connection);
75 | // execute SQL (update appropriate hero row with new data)
76 | command.ExecuteNonQuery();
77 |
78 | return true;
79 | }
80 | catch (Exception e)
81 | {
82 | Console.ForegroundColor = ConsoleColor.Red;
83 | Console.WriteLine("Failed to save hero exception: ");
84 | Console.ResetColor();
85 | Console.WriteLine(e.Message);
86 | return false;
87 | }
88 | }
89 |
90 | ///
91 | /// Saves the current hero as a new record in the database.
92 | ///
93 | /// True on success, otherwise false.
94 | public bool Create()
95 | {
96 | // check that id is the default (id is set by the database)
97 | if (Id != -1)
98 | {
99 | return false;
100 | }
101 |
102 | // check that an account with the specified account id exists
103 | if (!Account.CheckIfAccountExists(AccountId))
104 | {
105 | return false;
106 | }
107 |
108 | // check that a hero with this name does not already exist
109 | if (CheckIfHeroExists(AccountId, Name))
110 | {
111 | return false;
112 | }
113 |
114 | // initialize SQL statement
115 | SQLiteCommand command = new SQLiteCommand(string.Format("INSERT INTO hero (account_id, name, hero_class_id, hero_gender_id, experience, level) VALUES('{0}','{1}','{2}','{3}', '{4}', '{5}')", AccountId, Name, HeroClass, Gender, Experience, Level), Database.Instance.Connection);
116 |
117 | // execute SQL (create new record in database)
118 | int affectedRows = command.ExecuteNonQuery();
119 |
120 | // check that command succeeded
121 | if (affectedRows == 0)
122 | {
123 | return false;
124 | }
125 |
126 | // set instance id to the id assigned by the database
127 | Id = Database.Instance.GetLastInsertId();
128 | return true;
129 | }
130 |
131 | ///
132 | /// Queries the database to determine if a hero with the specified name and account id exists.
133 | ///
134 | /// The id of the account associated with the hero.
135 | /// The name of the hero.
136 | /// True if a hero with the specified name and account id exists in the database, otherwise false.
137 | private bool CheckIfHeroExists(int account_id, string hero_name)
138 | {
139 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT hero_id FROM hero WHERE account_id='{0}' AND name='{1}'", account_id, hero_name), Database.Instance.Connection);
140 | SQLiteDataReader reader = command.ExecuteReader();
141 | return reader.HasRows;
142 | }
143 |
144 | ///
145 | /// Retrieves data for a specific hero from the database.
146 | ///
147 | /// The hero_id of the desired hero.
148 | /// Reference to an existing Hero instance where data will be stored on success.
149 | /// True on success, otherwise false.
150 | public static bool Load(int id, out Hero hero)
151 | {
152 | // clear hero instance
153 | hero = null;
154 |
155 | // initialize SQL statement
156 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT hero_id, account_id, name, hero_class_id, hero_gender_id, experience, level FROM hero WHERE hero.hero_id='{0}'", id), Database.Instance.Connection);
157 |
158 | // execute SQL (retrieve hero data for the hero whose hero_id matches the input id
159 | SQLiteDataReader reader = command.ExecuteReader();
160 |
161 | if (reader.HasRows)
162 | {
163 | while (reader.Read())
164 | {
165 | // load data into hero instance
166 | hero = new Hero(reader.GetInt32(1), reader.GetString(2), reader.GetInt32(3), reader.GetInt32(4), reader.GetInt32(5), reader.GetInt32(6));
167 | // set hero id (not set by constructor)
168 | hero.Id = reader.GetInt32(0);
169 | return true;
170 | }
171 | }
172 |
173 | return false;
174 | }
175 |
176 | ///
177 | /// Returns a string that represents the current object.
178 | ///
179 | /// A string that represents the current object.
180 | public override string ToString()
181 | {
182 | return String.Format("Id: {0}, Name: {1}, HeroClass: {2}, Gender: {3}, Exp: {4}, Level: {5}", Id, Name, HeroClass, Gender, Experience, Level);
183 | }
184 | }
185 | }
186 |
--------------------------------------------------------------------------------
/source/HeroClasses.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | //TODO
10 | //Implementation of hero_class and SQL-Lite functions.
11 | public class HeroClasses
12 | {
13 | public int Id_Wizard { get; set; }
14 | public int Id_Witch_Doctor { get; set; }
15 | public int Id_Demon_Hunter { get; set; }
16 | public int Id_Monk { get; set; }
17 | public int Id_Barbarian { get; set; }
18 |
19 | public HeroClasses (int id_wizard,
20 | int id_witch_doctor,
21 | int id_demon_hunter,
22 | int id_monk,
23 | int id_barbarian)
24 | {
25 | Id_Wizard = id_wizard;
26 | Id_Witch_Doctor = id_witch_doctor;
27 | Id_Demon_Hunter = id_demon_hunter;
28 | Id_Monk = id_monk;
29 | Id_Barbarian = id_barbarian;
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/source/HeroDetails.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | // TODO
10 | // Implementation of hero_details and SQL_Lite functions.
11 | public class HeroDetails
12 | {
13 | public int Id { get; private set; }
14 | public int Title_Id { get; set; }
15 | public int BlockAmount { get; set; }
16 | public int BlockChance { get; set; }
17 | public int DodgeChance { get; set; }
18 | public int DamageReduction { get; set; }
19 | public int AttackDamageBonus { get; set; }
20 | public int PrecisionCritBonus{ get; set; }
21 | public int DefenseDamageReduction { get; set; }
22 | public int VitalityLife { get; set; }
23 | public int Armor { get; set; }
24 | public int Attack { get; set; }
25 | public int Precision { get; set; }
26 | public int Defense { get; set; }
27 | public int Vitality { get; set; }
28 | public int DamageIncrease { get; set; }
29 | public int AttacksPerSecond { get; set; }
30 | public int CritDamageBonus { get; set; }
31 | public int CritChanceBonus { get; set; }
32 | public int CastingSpeed { get; set; }
33 | public int LifePerKill { get; set; }
34 | public int LifePerHit { get; set; }
35 | public int MovementSpeed { get; set; }
36 | public int GoldFind { get; set; }
37 | public int Life { get; set; }
38 | public int LifePerSecond { get; set; }
39 | public int LifeSteal { get; set; }
40 | public int MagicFind { get; set; }
41 | public int FuryGain { get; set; }
42 | public int SpiritGain { get; set; }
43 | public int ManaGain { get; set; }
44 | public int ArcanumGain { get; set; }
45 | public int HatredGain { get; set; }
46 | public int DisciplineGain { get; set; }
47 | public int MaxMana { get; set; }
48 | public int MaxArcanum { get; set; }
49 | public int MaxHatred { get; set; }
50 | public int MaxFury { get; set; }
51 | public int MaxDiscipline { get; set; }
52 | public int MaxSpirit { get; set; }
53 | // Whats the deal with the first two id and herodetailid, can remove from constructor if unneeded - DarkLotus
54 | public HeroDetails (int hero_detail_id, int id, int title_id, int blockamount,
55 | int blockchance, int dodgechance,
56 | int damagereduction, int attackbonusdamage,
57 | int precisioncritbonus,
58 | int defensedamagereduction, int vitalitylife,
59 | int armor, int attack, int precision,
60 | int defense, int vitality,
61 | int damageincrease, int attackspersecond,
62 | int critdamagebonus, int critchancebonus,
63 | int castingspeed, int lifeperkill,
64 | int lifeperhit, int movementspeed,
65 | int goldfind, int life, int lifepersecond,
66 | int lifesteal, int magicfind, int furygain,
67 | int spiritgain, int managain,
68 | int arcanumgain, int hatredgain,
69 | int disciplinegain, int maxmana,
70 | int maxarcanum, int maxhatred,
71 | int maxfury, int maxdiscipline,
72 | int maxspirit)
73 | {
74 |
75 | Id = -1;
76 | Title_Id = title_id;
77 | BlockAmount = blockamount;
78 | BlockChance = blockchance;
79 | DodgeChance = dodgechance;
80 | DamageReduction = damagereduction;
81 | AttackDamageBonus = attackbonusdamage;
82 | PrecisionCritBonus = precisioncritbonus;
83 | DefenseDamageReduction = defensedamagereduction;
84 | VitalityLife = vitalitylife;
85 | Armor = armor;
86 | Attack = attack;
87 | Precision = precision;
88 | Defense = defense;
89 | Vitality = vitality;
90 | DamageIncrease = damageincrease;
91 | AttacksPerSecond = attackspersecond;
92 | CritDamageBonus = critdamagebonus;
93 | CritChanceBonus =critchancebonus;
94 | CastingSpeed = castingspeed;
95 | LifePerKill = lifeperkill;
96 | LifePerHit = lifeperhit;
97 | MovementSpeed = movementspeed;
98 | GoldFind = goldfind;
99 | Life = life;
100 | LifePerSecond = lifepersecond;
101 | LifeSteal = lifesteal;
102 | MagicFind = magicfind;
103 | FuryGain = furygain;
104 | SpiritGain = spiritgain;
105 | ManaGain = managain;
106 | ArcanumGain = arcanumgain;
107 | HatredGain = hatredgain;
108 | DisciplineGain = disciplinegain;
109 | MaxMana = maxmana;
110 | MaxArcanum = maxarcanum;
111 | MaxHatred = maxhatred;
112 | MaxFury = maxfury;
113 | MaxDiscipline = maxdiscipline;
114 | MaxSpirit = maxspirit;
115 | }
116 |
117 | public bool Save()
118 | {
119 | //stub todo
120 | // RA3OR: hero_id != hero_detail_id? whats the difference?
121 | // RA3OR: not using hero_detail_id
122 | try
123 | {
124 | SQLiteCommand command = new SQLiteCommand(string.Format("UPDATE hero_details SET title_id='{1}', BlockAmount='{2}', BlockChance='{3}', DodgeChance='{4}', DamageReduction='{5}', AttackDamageBonus='{6}', PrecisionCritBonus='{7}', DefenseDamageReduction='{8}', VitalityLife='{9}', Armor='{10}', Attack='{11}', Precision='{12}', Defense='{13}', Vitality='{14}', DamageIncrease='{15}', AttacksPerSecond='{16}', CritDamageBonus='{17}', CritChanceBonus='{18}', CastingSpeed='{19}', LifePerKill='{20}', LifePerHit='{21}', MovementSpeed='{22}', GoldFind='{23}', Life='{24}', LifePerSecond='{25}', LifeSteal='{26}', MagicFind='{27}', FuryGain='{28}', SpiritGain='{29}', ManaGain='{30}', ArcanumGain='{31}', HatredGain='{32}', DisciplineGain='{33}', MaxMana='{34}', MaxArcanum='{35}', MaxHatred='{36}', MaxFury='{37}', MaxDiscipline='{38}', MaxSpirit='{39}' WHERE hero_id='{40}'", Title_Id, BlockAmount, BlockChance, DodgeChance, DamageReduction, AttackDamageBonus, PrecisionCritBonus, DefenseDamageReduction, VitalityLife, Armor, Attack, Precision, Defense, Vitality, DamageIncrease, AttacksPerSecond, CritDamageBonus, CritChanceBonus, CastingSpeed, LifePerKill, LifePerHit, MovementSpeed, GoldFind, Life, LifePerSecond, LifeSteal, MagicFind, FuryGain, SpiritGain, ManaGain, ArcanumGain, HatredGain, DisciplineGain, MaxMana, MaxArcanum, MaxHatred, MaxFury, MaxDiscipline, MaxSpirit, Id), Database.Instance.Connection);
125 | command.ExecuteNonQuery();
126 | return true;
127 | }
128 | catch (Exception e)
129 | {
130 | Console.WriteLine("Hero_Details: Failed to Save hero details! Exception: {0}", e.Message);
131 | return false;
132 | }
133 | }
134 |
135 | // TODO
136 | // Implement create function
137 | public bool Create()
138 | {
139 | // might not work HeroDetailId isnt autoincrement in the db i think?
140 | // RA3OR: for sqlite its enough to be primary key (and in structure it shows autorincrement)
141 | // RA3OR: hero_id != hero_detail_id? whats the difference?
142 | // RA3OR: not using hero_detail_id
143 | SQLiteCommand command = new SQLiteCommand(string.Format("INSERT INTO hero_details (hero_id, title_id, BlockAmount, BlockChance, DodgeChance, DamageReduction, AttackDamageBonus, PrecisionCritBonus, DefenseDamageReduction, VitalityLife, Armor, Attack, Precision, Defense, Vitality, DamageIncrease, AttacksPerSecond, CritDamageBonus, CritChanceBonus, CastingSpeed, LifePerKill, LifePerHit, MovementSpeed, GoldFind, Life, LifePerSecond, LifeSteal, MagicFind, FuryGain, SpiritGain, ManaGain, ArcanumGain, HatredGain, DisciplineGain, MaxMana, MaxArcanum, MaxHatred, MaxFury, MaxDiscipline, MaxSpirit) VALUES('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}','{14}','{15}','{16}','{17}','{18}','{19}','{20}','{21}','{22}','{23}','{24}','{25}','{26}','{27}','{28}','{29}','{31}','{32}','{33}','{34}','{35}','{36}','{37}','{38}','{39}','{40}','{41}')", Id, Title_Id, BlockAmount, BlockChance, DodgeChance, DamageReduction, AttackDamageBonus, PrecisionCritBonus, DefenseDamageReduction, VitalityLife, Armor, Attack, Precision, Defense, Vitality, DamageIncrease, AttacksPerSecond, CritDamageBonus, CritChanceBonus, CastingSpeed, LifePerKill, LifePerHit, MovementSpeed, GoldFind, Life, LifePerSecond, LifeSteal, MagicFind, FuryGain, SpiritGain, ManaGain, ArcanumGain, HatredGain, DisciplineGain, MaxMana, MaxArcanum, MaxHatred, MaxFury, MaxDiscipline, MaxSpirit), Database.Instance.Connection);
144 | int affectedRows = command.ExecuteNonQuery();
145 | if (affectedRows == 0)
146 | return false;
147 | //HeroDetailId = Database.Instance.GetLastInsertId();
148 | return true;
149 | }
150 |
151 | private bool CheckIfDetailsExists(int account_id, string title_id)
152 | {
153 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT hero_id FROM hero_details WHERE account_id='{0}' AND title_id='{1}'", account_id, title_id), Database.Instance.Connection);
154 | SQLiteDataReader reader = command.ExecuteReader();
155 | return reader.HasRows;
156 | }
157 |
158 | public static bool Load(int heroid, out HeroDetails herodetails)
159 | {
160 |
161 | herodetails = null;
162 | try
163 | {
164 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT * FROM hero_details WHERE hero_detail_id='{0}'", heroid), Database.Instance.Connection);
165 | SQLiteDataReader reader = command.ExecuteReader();
166 | if (reader.HasRows)
167 | {
168 | while (reader.Read())
169 | {
170 | herodetails = new HeroDetails(reader.GetInt32(0), reader.GetInt32(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetInt32(4),
171 | reader.GetInt32(5), reader.GetInt32(6), reader.GetInt32(7), reader.GetInt32(8), reader.GetInt32(9), reader.GetInt32(10), reader.GetInt32(11),
172 | reader.GetInt32(12), reader.GetInt32(13), reader.GetInt32(14), reader.GetInt32(15), reader.GetInt32(16), reader.GetInt32(17), reader.GetInt32(18),
173 | reader.GetInt32(19), reader.GetInt32(20), reader.GetInt32(21), reader.GetInt32(22), reader.GetInt32(23), reader.GetInt32(24), reader.GetInt32(25),
174 | reader.GetInt32(26), reader.GetInt32(27), reader.GetInt32(28), reader.GetInt32(29), reader.GetInt32(30), reader.GetInt32(31), reader.GetInt32(32),
175 | reader.GetInt32(33), reader.GetInt32(34), reader.GetInt32(35), reader.GetInt32(36), reader.GetInt32(37), reader.GetInt32(38), reader.GetInt32(39),
176 | reader.GetInt32(40));
177 | return true;
178 | }
179 | }
180 | }
181 |
182 | catch (Exception e)
183 | {
184 | Console.WriteLine("Hero_Details: Failed to Load hero details! Exception: {0}", e.Message);
185 | return false;
186 | }
187 | return false;
188 | }
189 |
190 |
191 | public override string ToString()
192 | {
193 | return String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\t{9}\t{10}\t{11}\t{12}\t{13}\t{14}\t{15}\t{16}\t{17}\t{18}\t{19}\t{20}\t{21}\t{22}\t{23}\t{24}\t{25}\t{26}\t{27}\t{28}\t{29}\t{30}\t{31}\t{32}\t{33}\t{34}\t{35}\t{36}\t{37}\t{38}\t{39}\t{40}", Id, Title_Id, BlockAmount, BlockChance, DodgeChance, DamageReduction, AttackDamageBonus, PrecisionCritBonus, DefenseDamageReduction, VitalityLife, Armor, Attack, Precision, Defense, Vitality, DamageIncrease, AttacksPerSecond, CritDamageBonus, CritChanceBonus, CastingSpeed, LifePerKill, LifePerHit, MovementSpeed, GoldFind, Life, LifePerSecond, LifeSteal, MagicFind, FuryGain, SpiritGain, ManaGain, ArcanumGain, HatredGain, DisciplineGain, MaxMana, MaxArcanum, MaxHatred, MaxFury, MaxDiscipline, MaxSpirit);
194 | }
195 | }
196 | }
197 |
--------------------------------------------------------------------------------
/source/HeroGender.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 | namespace D3Database
7 | {
8 | public class HeroGender
9 | {
10 | public int GenderId { get; set; }
11 | public string CharacterName { get; set; }
12 | public int CharacterClass { get; set; }
13 | public HeroGender(int GenderID, string CharacterName, int CharacterClass)
14 | {
15 | this.GenderId = GenderId;
16 | this.CharacterClass = CharacterClass;
17 | this.CharacterName = CharacterName;
18 | }
19 | public static bool Load(int genderid, out HeroGender herogender)
20 | {
21 | herogender = null;
22 | try
23 | {
24 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT * FROM hero_gender WHERE gender_id='{0}'", genderid), Database.Instance.Connection);
25 | SQLiteDataReader reader = command.ExecuteReader();
26 | if (reader.HasRows)
27 | {
28 | while (reader.Read())
29 | {
30 | herogender = new HeroGender(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2));
31 | return true;
32 | }
33 | }
34 | }
35 | catch (Exception e)
36 | {
37 | Console.WriteLine("Failed to load HeroGender exception: {0}", e.Message);
38 | return false;
39 | }
40 |
41 | return false;
42 | }
43 |
44 |
45 |
46 |
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/source/HeroTitles.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using System.Text;
5 | using System.Data.SQLite;
6 |
7 | namespace D3Database
8 | {
9 | class HeroTitles
10 | {
11 | public int TitleID { get; set; }
12 | public string TitleName { get; set; }
13 | public int Level { get; set; }
14 | public int Gender { get; set; }
15 | public string HeroTitle { get; set; }
16 | public HeroTitles(int TitleID, string TitleName, int Level, int Gender, string HeroTitle)
17 | {
18 | this.TitleID = TitleID;
19 | this.TitleName = TitleName;
20 | this.Level = Level;
21 | this.Gender = Gender;
22 | this.HeroTitle = HeroTitle;
23 | }
24 | public static bool Load(int titleid, out HeroTitles herotitle)
25 | {
26 | herotitle = null;
27 | try {
28 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT * FROM hero_titles WHERE title_id='{0}'", titleid), Database.Instance.Connection);
29 | SQLiteDataReader reader = command.ExecuteReader();
30 | if (reader.HasRows)
31 | {
32 | while (reader.Read())
33 | {
34 | herotitle = new HeroTitles(reader.GetInt32(0), reader.GetString(1), reader.GetInt32(2), reader.GetInt32(3), reader.GetString(4));
35 | return true;
36 | }
37 | }
38 | }
39 | catch (Exception e)
40 | {
41 | Console.WriteLine("Failed to load HeroTitles exception: {0}", e.Message);
42 | return false;
43 | }
44 | return false;
45 | }
46 | }
47 | }
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/source/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Data.SQLite;
4 | using System.Text.RegularExpressions;
5 |
6 | namespace D3Database
7 | {
8 | class Program
9 | {
10 | ///
11 | /// Represents the account of the currently signed in user. Null if no user is signed in.
12 | ///
13 | static Account currentAccount = null;
14 |
15 | ///
16 | /// Program entry point.
17 | ///
18 | static void Main(string[] args)
19 | {
20 | Console.Title = "D3SharpDatabase CLI";
21 | try
22 | {
23 | string dbFile = "d3sharp_fixed20110918_2.sqlite";
24 | Database.Instance.Connect(dbFile);
25 | if (Database.Instance.Connection.State != System.Data.ConnectionState.Open)
26 | {
27 | Console.ForegroundColor = ConsoleColor.Red;
28 | Console.Write("Failed to open connection to: ");
29 | Console.WriteLine(dbFile);
30 | Console.ResetColor();
31 | Console.WriteLine("Press any key to exit.");
32 | Console.ReadKey();
33 | return;
34 | }
35 |
36 | Console.WriteLine("Connected to {0}", dbFile);
37 | PrintHelp();
38 |
39 | while (true)
40 | {
41 | if (currentAccount != null)
42 | {
43 | Console.ForegroundColor = ConsoleColor.White;
44 | Console.Write(currentAccount.Name);
45 | Console.ResetColor();
46 | }
47 |
48 | Console.Write(">");
49 | var command = Console.ReadLine();
50 | switch (command)
51 | {
52 | case "exit":
53 | return;
54 | case "list accounts":
55 | CommandListAccounts();
56 | break;
57 | case "create account":
58 | CommandCreateAccount();
59 | break;
60 | case "login":
61 | CommandLogin();
62 | break;
63 | case "logout":
64 | CommandLogout();
65 | break;
66 | case "list heroes":
67 | CommandListHeroes();
68 | break;
69 | case "create hero":
70 | CommandCreateHero();
71 | break;
72 | case "create banner":
73 | CommandCreateBanner();
74 | break;
75 | case "list banners":
76 | CommandListBanners();
77 | break;
78 | case "hero level up":
79 | CommandHeroLevelUp();
80 | break;
81 | case "clear":
82 | Console.Clear();
83 | break;
84 | default:
85 | Console.WriteLine("Unknown command");
86 | PrintHelp();
87 | break;
88 | }
89 | }
90 | }
91 | catch (Exception e)
92 | {
93 | Console.ForegroundColor = ConsoleColor.Red;
94 | Console.WriteLine("Exception:");
95 | Console.ResetColor();
96 | Console.WriteLine(e.Message);
97 | Console.WriteLine(e.StackTrace);
98 | Console.ReadLine();
99 | }
100 | finally
101 | {
102 | try { Database.Instance.Connection.Close(); }
103 | catch { }
104 | }
105 | }
106 |
107 | ///
108 | /// Outputs a list of acceptable commands.
109 | ///
110 | static void PrintHelp()
111 | {
112 | Console.Write("Commands: ");
113 | Console.Write("exit, login, logout, list accounts, create account, create hero, list heroes, hero level up, clear" + Environment.NewLine);
114 | }
115 |
116 | ///
117 | /// Handles the "create account" command which attempts to create a new account in the database.
118 | ///
119 | static void CommandCreateAccount()
120 | {
121 | // prompt for account name
122 | Console.Write("Name: ");
123 |
124 | // read input
125 | string name = Console.ReadLine();
126 |
127 | // check that name is valid
128 | while (string.IsNullOrEmpty(name))
129 | {
130 | Console.ForegroundColor = ConsoleColor.Red;
131 | Console.WriteLine("Invalid name.");
132 | Console.ResetColor();
133 | Console.Write("Name: ");
134 | name = Console.ReadLine();
135 | }
136 |
137 | string password;
138 | string passwordConfirm;
139 |
140 | // prompt for password
141 | Console.Write("Password: ");
142 |
143 | // hide password while typing
144 | Console.ForegroundColor = ConsoleColor.Black;
145 |
146 | password = Console.ReadLine();
147 |
148 | // check that password is valid
149 | while (string.IsNullOrEmpty(password))
150 | {
151 | Console.ForegroundColor = ConsoleColor.Red;
152 | Console.WriteLine("Invalid password.");
153 | Console.ResetColor();
154 | Console.Write("Password: ");
155 | // hide password while typing
156 | Console.ForegroundColor = ConsoleColor.Black;
157 | password = Console.ReadLine();
158 | }
159 |
160 | Console.ResetColor();
161 |
162 | // prompt for password again
163 | Console.Write("Confirm Password: ");
164 |
165 | // hide password while typing
166 | Console.ForegroundColor = ConsoleColor.Black;
167 |
168 | passwordConfirm = Console.ReadLine();
169 |
170 | // check that passwords match
171 | while (passwordConfirm != password)
172 | {
173 | Console.ForegroundColor = ConsoleColor.Red;
174 | Console.WriteLine("Passwords don't match.");
175 | Console.ResetColor();
176 |
177 | // prompt for password
178 | Console.Write("Password: ");
179 |
180 | // hide password while typing
181 | Console.ForegroundColor = ConsoleColor.Black;
182 |
183 | password = Console.ReadLine();
184 |
185 | // check that password is valid
186 | while (string.IsNullOrEmpty(password))
187 | {
188 | Console.ForegroundColor = ConsoleColor.Red;
189 | Console.WriteLine("Invalid password.");
190 | Console.ResetColor();
191 | Console.Write("Password: ");
192 | // hide password while typing
193 | Console.ForegroundColor = ConsoleColor.Black;
194 | password = Console.ReadLine();
195 | }
196 |
197 | Console.ResetColor();
198 |
199 | // prompt for password again
200 | Console.Write("Confirm Password: ");
201 |
202 | // hide password while typing
203 | Console.ForegroundColor = ConsoleColor.Black;
204 |
205 | passwordConfirm = Console.ReadLine();
206 |
207 | Console.ResetColor();
208 | }
209 |
210 | // prompt for gold amount
211 | Console.Write("Gold: ");
212 |
213 | // read input
214 | string goldString = Console.ReadLine();
215 | int gold;
216 |
217 | // check that gold is numeric
218 | while (int.TryParse(goldString, out gold))
219 | {
220 | Console.ForegroundColor = ConsoleColor.Red;
221 | Console.WriteLine("Invalid gold. Please choose a number.");
222 | Console.ResetColor();
223 | Console.Write("Gold: ");
224 | goldString = Console.ReadLine();
225 | }
226 |
227 | // prompt for gender
228 | Console.Write("Gender (male/female): ");
229 |
230 | int gender = 0;
231 |
232 | // check that gender is valid (1 or 2)
233 | while (gender == 0)
234 | {
235 | switch (Console.ReadLine().ToLower().Trim())
236 | {
237 | case "male":
238 | case "m":
239 | gender = 1;
240 | break;
241 | case "female":
242 | case "f":
243 | gender = 2;
244 | break;
245 | default:
246 | // red for errors
247 | Console.ForegroundColor = ConsoleColor.Red;
248 | Console.WriteLine("Invalid gender. Please choose male or female.");
249 | // reset colour
250 | Console.ResetColor();
251 | Console.Write("Gender (male/female): ");
252 | break;
253 | }
254 | }
255 |
256 | // initialize account
257 | Account account = new Account(name, gold, gender);
258 |
259 | // save account to database
260 | if (account.Create(password))
261 | {
262 | Console.Write("Account ");
263 | Console.ForegroundColor = ConsoleColor.Green;
264 | Console.Write(name);
265 | Console.ResetColor();
266 | Console.Write(" created.");
267 | }
268 | else
269 | {
270 | Console.ForegroundColor = ConsoleColor.Red;
271 | Console.WriteLine("An account with that name already exists");
272 | Console.ResetColor();
273 | }
274 | }
275 |
276 | ///
277 | /// Handles the "list accounts" command which lists all accounts in the database.
278 | ///
279 | static void CommandListAccounts()
280 | {
281 | // initialize SQL
282 | SQLiteCommand command = new SQLiteCommand(string.Format("SELECT account_id, account_name FROM account ORDER BY account_id ASC"), Database.Instance.Connection);
283 | // execute SQL (retrieve all accounts from database)
284 | SQLiteDataReader reader = command.ExecuteReader();
285 |
286 | // accounts found
287 | if (reader.HasRows)
288 | {
289 | while (reader.Read())
290 | {
291 | // :
292 | Console.WriteLine("{0}: {1}", reader.GetInt32(0), reader.GetString(1));
293 | }
294 | }
295 | else
296 | {
297 | Console.ForegroundColor = ConsoleColor.Red;
298 | Console.WriteLine("No accounts found in the database.");
299 | Console.ResetColor();
300 | }
301 | }
302 |
303 | ///
304 | /// Handles the "login" command which attempts to log in as a specific user.
305 | ///
306 | static void CommandLogin()
307 | {
308 | // prompt for name
309 | Console.Write("Name: ");
310 | string name = Console.ReadLine().Trim();
311 | // prompt for password
312 | Console.Write("Password: ");
313 |
314 | // hide password while typing
315 | Console.ForegroundColor = ConsoleColor.Black;
316 | string password = Console.ReadLine();
317 | Console.ResetColor();
318 |
319 | // attempt log in
320 | if (Account.Authorize(name, password, out currentAccount))
321 | {
322 | Console.Write("Logged in as ");
323 | Console.ForegroundColor = ConsoleColor.Green;
324 | Console.Write(name);
325 | Console.ResetColor();
326 | Console.WriteLine(".");
327 | }
328 | else
329 | {
330 | Console.ForegroundColor = ConsoleColor.Red;
331 | Console.WriteLine("Failed to log in.");
332 | Console.ResetColor();
333 | }
334 | }
335 |
336 | ///
337 | /// Handles the "logout" command which logs out the currently logged in user.
338 | ///
339 | static void CommandLogout()
340 | {
341 | // check that a user is even logged in
342 | if (currentAccount != null)
343 | {
344 | currentAccount = null;
345 | Console.WriteLine("Logged out.");
346 | }
347 | else
348 | {
349 | Console.ForegroundColor = ConsoleColor.Red;
350 | Console.WriteLine("Already logged out.");
351 | Console.ResetColor();
352 | }
353 | }
354 |
355 | ///
356 | /// Handles the "list heroes" command which lists all heroes in the database associated with the currently logged in account.
357 | ///
358 | static void CommandListHeroes()
359 | {
360 | // check that the user is logged in
361 | if (currentAccount == null)
362 | {
363 | Console.ForegroundColor = ConsoleColor.Red;
364 | Console.WriteLine("Not logged in.");
365 | Console.ResetColor();
366 | return; // exit
367 | }
368 |
369 | // get heroes for this account
370 | List heroes = currentAccount.GetHeroes();
371 |
372 | // check that there are one or more heroes
373 | if (heroes.Count > 0)
374 | {
375 | // iterate through collection
376 | foreach (Hero hero in heroes)
377 | {
378 | string classStr;
379 | ConsoleColor classColour;
380 |
381 | switch (hero.HeroClass)
382 | {
383 | case 1:
384 | classStr = "Wizard";
385 | classColour = ConsoleColor.Cyan;
386 | break;
387 | case 2:
388 | classStr = "Witch Doctor";
389 | classColour = ConsoleColor.Green;
390 | break;
391 | case 3:
392 | classStr = "Demon Hunter";
393 | classColour = ConsoleColor.Magenta;
394 | break;
395 | case 4:
396 | classStr = "Monk";
397 | classColour = ConsoleColor.Yellow;
398 | break;
399 | case 5:
400 | classStr = "Barbarian";
401 | classColour = ConsoleColor.Red;
402 | break;
403 | default:
404 | classStr = "Unknown";
405 | classColour = ConsoleColor.Gray;
406 | break;
407 | }
408 |
409 | string genderStr;
410 |
411 | switch (hero.Gender)
412 | {
413 | case 1:
414 | genderStr = "male";
415 | break;
416 | case 2:
417 | genderStr = "female";
418 | break;
419 | default:
420 | genderStr = "unknown";
421 | break;
422 | }
423 |
424 | Console.Write(hero.Id.ToString().PadLeft(3, '0'));
425 | Console.ForegroundColor = ConsoleColor.DarkGray;
426 | Console.Write(" | ");
427 | Console.ResetColor();
428 | Console.ForegroundColor = ConsoleColor.Green;
429 | Console.Write(hero.Name.PadRight(12));
430 | Console.ForegroundColor = ConsoleColor.DarkGray;
431 | Console.Write(" | ");
432 | Console.ResetColor();
433 | Console.Write("level " + hero.Level.ToString().PadLeft(3, '0'));
434 | Console.ForegroundColor = ConsoleColor.DarkGray;
435 | Console.Write(" | ");
436 | Console.ResetColor();
437 | Console.Write(genderStr.PadRight(6));
438 | Console.ForegroundColor = ConsoleColor.DarkGray;
439 | Console.Write(" | ");
440 | Console.ForegroundColor = classColour;
441 | Console.Write(classStr.PadRight(12));
442 | Console.ForegroundColor = ConsoleColor.DarkGray;
443 | Console.Write(" | ");
444 | Console.ResetColor();
445 | Console.WriteLine(" " + hero.Experience.ToString() + " XP");
446 | }
447 |
448 | // NO MORE HEROES ANYMOOOORE
449 | }
450 | else
451 | {
452 | Console.ForegroundColor = ConsoleColor.Red;
453 | Console.WriteLine("No heroes associated with this account.");
454 | Console.ResetColor();
455 | }
456 | }
457 |
458 | ///
459 | /// Handles the "create hero" command which creates a hero under the currently logged in account and saves it to the database.
460 | ///
461 | static void CommandCreateHero()
462 | {
463 | // check that user is logged in
464 | if (currentAccount == null)
465 | {
466 | Console.ForegroundColor = ConsoleColor.Red;
467 | Console.WriteLine("Not logged in.");
468 | Console.ResetColor();
469 | return; // exit
470 | }
471 |
472 | // prompt for hero name
473 | Console.Write("Name: ");
474 |
475 | // read input
476 | string name = Console.ReadLine();
477 |
478 | // check that name doesn't contain numbers
479 | while (Regex.IsMatch(name, @"\d"))
480 | {
481 | Console.ForegroundColor = ConsoleColor.Red;
482 | Console.WriteLine("Invalid name. Names cannot contain numbers.");
483 | Console.ResetColor();
484 | Console.Write("Name: ");
485 | name = Console.ReadLine();
486 | }
487 |
488 | while (name.Length < 3 || name.Length > 12)
489 | {
490 | Console.ForegroundColor = ConsoleColor.Red;
491 | Console.WriteLine("Invalid name. Names must be between 3 and 12 characters inclusive.");
492 | Console.ResetColor();
493 | Console.Write("Name: ");
494 | name = Console.ReadLine();
495 | }
496 |
497 | // prompt for hero class
498 | Console.WriteLine("Hero Class:\n1: Wizard\n2: Witch Doctor\n3: Demon Hunter\n4: Monk\n5: Barbarian");
499 |
500 | // read input
501 | string heroClassString = Console.ReadLine();
502 | int heroClass;
503 |
504 | // check that input is a valid class id
505 | while (!int.TryParse(heroClassString, out heroClass) || heroClass > 5 || heroClass < 1)
506 | {
507 | Console.ForegroundColor = ConsoleColor.Red;
508 | Console.WriteLine("Invalid class. Please choose a number.");
509 | Console.ResetColor();
510 | Console.WriteLine("Hero Class:\n1: Wizard\n2: Witch Doctor\n3: Demon Hunter\n4: Monk\n5: Barbarian");
511 | heroClassString = Console.ReadLine();
512 | }
513 |
514 | // prompt for gender
515 | Console.Write("Gender (male/female): ");
516 |
517 | int gender = 0;
518 |
519 | // check that gender is valid (1 or 2)
520 | while (gender == 0)
521 | {
522 | switch (Console.ReadLine().ToLower().Trim())
523 | {
524 | case "male":
525 | case "m":
526 | gender = 1;
527 | break;
528 | case "female":
529 | case "f":
530 | gender = 2;
531 | break;
532 | default:
533 | // red for errors
534 | Console.ForegroundColor = ConsoleColor.Red;
535 | Console.WriteLine("Invalid gender. Please choose male or female.");
536 | // reset colour
537 | Console.ResetColor();
538 | Console.Write("Gender (male/female): ");
539 | break;
540 | }
541 | }
542 |
543 | // prompt for hero level
544 | Console.Write("Level: ");
545 |
546 | // read input
547 | string levelString = Console.ReadLine();
548 | int level;
549 |
550 | // check that input is numeric
551 | while (!int.TryParse(levelString, out level))
552 | {
553 | Console.ForegroundColor = ConsoleColor.Red;
554 | Console.WriteLine("Invalid level. Please choose a number.");
555 | Console.ResetColor();
556 | Console.Write("Level: ");
557 | levelString = Console.ReadLine();
558 | }
559 |
560 | // prompt for hero experience
561 | Console.Write("Experience: ");
562 |
563 | // read input
564 | string experienceString = Console.ReadLine();
565 | int experience;
566 |
567 | // check that input is numeric
568 | while (!int.TryParse(experienceString, out experience))
569 | {
570 | Console.ForegroundColor = ConsoleColor.Red;
571 | Console.WriteLine("Invalid experience. Please choose a number.");
572 | Console.ResetColor();
573 | Console.Write("Experience: ");
574 | experienceString = Console.ReadLine();
575 | }
576 |
577 | // initialize hero object
578 | Hero hero = new Hero(currentAccount.Id, name, heroClass, gender, experience, level);
579 |
580 | // create hero
581 | if (hero.Create())
582 | {
583 | Console.Write("Hero ");
584 | Console.ForegroundColor = ConsoleColor.Green;
585 | Console.Write(name);
586 | Console.ResetColor();
587 | Console.WriteLine(" created.");
588 | }
589 | else // hero already exists
590 | {
591 | Console.ForegroundColor = ConsoleColor.Red;
592 | Console.WriteLine("Hero with that name already exists");
593 | Console.ResetColor();
594 | }
595 | }
596 |
597 | ///
598 | /// Handles the "create banner" command which creates a banner for the currently logged in account.
599 | ///
600 | static void CommandCreateBanner()
601 | {
602 | // check that user is logged in
603 | if (currentAccount == null)
604 | {
605 | Console.ForegroundColor = ConsoleColor.Red;
606 | Console.WriteLine("Not logged in");
607 | Console.ResetColor();
608 | return; // exit
609 | }
610 |
611 | // prompt for background colour
612 | Console.Write("Background Colour: ");
613 |
614 | // read input
615 | string backgroundColorString = Console.ReadLine();
616 | int backgroundColor;
617 |
618 | // check that background colour is numeric
619 | while (int.TryParse(backgroundColorString, out backgroundColor))
620 | {
621 | Console.ForegroundColor = ConsoleColor.Red;
622 | Console.WriteLine("Invalid background color. Please choose a number.");
623 | Console.ResetColor();
624 | Console.Write("Background Colour: ");
625 | backgroundColorString = Console.ReadLine();
626 | }
627 |
628 | // prompt for banner
629 | Console.Write("Banner: ");
630 |
631 | // read input
632 | string bannerString = Console.ReadLine();
633 | int banner;
634 |
635 | // check that banner is numeric
636 | while (int.TryParse(bannerString, out banner))
637 | {
638 | Console.ForegroundColor = ConsoleColor.Red;
639 | Console.WriteLine("Invalid banner. Please choose a number.");
640 | Console.ResetColor();
641 | Console.Write("Banner: ");
642 | bannerString = Console.ReadLine();
643 | }
644 |
645 | // prompt for pattern
646 | Console.Write("Pattern: ");
647 |
648 | // read input
649 | string patternString = Console.ReadLine();
650 | int pattern;
651 |
652 | // check that pattern is numeric
653 | while (int.TryParse(patternString, out pattern))
654 | {
655 | Console.ForegroundColor = ConsoleColor.Red;
656 | Console.WriteLine("Invalid pattern. Please choose a number.");
657 | Console.ResetColor();
658 | Console.Write("Pattern: ");
659 | patternString = Console.ReadLine();
660 | }
661 |
662 | // prompt for pattern colour
663 | Console.Write("Pattern Colour: ");
664 |
665 | // read input
666 | string patternColorString = Console.ReadLine();
667 | int patternColor;
668 |
669 | // check that pattern colour is numeric
670 | while (int.TryParse(patternColorString, out patternColor))
671 | {
672 | Console.ForegroundColor = ConsoleColor.Red;
673 | Console.WriteLine("Invalid pattern colour. Please choose a number.");
674 | Console.ResetColor();
675 | Console.Write("Pattern Colour: ");
676 | patternColorString = Console.ReadLine();
677 | }
678 |
679 | // prompt for placement
680 | Console.Write("Placement: ");
681 |
682 | // read input
683 | string placementString = Console.ReadLine();
684 | int placement;
685 |
686 | // check that placement is numeric
687 | while (int.TryParse(placementString, out placement))
688 | {
689 | Console.ForegroundColor = ConsoleColor.Red;
690 | Console.WriteLine("Invalid placement. Please choose a number.");
691 | Console.ResetColor();
692 | Console.Write("Placement: ");
693 | placementString = Console.ReadLine();
694 | }
695 |
696 | // prompt for sigil
697 | Console.Write("Sigil: ");
698 |
699 | // read input
700 | string sigilMainString = Console.ReadLine();
701 | int sigilMain;
702 |
703 | // check that sigil is numeric
704 | while (int.TryParse(sigilMainString, out sigilMain))
705 | {
706 | Console.ForegroundColor = ConsoleColor.Red;
707 | Console.WriteLine("Invalid sigil. Please choose a number.");
708 | Console.ResetColor();
709 | Console.Write("Sigil: ");
710 | sigilMainString = Console.ReadLine();
711 | }
712 |
713 | // prompt for sigil accent
714 | Console.Write("Sigil Accent: ");
715 |
716 | // read input
717 | string sigilAccentString = Console.ReadLine();
718 | int sigilAccent;
719 |
720 | // check that sigil accent is numeric
721 | while (int.TryParse(sigilAccentString, out sigilAccent))
722 | {
723 | Console.ForegroundColor = ConsoleColor.Red;
724 | Console.WriteLine("Invalid sigil accent. Please choose a number.");
725 | Console.ResetColor();
726 | Console.Write("Sigil Accent: ");
727 | sigilAccentString = Console.ReadLine();
728 | }
729 |
730 | // prompt for sigil colour
731 | Console.Write("Sigil Colour: ");
732 |
733 | // read input
734 | string sigilColorString = Console.ReadLine();
735 | int sigilColor;
736 |
737 | // check that sigil colour is numeric
738 | while (int.TryParse(sigilColorString, out sigilColor))
739 | {
740 | Console.ForegroundColor = ConsoleColor.Red;
741 | Console.WriteLine("Invalid sigil colour. Please choose a number.");
742 | Console.ResetColor();
743 | Console.Write("Sigil Colour: ");
744 | sigilColorString = Console.ReadLine();
745 | }
746 |
747 | // prompt for sigil variant
748 | Console.Write("Use Sigil Variant (yes/no): ");
749 |
750 | // read input
751 | string useSigilVariantString = Console.ReadLine();
752 | bool useSigilVariant = false;
753 | bool useSigilVariantSet = false;
754 |
755 | while (!useSigilVariantSet)
756 | {
757 | switch (useSigilVariantString.ToLower())
758 | {
759 | case "yes":
760 | case "y":
761 | useSigilVariant = true;
762 | useSigilVariantSet = true;
763 | break;
764 | case "no":
765 | case "n":
766 | useSigilVariant = false;
767 | useSigilVariantSet = true;
768 | break;
769 | default:
770 | Console.ForegroundColor = ConsoleColor.Red;
771 | Console.WriteLine("Invalid sigil colour. Please choose a number.");
772 | Console.ResetColor();
773 | Console.Write("Use Sigil Variant (yes/no): ");
774 | useSigilVariantString = Console.ReadLine();
775 | break;
776 | }
777 | }
778 |
779 | // initialize account banner
780 | AccountBanner accountBanner = new AccountBanner(currentAccount.Id, backgroundColor, banner, pattern, patternColor, placement, sigilAccent, sigilMain, sigilColor, useSigilVariant);
781 |
782 | // save account banner to database
783 | if (accountBanner.Create())
784 | {
785 | Console.WriteLine("Banner created");
786 | }
787 | else
788 | {
789 | Console.ForegroundColor = ConsoleColor.Red;
790 | Console.WriteLine("Failed to create banner.");
791 | Console.ResetColor();
792 | }
793 | }
794 |
795 | ///
796 | /// Handles the "list banners" command which lists all the banners associated with the currently logged in account.
797 | ///
798 | static void CommandListBanners()
799 | {
800 | // check that user is logged in
801 | if (currentAccount == null)
802 | {
803 | Console.ForegroundColor = ConsoleColor.Red;
804 | Console.WriteLine("Not logged in.");
805 | Console.ResetColor();
806 | return; // exit
807 | }
808 |
809 | // load banners
810 | List banners = currentAccount.GetBanners();
811 |
812 | // check that one or more banners exist for this account
813 | if (banners.Count > 0)
814 | {
815 | // iterate through collection
816 | foreach (AccountBanner banner in banners)
817 | {
818 | Console.WriteLine(banner);
819 | }
820 | }
821 | else
822 | {
823 | Console.ForegroundColor = ConsoleColor.Red;
824 | Console.WriteLine("No banners associated with this account.");
825 | Console.ResetColor();
826 | }
827 | }
828 |
829 | ///
830 | /// Handles the "hero level up" command which increments a hero's level.
831 | ///
832 | static void CommandHeroLevelUp()
833 | {
834 | // check that user is logged in
835 | if (currentAccount == null)
836 | {
837 | Console.ForegroundColor = ConsoleColor.Red;
838 | Console.WriteLine("Not logged in");
839 | Console.ResetColor();
840 | return; // exit
841 | }
842 |
843 | // prompt for hero id
844 | Console.Write("Hero id: ");
845 |
846 | // read input
847 | string heroIdString = Console.ReadLine();
848 | int heroId;
849 |
850 | // check input validity
851 | if (!int.TryParse(heroIdString, out heroId) || heroId == 0)
852 | {
853 | Console.ForegroundColor = ConsoleColor.Red;
854 | Console.WriteLine("Invalid hero id.");
855 | Console.ResetColor();
856 | return; // exit
857 | }
858 |
859 | // initialize hero object
860 | Hero hero;
861 |
862 | // check if hero exists
863 | if (!Hero.Load(heroId, out hero))
864 | {
865 | Console.ForegroundColor = ConsoleColor.Red;
866 | Console.WriteLine("No hero with the specified id exists.");
867 | Console.ResetColor();
868 | return; // exit
869 | }
870 |
871 | // check if hero account_id matches the logged in account
872 | if (hero.AccountId != currentAccount.Id)
873 | {
874 | Console.ForegroundColor = ConsoleColor.Red;
875 | Console.WriteLine("Specified hero is not associated with this account.");
876 | Console.ResetColor();
877 | return; // exit
878 | }
879 |
880 | // increment hero level
881 | hero.Level++;
882 |
883 | // save hero to database
884 | hero.Save();
885 |
886 | // output result
887 | Console.Write("Hero ");
888 | Console.ForegroundColor = ConsoleColor.Green;
889 | Console.Write(hero.Name);
890 | Console.ResetColor();
891 | Console.Write(" is now level ");
892 | Console.ForegroundColor = ConsoleColor.Green;
893 | Console.Write(hero.Level);
894 | Console.ResetColor();
895 | Console.WriteLine(".");
896 | }
897 | }
898 | }
899 |
--------------------------------------------------------------------------------
/source/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Runtime.CompilerServices;
3 | using System.Runtime.InteropServices;
4 |
5 | // General Information about an assembly is controlled through the following
6 | // set of attributes. Change these attribute values to modify the information
7 | // associated with an assembly.
8 | [assembly: AssemblyTitle("D3SharpDatabase")]
9 | [assembly: AssemblyDescription("")]
10 | [assembly: AssemblyConfiguration("")]
11 | [assembly: AssemblyCompany("")]
12 | [assembly: AssemblyProduct("D3SharpDatabase")]
13 | [assembly: AssemblyCopyright("")]
14 | [assembly: AssemblyTrademark("")]
15 | [assembly: AssemblyCulture("")]
16 |
17 | // Setting ComVisible to false makes the types in this assembly not visible
18 | // to COM components. If you need to access a type in this assembly from
19 | // COM, set the ComVisible attribute to true on that type.
20 | [assembly: ComVisible(false)]
21 |
22 | // The following GUID is for the ID of the typelib if this project is exposed to COM
23 | [assembly: Guid("c0782380-a14a-48ec-b9f3-d819f3fa7269")]
24 |
25 | // Version information for an assembly consists of the following four values:
26 | //
27 | // Major Version
28 | // Minor Version
29 | // Build Number
30 | // Revision
31 | //
32 | // You can specify all the values or you can default the Build and Revision Numbers
33 | // by using the '*' as shown below:
34 | // [assembly: AssemblyVersion("1.0.*")]
35 | [assembly: AssemblyVersion("1.0.0.0")]
36 | [assembly: AssemblyFileVersion("1.0.0.0")]
37 |
--------------------------------------------------------------------------------
/source/app.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/source/bin/Debug/D3Database.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/source/bin/Debug/D3Sharp.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/D3Sharp.db
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/D3SharpDatabase.exe
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/D3SharpDatabase.pdb
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.vshost.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/D3SharpDatabase.vshost.exe
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.vshost.exe.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/source/bin/Debug/D3SharpDatabase.vshost.exe.manifest:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/source/bin/Debug/d3db_fixed.db:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/d3db_fixed.db
--------------------------------------------------------------------------------
/source/bin/Debug/d3sharp.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/d3sharp.sqlite
--------------------------------------------------------------------------------
/source/bin/Debug/d3sharp_fixed20110918_2.sqlite:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/bin/Debug/d3sharp_fixed20110918_2.sqlite
--------------------------------------------------------------------------------
/source/obj/x86/Debug/D3Database.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\obj\x86\Debug\ResolveAssemblyReference.cache
2 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\bin\Debug\D3SharpDatabase.exe.config
3 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\bin\Debug\D3SharpDatabase.exe
4 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\bin\Debug\D3SharpDatabase.pdb
5 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\obj\x86\Debug\D3SharpDatabase.exe
6 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3Database\obj\x86\Debug\D3SharpDatabase.pdb
7 |
--------------------------------------------------------------------------------
/source/obj/x86/Debug/D3SharpDatabase.csproj.FileListAbsolute.txt:
--------------------------------------------------------------------------------
1 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3SharpDatabase\bin\Debug\D3SharpDatabase.exe.config
2 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3SharpDatabase\obj\x86\Debug\D3SharpDatabase.exe
3 | E:\Code\D3Sharp\raistlinthewiz-d3db\source\D3SharpDatabase\obj\x86\Debug\D3SharpDatabase.pdb
4 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.exe.config
5 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\obj\x86\Debug\D3SharpDatabase.exe
6 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\obj\x86\Debug\D3SharpDatabase.pdb
7 | E:\Code\D3SharpDatabase\source\obj\x86\Debug\ResolveAssemblyReference.cache
8 | E:\Code\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.exe.config
9 | E:\Code\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.exe
10 | E:\Code\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.pdb
11 | E:\Code\D3SharpDatabase\source\obj\x86\Debug\D3SharpDatabase.exe
12 | E:\Code\D3SharpDatabase\source\obj\x86\Debug\D3SharpDatabase.pdb
13 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.exe
14 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\bin\Debug\D3SharpDatabase.pdb
15 | C:\Users\TeTuBe\Desktop\Hacking\git\D3SharpDatabase\source\obj\x86\Debug\ResolveAssemblyReference.cache
16 |
--------------------------------------------------------------------------------
/source/obj/x86/Debug/D3SharpDatabase.exe:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/obj/x86/Debug/D3SharpDatabase.exe
--------------------------------------------------------------------------------
/source/obj/x86/Debug/D3SharpDatabase.pdb:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/obj/x86/Debug/D3SharpDatabase.pdb
--------------------------------------------------------------------------------
/source/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
--------------------------------------------------------------------------------
/source/obj/x86/Debug/ResolveAssemblyReference.cache:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/orior/D3SharpDatabase/17f390262d3699af61c907ecccff9469a2a68746/source/obj/x86/Debug/ResolveAssemblyReference.cache
--------------------------------------------------------------------------------