示例#1
0
        public static void Connect(Client handler, string line, string[] splitData)
        {
            if (handler.IsProperlyConnected)
                return;

            string[] data;
            if (ParserHelper.Connect(splitData, out data)) {
                if (handler.Handler.ClientsManager.NickRegistered(data[0])) {
                    System.Data.Common.DbDataReader reader = References.Database.Read(string.Format("SELECT {0}, {1} FROM {2} WHERE {3}=@val", InternalReferences.NICKS_PASS_COL, InternalReferences.NICKS_SALT_COL, InternalReferences.NICKS_TABLE, InternalReferences.NICKS_NICK_COL),
                                             new Mono.Data.Sqlite.SqliteParameter("@val", data[0]));
                    string hash = "";
                    string salt = "";
                    while (reader.Read()) {
                        hash = reader.GetString(0);
                        salt = reader.GetString(1);
                    }
                    reader.Close();
                    reader = null;
                    if (!Utils.ValidPassword(data[1], hash, salt)) {
                        handler.SendError(SendType.ERROR_0002, SendType.CONNECT, line);
                        return;
                    }
                    handler.SetAuthenticated(true);
                }
                if (handler.SetNickName(data[0])) {
                    handler.Send(SendType.CONNECT, string.Format("Connected{0}true", SyntaxCode.VALUE_SPLITTER));
                    handler.IsProperlyConnected = true;
                    handler.SetRealName(data[2] ?? data[0]);
                } else {
                    handler.SendError(SendType.ERROR_0006, SendType.CONNECT, line);
                }
            } else
                handler.SendError(SendType.ERROR_0005, SendType.CONNECT, line);
        }
示例#2
0
 public static void Register(Client handler, string line, string[] splitData)
 {
     string[] data;
     if (!ParserHelper.Register(splitData, out data)) {
         handler.SendError(SendType.ERROR_0005, SendType.REGISTER, line);
         return;
     }
     if (data[0] == "user") {
         if (handler.Handler.ClientsManager.NickRegistered(handler.NickName)) {
             handler.SendError(SendType.ERROR_0006, SendType.REGISTER, line);
             return;
         }
         string salt = Utils.GenerateSalt();
         References.Database.Insert(InternalReferences.NICKS_TABLE, InternalReferences.NICKS_NICK_COL, InternalReferences.NICKS_PASS_COL, InternalReferences.NICKS_SALT_COL,
                                    handler.NickName, Utils.Hash(data[1], salt), salt);
         handler.SetAuthenticated(true);
     } else if (data[0] == "channel") {
         if (handler.Handler.ChannelsManager.ChannelRegistered(data[2])) {
             handler.SendError(SendType.ERROR_0006, SendType.REGISTER, line);
             return;
         }
         string salt = Utils.GenerateSalt();
         References.Database.Insert(InternalReferences.CHANNELS_TABLE, InternalReferences.CHANNELS_CHANNEL_COL, InternalReferences.CHANNELS_OWNER_COL, InternalReferences.CHANNELS_PASS_COL, InternalReferences.CHANNELS_SALT_COL,
                                    data[2], handler.NickName, !string.IsNullOrEmpty(data[1]) ? Utils.Hash(data[1], salt) : null, !string.IsNullOrEmpty(data[1]) ? salt : null);
     } else {
         handler.SendError(SendType.ERROR_0005, SendType.REGISTER, line);
     }
 }