using System;
using System.Net.Sockets;
using System.IO;
using System.Text.RegularExpressions;
public class bouncer {
private static string paquete2 = "PRIVMSG #Alternativos :xD";
private static string paquete = "<irc src=\"chat12.terra.es\" cmd=\"PONG\" a0=\"chat12.terra.es\" rest=\"LAG2196474780\" />";
public static void Main(string[] args){
Console.WriteLine("################");
Console.WriteLine("# De XML a IRC #");
Console.WriteLine("################");
Console.WriteLine("Paquete XML: "+paquete);
Console.WriteLine("Paquete IRC: "+ToIrc(paquete)+"\n");
Console.WriteLine("################");
Console.WriteLine("# De IRC a XML #");
Console.WriteLine("################");
Console.WriteLine("Paquete IRC: "+paquete2);
Console.WriteLine("Paquete XML: "+ToXml(paquete2));
Console.ReadLine();
}
public static string ToXml(string DataIRC){
string DataXML = "";
DataIRC = DataIRC.Replace("\n","");
DataIRC = DataIRC.Replace("%","%3E");
DataIRC = DataIRC.Replace(" ","%20");
DataIRC = DataIRC.Replace("#","%23");
DataIRC = DataIRC.Replace(":","%3A");
DataIRC = DataIRC.Replace(".","%2E");
DataXML = "<raw>"+DataIRC+"</raw>";
return DataXML;
}
public static String Create_Nick(){
Random r = new Random();
string num1 = Convert.ToString(r.Next(9));
string num2 = Convert.ToString(r.Next(9));
string num3 = Convert.ToString(r.Next(9));
string frag1 = "{CiRc[";
string frag2 = "]BnC}";
string nick = frag1+num1+num2+num3+frag2;
return nick;
}
public static string ToIrc(string DataXML){
string packirc = "";
//probar array de expresiones regulares.
Regex r1 = new Regex("src=\\s*[\"']([^\\s]*)[\"']\\s*");
Regex r2 = new Regex("cmd=\\s*[\"']([^\\s]*)[\"']\\s*");
Regex r3 = new Regex("a\\d=\\s*[\"']([^\\s]*)[\"']\\s*");
Regex r4 = new Regex("rest=\\s*[\"']([^\\s]*)[\"']\\s*");
try{
Match m = r1.Match(DataXML);
string src = restrip(m.Value);
m = r2.Match(DataXML);
string cmd = restrip(m.Value);
m = r4.Match(DataXML);
string rest = restrip(m.Value);
MatchCollection mc = r3.Matches(DataXML);
string[] aes = new string[mc.Count];
int ctr = 0;
foreach(Match n in mc){
aes[ctr] = restrip(n.Value);
ctr++;
}
packirc += ":"+src+" "+cmd;
for(int i=0;i<aes.Length;i++){
packirc += " "+aes[i];
}
packirc += " :"+rest;
}catch(Exception e){
//eliminar captura de excepciones tras pruebas.
Console.WriteLine(e.ToString());
}
return packirc;
}
//eliminar tomando directamente el valor con la expresion regular.
public static string restrip(string data){
char[] r = {'"'};
string frag = data.Split(r)[1];
return frag;
}
}
Se que queda un poco mal ponerlo sin depurar, pero es que ando estudiando ensamblador asi que tengo este asunto un poco parado, tan solo queria que la gente tubiese una minima guia. Prometo que cuando tenga tiempo lo termino.
No hay comentarios:
Publicar un comentario