Beispiel #1
0
 public void AddRow(params object[] pColumns)
 {
     if (pColumns.Length != _columns.Count)
     {
         throw new Exception("Incorrect column count!");
     }
     _rows.Add(MySQL_Connection.BuildValuesRow(pColumns));
 }
Beispiel #2
0
        public override string ToString()
        {
            if (!HasRows())
            {
                throw new Exception("Row count = 0");
            }

            if (IgnoreDuplicates && OnDuplicateUpdate)
            {
                throw new Exception("Can't use both IgnoreDuplicates and OnDuplicateUpdate");
            }

            StringBuilder sb = new StringBuilder();

            sb.Append("INSERT " + (IgnoreDuplicates ? "IGNORE " : "") + "INTO\r\n\t" + this.TableName + "\r\n\t(");
            string[] columnlist = new string[_columns.Count];
            for (int i = 0; i < _columns.Count; i++)
            {
                columnlist[i] = "`" + _columns[i].Name + "`";
            }

            sb.Append(string.Join(", ", columnlist));
            sb.Append(")\r\nVALUES\r\n\t");

            List <string> tmp = new List <string>(_rows);

            if (_rowsColumnedCount > 0)
            {
                for (int j = 0; j < _columns.Count; j++)
                {
                    if (_rowsColumned[_columns[j].Name].Count != _rowsColumnedCount)
                    {
                        throw new Exception("Column " + _columns[j].Name + " did not have enough values!!!");
                    }
                }
                for (int i = 0; i < _rowsColumnedCount; i++)
                {
                    object[] inputobjects = new object[_columns.Count];
                    for (int j = 0; j < _columns.Count; j++)
                    {
                        inputobjects[j] = _rowsColumned[_columns[j].Name][i];
                    }
                    tmp.Add(MySQL_Connection.BuildValuesRow(inputobjects));
                }
            }

            sb.Append(string.Join(",\r\n\t", tmp));

            if (OnDuplicateUpdate)
            {
                List <string> updatecolumns = new List <string>();
                foreach (Column col in _columns.Where(c => { return(c.InUpdate); }))
                {
                    updatecolumns.Add(string.Format("`{0}` = VALUES(`{0}`)", col.Name));
                }

                if (updatecolumns.Count > 0)
                {
                    sb.Append("\r\nON DUPLICATE KEY UPDATE\r\n\t");
                    sb.Append(string.Join(",\r\n\t", updatecolumns.ToArray()));
                }
            }
            sb.Append(";");

            return(sb.ToString());
        }
Beispiel #3
0
 public void AddRowUnsafe(params object[] pColumns)
 {
     // :(
     _rows.Add(MySQL_Connection.BuildValuesRow(pColumns));
 }
Beispiel #4
0
        public static void HandleServerConnectionStatus(ClientConnection pConnection, MaplePacket pPacket)
        {
            if (pPacket.ReadBool())
            {
                string ip   = pPacket.ReadString();
                ushort port = pPacket.ReadUShort();
                pConnection.Logger_WriteLine("- Client got connection with MapleStory server @ {0}:{1}", ip, port);

                pConnection.ConnectedToIP   = ip;
                pConnection.ConnectedToPort = port;

                if (port == 8484)
                {
                    pConnection.SendInfoText("Mapler.me is awaiting account check! Happy mapling!");
                    var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection);
                    if (info != null)
                    {
                        SessionRestartCache.Instance.RemoveInfo(info);
                    }


                    pConnection.ChannelID = 255;
                }
                else
                {
                    pConnection.SendInfoText("You successfully connected, or are in the Cash Shop!");
                }

                pConnection.ConnectedTimeToServer = MasterThread.CurrentDate;
            }
            else
            {
                pConnection.Logger_WriteLine("- Client lost connection with MapleStory server");
                pConnection.SendInfoText("Maplestory is closed, or not connected properly.");

                pConnection.ConnectedToIP   = "0.0.0.0";
                pConnection.ConnectedToPort = 0;

                if (pConnection.ConnectedTimeToServer != DateTime.MinValue)
                {
                    var timespan = MasterThread.CurrentDate - pConnection.ConnectedTimeToServer;
                    pConnection.Logger_WriteLine("Player was connected for {0}", timespan);

                    if (timespan.TotalSeconds < 5)
                    {
                        pConnection.Logger_WriteLine("CLIENT PROBABLY FAILED TO CONNECT!!!");
                    }

                    if (pConnection.CharData != null)
                    {
                        // Probably CC-ing or something. record

                        MySQL_Connection.Instance.RunQuery("INSERT INTO connection_log VALUES " + MySQL_Connection.BuildValuesRow(pConnection.AccountID, pConnection.CharacterInternalID, pConnection.ChannelID, pConnection.ConnectedTimeToServer, new MySQL_Connection.NowType()));
                    }
                }

                // Delete if there's session info
                var info = SessionRestartCache.Instance.GetInfoForConnection(pConnection);
                if (info != null)
                {
                    SessionRestartCache.Instance.RemoveInfo(info);
                }

                pConnection.CharData            = null;
                pConnection.CharacterInternalID = -1;
                pConnection.CharacterID         = -1;
                pConnection.ChannelID           = 255;
            }
        }