コード例 #1
0
ファイル: Form1.cs プロジェクト: kellyelton/octgn-server-old
 private void button3_Click(object sender, EventArgs e)
 {
     SocketMessage sm = new SocketMessage("1");
     sm.Arguments.Add(textBox1.Text);
     sock.writeMessage(sm);
     addline("Output: " + sm.getMessage());
 }
コード例 #2
0
ファイル: Client.cs プロジェクト: kellyelton/octgn-server-old
 protected override void handleConnectionEvent(object Sender, ConnectionEvent e)
 {
     if(e.Event == ConnectionEvent.eConnectionEvent.eceConnect)
     {
         ConsoleEventLog.addEvent(new ConsoleEvent("Client " + e.Host + " connected."), true);
     }
     else
     {
         if(!NotifiedLoggedOff)
         {
             ClientContainer.UserEvent(UserEventType.LogOut, this);
             this.NotifiedLoggedOff = true;
             this.LoggedIn = false;
             List<HostedGame> ret = GameBox.RemoveByUID(User.UID);
             foreach(HostedGame b in ret)
             {
                 SocketMessage stemp2 = new SocketMessage("UNHOST");
                 String gstring = Convert.ToBase64String(HostedGame.Serialize(b));
                 stemp2.Arguments.Add(gstring);
                 ClientContainer.AllUserCommand(stemp2);
             }
         }
         ConsoleEventLog.addEvent(new ConsoleEvent("Client " + e.Host + " disconnected ."), true);
     }
 }
コード例 #3
0
ファイル: ShitSock.cs プロジェクト: kellyelton/netshit
 /// <summary>
 /// Sends a message to the remote socket.
 /// </summary>
 /// <param name="sm">SocketMessage to be sent.</param>
 /// <returns>true on success, false on error. Note: Success just means that the message has been sent, it doesn't verifiy it was recieved.</returns>
 public Boolean writeMessage(SocketMessage sm)
 {
     List<byte> temp = new List<byte>(SocketMessage.Serialize(sm));
     byte hbyte =System.Text.ASCIIEncoding.ASCII.GetBytes("#")[0];
     for(int i=0; i < 5; i++)
         temp.Add(hbyte);
     return WriteData(temp.ToArray());
 }
コード例 #4
0
ファイル: Form1.cs プロジェクト: kellyelton/octgn-server-old
        private void button1_Click(object sender, EventArgs e)
        {
            SocketMessage sm = new SocketMessage("LOG");
            sm.Arguments.Add(tbUsername.Text);
            sm.Arguments.Add(tbPassword.Text);
            sm.Arguments.Add("1.0.2.1");

            sock.writeMessage(sm);
        }
コード例 #5
0
ファイル: ShitSock.cs プロジェクト: kellyelton/netshit
 private void doInput(SocketMessage input)
 {
     if(!input.Empty)
     {
         handleInput(this, input);
         if(onSocketMessageInput != null)
             onSocketMessageInput.Invoke(this, input);
     }
 }
コード例 #6
0
 public static void AllUserCommand(SocketMessage command)
 {
     int intcount = Clients.Count;
     for(int i=0;i<intcount;i++)
     {
         if(Clients[i].Connected)
         {
             Clients[i].writeMessage(command);
         }
     }
 }
コード例 #7
0
ファイル: Client.cs プロジェクト: kellyelton/octgn-server-old
 public override void handleDisconnect(String reason, String host, int port)
 {
     if (!NotifiedLoggedOff)
     {
         ClientContainer.UserEvent(UserEventType.LogOut, this);
         this.NotifiedLoggedOff = true;
         this.LoggedIn = false;
         string ret = GameBox.RemoveByUID(User.UID);
         String[] rets = ret.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
         foreach (String b in rets)
         {
             if (!ret.Equals("-1"))
             {
                 SocketMessage stemp2 = new SocketMessage("UNHOST");
                 stemp2.Arguments.Add(b);
                 ClientContainer.AllUserCommand(stemp2);
             }
         }
     }
     ConsoleEventLog.addEvent(new ConsoleEvent("Client " + host + " disconnected because " + reason), true);
 }
コード例 #8
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
 public void unHost_Game()
 {
     SocketMessage sm = new SocketMessage("UNHOST");
     this.isHosting = false;
     writeMessage(sm);
 }
コード例 #9
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
 public void Register(String email, String username, String password)
 {
     SocketMessage sm = new SocketMessage("REG");
     sm.Arguments.Add(username);
     sm.Arguments.Add(email);
     sm.Arguments.Add(password);
     this.writeMessage(sm);
 }
コード例 #10
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
        public void Login(String email, String password)
        {
            Encoding enc = Encoding.ASCII;
            byte[] buffer = new byte[0];
            String pass = "";
            try
            {
                buffer = enc.GetBytes(password);
            }
            catch(Exception e)
            {
            }
            SHA1CryptoServiceProvider cryptoTransformSHA1 = new SHA1CryptoServiceProvider();

            try
            {
                pass = BitConverter.ToString(cryptoTransformSHA1.ComputeHash(buffer)).Replace("-", "");
            }
            catch(Exception e)
            {
            }
            cryptoTransformSHA1.Dispose();
            if(pass != null)
            {
                pass = pass.ToLower();
                SocketMessage sm = new SocketMessage("LOG");
                sm.Arguments.Add(email);
                sm.Arguments.Add(pass);
                sm.Arguments.Add(Settings.Default.currevision);
                this.writeMessage(sm);
            }
        }
コード例 #11
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
 public void Host_Game(Definitions.GameDef def)
 {
     SocketMessage sm = new SocketMessage("HOST");
     sm.Arguments.Add(def.Name);
     sm.Arguments.Add(def.Id.ToString());
     sm.Arguments.Add(def.Version.ToString());
     sm.Arguments.Add(LastGameInfo);
     this.isHosting = true;
     writeMessage(sm);
 }
