Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commit 20231008 #14

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added MySql.Data.dll
Binary file not shown.
Binary file added NetworkCommsDotNet_v3.0.3_ALv2.zip
Binary file not shown.
8 changes: 6 additions & 2 deletions WLMClient/UI/Windows/ChatWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -81,18 +81,22 @@
</Grid>

<Grid Grid.Row="1" UseLayoutRounding="True">
<RichTextBox Name="txtChat" Background="Transparent" BorderThickness="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Margin="0 0 0 32" FontStyle="Normal" FontSize="13" Padding="2 0 0 0" Foreground="Black" IsReadOnly="True" AcceptsReturn="False">
<RichTextBox Name="txtChat" Background="Transparent" BorderThickness="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Margin="0 0 0 32" FontStyle="Normal" FontSize="13" Padding="2 0 0 0" Foreground="Black" IsReadOnly="True" IsDocumentEnabled="True" AcceptsReturn="False">
<RichTextBox.Resources>
<Style TargetType="ScrollBar">
<Setter Property="Background" Value="Transparent"/>
</Style>
<Style TargetType="Hyperlink">
<Setter Property="Cursor" Value="Hand" />
<EventSetter Event="MouseLeftButtonDown" Handler="Hyperlink_MouseLeftButtonDown" />
</Style>
</RichTextBox.Resources>
</RichTextBox>
<RichTextBox Background="Transparent" BorderThickness="0" Name="txtLastUpdate" Height="25" VerticalAlignment="Bottom" FontSize="12" Margin="0 0 0 0" FontFamily="Segoe UI" Focusable="True" Foreground="#FFA0A0A0"></RichTextBox>
</Grid>

<Grid Grid.Row="2" Margin="-2 0 17 41" Background="#FFF9F9F9">
<RichTextBox Name="txtSend" Background="#FFF9F9F9" BorderThickness="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Margin="0 0 0 35" FontStyle="Normal" FontSize="13" Padding="2 4 0 0" Foreground="Black" TextChanged="txtSend_TextChanged" PreviewKeyUp="txtSend_PreviewKeyUp" AcceptsReturn="True" PreviewKeyDown="txtSend_PreviewKeyDown" PreviewDrop="txtSend_PreviewDrop" AllowDrop="True" PreviewDragOver="txtSend_PreviewDragOver"></RichTextBox>
<RichTextBox Name="txtSend" Background="#FFF9F9F9" BorderThickness="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Auto" Margin="0 0 0 35" FontStyle="Normal" FontSize="13" Padding="2 4 0 0" Foreground="Black" TextChanged="txtSend_TextChanged" PreviewKeyUp="txtSend_PreviewKeyUp" AcceptsReturn="True" PreviewKeyDown="txtSend_PreviewKeyDown" PreviewDrop="txtSend_PreviewDrop" AllowDrop="True" PreviewDragOver="txtSend_PreviewDragOver" SpellCheck.IsEnabled="True"></RichTextBox>
<Image Width="1" Margin="-1 0 0 0" HorizontalAlignment="Left" Stretch="Fill" Source="/WLMClient;component/Content/Interface/chatWindowSideBar.png"></Image>
<Image SnapsToDevicePixels="True" RenderOptions.BitmapScalingMode="NearestNeighbor"
RenderOptions.EdgeMode="Aliased" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Bottom" Margin="-13 0 0 0" StretchDirection="Both" Width="13" Height="44" Source="/WLMClient;component/Content/Interface/chatWindowTriangle.png" />
Expand Down
7 changes: 7 additions & 0 deletions WLMClient/UI/Windows/ChatWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
using WLMClient.UI.Data;

using System.Threading;
using System.Diagnostics;

namespace WLMClient.UI.Windows
{
Expand Down Expand Up @@ -527,5 +528,11 @@ public void moveWindow(int top, int left)
this.Left = this.Left + left;
}));
}

public void Hyperlink_MouseLeftButtonDown(object sender, MouseEventArgs e)
{
var hyperlink = (Hyperlink)sender;
Process.Start(hyperlink.NavigateUri.ToString());
}
}
}
68 changes: 51 additions & 17 deletions WLMServer/Database/AccountManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,40 @@ class AccountManager : DBConnection
{
public void UpdateAccount(string id, string name, string comment, string avatar)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", id);
cmd.Parameters.AddWithValue("@1", name);
cmd.Parameters.AddWithValue("@2", comment);
cmd.Parameters.AddWithValue("@3", avatar);

Write("UPDATE account SET name=@1, comment=@2, avatar=@3 WHERE id=@0", cmd);
}
}

public void InsertNewAccount(string username, string password)
{
password = PasswordEncrypter.GetEncryptedPassword(password);

MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", username);
cmd.Parameters.AddWithValue("@1", password);

Write("INSERT INTO account VALUES(@0, 'New User', @1, '', '', '')", cmd);
}
}

