예제 #1
0
        // checks to see what message we are dealing with.
        // e.g. "$To" , "$Search" etc
        private Message DeterminMessage(string StartOfMessage, int firstSpacePosition, Message msg)
        {
            Message simpleMessage = new Message();

            string[] splitMessage;

            switch (StartOfMessage)
            {
            case "$Supports":

                // Supports string done incorectly so ignore it.
                if (msg.stringFormat.Length < 11)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                splitMessage = msg.stringFormat.Substring(firstSpacePosition + 1).Split(' ');

                supports Support = new supports();
                Support.supporList = new string[splitMessage.Length - 1];
                for (int iCount = 0; iCount < splitMessage.Length - 1; iCount++)
                {
                    Support.supporList[iCount] = splitMessage[iCount];
                }

                Support.type         = (int)Messagetype.Supports;
                Support.RawFormat    = msg.RawFormat;
                Support.From         = (int)MessageFrom.Client;
                Support.soc          = this.soc;
                Support.stringFormat = msg.stringFormat;

                simpleMessage = null;
                splitMessage  = null;
                return(Support);

            case "$Key":

                // Key string done incorectly so ignore it.
                if (msg.stringFormat.Length < 6)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.Key;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$ValidateNick":

                // ValidateNick string done incorectly so ignore it.
                if (msg.stringFormat.Length < 15)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.ValidateNick;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$GetNickList":

                simpleMessage.type         = (int)Messagetype.GetNickList;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$GetINFO":

                splitMessage = msg.stringFormat.Split(' ');
                if (splitMessage.Length < 3)
                {
                    simpleMessage.type         = -1;
                    simpleMessage.RawFormat    = msg.RawFormat;
                    simpleMessage.From         = (int)MessageFrom.Client;
                    simpleMessage.soc          = this.soc;
                    simpleMessage.stringFormat = msg.stringFormat;

                    splitMessage = null;
                    return(simpleMessage);
                }

                messageToUser getInfo = new messageToUser();

                getInfo.type         = (int)Messagetype.GetINFO;
                getInfo.RawFormat    = msg.RawFormat;
                getInfo.From         = (int)MessageFrom.Client;
                getInfo.soc          = this.soc;
                getInfo.stringFormat = msg.stringFormat;
                getInfo.sender       = splitMessage[2];
                getInfo.reciever     = splitMessage[1];

                splitMessage  = null;
                simpleMessage = null;
                return(getInfo);

            case "$MyPass":


                // MyPass string done incorectly so ignore it.
                if (msg.stringFormat.Length < 9)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.MyPass;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$Version":

                // Version string done incorectly so ignore it.
                if (msg.stringFormat.Length < 10)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.Version;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            // a client is sending us a users MyINFO list
            case "$MyINFO":

                // myINFO string done incorectly so ignore it.
                if (msg.stringFormat.Length < 9)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                myInfo myINFO = new myInfo();
                myINFO.nick = this.nick;
                // convert the myinfo string to something
                // readable
                this.rawUserInfo = msg.stringFormat;

                // if the user has tried to change there nick while logged in.
                if (myINFO.nick != this.nick)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    myINFO             = null;
                    return(simpleMessage);
                }

                myINFO.type         = (int)Messagetype.MyINFO;
                myINFO.RawFormat    = msg.RawFormat;
                myINFO.From         = (int)MessageFrom.Client;
                myINFO.soc          = this.soc;
                myINFO.stringFormat = msg.stringFormat;

                myINFO.slots       = this.slots;
                myINFO.normHubs    = this.normHubs;
                myINFO.regHubs     = this.regHubs;
                myINFO.opHubs      = this.opHubs;
                myINFO.description = this.description;
                myINFO.email       = this.eMail;
                myINFO.nick        = this.nick;

                splitMessage  = null;
                simpleMessage = null;

                return(myINFO);

            // a user is leaving on another server
            case "$Quit":

                // Quit string done incorectly so ignore it.
                if (msg.stringFormat.Length < 7)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.QUIT;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                closeAndRemoveUser();
                splitMessage = null;
                return(simpleMessage);

            // a user on another server is atempting to chat to a user
            // on our server.
            case "$To:":

                splitMessage = msg.stringFormat.Split('$');
                string[] FirstPartOfSplit;

                // not enough parameters in the string for it to be right
                if (splitMessage.Length < 3)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;

                    splitMessage     = null;
                    FirstPartOfSplit = null;
                    return(simpleMessage);
                }

                FirstPartOfSplit = splitMessage[1].Split(' ');

                // not enough parameters in the string for it to be right
                if (FirstPartOfSplit.Length < 5)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;

                    splitMessage     = null;
                    FirstPartOfSplit = null;
                    return(simpleMessage);
                }

                // user trying to send a pm to some one using a nick other
                // than there own.
                if (FirstPartOfSplit[3] != this.nick)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;

                    splitMessage     = null;
                    FirstPartOfSplit = null;
                    return(simpleMessage);
                }

                messageToUser PrivateMessage = new messageToUser();

                PrivateMessage.type      = (int)Messagetype.ChatPM;
                PrivateMessage.RawFormat = msg.RawFormat;
                PrivateMessage.From      = (int)MessageFrom.Client;
                PrivateMessage.soc       = this.soc;

                PrivateMessage.sender            = FirstPartOfSplit[3];
                PrivateMessage.reciever          = FirstPartOfSplit[1];
                PrivateMessage.messageToReciever = splitMessage[2];
                PrivateMessage.stringFormat      = msg.stringFormat;

                splitMessage     = null;
                FirstPartOfSplit = null;
                simpleMessage    = null;
                return(PrivateMessage);

            // a user on another server is searching for somthing
            // this message must be relayed to all the clients on this
            // server.

            case "$Kick":

                if (msg.stringFormat.Length < 7)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                simpleMessage.type         = (int)Messagetype.Kick;
                simpleMessage.RawFormat    = msg.RawFormat;
                simpleMessage.From         = (int)MessageFrom.Client;
                simpleMessage.soc          = this.soc;
                simpleMessage.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$Search":


                splitMessage = msg.stringFormat.Split(' ');
                if (splitMessage.Length < 3)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                messageToUser Search = new messageToUser();
                Search.sender = splitMessage[1];

                Search.type         = (int)Messagetype.Search;
                Search.RawFormat    = msg.RawFormat;
                Search.From         = (int)MessageFrom.Client;
                Search.soc          = this.soc;
                Search.stringFormat = msg.stringFormat;

                splitMessage = null;
                return(simpleMessage);

            case "$ConnectToMe":
                //$ConnectToMe <remoteNick> <senderIp>:<senderPort>
                splitMessage = msg.stringFormat.Split(' ');

                if (splitMessage.Length != 3)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                messageToUser connectToMe = new messageToUser();

                connectToMe.sender   = this.nick;
                connectToMe.reciever = splitMessage[1];

                connectToMe.type         = (int)Messagetype.ConnectToMe;
                connectToMe.RawFormat    = msg.RawFormat;
                connectToMe.From         = (int)MessageFrom.Client;
                connectToMe.soc          = this.soc;
                connectToMe.stringFormat = msg.stringFormat;

                splitMessage  = null;
                simpleMessage = null;
                return(connectToMe);

            case "$RevConnectToMe":
                //$RevConnectToMe <nick> <remoteNick>
                splitMessage = msg.stringFormat.Split(' ');

                if (splitMessage.Length != 3)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }
                messageToUser ReConnectToMe = new messageToUser();

                ReConnectToMe.sender   = splitMessage[1];
                ReConnectToMe.reciever = splitMessage[2];

                ReConnectToMe.type         = (int)Messagetype.RevConnectToMe;
                ReConnectToMe.RawFormat    = msg.RawFormat;
                ReConnectToMe.From         = (int)MessageFrom.Client;
                ReConnectToMe.soc          = this.soc;
                ReConnectToMe.stringFormat = msg.stringFormat;

                splitMessage  = null;
                simpleMessage = null;
                return(ReConnectToMe);

            default:

                if (StartOfMessage.StartsWith("$"))
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;
                    splitMessage       = null;
                    return(simpleMessage);
                }

                mainChat MainChatMessage = new mainChat();

                MainChatMessage.type         = (int)Messagetype.MainChatMessage;
                MainChatMessage.RawFormat    = msg.RawFormat;
                MainChatMessage.From         = (int)MessageFrom.Client;
                MainChatMessage.soc          = this.soc;
                MainChatMessage.stringFormat = msg.stringFormat;
                MainChatMessage.sender       = this.nick;

                if (msg.stringFormat.Length < this.nick.Length + 3)
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;

                    splitMessage    = null;
                    MainChatMessage = null;
                    return(simpleMessage);
                }
                // if the message does not contain <nick>
                if (MainChatMessage.stringFormat.Substring(0, 3 + this.nick.Length) != "<" + this.nick + "> ")
                {
                    // -1 indicates we are just going to ignore this message
                    simpleMessage.type = -1;

                    splitMessage    = null;
                    MainChatMessage = null;
                    return(simpleMessage);
                }

                splitMessage  = null;
                simpleMessage = null;
                return(MainChatMessage);
            }
        }
예제 #2
0
 public DailyForecast_Model(HttpClient httpClient)
 {
     _httpClient = httpClient;
     Supports    = supports.daily;
 }
예제 #3
0
 public HourlyForecast_Model(HttpClient http)
 {
     _http    = http;
     Supports = supports.hourly;
 }