diff --git a/Luski/Clesses/Settings.cs b/Luski/Clesses/Settings.cs index f9fef7f..462e75f 100644 --- a/Luski/Clesses/Settings.cs +++ b/Luski/Clesses/Settings.cs @@ -8,6 +8,12 @@ public class Settings [JsonPropertyName("scale")] public double Scale { get; set; } = 1; [JsonInclude] + [JsonPropertyName("api_domain")] + public string Domain { get; set; } = "api.beta.luski.jacobtech.com"; + [JsonInclude] + [JsonPropertyName("api_v")] + public string Version { get; set; } = "v1"; + [JsonInclude] [JsonPropertyName("perscrollpixels")] public uint PerScrollPixels { get; set; } = 20; [JsonInclude] diff --git a/Luski/Clesses/UpdaterSettings.cs b/Luski/Clesses/UpdaterSettings.cs index 5e3a68a..8df4964 100644 --- a/Luski/Clesses/UpdaterSettings.cs +++ b/Luski/Clesses/UpdaterSettings.cs @@ -15,7 +15,7 @@ public class UpdaterSettings [JsonInclude] [JsonPropertyName("branch")] - public Branch Branch { get; set; } = Branch.Beta; + public string Branch { get; set; } = "beta"; [JsonInclude] [JsonPropertyName("platform")] diff --git a/Luski/GUI/MainScreen.cs b/Luski/GUI/MainScreen.cs index a3ed2da..87df501 100644 --- a/Luski/GUI/MainScreen.cs +++ b/Luski/GUI/MainScreen.cs @@ -6,13 +6,16 @@ using GraphicsManager.Enums; using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; +using JacobTechEncryption; using Luski.GUI.MainScreen.Interfaces; using Luski.GUI.MainScreen.UI; using Luski.GUI.StartPage.UI; using Luski.net; using Luski.net.Enums; +using Luski.net.Enums.Main; using Luski.net.Interfaces; using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.Desktop; @@ -101,8 +104,8 @@ public class MainScreen : Window Thread t = new(_ => { - Encryption.GenerateKeys(); - + Globals.Luski.MainServer.EncryptionHandler.GenerateKeys(); + }); t.Start(); WindowLoaded += OnWindowLoaded; @@ -131,7 +134,7 @@ public class MainScreen : Window return Task.CompletedTask; } - public void AddGroup(SocketGroupChannel group) + public void AddGroup(MainSocketGroupChannel group) { Group friend = new(group); friend.ClickCon += ChannelOnClickCon; @@ -143,20 +146,20 @@ public class MainScreen : Window private List chans = new(); private Dictionary FR_Index = new(); - public void AddFriendRequest(SocketRemoteUser user) + public void AddFriendRequest(MainSocketRemoteUser user) { FriendRequest frui = new(this, user); FR_Index.Add(user.Id, friend_request!.Controls.Length); friend_request.Controls.Add(frui); } - public void RemoveFriendRequest(SocketRemoteUser user) + public void RemoveFriendRequest(MainSocketRemoteUser user) { if (!FR_Index.ContainsKey(user.Id)) return; friend_request!.Controls.Remove(friend_request!.Controls[FR_Index[user.Id]]); } - public void AddFriend(SocketRemoteUser user) + public void AddFriend(MainSocketRemoteUser user) { Friend friend2 = new(user); friend2.ClickCon += ChannelOnClickCon; @@ -202,16 +205,14 @@ public class MainScreen : Window channelCancellationToken.Cancel(false); } channelCancellationToken = new CancellationTokenSource(); - Globals.Luski.ChangeChannel(arg.Channel.Id, channelCancellationToken.Token, Globals.Luski.CurrentUser.Servers.First()).Wait(); + //Globals.Luski.ChangeChannel(arg.Channel.Id, channelCancellationToken.Token).Wait(); Invoke(new Action(() => { chat!.Clear(); })); - IReadOnlyList messages = arg.Channel.GetMessages(channelCancellationToken.Token, Globals.Settings.LoadPerChannel).Result; - + IReadOnlyList messages = arg.Channel.GetMessages(channelCancellationToken.Token, Globals.Settings.LoadPerChannel).Result; - - foreach (SocketMessage message in messages.Reverse()) + foreach (MainSocketMessage message in messages.Reverse()) { if (channelCancellationToken is null || channelCancellationToken.Token.IsCancellationRequested) return; Invoke(new Action(() => @@ -249,7 +250,7 @@ public class MainScreen : Window // Luski.net.Encryption.File.Channels.AddKey(69, Private); //Clip // Console.WriteLine(Public); - Globals.Luski.SetMultiThreadPercent(Globals.Settings.MultiThreadPercent); + //Globals.Luski.SetMultiThreadPercent(Globals.Settings.MultiThreadPercent); Size = new((int)(1332 * Globals.Settings.Scale), (int)(866 * Globals.Settings.Scale)); DateTime start = DateTime.Now; CenterWindow(0); @@ -258,18 +259,12 @@ public class MainScreen : Window BackgroundColor = new Color4(34, 34, 34, 255); Rectangle u=new Rectangle(TextureManager.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Status.png"))) { Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Size = new((int)(46 * Globals.Settings.Scale)), Location = new((int)(62 * Globals.Settings.Scale), (int)(812 * Globals.Settings.Scale))}; - Texture uut = TextureManager.AddTexture(Globals.Luski.CurrentUser.GetAvatar(CancellationToken.None, Globals.Luski.CurrentUser.Servers.First()).Result); + Texture uut = TextureManager.AddTexture(Globals.Luski.MainServer.User.GetAvatar(CancellationToken.None).Result); uut.Unit = TextureUnit.Texture1; u.Shader = Rectangle.DefaultAlphaTextureShader[Context]; u.Textures.Add(uut); Controls.Add(u); - Globals.Luski.CurrentUser.AddServer(SocketServer.GetServer("TCLL.LuskiServers.JacobTech.com")); - foreach (SocketServer Server in Globals.Luski.CurrentUser.Servers) - { - Console.WriteLine("Loading Server: {0}", Server.Domain); - //add server to UI - } - Label ul = new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new(0, (int)(826 * Globals.Settings.Scale)), Text = Globals.Luski.CurrentUser.Username}; + Label ul = new Label(){ Font = Globals.DefaultFont, Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left, Location = new(0, (int)(826 * Globals.Settings.Scale)), Text = Globals.Luski.MainServer.User.DisplayName }; FlowLayout ser; ul.Location = new((int)(112 * Globals.Settings.Scale), (u.Location.Y + (u.Size.Y/2) - (ul.PostiveTrueHeight/2) - ul.Size.Y + ul.TrueHeight)); @@ -316,24 +311,24 @@ public class MainScreen : Window channelpicker.Controls.Add(FriendManagerBtn = new RoundedButton() { Font = Globals.DefaultFont, Text = "Friends", Size = new((int)(52* Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan}); FriendManagerBtn.Clicked += FriendManagerBtnOnClicked; Console.WriteLine("Templates loaded in " + (DateTime.Now - start).TotalSeconds + " seconds"); - foreach (SocketGroupChannel ch in Globals.Luski.CurrentUser.Channels.Where(s => s is SocketGroupChannel).Cast()) + foreach (MainSocketGroupChannel ch in Globals.Luski.MainServer.User.Channels.Where(s => s is MainSocketGroupChannel).Cast()) { AddGroup(ch); } - foreach (SocketRemoteUser item in Globals.Luski.CurrentUser.Friends) + foreach (MainSocketRemoteUser item in Globals.Luski.MainServer.User.Friends) { if (item.Channel is not null) AddFriend(item); } Console.WriteLine("Channels done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - SocketTextChannel chan = Globals.Luski.GetChannel(Globals.Luski.CurrentUser.SelectedChannel, CancellationToken.None, Globals.Luski.CurrentUser.Servers.First()).Result; + MainSocketTextChannel chan = Globals.Luski.MainServer.GetChannel(Globals.Luski.MainServer.User.SelectedChannel, CancellationToken.None).Result; chat.UpdateTitle(chans.First(s => s.Channel.Id == chan.Id)); chat.MessageFlow.BlockDraw = true; try { - IReadOnlyList messages = chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; + IReadOnlyList messages = chan.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; Console.WriteLine("Messages done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - foreach (SocketMessage message in messages.Reverse()) + foreach (MainSocketMessage message in messages.Reverse()) { chat.AddMessage(TextureManager, message); } @@ -348,7 +343,7 @@ public class MainScreen : Window chat.MessageFlow.BlockDraw = false; Console.WriteLine("Messages Fonts done in " + (DateTime.Now - start).TotalSeconds + " seconds"); - foreach (SocketRemoteUser cufr in Globals.Luski.CurrentUser.FriendRequests) + foreach (MainSocketRemoteUser cufr in Globals.Luski.MainServer.User.FriendRequests) { AddFriendRequest(cufr); } @@ -363,10 +358,10 @@ public class MainScreen : Window private Task OnMainShow() { - Globals.Luski.OnError += LuskiOnOnError; - Globals.Luski.UserStatusUpdate += LuskiOnUserStatusUpdate; - Globals.Luski.ReceivedFriendRequest += LuskiOnReceivedFriendRequest; - Globals.Luski.FriendRequestResult += LuskiOnFriendRequestResult; + Globals.Luski.MainServer.OnError += LuskiOnOnError; + Globals.Luski.MainServer.UserStatusUpdate += LuskiOnUserStatusUpdate; + Globals.Luski.MainServer.ReceivedFriendRequest += LuskiOnReceivedFriendRequest; + Globals.Luski.MainServer.FriendRequestResult += LuskiOnFriendRequestResult; return Task.CompletedTask; } @@ -378,7 +373,7 @@ public class MainScreen : Window return Task.CompletedTask; } - private Task LuskiOnFriendRequestResult(SocketRemoteUser arg1, bool arg2) + private Task LuskiOnFriendRequestResult(MainSocketRemoteUser arg1, bool arg2) { Console.WriteLine("new result"); Invoke(new Action(() => @@ -389,7 +384,7 @@ public class MainScreen : Window return Task.CompletedTask; } - private Task LuskiOnReceivedFriendRequest(SocketRemoteUser arg) + private Task LuskiOnReceivedFriendRequest(MainSocketRemoteUser arg) { Invoke(new Action(() => { @@ -402,7 +397,7 @@ public class MainScreen : Window { Console.WriteLine(before); Console.WriteLine(After); - if (before is not SocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends || Before.Id == 0) return Task.CompletedTask; + if (before is not MainSocketRemoteUser Before || Before.FriendStatus != FriendStatus.Friends || Before.Id == 0) return Task.CompletedTask; Friend per = fr.Where(s => s.User.Id == before.Id).First()!; Label stat = per.Status; Invoke(new Action(() => diff --git a/Luski/GUI/MainScreen/Interfaces/IChannelPick.cs b/Luski/GUI/MainScreen/Interfaces/IChannelPick.cs index ae7cfcf..ff782af 100644 --- a/Luski/GUI/MainScreen/Interfaces/IChannelPick.cs +++ b/Luski/GUI/MainScreen/Interfaces/IChannelPick.cs @@ -1,8 +1,8 @@ -using Luski.net.JsonTypes; +using Luski.net.Structures.Main; namespace Luski.GUI.MainScreen.Interfaces; public interface IChannelPick { - public SocketTextChannel Channel { get; } + public MainSocketTextChannel Channel { get; } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/AddFriendPage.cs b/Luski/GUI/MainScreen/UI/AddFriendPage.cs index eae05af..c98bfe1 100644 --- a/Luski/GUI/MainScreen/UI/AddFriendPage.cs +++ b/Luski/GUI/MainScreen/UI/AddFriendPage.cs @@ -1,6 +1,6 @@ using GraphicsManager.Enums; using GraphicsManager.Objects; -using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.GraphicsLibraryFramework; @@ -31,15 +31,15 @@ public class AddFriendPage : FlowLayout Input.BorderColor = Color4.Red; return Task.CompletedTask; } - SocketRemoteUser? result = Globals.Luski.SendFriendRequest(code, CancellationToken.None).Result; - if (result is null) Input.BorderColor = Color4.Red; - else - { - if (result.Channel is null) - Screen.AddFriendRequest(result); - else - Screen.AddFriend(result); - } + // MainSocketRemoteUser? result = Globals.Luski.MainServer.SendFriendRequest(code, CancellationToken.None).Result; + //if (result is null) Input.BorderColor = Color4.Red; + // else + // { + // if (result.Channel is null) + // Screen.AddFriendRequest(result); + // else + // Screen.AddFriend(result); + //} return Task.CompletedTask; } } \ No newline at end of file diff --git a/Luski/GUI/MainScreen/UI/Chat.cs b/Luski/GUI/MainScreen/UI/Chat.cs index ec6b950..3647e32 100644 --- a/Luski/GUI/MainScreen/UI/Chat.cs +++ b/Luski/GUI/MainScreen/UI/Chat.cs @@ -5,7 +5,9 @@ using GraphicsManager.Objects.Core; using Luski.GUI.MainScreen.Interfaces; using Luski.net; using Luski.net.Enums; +using Luski.net.Enums.Main; using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Mathematics; using OpenTK.Windowing.Common; using OpenTK.Windowing.GraphicsLibraryFramework; @@ -17,7 +19,7 @@ public class Chat : UserControl public FlowLayout MessageFlow; private Label title, desc; private Textbox tb; - private SocketTextChannel? Channel; + private MainSocketTextChannel? Channel; public Chat() { UserControl titlecon; @@ -50,7 +52,7 @@ public class Chat : UserControl Anchor = ObjectAnchor.Bottom | ObjectAnchor.Left | ObjectAnchor.Right }); tb.KeyPress += TbOnKeyPress; - Globals.Luski.MessageReceived += LuskiOnMessageReceived; + Globals.Luski.MainServer.MessageReceived += LuskiOnMessageReceived; } private Task TbOnKeyPress(KeyboardKeyEventArgs arg) @@ -63,11 +65,11 @@ public class Chat : UserControl private void Thr() { - Globals.Luski.SendMessage(tb.Text, Channel!.Id, Globals.Luski.CurrentUser.Servers.First(), CancellationToken.None); + //Globals.Luski.MainServer.SendMessage(tb.Text, Channel!.Id, CancellationToken.None); Window!.Invoke(() => { tb.Text = string.Empty; }); } - private Task LuskiOnMessageReceived(SocketMessage arg) + private Task LuskiOnMessageReceived(MainSocketMessage arg) { if (Channel!.Id != arg.ChannelID) return Task.CompletedTask; IRenderObject? reff = null; @@ -92,7 +94,7 @@ public class Chat : UserControl title.Text = channelPick.Channel.Title; tb.WatermarkFont = Globals.DefaultFont; if (channelPick.Channel.Type == ChannelType.DM) - title.Text = (channelPick.Channel as SocketDMChannel)!.User.Username; + title.Text = (channelPick.Channel as MainSocketDMChannel)!.User.DisplayName; tb.WatermarkText = "Message " + title.Text; if (channelPick.Channel.Description is not null) { @@ -106,11 +108,11 @@ public class Chat : UserControl } } - private SocketMessage? lastm; + private MainSocketMessage? lastm; private long? lastUser; private ChatMessage? LastChatMessage; - public void AddMessage(TextureManager m, SocketMessage Message) + public void AddMessage(TextureManager m, MainSocketMessage Message) { bool hasbeentenmin = false; if (lastm is not null) diff --git a/Luski/GUI/MainScreen/UI/ChatMessage.cs b/Luski/GUI/MainScreen/UI/ChatMessage.cs index a3e620e..b3428a7 100644 --- a/Luski/GUI/MainScreen/UI/ChatMessage.cs +++ b/Luski/GUI/MainScreen/UI/ChatMessage.cs @@ -6,8 +6,10 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using Luski.net; using Luski.net.Enums; +using Luski.net.Enums.Main; using Luski.net.Interfaces; using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; @@ -17,12 +19,12 @@ public class ChatMessage : UserControl { readonly int padding = 2; private static Font TimeFont = Font.MakeFontFromSystem(13); - private SocketMessage Msg { get; } + private MainSocketMessage Msg { get; } private Label label2, lastm; - private static Dictionary Menues = new(); - private static Dictionary> Messages = new(); + private static Dictionary Menues = new(); + private static Dictionary> Messages = new(); - public ChatMessage(TextureManager tm, SocketMessage message) + public ChatMessage(TextureManager tm, MainSocketMessage message) { Label label1; Size = new((int)(723.5 * Globals.Settings.Scale), (int)(37 * Globals.Settings.Scale)); @@ -32,7 +34,7 @@ public class ChatMessage : UserControl IUser user = message.GetAuthor(CancellationToken.None).Result; Anchor = ObjectAnchor.Left | ObjectAnchor.Right; - Controls.Add(label1 = new Label() { Font = Globals.DefaultFont, Location = new((int)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.Username}); + Controls.Add(label1 = new Label() { Font = Globals.DefaultFont, Location = new((int)(54 * Globals.Settings.Scale), (int)(6 * Globals.Settings.Scale)), Text = user.DisplayName}); @@ -53,7 +55,7 @@ public class ChatMessage : UserControl Controls.Add(new Label() { Scale = 0.8f, Font = Globals.DefaultFont, Location = new(label1.Location.X + label1.Size.X + 4, label1.Location.Y), Text = timestr}); Rectangle r = new Rectangle(tm.AddTexture(Tools.GetResourceBytes(Assembly.GetExecutingAssembly(), "Luski.Resources.Textures.Status.png"))) { Location = new((int)(10 * Globals.Settings.Scale), (int)(2 * Globals.Settings.Scale)), Size = new((int)(38 * Globals.Settings.Scale)) }; - Texture tex = tm.AddTexture(user.GetAvatar(CancellationToken.None, Globals.Luski.CurrentUser.Servers.First()).Result); + Texture tex = tm.AddTexture(user.GetAvatar(CancellationToken.None).Result); tex.Unit = TextureUnit.Texture1; r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; r.Textures.Add(tex); @@ -82,7 +84,7 @@ public class ChatMessage : UserControl } } - if (user is SocketRemoteUser u && u.FriendStatus == FriendStatus.NotFriends) + if (user is MainSocketRemoteUser u && u.FriendStatus == FriendStatus.NotFriends) { Tag = u; if (!Menues.ContainsKey(u)) @@ -107,7 +109,7 @@ public class ChatMessage : UserControl private Task DOnClicked(IRenderObject arg) { - if (arg.Tag is ChatMessage u && u.Tag is SocketRemoteUser uu) + if (arg.Tag is ChatMessage u && u.Tag is MainSocketRemoteUser uu) { foreach (ChatMessage cm in Messages[uu]) { @@ -118,18 +120,18 @@ public class ChatMessage : UserControl Messages.Remove(uu); Menues.Remove(uu); - SocketRemoteUser result = Globals.Luski - .SendFriendRequest(long.Parse(uu.friend_codes.First()), CancellationToken.None).Result; - if (result.Channel is null) - Globals.ms.AddFriendRequest(result); - else - Globals.ms.AddFriend(result); + // MainSocketRemoteUser result = Globals.Luski.MainServer + // .SendFriendRequest(long.Parse(uu.friend_codes.First()), CancellationToken.None).Result; + // if (result.Channel is null) + // Globals.ms.AddFriendRequest(result); + // else + // Globals.ms.AddFriend(result); } return Task.CompletedTask; } - public void AddMessage(SocketMessage msg) + public void AddMessage(MainSocketMessage msg) { Label newLabel = new() { @@ -169,7 +171,7 @@ public class ChatMessage : UserControl private Task NewLabel_MouseLeave(IRenderObject sender) { if (sender is not Label label) return Task.CompletedTask; - if (label.Tag is not SocketMessage Message) return Task.CompletedTask; + if (label.Tag is not MainSocketMessage Message) return Task.CompletedTask; DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); string b = time.ToString("h:mm tt"); Label[] l = Labels.Where(s => s.Text == b).ToArray(); @@ -185,7 +187,7 @@ public class ChatMessage : UserControl private Task NewLabel_MouseEnter(IRenderObject sender) { if (sender is not Label label) return Task.CompletedTask; - if (label.Tag is not SocketMessage Message) return Task.CompletedTask; + if (label.Tag is not MainSocketMessage Message) return Task.CompletedTask; DateTime time = new DateTime(2022, 1, 1, 0, 0, 0, 0).AddMilliseconds(Message.Id >> 22).ToLocalTime(); Label m = new() { diff --git a/Luski/GUI/MainScreen/UI/ContentEmbed.cs b/Luski/GUI/MainScreen/UI/ContentEmbed.cs index d732952..a8bcb99 100644 --- a/Luski/GUI/MainScreen/UI/ContentEmbed.cs +++ b/Luski/GUI/MainScreen/UI/ContentEmbed.cs @@ -2,7 +2,7 @@ using System.Reflection; using GraphicsManager; using GraphicsManager.Interfaces; using GraphicsManager.Objects; -using File = Luski.net.JsonTypes.File; +using File = Luski.net.Structures.File; namespace Luski.GUI.MainScreen.UI; diff --git a/Luski/GUI/MainScreen/UI/Friend.cs b/Luski/GUI/MainScreen/UI/Friend.cs index baea8c5..e19b113 100644 --- a/Luski/GUI/MainScreen/UI/Friend.cs +++ b/Luski/GUI/MainScreen/UI/Friend.cs @@ -8,6 +8,7 @@ using Luski.GUI.Windows; using Luski.net; using Luski.net.Enums; using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; using OpenTK.Windowing.GraphicsLibraryFramework; @@ -16,9 +17,9 @@ namespace Luski.GUI.MainScreen.UI; public class Friend : UserControl, IChannelPick { - public SocketRemoteUser User; + public MainSocketRemoteUser User; - public SocketTextChannel Channel + public MainSocketTextChannel Channel { get { @@ -27,13 +28,13 @@ public class Friend : UserControl, IChannelPick } public Rectangle r, rr; public Label Username, Status; - public Friend(SocketRemoteUser person) + public Friend(MainSocketRemoteUser person) { User = person; Size = new((int)(240 * Globals.Settings.Scale), (int)(62* Globals.Settings.Scale)); BackgroundColor = new(34, 34, 34, 255); - Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = person.Username, Location = new((int)(58 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); + Controls.Add(Username = new Label() { Font = Globals.DefaultFont, Text = person.DisplayName, Location = new((int)(58 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); Controls.Add(Status = new Label() { Scale = 0.8f, Font = Globals.DefaultFont, Text = person.Status.ToString(), Location = new((int)(58 * Globals.Settings.Scale),(int)(34* Globals.Settings.Scale))}); @@ -55,7 +56,7 @@ public class Friend : UserControl, IChannelPick UserStatus.Offline or UserStatus.Invisible or _ => Color4.LightGray }; r = new Rectangle(this.rr.Textures.First()) { Location = new(this.rr.Location.X + 4,this.rr.Location.Y + 4), Size = new(this.rr.Size.X - 8)}; - Texture t = Globals.ms.TextureManager.AddTexture(person.GetAvatar(CancellationToken.None, Globals.Luski.CurrentUser.Servers.First()).Result); + Texture t = Globals.ms.TextureManager.AddTexture(person.GetAvatar(CancellationToken.None).Result); t.Unit = TextureUnit.Texture1; r.Textures.Add(t); r.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; diff --git a/Luski/GUI/MainScreen/UI/FriendRequest.cs b/Luski/GUI/MainScreen/UI/FriendRequest.cs index ebc5a4b..8413951 100644 --- a/Luski/GUI/MainScreen/UI/FriendRequest.cs +++ b/Luski/GUI/MainScreen/UI/FriendRequest.cs @@ -6,7 +6,9 @@ using GraphicsManager.Objects; using GraphicsManager.Objects.Core; using Luski.net; using Luski.net.Enums; +using Luski.net.Enums.Main; using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; @@ -15,10 +17,10 @@ namespace Luski.GUI.MainScreen.UI; public class FriendRequest : UserControl { private MainScreen Screen; - public SocketRemoteUser User; + public MainSocketRemoteUser User; public Rectangle? Accept, Reject; - public FriendRequest(MainScreen Parent, SocketRemoteUser User) + public FriendRequest(MainScreen Parent, MainSocketRemoteUser User) { this.User = User; this.Screen = Parent; @@ -32,11 +34,11 @@ public class FriendRequest : UserControl Size = new ((int)(42 * Globals.Settings.Scale)) }); rr.BackgroundColor = BackgroundColor; - Texture t = Globals.ms.TextureManager.AddTexture(User.GetAvatar(CancellationToken.None, Globals.Luski.CurrentUser.Servers.First()).Result); + Texture t = Globals.ms.TextureManager.AddTexture(User.GetAvatar(CancellationToken.None).Result); t.Unit = TextureUnit.Texture1; rr.Textures.Add(t); rr.Shader = Rectangle.DefaultAlphaTextureShader[Globals.ms.Context]; - Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.Username, Location = new((int)(50 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); + Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.DisplayName, Location = new((int)(50 * Globals.Settings.Scale),(int)(14 * Globals.Settings.Scale))}); Controls.Add(new Label() { Font = Globals.DefaultFont, Text = User.FriendStatus.ToString(), Location = new((int)(50 * Globals.Settings.Scale),(int)(32 * Globals.Settings.Scale))}); if (User.FriendStatus == FriendStatus.PendingIn) { @@ -57,14 +59,14 @@ public class FriendRequest : UserControl private Task RejectOnClicked(IRenderObject arg) { - _ = Globals.Luski.SendFriendResult(User.Id, false, CancellationToken.None).Result; + //_ = Globals.Luski.SendFriendResult(User.Id, false, CancellationToken.None).Result; Screen.RemoveFriendRequest(User); return Task.CompletedTask; } private Task AcceptOnClicked(IRenderObject arg) { - Screen.AddFriend(Globals.Luski.SendFriendResult(User.Id, true, CancellationToken.None).Result); + //Screen.AddFriend(Globals.Luski.SendFriendResult(User.Id, true, CancellationToken.None).Result); Screen.RemoveFriendRequest(User); return Task.CompletedTask; } diff --git a/Luski/GUI/MainScreen/UI/Group.cs b/Luski/GUI/MainScreen/UI/Group.cs index 5232dd6..45bd51b 100644 --- a/Luski/GUI/MainScreen/UI/Group.cs +++ b/Luski/GUI/MainScreen/UI/Group.cs @@ -3,8 +3,8 @@ using GraphicsManager; using GraphicsManager.Interfaces; using GraphicsManager.Objects; using GraphicsManager.Objects.Core; -using Luski.net.JsonTypes; using Luski.GUI.MainScreen.Interfaces; +using Luski.net.Structures.Main; using OpenTK.Graphics.OpenGL4; using OpenTK.Mathematics; @@ -12,9 +12,9 @@ namespace Luski.GUI.MainScreen.UI; public class Group : UserControl, IChannelPick { - public SocketTextChannel Channel { get; set; } + public MainSocketTextChannel Channel { get; set; } // private string members = ""; - public Group(SocketGroupChannel chan) + public Group(MainSocketGroupChannel chan) { Label Status, Username; Rectangle r, rr; diff --git a/Luski/GUI/StartPage/UI/CreateAccount.cs b/Luski/GUI/StartPage/UI/CreateAccount.cs index 6743514..ae5def5 100644 --- a/Luski/GUI/StartPage/UI/CreateAccount.cs +++ b/Luski/GUI/StartPage/UI/CreateAccount.cs @@ -15,7 +15,7 @@ namespace Luski.GUI.StartPage.UI; public class CreateAccount : UserControl { private RoundedButton button; - private Textbox Password, Email, Username; + private Textbox Password, UsernameTextbox, DisplaynameTextBox; private Rectangle rec; private string? pfp; @@ -30,23 +30,23 @@ public class CreateAccount : UserControl Controls.Add(t=new Label() { Scale = 1.6f * (float)Globals.Settings.Scale, Font = Globals.DefaultFont, Location = new((int)(199*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) }); t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y); tt.Location = new((Size.X / 2) - (tt.Size.X / 2), tt.Location.Y); - Controls.Add(Email = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Email", Font = Globals.DefaultFont, Location = new((int)(27 * Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale)), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); - Controls.Add(Password = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Password", Font = Globals.DefaultFont, PasswordChar = '●', Location = new(Email.Location.X,(int)(346 * Globals.Settings.Scale)), Size = new(Email.Size.X, Email.Location.X), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); - Controls.Add(Username = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Username", Font = Globals.DefaultFont, Location = new(Email.Location.X,(int)(400 * Globals.Settings.Scale)), Size = new((int)(196 * Globals.Settings.Scale), Email.Location.X), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); - Controls.Add(button = new() { Font = Globals.DefaultFont, Text = "Create Account", Location = new(Email.Location.X, (int)(456 * Globals.Settings.Scale)), Size = new(Email.Size.X, (int)(46 * Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(UsernameTextbox = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Username", Font = Globals.DefaultFont, Location = new((int)(27 * Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale)), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); + Controls.Add(Password = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Password", Font = Globals.DefaultFont, PasswordChar = '●', Location = new(UsernameTextbox.Location.X,(int)(346 * Globals.Settings.Scale)), Size = new(UsernameTextbox.Size.X, UsernameTextbox.Location.X), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(DisplaynameTextBox = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Displayname", Font = Globals.DefaultFont, Location = new(UsernameTextbox.Location.X,(int)(400 * Globals.Settings.Scale)), Size = new((int)(196 * Globals.Settings.Scale), UsernameTextbox.Location.X), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(button = new() { Font = Globals.DefaultFont, Text = "Create Account", Location = new(UsernameTextbox.Location.X, (int)(456 * Globals.Settings.Scale)), Size = new(UsernameTextbox.Size.X, (int)(46 * Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); Controls.Add(rec = new Rectangle(){ Location = new((int)(228 * Globals.Settings.Scale), (int)(384 * Globals.Settings.Scale)), Size = new((int)(50 * Globals.Settings.Scale)), BackgroundColor = Color4.Red}); Password.KeyPress += PasswordOnKeyPress; - Email.KeyPress += EmailOnKeyPress; + UsernameTextbox.KeyPress += UsernameTextboxOnKeyPress; button.Clicked += ButtonOnClicked; - Username.KeyPress += UsernameOnKeyPress; + DisplaynameTextBox.KeyPress += DisplaynameTextBoxOnKeyPress; rec.FilesDroped += RecOnFilesDroped; } - private Task UsernameOnKeyPress(KeyboardKeyEventArgs arg) + private Task DisplaynameTextBoxOnKeyPress(KeyboardKeyEventArgs arg) { if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; if (arg.Key == Keys.Tab && arg.Shift) { Password.Focus(); return Task.CompletedTask; } - if (arg.Key == Keys.Enter || arg.Key == Keys.KeyPadEnter) ButtonOnClicked(Username); + if (arg.Key == Keys.Enter || arg.Key == Keys.KeyPadEnter) ButtonOnClicked(DisplaynameTextBox); return Task.CompletedTask; } @@ -79,7 +79,7 @@ public class CreateAccount : UserControl } private bool tab; - private Task EmailOnKeyPress(KeyboardKeyEventArgs arg) + private Task UsernameTextboxOnKeyPress(KeyboardKeyEventArgs arg) { if (arg.Key != Keys.Tab) return Task.CompletedTask; if (arg.Key == Keys.Tab){ Password.Focus(); tab = true;} @@ -94,8 +94,8 @@ public class CreateAccount : UserControl return Task.CompletedTask; }; if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab && arg.Shift) { Email.Focus(); return Task.CompletedTask; } - if (arg.Key == Keys.Tab ){ Username.Focus(); return Task.CompletedTask; } + if (arg.Key == Keys.Tab && arg.Shift) { UsernameTextbox.Focus(); return Task.CompletedTask; } + if (arg.Key == Keys.Tab ){ DisplaynameTextBox.Focus(); return Task.CompletedTask; } return Task.CompletedTask; } @@ -105,13 +105,13 @@ public class CreateAccount : UserControl { string[] arr = new string[] { - Email.Text, + UsernameTextbox.Text, Password.Text, - Username.Text, + DisplaynameTextBox.Text, pfp! }; if (arr.Any(s => string.IsNullOrEmpty(s))) return Task.CompletedTask; - Globals.Luski = Server.CreateAccount(Email.Text, Password.Text, Username.Text, pfp!, CancellationToken.None, Globals.UpdaterSettings.Branch); + Globals.Luski.MainServer.CreateAccount(UsernameTextbox.Text, Password.Text, DisplaynameTextBox.Text, pfp!, CancellationToken.None); ChangeToApp!.Invoke(); } catch (Exception e) diff --git a/Luski/GUI/StartPage/UI/Login.cs b/Luski/GUI/StartPage/UI/Login.cs index 44a79ec..3f54531 100644 --- a/Luski/GUI/StartPage/UI/Login.cs +++ b/Luski/GUI/StartPage/UI/Login.cs @@ -11,7 +11,7 @@ namespace Luski.GUI.StartPage.UI; public class Login : UserControl { private RoundedButton button; - private Textbox Password, Email; + private Textbox Password, UsernameTextbox; private Label ca; public event Func? ChangeToApp; public event Func? ChangeToCa; @@ -24,12 +24,12 @@ public class Login : UserControl Controls.Add(t=new Label() { Scale = 1.6f, Font = Globals.DefaultFont, Location = new((int)(199*Globals.Settings.Scale)), Text = "Luski", Color = new(243, 119, 53, 255) }); t.Location = new((Size.X / 2) - (t.Size.X / 2), t.Location.Y); tt.Location = new((Size.X / 2) - (tt.Size.X / 2), tt.Location.Y); - Controls.Add(Email = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Email", Font = Globals.DefaultFont, Location = new((int)(27*Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale)), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); - Controls.Add(Password = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Password", Font = Globals.DefaultFont, PasswordChar = '●', Location = new(Email.Location.X,(int)(365 * Globals.Settings.Scale)), Size = Email.Size, InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); - Controls.Add(ca = new Label() { Font = Globals.DefaultFont, Location = new(Email.Location.X,(int)(419 * Globals.Settings.Scale)), Text = "Create Account" }); - Controls.Add(button = new() { Font = Globals.DefaultFont, Text = "Login", Location = new(Email.Location.X, (int)(455 * Globals.Settings.Scale)), Size = new(Email.Size.X,(int)(46 * Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(UsernameTextbox = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Username", Font = Globals.DefaultFont, Location = new((int)(27*Globals.Settings.Scale),(int)(280 * Globals.Settings.Scale)), Size = new((int)(261 * Globals.Settings.Scale),(int)(27 * Globals.Settings.Scale)), InsideColor = new(28,28,28,255), BorderColor = Color4.DarkCyan }); + Controls.Add(Password = new Textbox() { TextLocation = TextLocation.TrueCenterLeft, WatermarkFont = Globals.DefaultFont, WatermarkText = "Password", Font = Globals.DefaultFont, PasswordChar = '●', Location = new(UsernameTextbox.Location.X,(int)(365 * Globals.Settings.Scale)), Size = UsernameTextbox.Size, InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); + Controls.Add(ca = new Label() { Font = Globals.DefaultFont, Location = new(UsernameTextbox.Location.X,(int)(419 * Globals.Settings.Scale)), Text = "Create Account" }); + Controls.Add(button = new() { Font = Globals.DefaultFont, Text = "Login", Location = new(UsernameTextbox.Location.X, (int)(455 * Globals.Settings.Scale)), Size = new(UsernameTextbox.Size.X,(int)(46 * Globals.Settings.Scale)), InsideColor = new(28, 28, 28, 255), BorderColor = Color4.DarkCyan }); Password.KeyPress += PasswordOnKeyPress; - Email.KeyPress += EmailOnKeyPress; + UsernameTextbox.KeyPress += UsernameTextboxOnKeyPress; button.Clicked += ButtonOnClicked; ca.Clicked += CaOnClicked; this.WindowLoaded += OnWindowLoaded; @@ -37,7 +37,7 @@ public class Login : UserControl private Task OnWindowLoaded(IRenderObject arg) { - Email.Focus(); + UsernameTextbox.Focus(); return Task.CompletedTask; } @@ -47,7 +47,7 @@ public class Login : UserControl return Task.CompletedTask; } - private Task EmailOnKeyPress(KeyboardKeyEventArgs arg) + private Task UsernameTextboxOnKeyPress(KeyboardKeyEventArgs arg) { if (arg.Key != Keys.Tab) return Task.CompletedTask; Password.Focus(); @@ -57,7 +57,7 @@ public class Login : UserControl private Task PasswordOnKeyPress(KeyboardKeyEventArgs arg) { if (arg.Key != Keys.Enter && arg.Key != Keys.KeyPadEnter && arg.Key != Keys.Tab) return Task.CompletedTask; - if (arg.Key == Keys.Tab && arg.Shift) Email.Focus(); + if (arg.Key == Keys.Tab && arg.Shift) UsernameTextbox.Focus(); if (arg.Key != Keys.Tab ) ButtonOnClicked(Password); return Task.CompletedTask; } @@ -66,7 +66,7 @@ public class Login : UserControl { try { - Globals.Luski = Server.Login(Email.Text, Password.Text, CancellationToken.None, Globals.UpdaterSettings.Branch).Result; + Globals.Luski.MainServer.Login(UsernameTextbox.Text, Password.Text, CancellationToken.None); ChangeToApp!.Invoke(); } catch (Exception e) @@ -75,7 +75,7 @@ public class Login : UserControl { BlockDraw = true; Password.BorderColor = Color4.DarkRed; - Email.BorderColor = Color4.DarkRed; + UsernameTextbox.BorderColor = Color4.DarkRed; BlockDraw = false; TryDraw(); } diff --git a/Luski/GUI/Windows/ChatWindow.cs b/Luski/GUI/Windows/ChatWindow.cs index 8fe8321..18fa5bc 100644 --- a/Luski/GUI/Windows/ChatWindow.cs +++ b/Luski/GUI/Windows/ChatWindow.cs @@ -2,7 +2,7 @@ using GraphicsManager; using GraphicsManager.Enums; using Luski.GUI.MainScreen.Interfaces; using Luski.GUI.MainScreen.UI; -using Luski.net.JsonTypes; +using Luski.net.Structures.Main; using OpenTK.Windowing.Common; using OpenTK.Windowing.Desktop; @@ -33,9 +33,9 @@ public class ChatWindow : Window Anchor = ObjectAnchor.All }); c.UpdateTitle(pick); - IReadOnlyList messages = pick.Channel.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; + IReadOnlyList messages = pick.Channel.GetMessages(CancellationToken.None, Globals.Settings.LoadPerChannel).Result; - foreach (SocketMessage message in messages.Reverse()) + foreach (MainSocketMessage message in messages.Reverse()) { c!.AddMessage(TextureManager, message); } diff --git a/Luski/Globals.cs b/Luski/Globals.cs index 4bf89af..cc9ab37 100644 --- a/Luski/Globals.cs +++ b/Luski/Globals.cs @@ -12,7 +12,7 @@ public class Globals { #pragma warning disable CS8618 public static bool Download { get; set; } = false; - public static Server Luski { get; set; } = null!; + public static API Luski { get; } = new(); public static MainScreen ms; public static Settings Settings { get; set; } diff --git a/Luski/Luski.csproj b/Luski/Luski.csproj index d9e4235..a072338 100644 --- a/Luski/Luski.csproj +++ b/Luski/Luski.csproj @@ -20,7 +20,7 @@ - + diff --git a/Luski/Program.cs b/Luski/Program.cs index 8d86a31..067aab8 100644 --- a/Luski/Program.cs +++ b/Luski/Program.cs @@ -11,6 +11,10 @@ using Image = OpenTK.Windowing.Common.Input.Image; try { Globals.Settings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "Settings.json"), SettingsContext.Default.Settings); + _ = Globals.Luski.GetMainServer(Globals.Settings.Domain, Globals.Settings.Version); + _ = Globals.Luski.GetPublicServer("TCLL.Luski.JacobTech.com", Globals.Settings.Version); + Console.WriteLine("Conecting to main server '{0}' using API {1}", Globals.Luski.MainServer.Domain, Globals.Luski.MainServer.ApiVersion); + Console.WriteLine("Conecting to public server '{0}' using API {1}", Globals.Luski.LoadedServers.First().Domain, Globals.Luski.LoadedServers.First().ApiVersion); Globals.UpdaterSettings = Globals.GetSettings(Path.Combine(Globals.LuskiPath, "UpdaterSettings.json"), UpdaterSettingsContext.Default.UpdaterSettings); Assembly assembly = Assembly.GetExecutingAssembly(); Stream? resource_stream = assembly.GetManifestResourceStream($"Luski.Resources.Textures.Luski.png"); @@ -18,7 +22,6 @@ try resource_stream?.CopyTo(ms); var Logo = SixLabors.ImageSharp.Image.Load(ms.ToArray()); - //List pixels = new List(4 * Logo.Width * Logo.Height); Span pixels = new byte[4 * Logo.Width * Logo.Height].AsSpan(); Logo.CopyPixelDataTo(pixels);