コード例 #12
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
        public String Chat(String text)
        {
            SocketMessage sm = new SocketMessage("LOBCHAT");
            text = text.Trim();
            for(int b = 0; b <= 6; b++)
            {
                text.Replace((char)b, (char)0);
            }
            if(!isHosting && !isJoining && Status != PlayerStatus.Available)
            {
                if(Status != PlayerStatus.Hosting)
                {
                    ChangePlayerStatus(PlayerStatus.Available);
                }
                lastMessageSent = DateTime.Now;
            }

            if(text.Length == 0)
                return text;
            try
            {
                String[] words = text.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                switch(words[0].ToLower())
                {
                    case "/reconnect":
                        if(!Connected)
                            Start();
                        return "";
                    case "/r":
                        if(strLastWhisperFrom.Equals(""))
                            return "";
                        else
                            text = "/w " + strLastWhisperFrom + " " + text.Substring(3);
                        break;
                    case "/login":
                        if(Connected && !loggedIn)
                        {
                            if(words.Length == 3)
                            {
                                Login(words[1], words[2]);
                            }
                        }
                        return "";
                    case "/away":
                        if(!isHosting && !isJoining && Status != PlayerStatus.Away)
                        {
                            if(Status != PlayerStatus.Hosting)
                            {
                                ChangePlayerStatus(PlayerStatus.Away);
                            }
                        }
                        return "";
                }
            }
            catch(ArgumentOutOfRangeException ae)
            {
            }
            catch(Exception e)
            {
                return text;
            }
            sm.Arguments.Add(text);
            writeMessage(sm);
            return text;
        }
コード例 #13
0
ファイル: Form1.cs プロジェクト: kellyelton/octgn-server-old
 private void sock_onSocketMessageInput(object Sender, SocketMessage sm)
 {
     addline("Input: " + sm.getMessage());
 }
