Skip to content

Commit

Permalink
smol update
Browse files Browse the repository at this point in the history
  • Loading branch information
leftspace89 committed Dec 10, 2020
1 parent 8c13188 commit 6e7196b
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 147 deletions.
6 changes: 5 additions & 1 deletion FWManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public class FWManager


public string chat_ip = string.Empty;
public string chat_dom = string.Empty;

public string RunAction(string strCmdText)
{

Expand Down Expand Up @@ -60,8 +62,10 @@ public void blockLOL()

if (str.Contains("LeftSpace_LolOfflineMode"))
{

LDebug.WriteLine("Chat endpoint already blocked");
return;
unblockLOL();

}


Expand Down
88 changes: 19 additions & 69 deletions LChatHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,21 @@ namespace LeagueOFFLINE
public class LChatHelper
{

public static List<string> servers = new List<string>()
{
"tr1.chat.si.riotgames.com",
"br.chat.si.riotgames.com",
"eun1.chat.si.riotgames.com",
"euw1.chat.si.riotgames.com",
"jp1.chat.si.riotgames.com",
"la1.chat.si.riotgames.com",
"la2.chat.si.riotgames.com",
"na2.chat.si.riotgames.com",
"oc1.chat.si.riotgames.com",
"ru1.chat.si.riotgames.com",
"na2.chat.si.riotgames.com"
};

public string lolPath = @"C:\Riot Games\League of Legends\";
public string GetLOLPath()
{
Expand Down Expand Up @@ -43,6 +58,7 @@ public string GetLOLPath()

public void Init()
{
lolPath = GetLOLPath();
if (!Directory.Exists(lolPath))
{
LDebug.WriteLine("Trying get LOL Path");
Expand All @@ -55,56 +71,12 @@ public void Init()
}
}

public string GetLog()
{
var defaultPath = Path.Combine(lolPath, @"Logs\LeagueClient Logs"); ;
var dir = Directory.GetFiles(defaultPath, "*_LeagueClient.log");
var mlog = "";
var ltime = TimeSpan.MaxValue;
foreach (var d in dir)
{
var curDelta = ltime.Subtract(new TimeSpan(File.GetLastAccessTime(d).Ticks));
if (curDelta < ltime)
{
ltime = curDelta;
mlog = d;
}
}
if (string.IsNullOrEmpty(mlog))
throw new ArgumentException("empty string", "mlog");

return mlog;
}
public string ReadClientLog()
{
try
{
var path = GetLog();
using (FileStream fileStream = new FileStream(
path,
FileMode.Open,
FileAccess.Read,
FileShare.ReadWrite))
{
using (StreamReader streamReader = new StreamReader(fileStream))
{
return streamReader.ReadToEnd();
}
}
}
catch (Exception ex)
{
LDebug.WriteLine(ex.ToString());
}

throw new ArgumentException("failed to read client log", "streamReader");

}

public string GetIPFromDomain()
{
try
{
var dns = Dns.GetHostAddresses(GetChatDomain()).FirstOrDefault();
var dns = Dns.GetHostAddresses(Globals.fw.chat_dom).FirstOrDefault();
if (dns != null)
return dns.ToString();
}
Expand All @@ -115,29 +87,7 @@ public string GetIPFromDomain()

throw new ArgumentException("ip null", "ping");
}
public string GetChatDomain()
{
try
{
string pattern = @"rcp-be-lol-chat\| Chat configured to (.*):5223";
var content = ReadClientLog().Split(new string[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries).Where(x => x.Contains("rcp-be-lol-chat"));
foreach (var s in content)
{
var IPRegex = Regex.Match(s, pattern);
if (IPRegex.Success)
{
return IPRegex.Groups[1].Value.ToString();
}
}

}
catch (Exception ex)
{
LDebug.WriteLine(ex.ToString());
}

throw new ArgumentException("failed to read client log", "IPRegex");
}

}

}
88 changes: 40 additions & 48 deletions LSLolOffline.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

65 changes: 39 additions & 26 deletions LSLolOffline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@ private void switchButton_Click(object sender, EventArgs e)
try
{


if (Globals.fw.isBlocked())
var isBlocked = Globals.fw.isBlocked();
if (isBlocked)
{
Globals.fw.unblockLOL();
}
else
{
Globals.fw.blockLOL();
}


UpdateState();

UpdateState(!isBlocked);

}
catch (Exception ex)
Expand All @@ -44,42 +44,55 @@ private void switchButton_Click(object sender, EventArgs e)
}
}

private void UpdateState()
{


if (Globals.fw.isBlocked())
{
switchButton.Text = "Switch to Online";
toolStripStatusLabel1.Text = "[OFFLINE MODE]";
statusStrip1.ForeColor = Color.DarkRed;
}
else
{
switchButton.Text = "Switch to Offline";
toolStripStatusLabel1.Text = "[ONLINE MODE]";
statusStrip1.ForeColor = Color.DarkGreen;

}
}

private void LSLolOffline_Load(object sender, EventArgs e)
{
try
{
srvbox.SelectedIndex = 0;

Globals.lc.Init();
Globals.fw.chat_ip = Globals.lc.GetIPFromDomain();

Globals.fw.test();

pathText.Text = Globals.lc.lolPath;
UpdateState();



}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}

private void pathText_TextChanged(object sender, EventArgs e)
{

}

private void UpdateState(bool isBlocked)
{
if (isBlocked)
{
switchButton.Text = "Switch to Online";
}
else
{
switchButton.Text = "Switch to Offline";
}

srvbox.ForeColor = isBlocked ? System.Drawing.Color.Red : System.Drawing.Color.Green;
}
private void srvbox_SelectedIndexChanged(object sender, EventArgs e)
{

Globals.fw.chat_dom = srvbox.Items[srvbox.SelectedIndex].ToString();

var isBlocked = Globals.fw.isBlocked();
srvLabel.Focus();
UpdateState(isBlocked);



}
}
}
3 changes: 0 additions & 3 deletions LSLolOffline.resx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,4 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
6 changes: 6 additions & 0 deletions bin/Debug/LeagueOFFLINE.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
2 changes: 2 additions & 0 deletions bin/Debug/Log.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Chat endpoint already blocked
Chat endpoint already blocked
6 changes: 6 additions & 0 deletions bin/Release/LeagueOFFLINE.exe.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>
Binary file added obj/Debug/LeagueOFFLINE.LSLolOffline.resources
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 6e7196b

Please sign in to comment.