2014-04-25 21:55:43 +00:00
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
using System.Net ;
using System.IO ;
using GlacialComponents.Controls ;
using Khendys.Controls ;
using System.Threading ;
using System.Reflection ;
2014-07-12 08:53:00 +00:00
using SzNPProjects ;
2014-10-24 17:02:38 +00:00
using System.Net.Sockets ;
using System.Diagnostics ;
using System.Net.NetworkInformation ;
2014-04-25 21:55:43 +00:00
namespace MSGer.tk
{
2015-03-26 19:36:18 +00:00
public partial class MainForm : ThemedForms
2014-04-25 21:55:43 +00:00
{
public static LoginForm LoginDialog ;
public static Thread LThread ;
public static Thread MainThread = null ;
public static Notifier taskbarNotifier ;
public MainForm ( )
{
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( "Starting..." ) ;
2015-03-26 19:36:18 +00:00
Program . MainF = this ;
2014-04-25 21:55:43 +00:00
InitializeComponent ( ) ;
Thread . CurrentThread . Name = "Main Thread" ;
toolStripMenuItem4 . Enabled = false ; //2014.04.12.
toolStripMenuItem8 . Enabled = false ; //2014.04.12.
this . WindowState = FormWindowState . Minimized ; //2014.04.19.
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( "Loading program settings..." ) ;
Storage . Load ( false ) ; //Töltse be a nyelvet, legutóbb használt E-mail-t...
2014-04-25 21:55:43 +00:00
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( "Checking available ports..." ) ;
//2014.09.04. - Amint lehet állítsa be a helyes IP-t, majd azt hagyja úgy, akármi történjék
while ( true )
2014-04-25 21:55:43 +00:00
{
2014-10-24 17:02:38 +00:00
if ( IPGlobalProperties . GetIPGlobalProperties ( ) . GetActiveUdpListeners ( ) . Select ( entry = > entry . Port ) . Contains ( Int32 . Parse ( Storage . Settings [ "port" ] ) ) )
Storage . Settings [ "port" ] = ( Int32 . Parse ( Storage . Settings [ "port" ] ) + 1 ) . ToString ( ) ;
else
break ;
2014-04-25 21:55:43 +00:00
}
2014-10-24 17:02:38 +00:00
Networking . ReceiverConnection = new UdpClient ( Int32 . Parse ( Storage . Settings [ "port" ] ) ) ; //2014.09.04.
Networking . SenderConnection . AllowNatTraversal ( true ) ; //2014.09.04.
BeforeLogin . SetText ( "Loading languages..." ) ;
new Language ( ) ;
2014-04-25 21:55:43 +00:00
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( Language . Translate ( "beforelogin_translatemainf" ) ) ;
2014-04-25 21:55:43 +00:00
#region Helyi beállitás
2014-10-24 17:02:38 +00:00
//try
//{
fájlToolStripMenuItem . Text = Language . Translate ( "menu_file" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { fájlToolStripMenuItem . Text = Language . Translate ( "menu_file" ) ; } ;
2014-10-24 17:02:38 +00:00
kijelentkezésToolStripMenuItem . Text = Language . Translate ( "menu_file_logout" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { kijelentkezésToolStripMenuItem . Text = Language . Translate ( "menu_file_logout" ) ; } ;
2014-10-24 17:02:38 +00:00
toolStripMenuItem1 . Text = Language . Translate ( "menu_file_loginnewuser" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { toolStripMenuItem1 . Text = Language . Translate ( "menu_file_loginnewuser" ) ; } ;
2014-10-24 17:02:38 +00:00
á llapotToolStripMenuItem . Text = Language . Translate ( "menu_file_status" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { á llapotToolStripMenuItem . Text = Language . Translate ( "menu_file_status" ) ; } ;
2014-10-24 17:02:38 +00:00
elérhetőToolStripMenuItem . Text = Language . Translate ( "menu_file_status_online" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { elérhetőToolStripMenuItem . Text = Language . Translate ( "menu_file_status_online" ) ; } ;
2014-10-24 17:02:38 +00:00
elfoglaltToolStripMenuItem . Text = Language . Translate ( "menu_file_status_busy" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { elfoglaltToolStripMenuItem . Text = Language . Translate ( "menu_file_status_busy" ) ; } ;
2014-10-24 17:02:38 +00:00
nincsAGépnélToolStripMenuItem . Text = Language . Translate ( "menu_file_status_away" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { nincsAGépnélToolStripMenuItem . Text = Language . Translate ( "menu_file_status_away" ) ; } ;
2014-10-24 17:02:38 +00:00
rejtveKapcsolódikToolStripMenuItem . Text = Language . Translate ( "menu_file_status_hidden" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { rejtveKapcsolódikToolStripMenuItem . Text = Language . Translate ( "menu_file_status_hidden" ) ; } ;
2014-10-24 17:02:38 +00:00
fájlKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_file_sendfile" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { fájlKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_file_sendfile" ) ; } ;
2014-10-24 17:02:38 +00:00
beérkezettFájlokMappájánakMegnyitásaToolStripMenuItem . Text = Language . Translate ( "menu_file_openreceivedfiles" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { beérkezettFájlokMappájánakMegnyitásaToolStripMenuItem . Text = Language . Translate ( "menu_file_openreceivedfiles" ) ; } ;
2014-10-24 17:02:38 +00:00
ü zenetekElőzményeinekMegtekintéseToolStripMenuItem . Text = Language . Translate ( "menu_file_openrecentmsgs" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ü zenetekElőzményeinekMegtekintéseToolStripMenuItem . Text = Language . Translate ( "menu_file_openrecentmsgs" ) ; } ;
2014-10-24 17:02:38 +00:00
bezárásToolStripMenuItem . Text = Language . Translate ( "menu_file_close" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { bezárásToolStripMenuItem . Text = Language . Translate ( "menu_file_close" ) ; } ;
2014-10-24 17:02:38 +00:00
kilépésToolStripMenuItem . Text = Language . Translate ( "menu_file_exit" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { kilépésToolStripMenuItem . Text = Language . Translate ( "menu_file_exit" ) ; } ;
2014-10-24 17:02:38 +00:00
ismerősökToolStripMenuItem . Text = Language . Translate ( "menu_contacts" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ismerősökToolStripMenuItem . Text = Language . Translate ( "menu_contacts" ) ; } ;
2014-10-24 17:02:38 +00:00
ismerősFelvételeToolStripMenuItem . Text = Language . Translate ( "menu_contacts_add" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ismerősFelvételeToolStripMenuItem . Text = Language . Translate ( "menu_contacts_add" ) ; } ;
2014-10-24 17:02:38 +00:00
ismerősSzerkesztéseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_edit" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ismerősSzerkesztéseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_edit" ) ; } ;
2014-10-24 17:02:38 +00:00
ismerősTörléseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_remove" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ismerősTörléseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_remove" ) ; } ;
2014-10-24 17:02:38 +00:00
toolStripMenuItem3 . Text = Language . Translate ( "menu_contacts_invite" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { toolStripMenuItem3 . Text = Language . Translate ( "menu_contacts_invite" ) ; } ;
2014-10-24 17:02:38 +00:00
csoportLétrehozásaToolStripMenuItem . Text = Language . Translate ( "menu_contacts_makegroup" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { csoportLétrehozásaToolStripMenuItem . Text = Language . Translate ( "menu_contacts_makegroup" ) ; } ;
2014-10-24 17:02:38 +00:00
kategóriaLétrehozásaToolStripMenuItem . Text = Language . Translate ( "menu_contacts_makecategory" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { kategóriaLétrehozásaToolStripMenuItem . Text = Language . Translate ( "menu_contacts_makecategory" ) ; } ;
2014-10-24 17:02:38 +00:00
kategóriaSzerkesztéseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_editcategory" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { kategóriaSzerkesztéseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_editcategory" ) ; } ;
2014-10-24 17:02:38 +00:00
kategóriaTörléseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_removecategory" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { kategóriaTörléseToolStripMenuItem . Text = Language . Translate ( "menu_contacts_removecategory" ) ; } ;
2014-10-24 17:02:38 +00:00
műveletekToolStripMenuItem . Text = Language . Translate ( "menu_operations" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { műveletekToolStripMenuItem . Text = Language . Translate ( "menu_operations" ) ; } ;
2014-10-24 17:02:38 +00:00
azonnaliÜzenetKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendmsg" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { azonnaliÜzenetKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendmsg" ) ; } ;
2014-10-24 17:02:38 +00:00
egyébKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendother" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { egyébKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendother" ) ; } ;
2014-10-24 17:02:38 +00:00
emailKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendother_sendmail" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { emailKüldéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_sendother_sendmail" ) ; } ;
2014-10-24 17:02:38 +00:00
fájlKüldéseToolStripMenuItem1 . Text = Language . Translate ( "menu_file_sendfile" ) ; //Ugyanaz a szöveg
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { fájlKüldéseToolStripMenuItem1 . Text = Language . Translate ( "menu_file_sendfile" ) ; } ;
2014-10-24 17:02:38 +00:00
ismerősSzámitógépénekFelhivásaToolStripMenuItem . Text = Language . Translate ( "menu_operations_callcontact" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { ismerősSzámitógépénekFelhivásaToolStripMenuItem . Text = Language . Translate ( "menu_operations_callcontact" ) ; } ;
2014-10-24 17:02:38 +00:00
videóhivásInditásaToolStripMenuItem . Text = Language . Translate ( "menu_operations_videocall" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { videóhivásInditásaToolStripMenuItem . Text = Language . Translate ( "menu_operations_videocall" ) ; } ;
2014-10-24 17:02:38 +00:00
onlineFájlokMegtekintéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_showonlinefiles" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { onlineFájlokMegtekintéseToolStripMenuItem . Text = Language . Translate ( "menu_operations_showonlinefiles" ) ; } ;
2014-10-24 17:02:38 +00:00
közösJátékToolStripMenuItem . Text = Language . Translate ( "menu_operations_playgame" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { közösJátékToolStripMenuItem . Text = Language . Translate ( "menu_operations_playgame" ) ; } ;
2014-10-24 17:02:38 +00:00
távsegitségKéréseToolStripMenuItem . Text = Language . Translate ( "menu_operations_askforhelp" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { távsegitségKéréseToolStripMenuItem . Text = Language . Translate ( "menu_operations_askforhelp" ) ; } ;
2014-10-24 17:02:38 +00:00
eszközökToolStripMenuItem . Text = Language . Translate ( "menu_tools" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { eszközökToolStripMenuItem . Text = Language . Translate ( "menu_tools" ) ; } ;
2014-10-24 17:02:38 +00:00
mindigLegfelülToolStripMenuItem . Text = Language . Translate ( "menu_tools_alwaysontop" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { mindigLegfelülToolStripMenuItem . Text = Language . Translate ( "menu_tools_alwaysontop" ) ; } ;
2014-10-24 17:02:38 +00:00
hangulatjelekToolStripMenuItem . Text = Language . Translate ( "menu_tools_emoticons" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { hangulatjelekToolStripMenuItem . Text = Language . Translate ( "menu_tools_emoticons" ) ; } ;
2014-10-24 17:02:38 +00:00
megjelenitendőKépVáltásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_changeimage" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { megjelenitendőKépVáltásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_changeimage" ) ; } ;
2014-10-24 17:02:38 +00:00
háttérMódositásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_changebackground" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { háttérMódositásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_changebackground" ) ; } ;
2014-10-24 17:02:38 +00:00
hangokÉsVideóBeállitásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_voicevideosettings" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { hangokÉsVideóBeállitásaToolStripMenuItem . Text = Language . Translate ( "menu_tools_voicevideosettings" ) ; } ;
2014-10-24 17:02:38 +00:00
beállitásokToolStripMenuItem . Text = Language . Translate ( "menu_tools_settings" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { beállitásokToolStripMenuItem . Text = Language . Translate ( "menu_tools_settings" ) ; } ;
2014-10-24 17:02:38 +00:00
súgóToolStripMenuItem . Text = Language . Translate ( "menu_help" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { súgóToolStripMenuItem . Text = Language . Translate ( "menu_help" ) ; } ;
2014-10-24 17:02:38 +00:00
témakörökToolStripMenuItem . Text = Language . Translate ( "menu_help_contents" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { témakörökToolStripMenuItem . Text = Language . Translate ( "menu_help_contents" ) ; } ;
2014-10-24 17:02:38 +00:00
aSzolgáltatásÁllapotsaToolStripMenuItem . Text = Language . Translate ( "menu_help_status" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { aSzolgáltatásÁllapotsaToolStripMenuItem . Text = Language . Translate ( "menu_help_status" ) ; } ;
2014-10-24 17:02:38 +00:00
adatvédelmiNyilatkozatToolStripMenuItem . Text = Language . Translate ( "menu_help_privacypolicy" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { adatvédelmiNyilatkozatToolStripMenuItem . Text = Language . Translate ( "menu_help_privacypolicy" ) ; } ;
2014-10-24 17:02:38 +00:00
használatiFeltételekToolStripMenuItem . Text = Language . Translate ( "menu_help_termsofuse" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { használatiFeltételekToolStripMenuItem . Text = Language . Translate ( "menu_help_termsofuse" ) ; } ;
2014-10-24 17:02:38 +00:00
visszaélésBejelentéseToolStripMenuItem . Text = Language . Translate ( "menu_help_report" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { visszaélésBejelentéseToolStripMenuItem . Text = Language . Translate ( "menu_help_report" ) ; } ;
2014-10-24 17:02:38 +00:00
segitsenAProgramTökéletesitésébenToolStripMenuItem . Text = Language . Translate ( "menu_help_improveprogram" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { segitsenAProgramTökéletesitésébenToolStripMenuItem . Text = Language . Translate ( "menu_help_improveprogram" ) ; } ;
2014-10-24 17:02:38 +00:00
névjegyToolStripMenuItem . Text = Language . Translate ( "menu_help_about" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { névjegyToolStripMenuItem . Text = Language . Translate ( "menu_help_about" ) ; } ;
2014-10-24 17:02:38 +00:00
2015-03-26 19:36:18 +00:00
textBox1 . Text = Language . Translate ( "searchbar" , textBox1 ) ;
2014-10-24 17:02:38 +00:00
//contactList.Items[0].SubItems[0].Text = Language.Translate("loading"); - 2014.08.28. - Nincs már rá szükség (hibát is ír, mivel nincs listaelem)
2015-03-26 19:36:18 +00:00
//üzenetküldésToolStripMenuItem.Text = Language.Translate("menu_operations_sendmsg");
//emailKüldéseemailToolStripMenuItem.Text = Language.Translate("contact_sendemail");
//toolStripMenuItem2.Text = Language.Translate("contact_copyemail");
//információToolStripMenuItem.Text = Language.Translate("contact_info");
//ismerősLetiltásaToolStripMenuItem.Text = Language.Translate("contact_block");
//ismerősTörléseToolStripMenuItem.Text = Language.Translate("contact_remove"); - Kétszer benne volt, ugyanilyen névvel, csak 1-re végződve lett volna a megfelelő
//becenévSzerkesztéseToolStripMenuItem.Text = Language.Translate("contact_editname");
//eseményértesitésekToolStripMenuItem.Text = Language.Translate("contact_eventnotifications");
//beszélgetésnaplóMegnyitásaToolStripMenuItem.Text = Language.Translate("contact_openchatlog");
2014-10-24 17:02:38 +00:00
toolStripMenuItem4 . Text = Language . Translate ( "iconmenu_show" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { toolStripMenuItem4 . Text = Language . Translate ( "iconmenu_show" ) ; } ;
2014-10-24 17:02:38 +00:00
toolStripMenuItem8 . Text = Language . Translate ( "menu_file_logout" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { toolStripMenuItem8 . Text = Language . Translate ( "menu_file_logout" ) ; } ;
2014-10-24 17:02:38 +00:00
toolStripMenuItem9 . Text = Language . Translate ( "menu_file_exit" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { toolStripMenuItem9 . Text = Language . Translate ( "menu_file_exit" ) ; } ;
2014-10-24 17:02:38 +00:00
//}
//catch
//{
//MessageBox.Show("Error while loading translations.");
//}
2015-03-26 19:36:18 +00:00
LoadMenu ( MenuType . ChatIconMenu ) ; //2014.12.12.
LoadMenu ( MenuType . PartnerMenu ) ; //2014.12.13.
2014-04-25 21:55:43 +00:00
#endregion
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( Language . Translate ( "beforelogin_loadtextformat" ) ) ;
2014-07-12 08:53:00 +00:00
//2014.05.16.
new TextFormat ( ) ;
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( Language . Translate ( "beforelogin_checkforupdates" ) ) ;
2014-04-25 21:55:43 +00:00
//2014.04.25.
string response = Networking . SendRequest ( "checkforupdates" ,
Assembly . GetExecutingAssembly ( ) . GetName ( ) . Version . ToString ( ) . Replace ( "." , "" ) ,
0 , false ) ;
if ( response = = "outofdate" )
{
2014-10-24 17:02:38 +00:00
var res = MessageBox . Show ( Language . Translate ( "outofdate" ) , Language . Translate ( "outofdate_caption" ) , MessageBoxButtons . YesNo ) ;
2014-04-25 21:55:43 +00:00
if ( res = = DialogResult . Yes )
2015-03-26 19:36:18 +00:00
//System.Diagnostics.Process.Start("http://msger.url.ph/download.php?version=latest");
//(new UpdateDialog()).Show(); //2014.12.13. - Elvileg át lehet nevezni a programot, miközben fut (ami érdekes) - De inkább csinálok külön programot
{ //2014.12.13.
Process . Start ( "Updater.exe" , "\"" + Language . Translate ( "updater" ) + "\" \"" + Language . Translate ( "updater_info" ) + "\"" ) ;
Program . Exit ( false ) ;
}
2014-04-25 21:55:43 +00:00
}
else if ( response ! = "fine" )
2014-10-24 17:02:38 +00:00
MessageBox . Show ( Language . Translate ( "error" ) + ": " + response ) ;
2014-04-25 21:55:43 +00:00
2015-03-26 19:36:18 +00:00
//BeforeLogin.SetText(Language.Translate("beforelogin_server")); //2015.01.07.
2014-10-24 17:02:38 +00:00
//2014.09.06.
2015-03-26 19:36:18 +00:00
/ * if ( Storage . Settings [ "isserver" ] = = "" )
2014-10-24 17:02:38 +00:00
{
if ( MessageBox . Show ( Language . Translate ( "isserver_msg" ) , "" , MessageBoxButtons . YesNo ) = = DialogResult . Yes )
Storage . Settings [ "isserver" ] = "1" ;
else
Storage . Settings [ "isserver" ] = "0" ;
2015-03-26 19:36:18 +00:00
} * /
/ * if ( Storage . Settings [ "isserver" ] = = "1" ) //2015.01.07.
{
NATUPNPLib . UPnPNAT upnpnat = new NATUPNPLib . UPnPNAT ( ) ;
NATUPNPLib . IStaticPortMappingCollection mappings = upnpnat . StaticPortMappingCollection ;
if ( mappings = = null )
{
//MessageBox.Show(Language.Translate("portforward_noaccess"));
}
//else
//{
foreach ( NATUPNPLib . IStaticPortMapping mapping in mappings )
{
if ( mapping . Protocol = = "UDP" & & mapping . InternalPort . ToString ( ) = = Storage . Settings [ "port" ] )
{
if ( MessageBox . Show ( Language . Translate ( "portforward_existsremove" ) , "" , MessageBoxButtons . YesNo ) = = DialogResult . Yes )
mappings . Remove ( mapping . ExternalPort , "UDP" ) ;
else
Storage . Settings [ "port" ] = ( Int32 . Parse ( Storage . Settings [ "port" ] ) + 1 ) . ToString ( ) ;
}
}
int port = int . Parse ( Storage . Settings [ "port" ] ) ;
mappings . Add ( port , "UDP" , port , Dns . GetHostEntry ( Dns . GetHostName ( ) ) . AddressList . Single ( entry = >
entry . AddressFamily = = AddressFamily . InterNetwork
& & ( entry . ToString ( ) . Contains ( "192.168.0." ) | | entry . ToString ( ) . Contains ( "192.168.1." ) | | entry . ToString ( ) . Contains ( "10.0.0." ) | | entry . ToString ( ) . Contains ( "172.16.0." ) ) //Helyi IP-k
) . ToString ( ) , true , "MSGer.tk chat program" ) ;
Networking . ReceiverConnection = new UdpClient ( Int32 . Parse ( Storage . Settings [ "port" ] ) ) ;
//}
} * /
//TO!DO: Nem kell az "isserver" beállítás, először kliensként próbáljon meg csatlakozni, majd szerverként fogadja az új klienseket
// a pwnat segítségével
//2015.03.15. - Nem kell az sem: IPv6 - A legtöbb eszköz már támogatja
2014-10-24 17:02:38 +00:00
BeforeLogin . SetText ( Language . Translate ( "beforelogin_loginform" ) ) ;
2014-04-25 21:55:43 +00:00
try
{
LoginDialog = new LoginForm ( ) ;
2014-10-24 17:02:38 +00:00
BeforeLogin . Destroy ( ) ;
2014-04-25 21:55:43 +00:00
LoginDialog . ShowDialog ( ) ;
}
catch ( Exception e )
{
ErrorHandling . FormError ( LoginDialog , e ) ;
}
//Nézzük, sikerült-e
2014-10-24 17:02:38 +00:00
if ( CurrentUser . UserID = = 0 )
return ; //2014.09.06.
contactList . Enabled = false ; //2014.03.05.
MainThread = Thread . CurrentThread ;
// Create the thread object, passing in the Alpha.Beta method
// via a ThreadStart delegate. This does not start the thread.
LThread = new Thread ( new ThreadStart ( new UpdateListAndChat ( ) . Run ) ) ;
LThread . Name = "Update Partnerlist and Chat" ;
2015-03-26 19:36:18 +00:00
/ * Thread keepupthread = new Thread ( new ThreadStart ( Networking . KeepUpThread ) ) ;
2014-10-24 17:02:38 +00:00
keepupthread . Name = "Keep Up Thread" ;
2015-03-26 19:36:18 +00:00
2014-10-24 17:02:38 +00:00
Thread keepupuserst = new Thread ( new ThreadStart ( Networking . KeepUpUsersThread ) ) ; //2014.09.26.
2015-03-26 19:36:18 +00:00
keepupuserst . Name = "Keep Up Users Thread" ; * /
Thread networkthread = new Thread ( new ThreadStart ( Networking . NetworkThread ) ) ; //2014.12.31.
networkthread . Name = "Network Thread" ;
2014-10-24 17:02:38 +00:00
Storage . Load ( true ) ; //2014.08.07.
if ( Storage . Settings [ "windowstate" ] = = "1" ) //2014.04.18. - 2014.08.08.
this . WindowState = FormWindowState . Maximized ;
else if ( Storage . Settings [ "windowstate" ] = = "2" )
this . WindowState = FormWindowState . Minimized ;
else if ( Storage . Settings [ "windowstate" ] = = "3" )
this . WindowState = FormWindowState . Normal ;
taskbarNotifier = new Notifier ( "popup-bg.bmp" , Color . FromArgb ( 255 , 0 , 255 ) , "close.bmp" , 5000 ) ;
taskbarNotifier . Click + = PopupClick ;
taskbarNotifier . CloseClick + = PopupCloseClick ;
toolStripMenuItem4 . Enabled = true ; //2014.04.12.
toolStripMenuItem8 . Enabled = true ; //2014.04.12.
// Start the thread
LThread . Start ( ) ;
2015-03-26 19:36:18 +00:00
//keepupthread.Start();
2014-10-24 17:02:38 +00:00
2015-03-26 19:36:18 +00:00
//keepupuserst.Start();
networkthread . Start ( ) ;
2014-10-24 17:02:38 +00:00
//2014.08.19. - Küldje el a bejelentkezés hírét, hogy frissítéseket kapjon
2015-03-26 19:36:18 +00:00
/ * byte [ ] strb = Encoding . Unicode . GetBytes ( CurrentUser . IP . ToString ( ) ) ;
byte [ ] tmpfinal = new byte [ 8 * UserInfo . KnownUsers . Count + strb . Length + 4 + 1 ] ; //Hosszúság, IP, ismert felh. ID, frissítési idő
2014-10-24 17:02:38 +00:00
Array . Copy ( BitConverter . GetBytes ( strb . Length ) , tmpfinal , 4 ) ;
Array . Copy ( strb , 0 , tmpfinal , 4 , strb . Length ) ;
//if (tmpfinal.Length != 0)
2015-03-26 19:36:18 +00:00
for ( int i = 0 ; i < UserInfo . KnownUsers . Count ; i + + ) //Ha a count 0, nem fogja végrehajtani
2014-10-24 17:02:38 +00:00
{
2015-03-26 19:36:18 +00:00
byte [ ] tmptmp = BitConverter . GetBytes ( UserInfo . KnownUsers [ i ] . UserID ) ;
Array . Copy ( tmptmp , 0 , tmpfinal , i * 4 + strb . Length + 4 , 4 ) ;
tmptmp = BitConverter . GetBytes ( UserInfo . KnownUsers [ i ] . LastUpdate ) ;
Array . Copy ( tmptmp , 0 , tmpfinal , i * 4 + strb . Length + 4 , 4 ) ;
2014-10-24 17:02:38 +00:00
}
2015-03-26 19:36:18 +00:00
tmpfinal [ tmpfinal . Length - 1 ] = ( Storage . Settings [ "isserver" ] = = "1" ) ? ( byte ) 0x01 : ( byte ) 0x00 ; //Mivel bejelentkezéstől függetlenül menti el, gépfüggő, hogy itt mit küld el
Networking . ParseUpdateInfo ( Networking . SendUpdate ( Networking . UpdateType . LoginUser , tmpfinal , false ) ) ; * /
while ( ! networkthread . IsAlive ) ;
SendLoginToUsers ( ) ; //2014.12.18.
2014-10-24 17:02:38 +00:00
notifyIcon1 . Visible = true ; //2014.09.22.
taskbarNotifier . Show ( "Teszt cím" , "Teszt tartalom\nMásodik sor" ) ;
2015-03-26 19:36:18 +00:00
Language . ReloadEvent + = delegate { textBox1 . Text = Language . Translate ( "searchbar" ) ; } ; //2014.12.22. - Nyelvváltáskor törölni fogja a beírt szöveget
}
private void SendLoginToUsers ( )
{ //2014.12.18.
var bytes = new List < byte > ( ) ;
//var tmpb = Encoding.Unicode.GetBytes(CurrentUser.IP.ToString());
//bytes.AddRange(BitConverter.GetBytes(tmpb.Length));
//bytes.AddRange(tmpb);
for ( int i = 0 ; i < UserInfo . KnownUsers . Count ; i + + ) //Ha a count 0, nem fogja végrehajtani
{
bytes . AddRange ( BitConverter . GetBytes ( UserInfo . KnownUsers [ i ] . UserID ) ) ;
bytes . AddRange ( BitConverter . GetBytes ( UserInfo . KnownUsers [ i ] . LastUpdate ) ) ;
}
//bytes.Add((Storage.Settings["isserver"] == "1") ? (byte)0x01 : (byte)0x00); //Mivel bejelentkezéstől függetlenül menti el, gépfüggő, hogy itt mit küld el
//Networking.ParseUpdateInfo(Networking.SendUpdate(Networking.UpdateType.LoginUser, bytes.ToArray(), false));
Networking . SendUpdateInThread ( Networking . UpdateType . LoginUser , bytes . ToArray ( ) , new EventHandler < byte [ ] [ ] > (
( e , resp ) = > Networking . ParseUpdateInfo ( resp ) ) ) ;
2014-10-24 17:02:38 +00:00
}
2015-03-26 19:36:18 +00:00
enum MenuType
{
ChatIconMenu ,
PartnerMenu
}
private void LoadMenu ( MenuType mt )
{
switch ( mt ) //2014.12.13.
{
case MenuType . ChatIconMenu :
chatIconMenu . Items . Add ( Language . Translate ( "close" ) , null ,
new EventHandler ( ( sender , e ) = > ( ( ChatPanel ) chatIconMenu . Tag ) . Close ( ) ) ) ; //Tag: A chatikon
chatIconMenu . Items [ chatIconMenu . Items . Count - 1 ] . Name = "close" ; //2014.12.22.
Language . ReloadEvent + = delegate { chatIconMenu . Items [ "close" ] . Text = Language . Translate ( "close" ) ; } ; //2014.12.22.
chatIconMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
/ * chatIconMenu . Items . AddRange (
partnerMenu . Items . Cast < ToolStripItem > ( ) . Select ( entry = > {
return new ToolStripMenuItem ( ( ToolStripItem ) entry . Clone ( ) ;
} ) . ToArray ( ) ) ; //Alapvetően eltávolítaná az eredeti menüből, és hibát jelezne*/
LoadMenuPrep ( chatIconMenu ) ;
break ;
case MenuType . PartnerMenu :
listPartnerMenu . Items . Add ( Language . Translate ( "menu_operations_sendmsg" ) , null , PartnerMenu_SendMessage ) ;
listPartnerMenu . Items [ listPartnerMenu . Items . Count - 1 ] . Name = "menu_operations_sendmsg" ; //2014.12.22.
Language . ReloadEvent + = delegate { listPartnerMenu . Items [ "menu_operations_sendmsg" ] . Text = Language . Translate ( "menu_operations_sendmsg" ) ; } ; //2014.12.22.
listPartnerMenu . Items . Add ( new ToolStripSeparator ( ) ) ;
//listPartnerMenu.Items.AddRange(partnerMenu.Items.Cast<ToolStripItem>().ToArray());
LoadMenuPrep ( listPartnerMenu ) ;
break ;
default :
throw new NotImplementedException ( "Menu type not implemented." ) ;
}
}
private void LoadMenuPrep ( ContextMenuStrip menu ) //Csak a menüelemeket készíti elő
{ //2014.12.13.
menu . Items . AddRange ( new System . Windows . Forms . ToolStripItem [ ] { //A dizájnerből, átalakítva, hogy rögtön le is fordítsa
new ToolStripMenuItem ( Language . Translate ( "contact_sendemail" ) ) , //Ide jönnek majd az event handlerek is
new ToolStripMenuItem ( Language . Translate ( "contact_copyemail" ) ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_info" ) ) ,
new ToolStripSeparator ( ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_block" ) ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_remove" ) ) ,
new ToolStripSeparator ( ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_editname" ) ) ,
new ToolStripSeparator ( ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_eventnotifications" ) ) ,
new ToolStripSeparator ( ) ,
new ToolStripMenuItem ( Language . Translate ( "contact_openchatlog" ) ) } ) ;
Language . ReloadEvent + = delegate
{
int i = menu . Items . Count - 1 ;
menu . Items [ i ] . Text = Language . Translate ( "contact_openchatlog" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_eventnotifications" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_editname" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_remove" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_block" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_info" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_copyemail" ) ;
i - - ;
menu . Items [ i ] . Text = Language . Translate ( "contact_sendemail" ) ;
} ;
}
public void LoadPartnerList ( ) //2014.08.28.
2014-10-24 17:02:38 +00:00
{
contactList . AutoUpdate = false ;
UserInfo . AutoUpdate = false ; //2014.09.26.
//string[] list = Networking.SendRequest("getlist", "", 0, true).Split('ͦ');
string [ ] list = Networking . SendRequest ( "getlist" , "" , 0 , true ) . Split ( new char [ ] { 'ͦ' } , StringSplitOptions . RemoveEmptyEntries ) ; //2014.09.26.
if ( list [ 0 ] . Contains ( "Fail" ) )
MessageBox . Show ( list [ 0 ] ) ;
UserInfo . KnownUsers = UserInfo . KnownUsers . Select ( entry = > { entry . IsPartner = false ; return entry ; } ) . ToList ( ) ; //2014.09.26.
for ( int i = 0 ; i + 1 < list . Length ; i + = 2 )
{
string username = list [ i ] ;
int uid = Int32 . Parse ( list [ i + 1 ] ) ;
if ( ! UserInfo . IDIsInList ( UserInfo . KnownUsers , uid ) )
{ //Ha nem tud róla semmit, akkor töltse le a felhasználónevét, és jelenítse meg azt
var tmp = new UserInfo ( ) ;
tmp . UserID = uid ;
tmp . UserName = username ;
tmp . LastUpdate = 0 ; //Lényegében nem tud róla túl sokat, ezért ha lehet, frissítse
tmp . Name = username ;
tmp . IsPartner = true ;
UserInfo . KnownUsers . Add ( tmp ) ;
}
else
{
UserInfo . Select ( uid ) . IsPartner = true ; //2014.09.26.
UserInfo . Select ( uid ) . UserName = username ; //2014.09.26. - Nem megváltoztatható, ha egy felhasználó megpróbálja, nem foglalkozik vele
}
}
CurrentUser . State = 1 ; //2014.08.31. 0:48
UserInfo . AutoUpdate = true ;
foreach ( var entry in UserInfo . KnownUsers )
{
entry . Update ( ) ; //Áthelyeztem, mert az értékek frissítésekor is szükség van rá
}
contactList . AutoUpdate = true ;
contactList . Enabled = true ;
contactList . Refresh ( ) ;
2014-04-25 21:55:43 +00:00
}
private void LogoutUser ( object sender , EventArgs e )
{
this . Hide ( ) ;
toolStripMenuItem4 . Enabled = false ; //2014.04.12.
toolStripMenuItem8 . Enabled = false ; //2014.04.12.
2014-10-24 17:02:38 +00:00
Storage . Save ( true ) ; //2014.08.28.
2014-04-25 21:55:43 +00:00
SetOnlineState ( null , null ) ; //2014.04.11. - Erre nincs beállitva, ezért automatikusan 0-ra, azaz kijelentkeztetettre állítja az állapotát
2014-10-24 17:02:38 +00:00
contactList . Items . Clear ( ) ; //2014.09.19.
UserInfo . KnownUsers . Clear ( ) ; //2014.09.19.
Storage . Dispose ( ) ;
LThread = null ;
CurrentUser . SendChanges = false ; //2014.08.30.
2015-03-26 19:36:18 +00:00
while ( ChatPanel . ChatWindows . Count > 0 )
2014-10-24 17:02:38 +00:00
{ //2014.09.06. - A Close() hatására törli a gyűjteményből, ezért sorra végig fog haladni rajta
2015-03-26 19:36:18 +00:00
ChatPanel . ChatWindows [ 0 ] . Close ( ) ;
2014-10-24 17:02:38 +00:00
}
2014-04-25 21:55:43 +00:00
LoginDialog = new LoginForm ( ) ; //2014.04.04.
LoginDialog . ShowDialog ( ) ;
//Nézzük, sikerült-e
if ( CurrentUser . UserID = = 0 )
Close ( ) ;
2014-10-24 17:02:38 +00:00
Storage . Load ( true ) ; //2014.08.07.
2014-04-25 21:55:43 +00:00
toolStripMenuItem4 . Enabled = true ; //2014.04.12.
toolStripMenuItem8 . Enabled = true ; //2014.04.12.
2014-10-24 17:02:38 +00:00
CurrentUser . SendChanges = true ; //2014.08.30.
contactList . Items . Clear ( ) ; //2014.10.09. - Kijelentkezéskor hozzáad egy üres listelemet egy (Nem elérhető) felirattal, ezt tünteti el
2015-03-26 19:36:18 +00:00
//LoadPartnerList();
//this.Show();
2014-04-25 21:55:43 +00:00
// Create the thread object, passing in the Alpha.Beta method
// via a ThreadStart delegate. This does not start the thread.
2014-10-24 17:02:38 +00:00
LThread = new Thread ( new ThreadStart ( new UpdateListAndChat ( ) . Run ) ) ;
2014-04-25 21:55:43 +00:00
LThread . Name = "Update Partner List" ;
// Start the thread
LThread . Start ( ) ;
2015-03-26 19:36:18 +00:00
SendLoginToUsers ( ) ; //2014.12.18.
LoadPartnerList ( ) ;
this . Show ( ) ;
2014-04-25 21:55:43 +00:00
}
2015-03-26 19:36:18 +00:00
public void PlaceChatIcon ( ChatPanel cp )
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
var newicon = new PictureBox ( ) ;
//newicon.ImageLocation = cp.ChatPartners[0].GetImage();
newicon . ImageLocation = cp . ChatPartners [ 0 ] . ImagePath ; //2014.12.31.
newicon . Size = new Size ( 100 , 100 ) ;
newicon . SizeMode = PictureBoxSizeMode . Zoom ;
newicon . Click + = new EventHandler ( ( a , b ) = > cp . Show ( ) ) ;
newicon . MouseClick + = new MouseEventHandler ( ( s , e ) = > {
if ( e . Button = = MouseButtons . Middle )
cp . Close ( ) ;
else if ( e . Button = = MouseButtons . Right ) //Chat menü
{ //2014.12.13.
chatIconMenu . Tag = cp ;
chatIconMenu . Show ( Cursor . Position ) ;
}
} ) ;
cp . ChatIcon = newicon ;
//---------------------------------------------------------------------
int size = 0 ;
bool putright = false ;
foreach ( Control item in flowLayoutPanel1 . Controls )
2014-10-24 17:02:38 +00:00
{
2015-03-26 19:36:18 +00:00
size + = item . Size . Height ;
2014-10-24 17:02:38 +00:00
}
2015-03-26 19:36:18 +00:00
size + = newicon . Size . Height ;
if ( size > flowLayoutPanel1 . Size . Height )
putright = true ; //Ha nem fér el bal oldalt, rakja jobbra
//---------------------------------------------------------------------
size = 0 ;
foreach ( Control item in flowLayoutPanel2 . Controls )
{
size + = item . Size . Height ;
}
size + = newicon . Size . Height ;
if ( size > flowLayoutPanel2 . Size . Height )
putright = false ; //Ha jobbra sem fér el, csak rakja balra
//---------------------------------------------------------------------
if ( ! putright )
flowLayoutPanel1 . Controls . Add ( newicon ) ;
else
flowLayoutPanel2 . Controls . Add ( newicon ) ;
2014-04-25 21:55:43 +00:00
}
2015-03-26 19:36:18 +00:00
public enum StatType
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
MainServer ,
Servers ,
OnlineServers
}
public void UpdateStats ( StatType type , int value )
{ //Elvileg ha van forgalom, gyorsan frissíti a nyelvet is
switch ( type )
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
case StatType . MainServer :
if ( value = = 0 )
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
mainserver . Text = Language . Translate ( "stats_mainserver" ) + ": " + Language . Translate ( "stats_nonetwork" ) ;
mainserver . ForeColor = Color . Red ;
2014-04-25 21:55:43 +00:00
}
2015-03-26 19:36:18 +00:00
else if ( value = = 1 )
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
mainserver . Text = Language . Translate ( "stats_mainserver" ) + ": " + Language . Translate ( "stats_retrying" ) ;
mainserver . ForeColor = Color . Orange ;
2014-04-25 21:55:43 +00:00
}
2015-03-26 19:36:18 +00:00
else if ( value = = 2 )
2014-04-25 21:55:43 +00:00
{
2015-03-26 19:36:18 +00:00
mainserver . Text = Language . Translate ( "stats_mainserver" ) + ": " + Language . Translate ( "stats_connected" ) ;
mainserver . ForeColor = Color . Green ;
2014-04-25 21:55:43 +00:00
}
2014-10-24 17:02:38 +00:00
break ;
2015-03-26 19:36:18 +00:00
case StatType . Servers :
servers . Text = Language . Translate ( "stats_servers" ) + ": " + value ;
break ;
case StatType . OnlineServers :
onlineservers . Text = Language . Translate ( "stats_onlineservers" ) + ": " + value ;
break ;
2014-07-12 08:53:00 +00:00
}
2014-10-24 17:02:38 +00:00
}
2014-04-25 21:55:43 +00:00
}
}