コード例 #14
0
ファイル: Client.cs プロジェクト: kellyelton/octgn-server-old
        public override void handleInput(SocketMessage input)
        {
            if (!LoggedIn)
            {
                switch (input.Header)
                {
                    case "LOG":
                        Boolean worked = UserMysql.login(this, input.Arguments[0], input.Arguments[1]);
                        if (worked)
                        {
                            for (int i = 0; i < ClientContainer.Clients.Count; i++)
                            {
                                if (ClientContainer.Clients[i].User.UID == User.UID)
                                {
                                    if (ClientContainer.Clients[i].ID != this.ID)
                                    {
                                        if (ClientContainer.Clients[i].Connected)
                                        {
                                            ClientContainer.UserEvent(UserEventType.LogOut, ClientContainer.Clients[i]);
                                            ClientContainer.Clients[i].Close("Another user logged in.", false);
                                        }
                                    }
                                }
                            }
                            SocketMessage sm;
                            if (input.Arguments.Count < 3)
                            {
                                sm = new SocketMessage("LOGSUCCESS");
                                sm.Arguments.Add(this.User.Username);
                                writeMessage(sm);
                                ClientContainer.UserEvent(UserEventType.LogIn, this);
                                Thread th = new Thread(new ThreadStart(delegate()
                                {
                                    Thread.Sleep(1000);
                                    sm = new SocketMessage("CHATINFO");
                                    sm.Arguments.Add("YOU DO NOT HAVE THE LATEST LOBBY VERSION. PLEASE VISIT http://www.skylabsonline.com/blog/project/octgn-w-lobby/ TO GET IT!");
                                    this.writeMessage(sm);
                                    sm = new SocketMessage("CHATINFO");
                                    sm.Arguments.Add("User " + this.User.Username + " could not log in because he/she needs an update.");
                                    ClientContainer.AllUserCommand(sm);
                                    Thread.Sleep(1000);
                                    this.Close("Incompatable version.", true);
                                }
                                ));
                                th.Start();
                            }
                            else
                            {
                                if (!input.Arguments[2].Equals(MainClass.getCurRevision().Trim()))
                                {
                                    sm = new SocketMessage("LOGSUCCESS");
                                    sm.Arguments.Add(this.User.Username);
                                    writeMessage(sm);
                                    ClientContainer.UserEvent(UserEventType.LogIn, this);
                                    Thread th = new Thread(new ThreadStart(delegate()
                                        {
                                            Thread.Sleep(1000);
                                            sm = new SocketMessage("CHATINFO");
                                            sm.Arguments.Add("YOU DO NOT HAVE THE LATEST LOBBY VERSION. PLEASE VISIT http://www.skylabsonline.com/blog/project/octgn-w-lobby/ TO GET IT!");
                                            this.writeMessage(sm);
                                            sm = new SocketMessage("CHATINFO");
                                            sm.Arguments.Add("User " + this.User.Username + " could not log in because he/she needs an update.");
                                            ClientContainer.AllUserCommand(sm);
                                            Thread.Sleep(1000);
                                            this.Close("Incompatable version.", true);
                                        }
                                    ));
                                    th.Start();
                                }
                                else
                                {
                                    sm = new SocketMessage("LOGSUCCESS");
                                    sm.Arguments.Add(this.User.Username);
                                    writeMessage(sm);
                                    ClientContainer.UserEvent(UserEventType.LogIn, this);
                                    sm = new SocketMessage("CHATINFO");
                                    sm.Arguments.Add(MainClass.getDailyMessage());
                                    this.writeMessage(sm);
                                    LoggedIn = true;
                                }
                            }
                        }
                        else
                        {
                            SocketMessage sm = new SocketMessage("LOGERROR");
                            writeMessage(sm);
                            LoggedIn = false;
                        }
                        break;
                    case "REG":
                        String nick = input.Arguments[0];
                        String email = input.Arguments[1];
                        String pass = input.Arguments[2];
                        String regret = UserMysql.register(nick, email, pass);
                        writeMessage(new SocketMessage(regret));
                        break;
                    case "RC":
                        this.isRc = true;
                        User = new User(987654321, "rc", "rc");
                        break;
                }
            }
            else if (LoggedIn)
            {
                switch (input.Header)
                {
                    case "GETONLINELIST":

                        StringBuilder sb = new StringBuilder();
                        SocketMessage sm = new SocketMessage("ONLINELIST");
                        List<User> listOnlineUsers = ClientContainer.getOnlineUserList();
                        int intOnlineUsers = listOnlineUsers.Count;
                        for (int i = 0; i < intOnlineUsers; i++)
                        {
                            sb = new StringBuilder();
                            sb.Append(listOnlineUsers[i].Email);
                            sb.Append(':');
                            sb.Append(listOnlineUsers[i].Username);
                            sb.Append(':');
                            sb.Append(listOnlineUsers[i].Status.ToString());
                            sm.Arguments.Add(sb.ToString());
                        }
                        foreach (String user in IrcBot.Users)
                        {
                            sb = new StringBuilder();
                            sb.Append(user + "@irc.irc");
                            sb.Append(':');
                            sb.Append("<irc>" + user);
                            sb.Append(':');
                            sb.Append(UserStatus.Available.ToString());
                            sm.Arguments.Add(sb.ToString());
                        }
                        writeMessage(sm);
                        break;
                    case "LOBCHAT":
                        ClientContainer.LobbyChat(User.Username, input.Arguments[0].Trim());
                        break;
                    case "HOST":
                        String[] ips = input.Arguments[0].Split(new char[1] { '?' });
                        HostedGame h = new HostedGame(User.UID, input.Arguments[3], input.Arguments[1], input.Arguments[0], input.Arguments[2], "");
                        int gID = GameBox.AddGame(h);
                        SocketMessage stemp = input;
                        stemp.Arguments.Add(this.User.Username);
                        stemp.Arguments.Add(gID.ToString());
            #if(DEBUG)
                        stemp.Arguments.Add("localhost");
                        IPAddress[] addresslist = Dns.GetHostAddresses("localhost");
            #else
                        stemp.Arguments.Add(MainClass.getProperty("OusideHost"));
                        IPAddress[] addresslist = Dns.GetHostAddresses(MainClass.getProperty("OusideHost"));
            #endif
                        int port = (gID + 6000);
                        stemp.Arguments.Add(port.ToString());
                        ClientContainer.AllUserCommand(stemp);

                        IrcBot.GeneralChat(this.User.Username + " is hosting a " + h.GameName + " game at " + addresslist[0].ToString() + ":" + port.ToString() + " :" + h.Name);
                        foreach (IPAddress theaddress in addresslist)
                        {
                            Console.WriteLine(theaddress.ToString());
                        }
                        break;
                    case "UNHOST":
                        string ret = GameBox.RemoveByUID(User.UID);
                        String[] rets = ret.Split(new char[1] { ':' }, StringSplitOptions.RemoveEmptyEntries);
                        foreach (String b in rets)
                        {
                            if (!ret.Equals("-1"))
                            {
                                SocketMessage stemp2 = input;
                                stemp2.Arguments.Add(b);
                                ClientContainer.AllUserCommand(stemp2);
                            }
                        }
                        break;
                    case "STATUS":
                        User.Status = (UserStatus)Enum.Parse(typeof(UserStatus), input.Arguments[0], true);
                        input.Arguments.Add(User.Username);
                        ClientContainer.AllUserCommand(input);
                        break;
                    case "GAMELIST":
                        int mGames = GameBox.Games.Count;
                        for (int i = 0; i < mGames; i++)
                        {
                            HostedGame hg = (HostedGame)GameBox.Games[i];
                            if (hg.Available)
                            {
                                SocketMessage stemp3 = new SocketMessage("GAMELIST");

                                //Game list
                                //GID,IP,Port,GameName,GUID,GameVersion,Username,Name
                                //GID
                                stemp3.Arguments.Add(hg.ID.ToString());
                                //IP
            #if(DEBUG)
                                stemp3.Arguments.Add("localhost");
            #else
                                stemp3.Arguments.Add(MainClass.getProperty("OusideHost"));
            #endif
                                //Port
                                port = (hg.ID + 6000);
                                stemp3.Arguments.Add(port.ToString());
                                //GameName
                                stemp3.Arguments.Add(hg.GameName);
                                //GUID
                                stemp3.Arguments.Add(hg.GUID);
                                //GameVersion
                                stemp3.Arguments.Add(hg.GameVersion);

                                int uid = hg.UID;
                                Client cl = ClientContainer.getClientFromUID(uid);
                                //Username
                                stemp3.Arguments.Add(cl.User.Username);
                                //Name
                                stemp3.Arguments.Add(hg.Name);
                                //Main.writeEvent("Sending GAMELIST: " + stemp3.getMessage());
                                this.writeMessage(stemp3);
                            }
                        }
                        break;
                    default:
                        //TODO add ConsoleEvent to handle unknown input
                        //Main.writeEvent("Input from `" + super.strHost + "' :" + input.getMessage());
                        //Main.writeIn();
                        break;
                }
            }
            if (isRc)
            {
                ConsoleEventLog.addEvent(new ConsoleEvent("#RC: ", input.getMessage()), true);
                switch (input.Header)
                {
                    case "1":
                        SocketMessage sm = new SocketMessage("CHATINFO");
                        sm.Arguments.Add(input.Arguments[0]);
                        ClientContainer.AllUserCommand(sm);
                        break;
                    case "2":
                        MainClass.KillServer();
                        break;
                    case "3":
                        try
                        {
                            int time = int.Parse(input.Arguments[0]);
                            MainClass.TimeKillServer(time, null);
                        }
                        catch (Exception e)
                        {
                        }
                        break;
                    case "4":
                        try
                        {
                            int time = int.Parse(input.Arguments[0]);
                            MainClass.TimeKillServer(time, input.Arguments[1]);
                        }
                        catch (Exception e)
                        {
                        }
                        break;
                }
            }
        }
コード例 #15
0
ファイル: SocketMessage.cs プロジェクト: kellyelton/netshit
 public static byte[] Serialize(SocketMessage obj)
 {
     BinaryFormatter bff = new BinaryFormatter();
     MemoryStream ms = new MemoryStream();
     bff.Serialize(ms, obj);
     return ms.ToArray();
 }
コード例 #16
0
ファイル: ShitSock.cs プロジェクト: kellyelton/netshit
 protected virtual void handleInput(object Sender, SocketMessage mess)
 {
 }
