Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

Commit

Permalink
Telnet working.
Browse files Browse the repository at this point in the history
Todo: Add options to configure telnet.
  • Loading branch information
NiekNijland committed Mar 16, 2021
1 parent 5fedf69 commit db613b6
Show file tree
Hide file tree
Showing 18 changed files with 30 additions and 15 deletions.
Binary file modified .vs/CsgoTranslator/v16/.suo
Binary file not shown.
2 changes: 1 addition & 1 deletion CsgoTranslator/Controllers/LogsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static public void LoadLogs(int amount)
{
Chat chat = new Chat(chatTypes[i], names[i], messages[i]);
Chats.Add(chat);
if(chat.ChatType == ChatType.All)
if(chat.ChatType == ChatType.All && chat.Translation != chat.Message && chat.Translation != "")
{
TelnetHelper.SendTranslationInTeamChat(chat);
}
Expand Down
10 changes: 7 additions & 3 deletions CsgoTranslator/Helpers/Translator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ namespace CsgoTranslator
/// </summary>
public static class Translator
{
public static string Translate(string sourceText)
public static string Translate(string sourceText, string lang = null)
{
//Downloading translation
if(lang == null)
{
lang = Properties.Settings.Default.Lang;
}

string url = string.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={0}&dt=t&q={1}",Properties.Settings.Default.Lang,HttpUtility.UrlEncode (sourceText));
string url = string.Format("https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl={0}&dt=t&q={1}", lang , HttpUtility.UrlEncode (sourceText));
string outputFile = Path.GetTempFileName();

//sometimes will throw an exeption when too many requests are made
Expand All @@ -30,7 +34,7 @@ public static string Translate(string sourceText)
}
catch(Exception)
{
return null;
return "";
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion CsgoTranslator/MinimalisticTelnet/MinimalisticTelnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ private bool Connect()

public void WriteLine(string cmd)
{
byte[] buf = System.Text.ASCIIEncoding.ASCII.GetBytes((cmd + "\n").Replace("\0xFF", "\0xFF\0xFF"));
var utf8 = Encoding.UTF8;
byte[] buf = utf8.GetBytes((cmd + "\n").Replace("\0xFF", "\0xFF\0xFF"));

_tcpSocket.GetStream().Write(buf, 0, buf.Length);
}

Expand Down
11 changes: 7 additions & 4 deletions CsgoTranslator/Models/Command.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
namespace CsgoTranslator
using System;

namespace CsgoTranslator
{
public abstract class Command
{
public string Name { get; private set; }
public string Message { get; set; }
public ChatType ChatType { get; private set; }
public string CommandParams { get; private set; }
public string LangParam { get; private set; }

private bool _executed;
public bool Executed
Expand All @@ -20,12 +22,13 @@ public bool Executed
}
}

protected Command(ChatType chatType, string name, string message, string commandParams = null)
protected Command(ChatType chatType, string name, string message, string langParam = null)
{
this.Name = name;
this.Message = message;
this.ChatType = chatType;
this.CommandParams = commandParams;
this.LangParam = langParam;
Console.WriteLine($"param: {langParam}");
this.Executed = false;
}

Expand Down
2 changes: 1 addition & 1 deletion CsgoTranslator/Models/TransAllCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ public TransAllCommand(ChatType chatType, string name, string message, string co

public override void Execute()
{
TelnetHelper.SendInAllChat(Translator.Translate(this.Message));
TelnetHelper.SendInAllChat(Translator.Translate(this.Message, this.LangParam));
this.Executed = true;
}
}
Expand Down
8 changes: 7 additions & 1 deletion CsgoTranslator/Models/TransTeamCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ public TransTeamCommand(ChatType chatType, string name, string message, string c

public override void Execute()
{
TelnetHelper.SendInTeamChat(Translator.Translate(this.Message));
string translation = Translator.Translate(this.Message, this.LangParam).Trim();

if(translation != this.Message && translation != "")
{
TelnetHelper.SendInTeamChat(translation);
}

this.Executed = true;
}
}
Expand Down
Binary file modified CsgoTranslator/bin/Release/CsgoTranslator.exe
Binary file not shown.
Binary file modified CsgoTranslator/bin/Release/CsgoTranslator.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
68c945506b189a3d5b31c15201a3460debf61d1e
257c914ca1429d5075537121b4af7d402a879d45
Binary file not shown.
Binary file modified CsgoTranslator/obj/Release/CsgoTranslator.exe
Binary file not shown.
Binary file modified CsgoTranslator/obj/Release/CsgoTranslator.g.resources
Binary file not shown.
Binary file modified CsgoTranslator/obj/Release/CsgoTranslator.pdb
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ TRACE
C:\Users\Niek Nijland\source\repos\CSGO-Translator\CsgoTranslator\App.xaml
21361147038

141317569001
16-2061352256
12613261466
MainWindow.xaml;OptionsWindow.xaml;

Expand Down
Binary file not shown.
2 changes: 1 addition & 1 deletion CsgoTranslator/obj/Release/MainWindow.g.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "033F05B18CE74F62E82BED1D099F5854C700B4444B150145057897EF56FB156D"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "350E6D81018B1C2F7DA8EB6D8E18D815F057F757A9325740339BDF75CB8EE4FE"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down
2 changes: 1 addition & 1 deletion CsgoTranslator/obj/Release/MainWindow.g.i.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "033F05B18CE74F62E82BED1D099F5854C700B4444B150145057897EF56FB156D"
#pragma checksum "..\..\MainWindow.xaml" "{8829d00f-11b8-4213-878b-770e8597ac16}" "350E6D81018B1C2F7DA8EB6D8E18D815F057F757A9325740339BDF75CB8EE4FE"
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
Expand Down

0 comments on commit db613b6

Please sign in to comment.