Value Is too large

0

I am trying to make a plugin with SQL and I get some errors which I don't know what to do with them. SQL Database manager + adding the player from the main class.

  private void Events_OnPlayerConnected(UnturnedPlayer player)
        {
            FriendsGroupID_t id;
            id.m_FriendsGroupID = (short)player.SteamGroupID.m_SteamID;
            Database.addPlayer(player.CharacterName, player.SteamName, SteamFriends.GetFriendsGroupName(id), player.CSteamID.m_SteamID.ToString());
        }

Other code:

using System;
using I18N.West;
using MySql.Data.MySqlClient;
using Rocket.Core.Logging;
using Steamworks;

namespace SQLPlayer
{

    internal class DatabaseController
    {

        private MySqlConnection createConnection()
        {
            MySqlConnection Connection = null;
            try
            {
                if (SQLPlayer.Instance.Configuration.Instance.DatabasePort == 0)
                {
                    SQLPlayer.Instance.Configuration.Instance.DatabasePort = 3306;
                }
                Connection = new MySqlConnection(string.Format("SERVER={0};DATABASE={1};UID={2};PASSWORD={3};PORT={4};", new object[]
                {
                    SQLPlayer.Instance.Configuration.Instance.DatabaseAddress,
                    SQLPlayer.Instance.Configuration.Instance.DatabaseName,
                    SQLPlayer.Instance.Configuration.Instance.DatabaseUsername,
                    SQLPlayer.Instance.Configuration.Instance.DatabasePassword,
                    SQLPlayer.Instance.Configuration.Instance.DatabasePort
                }));
            }
            catch (Exception) { }
            return Connection;
        }


        public DatabaseController()
        {
            new CP1250();
            CheckSchema();
        }


        internal void CheckSchema()
        {
            try
            {
                MySqlConnection mySqlConnection = createConnection();
                MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
                mySqlCommand.CommandText = "show tables like '" + SQLPlayer.Instance.Configuration.Instance.LogTableName + "'";
                mySqlConnection.Open();
                if (mySqlCommand.ExecuteScalar() == null)
                {
                    mySqlCommand.CommandText = "CREATE TABLE `" + SQLPlayer.Instance.Configuration.Instance.LogTableName + "` ( `id` INT NOT NULL AUTO_INCREMENT , `player_display_name` TEXT NOT NULL , `player_steam_name` TEXT NOT NULL ,`player_steamgroup_name` TEXT NOT NULL , `player_steam_id` INT NOL NULL , `sent_on` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP , PRIMARY KEY (`id`));";
                    mySqlCommand.ExecuteNonQuery();
                }
                mySqlConnection.Close();
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
            }
        }

        // Token: 0x06000006 RID: 6 RVA: 0x00002250 File Offset: 0x00000450
        public void addPlayer(string charactername, string steamname , string steamgroupname , int steamid)
        {
            try
            {
                MySqlConnection mySqlConnection = createConnection();
                MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
                mySqlCommand.Parameters.AddWithValue("@steamname", steamname);
                mySqlCommand.Parameters.AddWithValue("@charactername", charactername);
                mySqlCommand.Parameters.AddWithValue("@steamgroupname", steamgroupname);
                mySqlCommand.Parameters.AddWithValue("@steamid", steamid);
                string commandText = "insert into `" + SQLPlayer.Instance.Configuration.Instance.LogTableName + "` (`player_display_name` , `player_steam_name`,`player_steamgroup_name`,`player_steam_id`) values(@charactername,@steamname , @steamgroupname ,@steamid);";
                mySqlCommand.CommandText = commandText;
                mySqlConnection.Open();
                mySqlCommand.ExecuteNonQuery();
                mySqlConnection.Close();
            }
            catch (Exception) { }
        }


        public void DeletePlayers()
        {
            try
            {
                MySqlConnection mySqlConnection = createConnection();
                MySqlCommand mySqlCommand = mySqlConnection.CreateCommand();
                DateTime dateTime = DateTime.Now.AddDays(-SQLPlayer.Instance.Configuration.Instance.DeleteAfterDays);
                mySqlCommand.Parameters.AddWithValue("@days", dateTime);
                string commandText = "DELETE FROM " + SQLPlayer.Instance.Configuration.Instance.LogTableName + " WHERE `last_login` > @date; ";
                mySqlCommand.CommandText = commandText;
                mySqlConnection.Open();
                mySqlCommand.ExecuteNonQuery();
                mySqlConnection.Close();
            }
            catch (Exception) { }
        }
    }
}

This is the error I am getting when I am calling the fuction addPlayer:

 Error in MulticastDelegate PlayerConnected: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.OverflowException: Value is too large
  at System.Int16.Parse (System.String s) [0x00000] in <filename unknown>:0 
  at SQLPlayer.SQLPlayer.Events_OnPlayerConnected (Rocket.Unturned.Player.UnturnedPlayer player) [0x00000] in <filename unknown>:0 
  at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (object,object[],System.Exception&)
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  --- End of inner exception stack trace ---
  at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0 
  at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.MulticastDelegate.DynamicInvokeImpl (System.Object[] args) [0x00000] in <filename unknown>:0 
  at System.Delegate.DynamicInvoke (System.Object[] args) [0x00000] in <filename unknown>:0 
  at Rocket.Core.Extensions.MulticastDelegateExtension.TryInvoke (System.MulticastDelegate theDelegate, System.Object[] args) [0x00000] in <filename unknown>:0 
c#
sql
unity3d
asked on Stack Overflow Feb 28, 2017 by Plugin4U • edited Nov 20, 2020 by Dharman

1 Answer

2

Your problem is this line:

id.m_FriendsGroupID = (short)player.SteamGroupID.m_SteamID;

The m_SteamID value is likely an int and too large to fit inside a variable of type short. The best solution here would be to make sure id.m_FriendsGroupID is also of type int and remove the cast to short.

answered on Stack Overflow Feb 28, 2017 by DavidG

User contributions licensed under CC BY-SA 3.0