コード例 #17
0
 public static void UserEvent(UserEventType ue, Client c)
 {
     SocketMessage sm;
     switch (ue)
     {
         case Containers.UserEventType.LogIn:
             sm = new SocketMessage("USERONLINE");
             sm.Arguments.Add(c.User.Email + ":" + c.User.Username);
             AllUserCommand(sm);
         break;
         case Containers.UserEventType.LogOut:
             sm = new SocketMessage("USEROFFLINE");
             sm.Arguments.Add(c.User.Email);
             AllUserCommand(sm);
         break;
     }
 }
コード例 #18
0
        public static void LobbyChat(String user, String chat)
        {
            if(chat.Substring(0,1).Equals("/"))
            {
                int sp = chat.IndexOf(' ');
                String command = "";
                if(sp == -1)
                    command = chat.Substring(1);
                else
                    command =chat.Substring(1,sp-1);
                chat = chat.Substring(sp+1);
                if(command.ToLower().Equals("w"))
                {
                    String to;
                    sp = chat.IndexOf(' ');
                    if(sp != -1)
                    {
                        to = chat.Substring(0,sp);
                        chat = chat.Substring(sp+1);
                        Client c = getClientFromUserName(to);
                        Client from = getClientFromUserName(user);
                        if(!c.User.Email.Equals("") && c.Connected)
                        {
                            SocketMessage sm = new SocketMessage("LOBW");
                            sm.Arguments.Add(user + ":" + to);
                            sm.Arguments.Add(chat);
                            c.writeMessage(sm);
                            from.writeMessage(sm);
                        }
                        else
                        {
                            if (to.Substring(0, 5).ToLower().Equals("<irc>"))
                            {
                                IrcBot.PMUser(to.Substring(5),from.User.Username, chat);
                            }
                            else
                            {
                                SocketMessage sm = new SocketMessage("CHATERROR");
                                sm.Arguments.Add("User '" + to + "' not online.");
                                from.writeMessage(sm);
                            }
                        }
                    }

                }
                else if (command.Equals("i"))
                {
                    SocketMessage sm = new SocketMessage("LOBCHAT");
                    sm.Arguments.Add(user);
                    sm.Arguments.Add("<ircvisible>" + chat);
                    AllUserCommand(sm);
                    if (user.Length > 5)
                    {
                        if (!user.Substring(0, 5).Equals("<irc>"))
                            IrcBot.ChatAsUser(user, chat);
                    }
                    else
                        IrcBot.ChatAsUser(user, chat);
                }
                else if (command.Equals("?"))
                {
                    String ch = "";
                    ch += "Lobby chat help\n";
                    ch += "-----------------------------------------------------------\n";
                    ch += "\\?\n";
                    ch += "--This menu.\n";
                    ch += "\\w user message\n";
                    ch += "--Sends the 'user' 'message'\n";
                    ch += "\\r message\n";
                    ch += "--Replies to the last received whisper 'message'\n";
                    ch += "\\i message\n";
                    ch += "--Writes the 'message' to the irc chat as you\n";
                    ch += "-----------------------------------------------------------\n";
                    SocketMessage sm = new SocketMessage("CHATINFO");
                    sm.Arguments.Add(ch);
                    Client c = ClientContainer.getClientFromUserName(user);
                    if(c!= null)
                    {
                     if(c.Connected && c.LoggedIn)
                         c.writeMessage(sm);
                    }
                    //from.writeLine(ch);
                }
                else
                {
                    SocketMessage sm = new SocketMessage("LOBCHAT");
                    sm.Arguments.Add(user);
                    sm.Arguments.Add(chat);
                    AllUserCommand(sm);
                }
            }
            else
            {
                SocketMessage sm =new SocketMessage("LOBCHAT");
                sm.Arguments.Add(user);
                sm.Arguments.Add(chat);
                AllUserCommand(sm);
            }
        }
コード例 #19
0
ファイル: Main.cs プロジェクト: kellyelton/octgn-server-old
        public static void WriteAd(TimeSpan lastAd)
        {
            return;
            if(lastAd >= timebetweenads)
            {
                WebClient wc = new WebClient();
                try
                {
                    Uri u = new Uri("http://www.qksz.net/1e-jror");

                    String ad = @wc.DownloadString(u);
                    ad = ad.Replace("\\\\\\", "\\");
                    Regex r = new Regex("^document\\.write\\(\"(.+)+\"\\);$");
                    Match m = r.Match(ad);
                    if(m.Groups.Count >= 2)
                    {
                        String fullhtml = m.Groups[1].Value;
                        //ConsoleWriter.writeLine(fullhtml, true);
                        String xaml = "";// HtmlToXamlConverter.ConvertHtmlToXaml(fullhtml, true);
                        if(!xaml.Trim().Equals(""))
                        {
                            SocketMessage sm = new SocketMessage("XAMLCHAT");
                            sm.Arguments.Add("SUPPORT");
                            sm.Arguments.Add(xaml);
                            ClientContainer.AllUserCommand(sm);
                        }
                        //ConsoleWriter.writeLine(xaml, true);
                    }
                    //ConsoleWriter.writeLine(evalstring, true);
                }
                catch(Exception e)
                {
                }
            }
        }
コード例 #20
0
ファイル: Main.cs プロジェクト: kellyelton/octgn-server-old
 public static void TimeKillServer(int time, String message)
 {
     fKillTime = time;
     SocketMessage sm = new SocketMessage("CHATINFO");
     String mess = "Server shutting down in " + fKillTime.ToString() + " seconds. ";
     if(message != null && !String.IsNullOrEmpty(message))
         mess += "\n Reason: " + message;
     sm.Arguments.Add(mess);
     ClientContainer.AllUserCommand(sm);
 }
