Skip to content

Commit bb49be7

Browse files
committed
word wrap is now a thing, long messages are no longer an issue (maybe)
1 parent 4c2c874 commit bb49be7

3 files changed

Lines changed: 61 additions & 15 deletions

File tree

Additions.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.IO;
4+
using System.Linq;
35
using System.Security.Cryptography;
46
using System.Text;
5-
using System.Linq;
67
using System.Threading;
78
using Org.BouncyCastle.Crypto;
89
using Org.BouncyCastle.Crypto.Generators;
9-
using Org.BouncyCastle.Security;
10-
using Org.BouncyCastle.OpenSsl;
1110
using Org.BouncyCastle.Crypto.Parameters;
11+
using Org.BouncyCastle.OpenSsl;
12+
using Org.BouncyCastle.Security;
1213

1314
namespace Security
1415
{

User.cs

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ public void Generate_Chat(string Name) {
118118
writer.WriteLine(
119119
this.Username+
120120
":"+
121-
this.Key.Encrypt(SymmetricKey.Item1, User.Read_User_PublicKey(Name))+
121+
this.Key.Encrypt(SymmetricKey.Item1, User.Read_User_PublicKey(this.Username))+
122122
":"+
123-
this.Key.Encrypt(SymmetricKey.Item2, User.Read_User_PublicKey(Name))
123+
this.Key.Encrypt(SymmetricKey.Item2, User.Read_User_PublicKey(this.Username))
124124
);
125125

126126
// User.Read_User_PublicKey(Name);
@@ -208,9 +208,7 @@ public string[] Read_Messages_Chat(string[] EncryptedMessages) {
208208

209209

210210
for (int i = 2; i < EncryptedMessages.Length; i++) {
211-
212211
DecryptedMessages[i-2] = SymmetricEncryption.DecryptString(SymmetricKey.Item1, EncryptedMessages[i], SymmetricKey.Item2);
213-
214212
}
215213

216214
return DecryptedMessages;
@@ -322,6 +320,33 @@ public static string Read_User_PublicKey(string User) {
322320
}
323321
}
324322

323+
public Tuple<int, int> Read_User_BoardSettings() {
324+
string User = this.Username;
325+
var conn = new SQLiteConnection(@"Data Source=UserList.db;Version=3;");
326+
conn.Open();
327+
328+
string stm = "SELECT Width, Height FROM Main WHERE Username = @username";
329+
var cmd = new SQLiteCommand(stm, conn);
330+
cmd.Parameters.AddWithValue("@username", User);
331+
332+
SQLiteDataReader rdr = cmd.ExecuteReader();
333+
334+
if (rdr.Read())
335+
{
336+
//string TempString2 = rdr.GetString(0);
337+
Tuple<int, int> BoardDimensions = new Tuple<int, int>(rdr.GetInt32(0), rdr.GetInt32(1));
338+
rdr.Close();
339+
return BoardDimensions;
340+
}
341+
else
342+
{
343+
while (true) {
344+
Console.WriteLine("error at chat Read_User_BoardSettings (Width)");
345+
Console.Read();
346+
}
347+
}
348+
}
349+
325350
public class Display
326351
{
327352
public class With
@@ -356,8 +381,33 @@ public static void Content(string[] Content, Tuple<int, int> BoardDimensions, st
356381
Board = Square.Create(new Square(Board.Width,Board.Height,Tuple.Create(0,0)), Board);
357382

358383
if (IfChat) {
359-
for (int i = Content.Length-1; i >= 0; i--) {
360-
Board = Text.Create(new Text(Tuple.Create(2,2-(i-(Content.Length-1))), Content[i]), Board);
384+
int Interval = (BoardDimensions.Item1-3)*2; // your interval
385+
List<string> DisplayedMessages = new List<string>(); // we use a List for simplicity, you can convert it to an array later
386+
387+
foreach (string message in Content)
388+
{
389+
if (message.Length > Interval)
390+
{
391+
int startIndex = 0;
392+
while (startIndex < message.Length)
393+
{
394+
int length = Math.Min(Interval, message.Length - startIndex);
395+
DisplayedMessages.Add(message.Substring(startIndex, length));
396+
startIndex += length;
397+
}
398+
}
399+
else
400+
{
401+
DisplayedMessages.Add(message);
402+
}
403+
}
404+
405+
string[] DisplayedMessagesArray = DisplayedMessages.ToArray(); // if you need an array
406+
Array.Reverse(DisplayedMessagesArray);
407+
408+
int VerticalBorder = 5;
409+
for (int i = 0; (i < BoardDimensions.Item2 - VerticalBorder) && (i < DisplayedMessagesArray.Length); i++) {
410+
Board = Text.Create(new Text(Tuple.Create(2,2+i), DisplayedMessagesArray[i]), Board);
361411
}
362412
} else {
363413
for (int i = 0; i < Content.Length; i++) {

program.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ static void Main(string[] args)
115115

116116
Console.WriteLine("Correct Password");
117117

118+
BoardDimensions = CurrentUser.Read_User_BoardSettings();
118119

119120
ChooseChat:
120121
bool ChooseChatLoop = true;
@@ -301,12 +302,6 @@ public static void PrivateChatLoop(string SelectedChat, Tuple<int, int> BoardDim
301302

302303
}
303304

304-
// Console.WriteLine("line");
305-
// Console.WriteLine(ChatMessages.Length);
306-
// Console.WriteLine("line");
307-
// Console.WriteLine(ChatListener.GetChatContent());
308-
// Console.WriteLine("line");
309-
310305
if (!ChatMessages.SequenceEqual(ChatListener.GetChatContent())) {
311306

312307
// Console.WriteLine("chat start");

0 commit comments

Comments
 (0)