Jump to content
Xtreme .Net Talk

MrLucky

Avatar/Signature
  • Posts

    47
  • Joined

  • Last visited

Everything posted by MrLucky

  1. How can I add a close button to a tab? Like in Firefox 2, you have a small button on the right on every tab, to close it. Is this possible, and if so, How?
  2. Something really strange: protected void WaitForData() { if(this.SocketCallback == null) { this.SocketCallback = new AsyncCallback(OnDataReceive); } ServerSocket state = new ServerSocket(); state.Socket = this.Socket; this.Socket.BeginReceive(state.buffer1, 0, state.buffer1.Length, SocketFlags.None, this.SocketCallback, state); } public void OnDataReceive(IAsyncResult result) { ServerSocket socket = (ServerSocket) result.AsyncState; int bufferOffset = this.Socket.EndReceive(result); if(bufferOffset > 0 && bufferOffset != socket.buffer1.Length) { byte[] temp = new byte[bufferOffset]; for(int i = 0; i < temp.Length; i++) { temp[i] = socket.buffer1[i]; } this.buffer1 = temp; temp = null; } } I get an ObjectDisposedException at this line: int bufferOffset = this.Socket.EndReceive(result); But: protected void WaitForData() { if(this.SocketCallback == null) { this.SocketCallback = new AsyncCallback(OnDataReceive); } ServerSocket state = new ServerSocket(); state.Socket = this.Socket; this.Socket.BeginReceive(state.buffer1, 0, state.buffer1.Length, SocketFlags.None, this.SocketCallback, state); MessageBox.Show("Foo"); } public void OnDataReceive(IAsyncResult result) { ServerSocket socket = (ServerSocket) result.AsyncState; int bufferOffset = this.Socket.EndReceive(result); if(bufferOffset > 0 && bufferOffset != socket.buffer1.Length) { byte[] temp = new byte[bufferOffset]; for(int i = 0; i < temp.Length; i++) { temp[i] = socket.buffer1[i]; } this.buffer1 = temp; temp = null; } } (Note de MessageBox in WaitForData()) Works perfect. What's wrong?
  3. Hi, I've a question :) I'm trying to create a LAN Game browser for all Source games (e.g. Counter Strike Source). But I've no clue on how to create such a thing. Is the're a way so I can get a list of all computers on the network, and check all ports or something? Thanks in advance :)
  4. Ah thnx, bit stupid of me ^^
  5. I have this code: using System; using System.Collections.Generic; using System.Text; using System.Net; using System.Net.Sockets; using System.Threading; using System.Diagnostics; namespace CSSServer.ServerBrowser { class Source : ServerBrowserMain { private byte region; private string filter; public override event ServerFound ServerAdded; public override event EndOfList EndOfListReached; public override void GetServers(string last_ip, byte region, string filter) { if (last_ip.Length == 0) { return; } this.region = region; this.filter = filter; string query = "1" + (char)region + last_ip + filter; try { this.SendQuery(query); } catch (SocketException) { return; } this.ParseServers(); } protected void ParseServers() { this.offset = 6; this.Cancel = false; for (int i = 0; (i < this.buffer1.Length); i++) { if (this.Cancel) { break; } StringBuilder ip = new StringBuilder(); int port = 0; string final_ip = null; try { final_ip = String.Format("{0}.{1}.{2}.{3}", this.buffer1[this.offset++], this.buffer1[this.offset++], this.buffer1[this.offset++], this.buffer1[this.offset++]); port = BitConverter.ToUInt16(this.buffer1, this.offset++); port = IPAddress.HostToNetworkOrder((short)port); this.offset++; } catch (IndexOutOfRangeException) { this.EndOfListReached(); break; } catch (ArgumentException) { this.EndOfListReached(); break; } IP serverAddress = new IP(final_ip, port); Thread t = new Thread(new ParameterizedThreadStart(GetExtraInfo)); t.Start((object) serverAddress); } } private void GetExtraInfo(object address) { IP serverIp = (IP) address; bool add_server = true; Protocols.Source server = new Protocols.Source(); server.Timeout = 5000; try { server.Connect(serverIp.Address, serverIp.Port); } catch(Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); add_server = false; } try { server.GetServerInfo(true); } catch(Exception ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); add_server = false; } if (add_server) { Types.Server new_server = new Types.Server(); new_server.Host = serverIp.Address; new_server.Port = port; new_server.Players = Convert.ToInt32(server.ServerInfo["player_count"]); new_server.MaxPlayers = Convert.ToInt32(server.ServerInfo["max_players"]); new_server.Name = server.ServerInfo["server_name"]; new_server.Map = server.ServerInfo["map"]; new_server.Ping = Convert.ToInt32(server.ServerInfo["ping"]); new_server.Password = server.ServerInfo["passworded"] == "1" ? true : false; new_server.VAC = server.ServerInfo["secure"] == "1" ? true : false; new_server.Game = server.ServerInfo["game_desc"]; new_server.AppID = Convert.ToInt32(server.ServerInfo["app_id"]); this.number++; this.ServerAdded(new_server); this.servers.Add(new_server); this.last_ip = serverIp.Address; this.last_port = serverIp.Port; } } } public enum SourceRegion : byte { UsEastCoast = 0x00, UsWestCoast = 0x01, SouthAmerica = 0x02, Europe = 0x03, Asia = 0x04, Australia = 0x05, MiddleEast = 0x06, Africa = 0x07, RestOfTheWorld = 0xFF } public class IP { private string address; private int port; public IP() { } public IP(string address, int port) { this.address = address; this.port = port; } public string Address { get { return this.address; } set { this.address = value; } } public int Port { get { return this.Port; } set { this.port = value; } } public override string ToString() { return this.address + ":" + this.port.ToString(); } } } As you can see, this program gets a list of servers from a steam master server, and then parses all info from each server. But then I get the error: What is the problem here?
  6. I've found something very strange. Based on this information: Reply Format The reply always starts with FF FF FF FF 66 0A. The format is then a series of these server address blocks: Type Data Byte First octet of IP address Byte Second octet of IP address Byte Third octect of IP address Byte Fourth octet of IP address [b]Unsigned Short Port number - usually 27015 (69 87) - this is network ordered, which is unlike every other Steam protocol.[/b] Some of the servers may be unreachable, so query each server directly to find out. Note also that this list is not exhaustive, so if you're looking for a particular type of server make sure that you specify a filter with the query, rather than filtering client side. http://developer.valvesoftware.com/wiki/Master_Server_Query_Protocol But when I do this: System.Windows.Forms.MessageBox.Show(BitConverter.ToUInt16(new byte[] { 0x69, 0x87 }, 0).ToString()); I get as result this: And as the information said, 69 87 should be 27015 (which is the default port for steam servers). Am I using the wrong function for a Unsigned short or is an other problem? Fixed, I used IPAddress.HostToNetworkOrder() :)
  7. Well, I searhced a little. And I found out that, when a server doesn't respond, UdpClient freezes. So I stepped over to the Socket class. I tried some servers I also tried with the UdpClient. 1 server did it, with the 2 other servers, the app freezes. The same servers now with Socket class: 1 did it, with the other 2 I got an exception the server didn't respond. (time out) But Xfire can get the information from the servers which didn;t work with my app.. How can I fix this?
  8. see post below
  9. I'm busy with an app that can get some information about a CS:S server. http://www.int64.org/docs/gamestat-protocols/source.html Here's a page about the protocol. But, my question is: how can I send the query? do I have to create a byte array with the query? or is there another way?
  10. Ok thanks!
  11. Is there also a function in C# like this PHP function: http://www.php.net/ord The get the charachter with a ASCII value.
  12. You're great! Got it working :D
  13. Great thanks! :) But here's my next problem: With a memory stream I thought I could finally uncompress the contents, but no. I still got an error with the message that the first byte didn't matched. After some searching, I found that the PHP function gzcompress() is not the same as gzip compression. so gzuncompress() is also not the same als gzip uncompression. The difference: (found in the PHP manual (http://www.php.net/gzcompress)) So there's no header in my file I want to be uncompressed, and that's why I still get the error I think. But how can I uncompress this then?
  14. I thought it only can be used with streams? How can I decompress a byte array then? I'm using this function: static void Main(string[] args) { FileStream fs = new FileStream(@"C:\Documents and Settings\Lucas\My Documents\Mijn downloads\test.age3rec", FileMode.Open, FileAccess.Read); BinaryReader reader = new BinaryReader(fs); byte[] header = new byte[4]; byte[] bytes = new byte[4]; header = reader.ReadBytes(4); bytes = reader.ReadBytes(4); int ByteSize = (int) Convert.ToInt16(bytes[0]) + (Convert.ToInt16(bytes[1]) << 8) + (Convert.ToInt16(bytes[2]) << 16) + (Convert.ToInt16(bytes[3]) << 24); // This array needs to be gzip uncompressed byte[] contents = reader.ReadBytes((int)fs.Length - 8); Console.ReadLine(); } And I'm 100% sure it is gzip compressed, because I found a PHP script, which does the same as what I want my program to do. And that PHP script uses gzuncompress();
  15. IS it possible to uncompress a gzipped byte array?
  16. Well I played a little with it, but I have some problems: I every time get the exception, first byte doens't match But i'm sure it's compressed with gzip..
  17. Uncompress a gzipped byte array Is it possible to uncompress a gzipped byte array?
  18. ah ok thanks. I'll give it a try
  19. I'm trying to create a version checker in C#. But I have a little problem. I have a webpage, containing only the version. (http://ircbot.aoe3capitol.nl/e107_plugins/ircbot_menu/version.php) I want that version to a double in C# so I can compare it with the version of the program. But the problem is, when I use Convert.ToDouble or double.Parse the dots disapear, so the version will become 35 instead of 0.3.5. How can I fix this? My Function: private void Checkversion() { System.Net.WebClient wClient = new System.Net.WebClient(); byte[] buffer = wClient.DownloadData(@"http://ircbot.aoe3capitol.nl/e107_plugins/ircbot_menu/version.php"); double latest_version = double.Parse(System.Text.Encoding.Default.GetString(buffer, 0, buffer.Length)); double current_version = double.Parse(settings.Version); wClient.Dispose(); MessageBox.Show("Latest: " + latest_version.ToString() + "\nCurrent: " + current_version.ToString()); if(current_version < latest_version) { DialogResult result = MessageBox.Show("Er is een nieuwe versie van Lucky Bot beschikbaar. Wil je deze nu downloaden?", "Nieuwe versie", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if(result == DialogResult.Yes) { System.Diagnostics.Process.Start("http://sourceforge.net/project/showfiles.php?group_id=164639&package_id=186478"); Application.Exit(); } } }
  20. Got it to work now :) thanks :)
  21. Not a bad idea, but the main problem I was thinking of is how to store the settings..
  22. Hi, I have a fully working plugin system now, but I always want to go further. I want a CheckedListBox control with all plugins found in my plugins folder. I want that a user can select the plugins which he wants to use. But how can I do this? does anyone this, or has a good tutorial?
  23. Is it possible to get some hardware info of the current computer in C#? Such as CPU Load, Total RAM, RAM Free, Hard disk space etc.. Thanks in advance :)
  24. Ok, I've tried to create a module system, But I don't get it to work.. I have these 2 interfaces: Both are saved in the same Assembly. IHost.cs using System; using System.Collections.Generic; using System.Text; namespace IRCBot.Modules.Interfaces { public interface IHost { void SendCommand(string command); void SendPM(string to, string message); void SendNotice(string to, string message); void MessageWindow(string message); void ErrorBox(string message); string CommandPrefix { get; set; } string Channel { get; set; } string Nick { get; set; } bool IsLoggedIn { get; set; } string ConnectionString { get; set; } System.Net.IRC IRC { get; set; } } } IPlugin.cs using System; using System.Collections.Generic; using System.Text; namespace IRCBot.Modules.Interfaces { public interface IPlugin { void Initialize(IHost Host); void CommandHandler(string command, string arguments); string Name { get; } string Description { get; } string Author { get; } string[] CommandsList { get; } } } Then my host application: ModuleHost.cs using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; namespace IRCBot { class ModuleHost : IRCBot.Modules.Interfaces.IHost { private System.Net.IRC irc_object; private string channel; private string nick; private string command_prefix; private string connection_string; private bool is_logged_in; public string CommandPrefix { get { return this.command_prefix; } set { this.command_prefix = value; } } public string Channel { get { return this.channel; } set { this.channel = value; } } public string Nick { get { return this.nick; } set { this.nick = value; } } public string ConnectionString { get { return this.connection_string; } set { this.connection_string = value; } } public bool IsLoggedIn { get { return is_logged_in; } set { is_logged_in = value; } } public System.Net.IRC IRC { get { return this.irc_object; } set { this.irc_object = value; } } public void SendCommand(string command) { this.IRC.SendCommand(command); } public void SendPM(string to, string message) { this.IRC.SendPM(to, message); } public void SendNotice(string to, string message) { this.IRC.SendNotice(to, message); } public void MessageWindow(string message) { MessageBox.Show(message); } public void ErrorBox(string message) { MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } ModuleHandler.cs using System; using System.Collections.Generic; using System.Text; using System.Collections; using System.IO; using System.Reflection; using System.Windows.Forms; namespace IRCBot { class ModuleHandler { public struct Module { public string Path; public string ClassName; } /// <summary> /// Searches for modules /// </summary> /// <param name="Path">Path to search</param> /// <param name="Interface">Interface name</param> /// <returns>array with all modules</returns> public static Module[] FindModules(string Path, string Interface) { ArrayList Modules = new ArrayList(); string[] ModuleFiles; Assembly ModuleObject; ModuleFiles = Directory.GetFileSystemEntries(Path, "*.dll"); for(int i = 0; i < ModuleFiles.Length; i++) { try { ModuleObject = Assembly.LoadFrom(ModuleFiles[i]); ExamineAssembly(ModuleObject, Interface, Modules); } catch { MessageBox.Show("Could not load plugin " + ModuleFiles[i]); } } Module[] Results = new Module[Modules.Count]; if(Modules.Count != 0) { Modules.CopyTo(Results); return Results; } else { return null; } } /// <summary> /// Examines an assembly /// </summary> /// <param name="ModuleObject">Module Object</param> /// <param name="Interface">Interface name</param> /// <param name="Modules">Arraylist with all modules</param> public static void ExamineAssembly(Assembly ModuleObject, string Interface, ArrayList Modules) { Type oInterface; Module Module; foreach(Type ModuleType in ModuleObject.GetTypes()) { if(ModuleType.IsPublic == true) { if((ModuleType.Attributes) != TypeAttributes.Abstract) { // Check if implement our interface oInterface = ModuleType.GetInterface(Interface, true); if(oInterface != null) { // It does =D Module = new Module(); Module.Path = ModuleObject.Location; Module.ClassName = ModuleType.FullName; Modules.Add(Module); } } } } } /// <summary> /// starts a specific module /// </summary> /// <param name="Module">The module</param> /// <returns>an object with the class</returns> public static object StartModule(Module Module) { Assembly ModuleDLL; object oModule = null; try { ModuleDLL = Assembly.LoadFrom(Module.Path); oModule = ModuleDLL.CreateInstance(Module.ClassName); } catch(Exception ex) { MessageBox.Show("Could not starts module: " + ex.Message); } return oModule; } } } And than, I'm using this piece of code in my Form1.cs file: In Form_Load event: // Load Modules this.Modules = ModuleHandler.FindModules(System.IO.Path.GetDirectoryName(Application.ExecutablePath) + "/modules", "IRCBot.Modules.Interfaces.IPlugin"); this.Host = new ModuleHost(); this.Host.CommandPrefix = this.CommandPrefix; And this piece of code in a custom event: (Which triggers when a new command from the server is recieved) this.AddToLog("Setting host object..", "other"); this.Host.IRC = irc; this.Host.Channel = channel; this.Host.Nick = nick; this.Host.ConnectionString = this.conn_string; this.Host.IsLoggedIn = this.IsLoggedIn(nick); this.AddToLog("Starting Modules.. - Number of modules: " + this.Modules.Length.ToString(), "other"); IRCBot.Modules.Interfaces.IPlugin oModule; for(int i = 0; i < this.Modules.Length; i++) { this.AddToLog("Creating Object..", "other"); oModule = (IRCBot.Modules.Interfaces.IPlugin) ModuleHandler.StartModule(this.Modules[i]); /*this.AddToLog("Initialize..", "other"); oModule.Initialize(this.Host);*/ this.AddToLog("Starting module: " + oModule.Name, "other"); //oModule.CommandHandler(bot_command[0], arguments); } A lot of code, I know :P I build my Host application, no build errors. The application also starts up with no errors. But when I click my connect button, and my custom event triggers, I get the a problem. When my app wants to create an instance of the plugin, it stops. My windows form is normal (can resize etc), but it does not handle any commands from the server anymore. It does nothing.. :S What am I doing wrong?
  25. Great thnx! :)
×
×
  • Create New...