コード例 #21
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
        private void LobbyClient_onSocketMessageInput(object Sender, SocketMessage input)
        {
            String head = input.Header;
            String a = "";
            String[] up;
            List<String> args = input.Arguments;
            String sPing = new String(new char[1] { (char)1 });
            switch(head)
            {
                case "LOGSUCCESS":
                    loggedIn = true;
                    try
                    {
                        strUserName = args[0];
                        Settings.Default.NickName = Program.LClient.strUserName;
                        Settings.Default.Save();
                    }
                    catch(Exception e)
                    {
                    }
                    eLogEvent.Invoke("LSUCC");
                    break;
                case "LOGERROR":
                    MessageBox.Show("E-Mail or password is incorrect.", "Error");
                    eLogEvent.Invoke("LERR");
                    break;
                case "REGERR0":
                    MessageBox.Show("Lobby server error. Please try again later.");
                    eLogEvent.Invoke("RERR");
                    break;
                case "REGERR1":
                    MessageBox.Show("Please enter a valid e-mail address.");
                    eLogEvent.Invoke("RERR");
                    break;
                case "REGERR2":
                    MessageBox.Show("Password must be at least 6 characters long.");
                    eLogEvent.Invoke("RERR");
                    break;
                case "REGERR3":
                    MessageBox.Show("Nickname already exists.");
                    eLogEvent.Invoke("RERR");
                    break;
                case "REGERR4":
                    MessageBox.Show("E-Mail already registered.");
                    eLogEvent.Invoke("RERR");
                    break;
                case "REGSUCCESS":
                    MessageBox.Show("Account successfully registered.");
                    eLogEvent.Invoke("RSUCC");
                    break;
                default:
                    if(head.Equals(sPing))
                    {
                        if(Program.lwLobbyWindow == null)
                            this.Close(true);
                        else
                        {
                            if(!Program.lwLobbyWindow.IsActive)
                                this.Close(true);
                        }
                    }
                    if(loggedIn)
                    {
                        if(Status != PlayerStatus.Away)
                        {
                            TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - lastMessageSent.Ticks);
                            if(ts.TotalMinutes >= 5)
                            {
                                if(!isHosting && !isJoining)
                                {
                                    Status = PlayerStatus.Away;
                                }
                            }
                        }
                        switch(head)
                        {
                            case "USERONLINE":
                                //User[] temp = new User[args.Count];
                                try
                                {
                                    a = args[0];
                                    up = a.Split(new char[1] { ':' });
                                    Boolean userAlreadyOnList = false;
                                    for(int i = 0; i < OnlineUsers.Count; i++)
                                    {
                                        if(OnlineUsers[i].Username.Equals(up[1]))
                                        {
                                            userAlreadyOnList = true;
                                            break;
                                        }
                                    }
                                    if(!userAlreadyOnList)
                                        OnlineUsers.Add(new User(up[0], up[1]));
                                    eUserEvent.Invoke(new User(up[0], up[1]), true);
                                }
                                catch(Exception e)
                                {
                                    break;
                                }
                                break;
                            case "USEROFFLINE":
                                try
                                {
                                    a = args[0];
                                    up = a.Split(new char[1] { ':' });
                                    for(int i = 0; i < OnlineUsers.Count; i++)
                                    {
                                        if(OnlineUsers[i].Email.Equals(up[0]))
                                        {
                                            User temp = OnlineUsers[i];
                                            OnlineUsers.RemoveAt(i);
                                            eUserEvent.Invoke(temp, false);

                                            break;
                                        }
                                    }
                                }
                                catch(Exception e)
                                {
                                    break;
                                }
                                break;
                            case "ONLINELIST":
                                try
                                {
                                    OnlineUsers = new List<User>(0);
                                    for(int i = 0; i < args.Count; i++)
                                    {
                                        a = (String)args[i];
                                        up = a.Split(new char[1] { ':' });
                                        if(up.Length == 2)
                                            OnlineUsers.Add(new User(up[0], up[1]));
                                        else if(up.Length == 3)
                                            OnlineUsers.Add(new User(up[0], up[1], (PlayerStatus)Enum.Parse(typeof(PlayerStatus), up[2], true)));
                                    }
                                    eUserEvent.Invoke(new User("", ""), true);
                                    SocketMessage sm = new SocketMessage("GAMELIST");
                                    writeMessage(sm);
                                }
                                catch(Exception e)
                                { }
                                break;
                            case "LOBCHAT":
                                try
                                {
                                    eLobbyChat.Invoke(LobbyChatTypes.Global, (String)args[0], (String)args[1], false);
                                }
                                catch(Exception e)
                                { }
                                break;
                            case "XAMLCHAT":
                                try
                                {
                                    eLobbyChat.Invoke(LobbyChatTypes.System, (String)args[0], (String)args[1], true);
                                }
                                catch(Exception e)
                                { }
                                break;
                            case "LOBW":
                                try
                                {
                                    String[] s = args[0].Split(new char[1] { ':' });
                                    if(s[0] != strUserName)
                                        strLastWhisperFrom = s[0];
                                    eLobbyChat.Invoke(LobbyChatTypes.Whisper, (String)args[0], (String)args[1], false);
                                }
                                catch(Exception e) { };
                                break;
                            case "CHATERROR":
                                try
                                {
                                    eLobbyChat.Invoke(LobbyChatTypes.Error, "ERROR", (String)args[0], false);
                                }
                                catch(Exception e) { };
                                break;
                            case "CHATINFO":
                                try
                                {
                                    eLobbyChat.Invoke(LobbyChatTypes.System, "SYSTEM", (String)args[0], false);
                                }
                                catch(Exception e) { };
                                break;
                            case "STATUS":
                                String stat = args[0];
                                String usn = args[1];
                                if(usn.Equals(strUserName))
                                {
                                    Status = (PlayerStatus)Enum.Parse(typeof(PlayerStatus), stat, true);
                                    eUserStatusChanged.Invoke(new User("", strUserName), Status);
                                }
                                foreach(User u in OnlineUsers)
                                {
                                    if(u.Username.Equals(usn))
                                    {
                                        u.Status = (PlayerStatus)Enum.Parse(typeof(PlayerStatus), stat, true);
                                        eUserStatusChanged.Invoke(u, u.Status);
                                        break;
                                    }
                                }

                                break;
                            case "HOST":
                                try
                                {
                                    String t = (string)args[6];
                                    String[] ips = t.Split(new char[1] { '?' });
                                    HostedGame hg = new HostedGame((string)args[3], (string)args[1], (string)args[0], (string)args[2], "", ips, int.Parse((string)args[7]));
                                    hg.strHostName = (string)args[4];
                                    hg.intUGameNum = int.Parse((string)args[5]);
                                    eGameHost.Invoke(hg, false, false);
                                }
                                catch(Exception e) { };
                                break;
                            case "UNHOST":
                                try
                                {
                                    HostedGame hg = new HostedGame();
                                    hg.intUGameNum = int.Parse((String)args[0]);
                                    eGameHost.Invoke(hg, true, false);
                                }
                                catch(Exception e) { };
                                break;
                            case "GAMELIST":
                                try
                                {
                                    String t = (string)args[1];
                                    String[] ips = t.Split(new char[1] { '?' });
                                    HostedGame hg = new HostedGame((string)args[7], (string)args[4], (string)args[3], (string)args[5], "", ips, int.Parse((string)args[2]));
                                    hg.strHostName = (string)args[6];
                                    hg.intUGameNum = int.Parse((string)args[0]);
                                    eGameHost.Invoke(hg, false, true);
                                }
                                catch(Exception e) { };
                                break;
                            default:
            #if (DEBUG)
                                MessageBox.Show(input.getMessage(), "Input from sock");
            #endif
                                break;
                        }
                    }
                    else
                    {
            #if (DEBUG)
                        MessageBox.Show(input.getMessage(), "Input from sock");
            #endif
                    }
                    break;
            }
        }
