Skip to content

Instantly share code, notes, and snippets.

@yellows111
Created October 9, 2024 18:56
Show Gist options
  • Save yellows111/e3ef1a57eba79a105ad80ecc5f2d2fb2 to your computer and use it in GitHub Desktop.
Save yellows111/e3ef1a57eba79a105ad80ecc5f2d2fb2 to your computer and use it in GitHub Desktop.
a MSN Messenger config server that supports both types of output formats that I made to prove a point (.NET Framework 2 or higher)
// messenger config server, macaroni and beef, serves 3 people.
// How to do it:
// 1) csc /target:winexe __FILE
// 2) Run the exe and enjoy.
// A server for MsgrConfig.xml, because someone wouldn't stop asking for it.
// Copyright 2024, yellows111
// I don't really care, so this is public domain or your favorite license.
// Author Doesn't Care Public License
// 0: I DO NOT CARE WHAT YOU DO WITH THIS PROGRAM, CODE, OR OTHER SUCH
// YOU ARE ENTIRELY FREE TO MODIFY, SELL IT, OR WHATEVER YOU DESIRE
// LEGAL NOTICE: THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. OF ANY KIND
using System;
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
using System.Threading;
using System.Xml;
namespace msgrConfigServer {
class Program {
private static TcpListener listener;
private static NotifyIcon aWayToCloseMe;
[STAThread]
public static void Main(string[] args) {
Int16 port = 80;
if(args.Length > 0) {
port = Int16.Parse(args[1]);
}
// notification area setup
MenuItem exitButtonInThatContextMenu = new MenuItem();
exitButtonInThatContextMenu.Index = 0;
exitButtonInThatContextMenu.Text = "S&top service";
exitButtonInThatContextMenu.Click += new System.EventHandler(quit);
ContextMenu ourContextMenu = new ContextMenu();
ourContextMenu.MenuItems.Add(exitButtonInThatContextMenu);
aWayToCloseMe = new NotifyIcon();
aWayToCloseMe.Icon = System.Drawing.Icon.ExtractAssociatedIcon(System.Reflection.Assembly.GetExecutingAssembly().Location);
aWayToCloseMe.ContextMenu = ourContextMenu;
aWayToCloseMe.Text = "Messenger Config Server is running";
aWayToCloseMe.Visible = true;
// http listener
listener = new TcpListener(IPAddress.Parse("127.0.0.1"), (int)port);
Thread serverThread = new Thread(new ThreadStart(httpService));
serverThread.Start();
}
private static void httpService() {
listener.Start();
try {
while(true) {
TcpClient httpClient = listener.AcceptTcpClient();
byte[] buffer = new byte[10240];
NetworkStream stream = httpClient.GetStream();
int length = stream.Read(buffer, 0, buffer.Length);
string request = System.Text.Encoding.UTF8.GetString(buffer, 0, length);
bool isPost = (request.Substring(0, 4) == "POST");
Console.WriteLine("Got Request:\r\n" + request);
XmlDocument MsgrConfig = new XmlDocument();
MsgrConfig.Load("MsgrConfig.xml");
string responseText;
if(isPost) {
responseText = "<?xml version=\"1.0\" encoding=\"utf-8\" ?> <soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><soap:Body><GetClientConfigResponse xmlns=\"http://www.msn.com/webservices/Messenger/Client\"><GetClientConfigResult><![CDATA[" + MsgrConfig.OuterXml + "]]></GetClientConfigResult></GetClientConfigResponse></soap:Body></soap:Envelope>";
} else {
responseText = "<?xml version=\"1.0\" encoding=\"utf-8\"?> " + MsgrConfig.OuterXml;
}
byte[] response = System.Text.Encoding.UTF8.GetBytes(
"HTTP/1.1 200 OK" + Environment.NewLine +
"Content-Length: " + (responseText.Length+4) + Environment.NewLine +
"Content-Type: text/xml;charset=UTF-8" + Environment.NewLine +
"Connection: close" + Environment.NewLine +
Environment.NewLine +
responseText +
Environment.NewLine +
Environment.NewLine
);
stream.Write(response, 0, response.Length);
System.Threading.Thread.Sleep(1000);
}
} catch (Exception ex) {
MessageBox.Show(ex.Message, "Messenger Config Server Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
} finally {
quit(null, null);
}
}
private static void quit(object Sender, EventArgs e) {
aWayToCloseMe.Visible = false;
listener.Stop();
Environment.Exit(0);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment