Jump to content
Sign in to follow this  
deguix

How to create server on Linux

Recommended Posts

This guide uses the Terminal almost all the way. This is not for everyone, you need some understanding of your Linux!

 

There are 2 versions of SQL available on Linux: 2017 (evaluation - but it's for 64 bit apps only) and 2000. This guide will follow the installation of 2000 - the game can only be run 32 bits...

 

Installing SQL 2000 under wine:

Note for 64 bits systems: for any wine/winetricks related instruction to SQL server and your top server, you have to add this:

env WINEARCH=win32 WINEPREFIX=~/.wine32

This is because Winetricks prevents dotnet20sp2 from installing into a 64 bits prefix - it is 32 bits only! Examples:

env WINEARCH=win32 WINEPREFIX=~/.wine32 winetricks winxp
env WINEARCH=win32 WINEPREFIX=~/.wine32 winetricks dotnet20sp2
...
env WINEARCH=win32 WINEPREFIX=~/.wine32 wine MSDE2000A
...

 

 

First, make sure you have wine and winetricks installed. Then, download MS SQL 2000 from here: https://www.microsoft.com/en-us/download/details.aspx?id=22661.

 

Then, to configure Wine to support SQL 2000, set it to win xp mode and install Net Framework 2.0 SP 2 and MDAC 2.8 (SP 2 is not needed but it is recommended):

winetricks winxp
winetricks dotnet20sp2
winetricks mdac28

Then, cd to folder where MSDE2000A.exe is and install it - Remember to use .wine32 folder instead of .wine to use the 32 bits prefix on a 64 bit system:

wine MSDE2000A.exe
wine ~/.wine/drive_c/MSDERelA/setup.exe DISABLEROLLBACK=1 BLANKSAPWD=1 DISABLENETWORKPROTOCOLS=0 SECURITYMODE=SQL

The installer will fail! When time out failures start appearing, do a ctrl+c to abort, then copy the remaining files over - - Remember to use .wine32 folder instead of .wine (on both parameters) to use the 32 bits prefix on a 64 bit system, and to use your user name instead of "myusername":

cp ~/.wine/drive_c/users/myusername/Temp/SqlSetup/Temp/*.* ~/.wine/drive_c/windows/system32/

Now installation is finished. Restart wine or computer (otherwise SQL service might not run). Then MSSQLSERVER service will start automatically when first running a program on wine on 32 bits prefix. You can also do the following to start it manually directly:

wine net start MSSQLSERVER

To start the program that controls the service, you can do the following:

wine "C:/Program Files/Microsoft SQL Server/80/Tools/Binn/sqlmangr.exe"

Sources:
http://mynixworld.info/2012/12/22/ms-sql-server-on-linux-yes-it-works/
https://appdb.winehq.org/objectManager.php?sClass=version&iId=11016

 

Before we continue, the dbs have to be in the same environment of the installed SQL server. That means, you are using the ~/.wine32/drive_c folder on 64 bits and ~/.wine/drive_c on 32 bits.


These folders are usually hidden, so you might need to unhide them first (you need to configure that in your system). Then unpack the db files to a folder inside that drive_c folder.

 

---

 

This guide will show how to setup SQuirreL SQL client. SQuirrel SQL and similar gui clients should be used for fully setup gui Linux environments and ease of use. This guide will assume you already installed the SQL server.

 

Setting up SQuirreL SQL client and connecting to server:

Installing:

Download it using your package manager - on Arch Linux it's named squirrel-sql.

After installing it, download MSSQL JDBC driver depending on the SQL version installed:

 

Setting up the SQL client:

Start the client, click the drivers tab on the left side of the window, then right click "Microsoft MSSQL Server JDBC Driver", then click modify.

Click "Extra Class Path" tab, then click "Add" button.

Now search for that file you just extracted. Then click "OK". On the bottom of window, you'll see "Driver class com.microsoft.sqlserver.jdbc.SQLServerDriver successfully registered for driver definition: Microsoft MSSQL Server JDBC Driver", that means it worked.

Now click the "Aliases" tab on left side of window. Then click the "+" sign button (create new alias).

Put any name, select "Microsoft MSSQL Server JDBC Driver". Now for the url, it's going to be like this:

jdbc:sqlserver://localhost:1433

localhost can be the ip of your SQL server, if not local, and the 1433 can be changed to another if you have another SQL 2000 instance running or are using another port for the SQL server.

The user name is sa, and:

  • SQL 2017: put the sa password given at installation.
  • SQL 2000: leave the pass blank.

Then click OK.

 

Connecting to SQL server:

Now start SQL server if not started yet:

  • SQL 2017: it already starts on system start.
  • SQL 2000: starts only if you manually run a wine command or run the SQL manager.

Then click "Aliases" tab again, select the connection you created, and click the Connect button.

 

To run SQL commands, there's a set of tabs: Objects, SQL, Hibernate, Monitor. Click the SQL tab. Now the torture will start. Type the commands in the SQL commands section and then click the first line, and click the "running guy"  button. If you did any mistakes, red text is going to appear on the bottom.

 

SQL Commands:

 

Now continuing, this is the tricky part for those who don't know the SQL language (like me) - you gotta attach using the SQL language (specifically, TSQL for SQL 2000)! The scripts that follow will be the same in all and any SQL clients.

 

Attaching the databases (using SQL 2000 language):

EXEC sp_attach_db @dbname = 'dbname',
    @filename1 = 'dbpathfile.mdf',
    @filename2 = 'dbpathfile.ldf';

   
Where dbname is the name of db (either 'accountserver' or 'gamedb'), the dbpathfile.mdf is the path to the db .mdf file in wine, like 'C:\folder\db.mdf' and dbpathfile.ldf is the path to the db .ldf in wine too. So for example:

EXEC sp_attach_db @dbname = 'accountserver',
    @filename1 = 'C:\games\top-server-db\accountserver_data.mdf',
    @filename2 = 'C:\games\top-server-db\accountserver_log.ldf';
EXEC sp_attach_db @dbname = N'gamedb',
    @filename1 = N'C:\games\top-server-db\gamedb_data.mdf',
    @filename2 = N'C:\games\top-server-db\gamedb_log.ldf';

 

Creating SQL logins (using SQL 2000 language):

Now you have to create the logins needed by the server. Type in:

EXEC sp_addlogin 'account', 'pass', 'db';

For example:

EXEC sp_addlogin 'pko_account', 'Y87dc#$98', 'AccountServer';
EXEC sp_addlogin 'pko_game', 'Y87dc#$98', 'GameDB';

 

Assigning ownership of databases to a SQL login (using SQL 2000 language):

Of course, changing the account names/passwords depending on server file cfgs. Then add the users to the dbs as owners, by typing in:

USE db;
EXEC sp_adduser 'account', 'account', 'db_owner';

For example:

USE AccountServer;
EXEC sp_adduser 'pko_account', 'pko_account', 'db_owner';
USE GameDB;
EXEC sp_adduser 'pko_game', 'pko_game', 'db_owner';

 

Creating in-game accounts:

 

Using one of the sql clients above, use the guide below:

But just in case the forums get deleted for some reason, it's a good idea to keep a summary of it here - first part to create account, second part to make it gm or not:

USE AccountServer;
INSERT INTO account_login (name, password) VALUES ('<Login>', '<PasswordMD5>')

USE GameDB;
INSERT INTO account (act_id, act_name, gm) VALUES ((SELECT MAX(act_id) + 1 FROM account), '<Login>', <GM-level>);


Getting the server up and running:

Now you also need to unpack the server files to a folder in the:

  • SQL 2000: wine environment used by SQL server.
  • SQL 2017: anywhere as long as you own the folder. It doesn't matter which wine prefix you use either. Databases need to be in the certain folder specified in SQL 2017 guide part.

When you do, run them. Now, if you run gameserver, you might run into some errors that usually won't happen in Windows:

  • "Bad allocation" error: Your server is using too much memory. 32 bit programs can use at most 4 GB of memory, but on Linux, for some reason, it can't use that much. Maybe even 2 GB is too much. I'm still not sure how to fix this, but the workaround is to load less things into 1 game server. Running linux with just barebones installed might help (which you would usually do on a dedicated server).
  • "Access Violation" error on GateServer: Regular IP's put at IP key on [ToClient] will make this error to appear. You have to put a long and invalid string on that field. 1231234h25giftuihfi223 is good, hdf8duity357hruasdklhfj is good too. Anything is good, as long as it's not an IP and is long (maybe over 16 bytes long).

 

(EXTRA) Running client on Linux notes:

The client can run on a 64 bits prefix wine as well, and performance is like on Windows for me. There are some things to take note that are as follows:

  • It's best to install wine-staging-nine - it has patches that improve dx 9 games. I didn't test the client with it yet, but it should work. Configure it at winecfg at Staging tab.
  • Some private server launchers will require wine-mono to be installed. Net Framework 4.0 might work too (look here: https://wiki.archlinux.org/index.php/wine#Installing_.NET_Framework_4.0). When installing SQL 2000, mono gets uninstalled from that prefix. You might want to create another prefix just for that.
  • The flash bug on the server selection screen has the workaround which is on wine online database. But there's another workaround found by me which only applies to a Linux with borderless and titlebar-less window management - just move the window to the top-left corner until it snaps there. Now Flash will draw normally like on Windows!

 

Removed sections:

 

Quote

Ignore this - this will stay here if Microsoft ever releases a 32 bit version of this or the game is made 64 bits... (or buy the bridge)

Installing SQL 2017:

More info on this new Microsoft development: https://docs.microsoft.com/en-us/sql/linux/

Yaourt or another AUR client is required to install it. These instructions use sudo or su for root priviledges, and follow yaourt usage:


yaourt -S mssql-server
sudo /opt/mssql/bin/mssql-conf setup

Then answer the following prompts:

  • Do you accept licence terms? "Yes"
  • Enter the SQL Server system administrator password: Type the password you would like the system admin to use. 8 chars long at least, with 3 of the 4 of the following: upper case letters, lower case letters, numbers, and symbols.
  • Confirm the SQL Server system administrator password: Same as above.

That's all - very simple!

 

Until you get to handle permissions on your db... then you'll get into the common Linux headache:

 

Permissions:

FIrst, you need to add yourself to mssql group:


sudo usermod -aG mssql myusername

Where username is the name of your user. This won't be enough to make SQL access the databases. To do that the files need to be owned by user mssql and group mssql, and also have make follow rights set for other dbs. The only way to do that is by moving all databases to /var/opt/mssql/data folder, and making sure the permissions as above are set. Here's the Terminal way to do it:

 


su #all following commands need root rights

Repeat the following for each database you have - remember upper/lower case matter on Linux:


#Copy database to mssql database folder
cp mydatabase.mdf /var/opt/mssql/data/mydatabase.mdf
cp mydatabase.ldf /var/opt/mssql/data/mydatabase.ldf

cd /var/opt/mssql/data

#Change user ownership to mssql
chown mssql mydatabase.mdf
chown mssql mydatabase.ldf

#Change group ownership to mssql
chgrp mssql mydatabase.mdf
chgrp mssql mydatabase.ldf

#Set the same rights as the other files in folder (in octal)
chmod 640 mydatabase.mdf
chmod 640 mydatabase.ldf

Then exit su block:


exit #Leaves su block

This process should allow all the dbs to be attached without any problems. Just remember the path to the files per database:


/var/opt/mssql/data/mydatabase.mdf
/var/opt/mssql/data/mydatabase.ldf


 

Quote

 

Ignore this - mstools doesn't work on SQL 2000 servers or below.

Setting up mstools and connecting to server:

Run the follows:


yaourt -S mssql-tools

This will install sqlcmd and bcp. Then we need to connect to server:


sqlcmd -S localhost,1433 -U username -P sapassword

localhost can be the ip of your SQL server, if not local, and the 1433 can be changed to another if you have another SQL 2000 instance running or are using another port for the SQL server.

The user name is sa, and:

  • SQL 2017: put the sa password given at installation.
  • SQL 2000: leave the pass blank.

Then click OK.

 

Then an interactive prompt will show up. Type the sql commands as they are in the next section.

 

 

Edited by deguix
  • Like 8
  • Thanks 1

Share this post


Link to post
Share on other sites

Cool, this will surely come in handy. I only have linux servers no windows server unfortunately.

 

Will definitely be trying this out =)


fa806971ebc265ed5ebee27896f16509.png

Share this post


Link to post
Share on other sites

First of all thank you for the tutorial, I feel more at home in a Linux environment than a Windows. However, I have a few questions for you.

 

Would it perhaps be possible to provide download links? For example, from the SQL server 2000 you used?

 

Is there a special reason why Arch linux was chosen? I feel more at home on a Debian environment.

Share this post


Link to post
Share on other sites

hmm, you're right, I forgot the download link: https://www.microsoft.com/en-us/download/details.aspx?id=22661

 

well, I'm used to Arch Linux - the instructions should basically be the same in others, except you would use a different package system. I made the guide more neutral, mentioned that wine and winetricks need to be installed first, and mentioned the MS SQL 2000 download link.

Edited by deguix

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...