コード例 #22
0
ファイル: IrcBot.cs プロジェクト: kellyelton/octgn-server-old
        private static void HandleLine(String line)
        {
            //ConsoleWriter.writeLine(line, false);
            //return;
            if(line == null)
                return;
            //Split the line up into command parts
            string[] commandParts = line.Split(' ');
            if(commandParts[0].Substring(0, 1) == ":")
            {
                commandParts[0] = commandParts[0].Remove(0, 1);
            }
            if(commandParts[0] == SERVERNAME)
            {
                // Server message
                switch(commandParts[1])
                {
                    // case "332": this.IrcTopic(commandParts); break;
                    //case "333": this.IrcTopicOwner(commandParts); break;
                    case "353":
                        string s = commandParts[1];
                        List<String> temp = new List<String>(0);
                        for(int i = 6; i < commandParts.Length; i++)
                            temp.Add(commandParts[i]);
                        _users = temp.ToArray();
                        break;
                    case "366": /*this.IrcEndNamesList(commandParts);*/ break;
                    case "372": /*this.IrcMOTD(commandParts);*/ break;
                    case "376":
                        WriteLine("JOIN " + CHANNEL + " x");
                        break;
                    //default: this.IrcServerMessage(commandParts); break;
                }
            }
            else if(commandParts[0] == "PING")
            {
                // Server PING, send PONG back
                WriteLine("PONG :" + commandParts[1].Replace(":", ""));
            }
            else
            {
                // Normal message
                string commandAction = commandParts[1];
                switch(commandAction)
                {
                    case "JOIN":
                        // Make sure that user isn't online first
                        int a = commandParts[0].IndexOf('!');
                        string user = commandParts[0].Remove(a);
                        Array.Resize<String>(ref _users, _users.Length + 1);
                        _users[_users.Length - 1] = user;

                        SocketMessage sm = new SocketMessage("USERONLINE");
                        sm.Arguments.Add(user + "@irc.irc" + ":<irc>" + user);
                        ClientContainer.AllUserCommand(sm);
                        break;
                    //case "PART": this.IrcPart(commandParts); break;
                    //case "MODE": this.IrcMode(commandParts); break;
                    //case "NICK": this.IrcNick(commandParts); break;
                    //case "KICK": this.IrcKick(commandParts); break;
                    case "NOTICE AUTH":
                        SERVERNAME = commandParts[0];
                        break;

                    case "QUIT":
                        user = commandParts[2];
                        if(user != null)
                        {
                            if(UserOnline(user))
                            {
                                String[] temp = new String[_users.Length - 1];
                                int i = 0;
                                foreach(String u in _users)
                                {
                                    if(!u.Equals(user))
                                    {
                                        temp[i] = u;
                                        i++;
                                    }
                                }
                                _users = temp;
                                sm = new SocketMessage("USEROFFLINE");
                                sm.Arguments.Add(user + "@irc.irc");
                                ClientContainer.AllUserCommand(sm);
                            }
                        }
                        break;
                }
            }
            return;
            Regex rpm = new Regex("\\:([^!]+){1}![^ ]+ PRIVMSG #octgn \\:(.+)", RegexOptions.IgnoreCase);
            Regex rquit = new Regex("\\:([^!]+){1}![^ ]+ QUIT", RegexOptions.IgnoreCase);
            Regex rjoin = new Regex("\\:([^!]+){1}![^ ]+ JOIN", RegexOptions.IgnoreCase);
            Regex rMOTDdone = new Regex("\\:([^!]+){1}[^ ]+ MODE ");
            Regex rpmess = new Regex("\\:([^!]+){1}![^ ]+ PRIVMSG ([^ #]+){1} \\:(.+)", RegexOptions.IgnoreCase);
            Regex rpolist = new Regex(":.+353.+:(.+)+", RegexOptions.IgnoreCase);
            //353 OctgnwLobby = #OCTGN :
            //line = line.Replace(":helios.ircstorm.net", "");
            line = line.Trim();
            try
            {
                if(rpm.IsMatch(line))
                {
                    Match m = rpm.Match(line);
                    String user = m.Groups[1].Value;
                    String mess = m.Groups[2].Value;
                    //SocketMessage sm = new SocketMessage("CHAT");
                    ClientContainer.LobbyChat("<irc>" + user, mess);
                    //ClientContainer.AllUserCommand(
                }
                else if(rMOTDdone.IsMatch(line))
                {
                    WriteLine("JOIN " + CHANNEL + " x");
                }
                else if(rpmess.IsMatch(line))
                {
                    //TODO PM's go here, so put OP commands here
                    //1 is who it's from, 2 is who it goes to, and 3 is the message.
                    Match m = rpmess.Match(line);
                    if(m.Groups[1].Value.Equals("StatServ"))
                    {
                        if(m.Groups[3].Value.Contains("VERSION"))
                        {
                            WriteLine("JOIN " + CHANNEL + " x");
                        }
                    }
                    else
                    {
                        PMUser(m.Groups[1].Value, "Replying is not implemented yet.");
                    }
                }
                else if(rquit.IsMatch(line))
                {
                    Match m = rquit.Match(line);
                    String user = m.Groups[1].Value;
                    if(user != null)
                    {
                        if(UserOnline(user))
                        {
                            String[] temp = new String[_users.Length - 1];
                            int i = 0;
                            foreach(String u in _users)
                            {
                                if(!u.Equals(user))
                                {
                                    temp[i] = u;
                                    i++;
                                }
                            }
                            _users = temp;
                            SocketMessage sm = new SocketMessage("USEROFFLINE");
                            sm.Arguments.Add(user + "@irc.irc");
                            ClientContainer.AllUserCommand(sm);
                        }
                    }
                }
                else if(rjoin.IsMatch(line))
                {
                    // Make sure that user isn't online first
                    Match m = rjoin.Match(line);
                    String user = m.Groups[1].Value;
                    Array.Resize<String>(ref _users, _users.Length + 1);
                    _users[_users.Length - 1] = user;

                    SocketMessage sm = new SocketMessage("USERONLINE");
                    sm.Arguments.Add(user + "@irc.irc" + ":<irc>" + user);
                    ClientContainer.AllUserCommand(sm);

                    //SocketMessage sm = new SocketMessage("CHATINFO");
                    //sm.Arguments.Add("IRC User " + user + " online.");
                    //ClientContainer.AllUserCommand(sm);
                }
                else if(rpolist.IsMatch(line))
                {
                    Match m = rpolist.Match(line);
                    String strusers = m.Groups[1].Value;

                    _users = strusers.Split(new char[1] { ' ' });
                    //ConsoleWriter.writeLine("#IRC-IN: " + line, true);
                }
                else if(line.Substring(0, 4).Equals("PING"))
                {
                    WriteLine("PONG :" + line.Substring(6).Trim());
                }
                else
                {
                    ConsoleWriter.writeLine("#IRC-IN: " + line, true);
                }
            }
            catch(ArgumentOutOfRangeException e)
            {
                ConsoleWriter.writeLine("#IRC-IN: " + line, true);
            }
        }