public bool IsUserInDatabase(string userID)
{
bool returnValue = false;

MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", userID);

MySqlDataReader reader = Read("SELECT id FROM account WHERE id=@0", cmd);
using (MySqlDataReader reader = Read("SELECT id FROM account WHERE id=@0", cmd))
{
while (reader.Read())
{
if (reader.GetString("id") == userID)
Expand All @@ -53,6 +59,8 @@ public bool IsUserInDatabase(string userID)
}

reader.Close();
}
}

return returnValue;
}
Expand All @@ -62,13 +70,15 @@ public bool AuthenticateAccount(string username, string password, out UserInfo u
bool returnValue = false;
userInfo = null;

MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", username);
cmd.Parameters.AddWithValue("@1", password);

string encryptedPassword = PasswordEncrypter.GetEncryptedPassword(password);

MySqlDataReader reader = Read("SELECT * FROM account WHERE id=@0", cmd);
using (MySqlDataReader reader = Read("SELECT * FROM account WHERE id=@0", cmd))
{
while (reader.Read())
{
if (reader.GetString("password").Equals(encryptedPassword))
Expand All @@ -95,17 +105,23 @@ public bool AuthenticateAccount(string username, string password, out UserInfo u
}

reader.Close();
}
}
return returnValue;
}

public UserInfo GetUser(string id)
{
MySqlCommand cmd = new MySqlCommand();
UserInfo userInfo = null;

using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", id);

MySqlDataReader reader = Read("SELECT * FROM account WHERE id=@0", cmd);
using (MySqlDataReader reader = Read("SELECT * FROM account WHERE id=@0", cmd))
{

UserInfo userInfo = null;

while (reader.Read())
{
userInfo = new UserInfo(reader.GetString("id"),
Expand All @@ -114,6 +130,8 @@ public UserInfo GetUser(string id)
}

reader.Close();
}
}

if (!Config.Properties.AVATAR_ENABLE)
{
Expand All @@ -134,10 +152,12 @@ public List<string> GetFriendRequests(string requesterID)
{
List<string> requests = new List<string>();

MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", requesterID);

MySqlDataReader reader = Read("SELECT requesterID FROM friend_requests WHERE targetID=@0", cmd);
using (MySqlDataReader reader = Read("SELECT requesterID FROM friend_requests WHERE targetID=@0", cmd))
{

while (reader.Read())
{
Expand All @@ -147,17 +167,23 @@ public List<string> GetFriendRequests(string requesterID)
}

reader.Close();
}
}

return requests;
}

public string GetContacts(string id)
{
MySqlCommand cmd = new MySqlCommand();
string contacts = "";

using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", id);

string contacts = "";
MySqlDataReader reader = Read("SELECT contacts FROM account WHERE id=@0", cmd);

using (MySqlDataReader reader = Read("SELECT contacts FROM account WHERE id=@0", cmd))
{
while (reader.Read())
{
contacts = reader.GetString("contacts");
Expand All @@ -166,35 +192,43 @@ public string GetContacts(string id)
}

reader.Close();
}
}

return contacts;
}

public void SaveContactData(string id, string contactData)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", id);
cmd.Parameters.AddWithValue("@1", contactData);

Write("UPDATE account SET contacts=@1 WHERE id=@0", cmd);
}
}

public void AddNewFriendRequest(string requesterID, string targetID)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", requesterID);
cmd.Parameters.AddWithValue("@1", targetID);

Write("INSERT INTO friend_requests VALUES(@0, @1)", cmd);
}
}

public void RemoveFriendRequest(string requesterID, string targetID)
{
MySqlCommand cmd = new MySqlCommand();
using (MySqlCommand cmd = new MySqlCommand())
{
cmd.Parameters.AddWithValue("@0", requesterID);
cmd.Parameters.AddWithValue("@1", targetID);

Write("DELETE FROM friend_requests WHERE requesterID=@0 AND targetID=@1", cmd);
}
}
}
}
8 changes: 6 additions & 2 deletions WLMServer/Database/DBConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ public DBConnection()
{
connectionString = String.Format("server={0};user id={1}; password={2}; database=msn; pooling=false; Charset=utf8; Keepalive=60;",
Config.Properties.DATABASE_HOST, Config.Properties.DATABASE_ID, Config.Properties.DATABASE_PASSWORD);
dbConnection = new MySqlConnection(connectionString);
using (dbConnection = new MySqlConnection(connectionString))
{
dbConnection.Open();
}
}

public void CheckDatabaseAccess()
Expand All @@ -34,13 +36,15 @@ public void CheckDatabaseAccess()
{
try
{
MySqlCommand command = new MySqlCommand();
using (MySqlCommand command = new MySqlCommand())
{
command.Connection = dbConnection;
command.CommandType = CommandType.Text;
command.CommandText = "SELECT 1;";
command.Prepare();

command.ExecuteNonQuery();
}
}
catch
{
Expand Down