Skip to content

Commit 92ffcbf

Browse files
committed
bug fixes, need to actually label with version numbers
1 parent bb49be7 commit 92ffcbf

2 files changed

Lines changed: 159 additions & 42 deletions

File tree

User.cs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,10 @@ public string[] Read_Messages_Chat(string[] EncryptedMessages) {
208208

209209

210210
for (int i = 2; i < EncryptedMessages.Length; i++) {
211-
DecryptedMessages[i-2] = SymmetricEncryption.DecryptString(SymmetricKey.Item1, EncryptedMessages[i], SymmetricKey.Item2);
211+
DecryptedMessages[i-2] =
212+
System.Text.Encoding.Default.GetString(Security.Encode.HexStringToByteArray(
213+
SymmetricEncryption.DecryptString(SymmetricKey.Item1, EncryptedMessages[i], SymmetricKey.Item2)
214+
));
212215
}
213216

214217
return DecryptedMessages;
@@ -285,8 +288,17 @@ public Tuple<string, string> Read_Chat_SymmetricKey(string[] EncryptedMessages)
285288

286289

287290
public void Write_Messages_Chat(Tuple<string, string> SymmetricKey, string ChatName, string Content) {
291+
WriteToChat:
288292
//SymmetricEncryption.EncryptString(SymmetricKey.Item1, this.Username+" "+Name, SymmetricKey.Item2);
289-
File.AppendAllText(@"chats\"+ChatName+".txt", "\n"+SymmetricEncryption.EncryptString(SymmetricKey.Item1, "["+this.Username+"] "+Content, SymmetricKey.Item2));
293+
try {
294+
File.AppendAllText(@"chats\"+ChatName+".txt", "\n"+
295+
SymmetricEncryption.EncryptString(SymmetricKey.Item1,
296+
Encode.ByteArrayToHexString(Encoding.ASCII.GetBytes(Content)),
297+
SymmetricKey.Item2)
298+
);
299+
} catch {
300+
goto WriteToChat;
301+
}
290302
}
291303

292304
public static string Read_User_PublicKey(string User) {
@@ -376,12 +388,12 @@ public static void Pointer(string[] Content, Tuple<int, int> BoardDimensions, in
376388
}
377389

378390
}
379-
public static void Content(string[] Content, Tuple<int, int> BoardDimensions, string TypedText = "", bool IfChat = false) {
391+
public static void Content(string[] Content, Tuple<int, int> BoardDimensions, string TypedText = "", bool IfChat = false, string Username = "TEMPVALUE") {
380392
Board Board = new Board(BoardDimensions.Item1, BoardDimensions.Item2);
381393
Board = Square.Create(new Square(Board.Width,Board.Height,Tuple.Create(0,0)), Board);
382394

383395
if (IfChat) {
384-
int Interval = (BoardDimensions.Item1-3)*2; // your interval
396+
int Interval = (BoardDimensions.Item1-2)*2; // your interval
385397
List<string> DisplayedMessages = new List<string>(); // we use a List for simplicity, you can convert it to an array later
386398

387399
foreach (string message in Content)
@@ -406,6 +418,8 @@ public static void Content(string[] Content, Tuple<int, int> BoardDimensions, st
406418
Array.Reverse(DisplayedMessagesArray);
407419

408420
int VerticalBorder = 5;
421+
Board = Line.Create(new Line(Tuple.Create(0, Board.Height-3),Tuple.Create(Board.Width, Board.Height-3)), Board);
422+
Board = Text.Create(new Text(Tuple.Create(1,Board.Height-2), "Chatting With: "+Username), Board);
409423
for (int i = 0; (i < BoardDimensions.Item2 - VerticalBorder) && (i < DisplayedMessagesArray.Length); i++) {
410424
Board = Text.Create(new Text(Tuple.Create(2,2+i), DisplayedMessagesArray[i]), Board);
411425
}

program.cs

Lines changed: 141 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ static void Main(string[] args)
5050
Start:
5151

5252

53-
string[] Content = new string[3]{"Login", "New", "Public Room (404 not found)"};
53+
string[] Content = new string[2]{"Login", "New"};
5454

5555
Tuple<int, string> Tuple = MenuLoop(Content, BoardDimensions, false);
5656

@@ -66,8 +66,8 @@ static void Main(string[] args)
6666
Tuple = MenuLoop(Content, BoardDimensions, true);
6767

6868
if (BadWords.BadWords.list.Any(Tuple.Item2.Contains)) {
69-
Console.WriteLine("bad Word Found, Redo Step");
70-
System.Threading.Thread.Sleep(5000);
69+
Console.WriteLine("bad Word Found, Redo Step (wait a sec)");
70+
System.Threading.Thread.Sleep(3000);
7171
goto BadNameUsername;
7272
}
7373

@@ -81,13 +81,8 @@ static void Main(string[] args)
8181

8282
new User.User(TempUsername, TempPassword).Generate();
8383

84-
Console.WriteLine("Account Made");
85-
System.Threading.Thread.Sleep(5000);
86-
goto Start;
87-
} else if (Tuple.Item1 == 2) {
88-
Console.WriteLine("Public Chat not exist yet");
89-
System.Threading.Thread.Sleep(5000);
90-
//Not Valid Account Username
84+
Console.WriteLine("Account Made (wait a sec)");
85+
System.Threading.Thread.Sleep(3000);
9186
goto Start;
9287
}
9388

@@ -109,13 +104,46 @@ static void Main(string[] args)
109104

110105
if (!(User.User.Exists(Username) && User.User.Exists_PublicKey(CurrentUser.Key.Public))) {
111106
Console.WriteLine("Not The Correct Password");
112-
System.Threading.Thread.Sleep(5000);
107+
Console.WriteLine("Login Timeout: 5");
108+
System.Threading.Thread.Sleep(500);
109+
Console.WriteLine("Login Timeout: 4");
110+
System.Threading.Thread.Sleep(500);
111+
Console.WriteLine("Login Timeout: 3");
112+
System.Threading.Thread.Sleep(500);
113+
Console.WriteLine("Login Timeout: 2");
114+
System.Threading.Thread.Sleep(500);
115+
Console.WriteLine("Login Timeout: 1");
116+
System.Threading.Thread.Sleep(500);
113117
goto Start;
114118
}
115119

116120
Console.WriteLine("Correct Password");
117121

118-
BoardDimensions = CurrentUser.Read_User_BoardSettings();
122+
123+
124+
while (true) {
125+
Content = new string[3]{"Private Chat", "Public Chat (404 not found)", "Settings"};
126+
BoardDimensions = CurrentUser.Read_User_BoardSettings();
127+
Tuple = MenuLoop(Content, BoardDimensions, false);
128+
129+
if (Tuple.Item1 == 0) {
130+
PrivateChat(CurrentUser);
131+
} else if (Tuple.Item1 == 1) {
132+
Console.WriteLine("Not Quite Yet Here");
133+
System.Threading.Thread.Sleep(1000);
134+
} else if (Tuple.Item1 == 2) {
135+
ChangeSettings(CurrentUser);
136+
}
137+
}
138+
}
139+
140+
141+
142+
143+
public static void PrivateChat(User.User CurrentUser) {
144+
DMSExtras.DMSExtras.TextListener TextListener = new DMSExtras.DMSExtras.TextListener();
145+
Tuple<int, string> Tuple = new Tuple<int, string>(0, "");
146+
Tuple<int,int> BoardDimensions = CurrentUser.Read_User_BoardSettings();
119147

120148
ChooseChat:
121149
bool ChooseChatLoop = true;
@@ -157,7 +185,9 @@ static void Main(string[] args)
157185
for (int i = 0; i < Step-1; i++) {
158186
if ((Multiplyer*Step)+i < var.Length) {
159187
DisplayedChats[i] = var[(Multiplyer*Step)+i];
160-
} if ((Multiplyer*Step)+i >= var.Length) { DisplayedChats[i] = "{EMPTY}"; }
188+
} if ((Multiplyer*Step)+i >= var.Length) {
189+
DisplayedChats[i] = "{EMPTY}";
190+
}
161191
}
162192
DisplayedChats[Step-1] = "Go Back";
163193
DisplayedChats[Step] = "Next (pg "+Multiplyer+"/"+Math.Ceiling((decimal)(var.Length/Step))+")";
@@ -175,30 +205,14 @@ static void Main(string[] args)
175205
CurrentUser.Generate_Chat(DisplayedChats[Tuple.Item1]);
176206
}
177207
}
178-
179-
180-
181208
string SelectedChat = DisplayedChats[Tuple.Item1];
182-
209+
string OtherUser = SelectedChat;
183210
SelectedChat = CurrentUser.Read_Messages_FileName(SelectedChat);
184-
185-
186211
string[] ChatContent = File.ReadLines(@"chats\"+SelectedChat+".txt").ToArray();
187-
188-
189212
string[] DecryptedChatContent = CurrentUser.Read_Messages_Chat(ChatContent);
190-
191-
//User.Display.Content(DecryptedChatContent);
192-
193213
Tuple<string, string> SymmetricKey = CurrentUser.Read_Chat_SymmetricKey(ChatContent);
194-
195-
196-
// while (true) { System.Threading.Thread.Sleep(5000); }
197-
198-
199-
PrivateChatLoop(SelectedChat, BoardDimensions, CurrentUser, SymmetricKey);
200-
201-
214+
TextListener.StopListening();
215+
PrivateChatLoop(SelectedChat, BoardDimensions, CurrentUser, SymmetricKey, OtherUser);
202216
}
203217

204218

@@ -246,7 +260,7 @@ public static Tuple<int, string> MenuLoop(string[] Content, Tuple<int,int> Board
246260
return new Tuple<int, string>(Pointer, TypedText);
247261
}
248262

249-
public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDimensions, User.User CurrentUser, Tuple<string, string> SymmetricKey) {
263+
public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDimensions, User.User CurrentUser, Tuple<string, string> SymmetricKey, string OtherUser) {
250264
DMSExtras.DMSExtras.TextListener TextListener = new DMSExtras.DMSExtras.TextListener();
251265
DMSExtras.DMSExtras.ChatListener ChatListener = new DMSExtras.DMSExtras.ChatListener();
252266

@@ -273,16 +287,19 @@ public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDim
273287
TextListener.StartListening();
274288
while (true)
275289
{
276-
// Console.WriteLine("start");
290+
277291
Thread.Sleep(50);
278292

279293
if (TextListener.GetEndProgram() && !string.IsNullOrEmpty(TypedText)) {
280294

281295
if (BadWords.BadWords.list.Any(TypedText.Contains)) {
282296
Console.WriteLine("bad Word Found, Message not Sent");
283297
System.Threading.Thread.Sleep(1000);
298+
TextListener.StopListening();
299+
TextListener.SetEndProgram(false);
300+
TextListener.StartListening();
284301
} else {
285-
CurrentUser.Write_Messages_Chat(SymmetricKey, SelectedChat, TypedText);
302+
CurrentUser.Write_Messages_Chat(SymmetricKey, SelectedChat, "["+CurrentUser.Username+"] "+TypedText);
286303

287304
TextListener.StopListening();
288305
TextListener.SetTypedText("");
@@ -297,7 +314,7 @@ public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDim
297314

298315
TypedText = TextListener.GetTypedText();
299316

300-
User.User.Display.Content(DecryptedMessages,BoardDimensions,TypedText, true);
317+
User.User.Display.Content(DecryptedMessages,BoardDimensions,TypedText, true, OtherUser);
301318
// Console.WriteLine("text end");
302319

303320
}
@@ -309,12 +326,98 @@ public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDim
309326
ChatMessages = ChatListener.GetChatContent();
310327
DecryptedMessages = CurrentUser.Read_Messages_Chat(ChatMessages);
311328

312-
313-
User.User.Display.Content(DecryptedMessages,BoardDimensions,TypedText, true);
329+
User.User.Display.Content(DecryptedMessages,BoardDimensions,TypedText, true, OtherUser);
314330
// Console.WriteLine("chat end");
315331

316332
}
317333
// Console.WriteLine("end");
318334
}
319335
}
336+
337+
public static void ChangeSettings(User.User CurrentUser) {
338+
Tuple<int,int> BoardDimensions = CurrentUser.Read_User_BoardSettings();
339+
DMSExtras.DMSExtras.TextListener TextListener = new DMSExtras.DMSExtras.TextListener();
340+
string connectionString = "Data Source=UserList.db;Version=3;";
341+
342+
string[] Content = new string[3]{"Exit Settings", "Width: "+BoardDimensions.Item1, "Height: "+BoardDimensions.Item2};
343+
344+
TextListener.SetPointer(0);
345+
TextListener.SetTypedText(" ");
346+
TextListener.SetEndProgram(false);
347+
348+
int Pointer = 0;
349+
string TypedText = " ";
350+
int TempInt = 0;
351+
string TempString = "";
352+
var Value = 0;
353+
354+
User.User.Display.With.Pointer(Content,BoardDimensions,Pointer,TypedText);
355+
356+
TextListener.StartListening();
357+
358+
while (true) {
359+
Thread.Sleep(50);
360+
// Console.WriteLine(Pointer);
361+
if (TypedText != TextListener.GetTypedText()) {
362+
363+
TypedText = TextListener.GetTypedText();
364+
365+
User.User.Display.With.Pointer(Content,BoardDimensions,Pointer,TypedText);
366+
}
367+
368+
if (Pointer != TextListener.GetPointer()) {
369+
370+
Pointer = TextListener.GetPointer();
371+
372+
if (Pointer >= Content.Length) {
373+
TextListener.SetPointer(0);
374+
} else if (Pointer < 0) {
375+
TextListener.SetPointer(Content.Length-1);
376+
}
377+
378+
User.User.Display.With.Pointer(Content,BoardDimensions,Pointer,TypedText);
379+
380+
}
381+
382+
if (TextListener.GetEndProgram()) {
383+
if (Pointer == 0) {
384+
TextListener.StopListening();
385+
return;
386+
} else if (Pointer == 1) {
387+
if (int.TryParse(TypedText, out TempInt)) {
388+
Value = int.Parse(TypedText);
389+
} else {
390+
Value = 25;
391+
}
392+
TempString = "Width";
393+
} else if (Pointer == 2) {
394+
if (int.TryParse(TypedText, out TempInt)) {
395+
Value = int.Parse(TypedText);
396+
} else {
397+
Value = 25;
398+
}
399+
TempString = "Height";
400+
}
401+
402+
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
403+
{
404+
connection.Open();
405+
string sql = "UPDATE Main SET "+TempString+" = @newValue WHERE Username = @username";
406+
using (SQLiteCommand command = new SQLiteCommand(sql, connection))
407+
{
408+
command.Parameters.AddWithValue("@newValue", Value);
409+
command.Parameters.AddWithValue("@username", CurrentUser.Username);
410+
command.ExecuteNonQuery();
411+
}
412+
}
413+
414+
TextListener.StopListening();
415+
TextListener.SetEndProgram(false);
416+
TextListener.SetTypedText(" ");
417+
TextListener.StartListening();
418+
BoardDimensions = CurrentUser.Read_User_BoardSettings();
419+
Content = new string[3]{"Exit", "Width: "+BoardDimensions.Item1, "Height: "+BoardDimensions.Item2};
420+
}
421+
}
422+
}
320423
}

0 commit comments

Comments
 (0)