コード例 #23
0
ファイル: LobbyClient.cs プロジェクト: kellyelton/octgnwlobby
 public void ChangePlayerStatus(PlayerStatus status)
 {
     this.Status = status;
     SocketMessage sm = new SocketMessage("STATUS");
     sm.Arguments.Add(status.ToString());
     writeMessage(sm);
 }
コード例 #24
0
ファイル: Client.cs プロジェクト: kellyelton/octgn-server-old
 private void iLogin(SocketMessage input)
 {
     Boolean worked = UserMysql.login(this, input.Arguments[0], input.Arguments[1]);
     if(worked)
     {
         //See if we are already logged on width a different client.
         //If we are, dominate him and destroy his connection.
         for(int i = 0; i < ClientContainer.Clients.Count; i++)
         {
             if(ClientContainer.Clients[i].User.UID == User.UID)
             {
                 if(ClientContainer.Clients[i].ID != this.ID)
                 {
                     if(ClientContainer.Clients[i].Connected)
                     {
                         //Domination///////////////////////////////////////////////////////////////
                         ClientContainer.UserEvent(UserEventType.LogOut, ClientContainer.Clients[i]);
                         //////////////////////////////////////////
                         //     _________________.---.______     //
                         //    (_(______________(_o o_(____()    //
                         //                 .___.'. .'.___.      //
                         //                 \ o    Y    o /      //
                         //  DISTRUCTION     \ \__   __/ /       //
                         //                   '.__'-'__.'        //
                         //    BOOOOOOM!          ```            //
                         //////////////////////////////////////////
                         ClientContainer.Clients[i].Close();
                     }
                 }
             }
         }
         writeMessage(SocketMessages.LoginSuccess(this.User));
         ClientContainer.UserEvent(UserEventType.LogIn, this);
         //this.writeMessage(SockMessages.ChatInfo(MainClass.getDailyMessage()));
         LoggedIn = true;
     }
     else
     {
         writeMessage(SocketMessages.LoginError());
         LoggedIn = false;
     }
 }
コード例 #25
0
ファイル: Form1.cs プロジェクト: kellyelton/octgn-server-old
 private void sock_onConnectionEvent(object Sender, ConnectionEvent e)
 {
     if(e.Event == ConnectionEvent.eConnectionEvent.eceConnect)
     {
         addline("#Connected");
         SocketMessage sm = new SocketMessage("RC");
         sm.getMessage();
         sock.writeMessage(sm);
         //sock.writeMessage(sm);
     }
     else
     {
         addline("#Disconnected");
         sock.Connect("www.skylabsonline.com", 5583);
     }
 }
コード例 #26
0
ファイル: Client.cs プロジェクト: kellyelton/octgn-server-old
 protected override void handleInput(object me, SocketMessage input)
 {
     if(!LoggedIn)
     {
         switch(input.Header)
         {
             case "LOG":
                 iLogin(input);
                 break;
             case "REG":
                 String nick = input.Arguments[0];
                 String email = input.Arguments[1];
                 String pass = input.Arguments[2];
                 String regret = UserMysql.register(nick, email, pass);
                 writeMessage(new SocketMessage(regret));
                 break;
             case "RC":
                 this.isRc = true;
                 User = new User(987654321, "rc", "rc");
                 break;
         }
     }
     else if(LoggedIn)
     {
         switch(input.Header)
         {
             case "GETONLINELIST":
                 writeMessage(SocketMessages.OnlineUserList(ClientContainer.getOnlineUserList()));
                 break;
             case "LOBCHAT":
                 ClientContainer.LobbyChat(User.Username, input.Arguments[0].Trim());
                 break;
             case "HOST":
                 //HACK Should serialize game data and send it here.
                 HostedGame h = HostedGame.DeSerialize(Convert.FromBase64String(input.Arguments[0]));
                 h.UID = User.UID;
                 int gID = GameBox.AddGame(h);
                 h.ID = gID;
                 SocketMessage stemp = new SocketMessage("HOST");
                 stemp.Arguments.Add(Convert.ToBase64String(HostedGame.Serialize(h)));
                 ClientContainer.AllUserCommand(stemp);
                 break;
             case "UNHOST":
                 int g = GameBox.GetGame(User);
                 if(g != -1)
                 {
     #if(DEBUG)
                     ConsoleWriter.writeLine("#UNHOST", true);
     #endif
                     SocketMessage stemp2 = new SocketMessage("UNHOST");
                     stemp2.Arguments.Add(Convert.ToBase64String(HostedGame.Serialize(GameBox.Games[g])));
                     ClientContainer.AllUserCommand(stemp2);
                     GameBox.RemoveByUID(User.UID);
                 }
                 break;
             case "STATUS":
                 User.Status = (UserStatus)Enum.Parse(typeof(UserStatus), input.Arguments[0], true);
                 input.Arguments.Add(User.Username);
                 ClientContainer.AllUserCommand(input);
                 break;
             case "GAMELIST":
                 int mGames = GameBox.Games.Count;
                 for(int i = 0; i < mGames; i++)
                 {
                     HostedGame hg = (HostedGame)GameBox.Games[i];
                     if(hg.Available)
                     {
                         SocketMessage stemp3 = new SocketMessage("GAMELIST");
                         stemp3.Arguments.Add(Convert.ToBase64String(HostedGame.Serialize(hg)));
                         this.writeMessage(stemp3);
                     }
                 }
                 break;
             case "JOINGAME":
                 HostedGame hgg = HostedGame.DeSerialize(Convert.FromBase64String(input.Arguments[0]));
                 ConsoleWriter.writeLine("#JOINGAME(" + User.Username + ")", true);
                 int gn = GameBox.GetGame(hgg.ID);
                 if(gn > -1)
                 {
                     Client c = ClientContainer.getClientFromUID(GameBox.Games[gn].UID);
                     if(c.User.UID != -1)
                     {
                         c.writeMessage(input);
                     }
                 }
                 break;
             case "LEAVEGAME":
                 HostedGame hggg = HostedGame.DeSerialize(Convert.FromBase64String(input.Arguments[0]));
                 ConsoleWriter.writeLine("#LEAVEGAME(" + User.Username + ")", true);
                 int gnn = GameBox.GetGame(hggg.ID);
                 if(gnn > -1)
                 {
                     Client c = ClientContainer.getClientFromUID(GameBox.Games[gnn].UID);
                     if(c.User.UID != -1)
                     {
                         c.writeMessage(input);
                     }
                 }
                 break;
             case "USERMESSAGE":
                 User u = User.DeSerialize(Convert.FromBase64String(input.Arguments[0]));
                 String m = input.Arguments[1];
                 Client cl = ClientContainer.getClientFromUID(u.UID);
                 if(cl.User.UID != -1)
                 {
                     input.Arguments[0] = Convert.ToBase64String(User.Serialize(this.User));
                     cl.writeMessage(input);
                     //writeMessage(input);
                 }
                 break;
             case "GAMEFORWARD":
                 //Basically just forward the whole package to the Host, found by the game ID
                 //which resides at Argument 0
                 //Get the int
                 try
                 {
                     int gid = int.Parse(input.Arguments[0]);
                     HostedGame hg = GameBox.Games[GameBox.GetGame(gid)];
                     if(hg.Available)
                     {
                         if(hg.UID != User.UID)
                         {
                             Client tclient = ClientContainer.getClientFromUID(hg.UID);
                             if(tclient != null)
                             {
                                 input.Arguments.Insert(1, Convert.ToBase64String(User.Serialize(User)));
                                 tclient.writeMessage(input);
                             }
     #if DEBUG
                             else
                                 System.Diagnostics.Debugger.Break();
     #endif
                         }
                         else
                         {
                             int cid = int.Parse(input.Arguments[2]);
                             Client tclient = ClientContainer.getClientFromUID(cid);
                             if(tclient != null)
                             {
                                 input.Arguments.RemoveAt(2);
                                 input.Arguments.Insert(1, Convert.ToBase64String(User.Serialize(tclient.User)));
                                 tclient.writeMessage(input);
                             }
                         }
                     }
                 }
                 catch(FormatException fe)
                 {
     #if DEBUG
                     System.Diagnostics.Debugger.Break();
     #endif
                 }
                 break;
             default:
                 //TODO add ConsoleEvent to handle unknown input
                 //Main.writeEvent("Input from `" + super.strHost + "' :" + input.getMessage());
                 //Main.writeIn();
                 break;
         }
     }
     if(isRc)
     {
         ConsoleEventLog.addEvent(new ConsoleEvent("#RC: ", input.getMessage()), true);
         switch(input.Header)
         {
             case "1":
                 SocketMessage sm = new SocketMessage("CHATINFO");
                 sm.Arguments.Add(input.Arguments[0]);
                 ClientContainer.AllUserCommand(sm);
                 break;
             case "2":
                 MainClass.KillServer();
                 break;
             case "3":
                 try
                 {
                     int time = int.Parse(input.Arguments[0]);
                     MainClass.TimeKillServer(time, null);
                 }
                 catch(Exception e)
                 {
                 }
                 break;
             case "4":
                 try
                 {
                     int time = int.Parse(input.Arguments[0]);
                     MainClass.TimeKillServer(time, input.Arguments[1]);
                 }
                 catch(Exception e)
                 {
                 }
                 break;
         }
     }
 }
コード例 #27
0
ファイル: Lobby.xaml.cs プロジェクト: kellyelton/octgnwlobby
 private void Page_Loaded(object sender, RoutedEventArgs e)
 {
     NavigationService.RemoveBackEntry();
     SocketMessage sm = new SocketMessage("GETONLINELIST");
     Program.LClient.writeMessage(sm);
     Update_Online_Users();
     tbNickname.Text = "Your nickname: " + Program.LClient.strUserName;
     rtbChat.ScrollToEnd();
     NavigationService.Navigating += new System.Windows.Navigation.NavigatingCancelEventHandler(NavigationService_Navigating);
 }