Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi guys, I have a game server running on ubuntu 14.. So there are 2 servers for the specific game and each of them is kept in different screens such as:
Quote:
screen -ls
There are screens on:
1663.cave (21/10/15 02:20:21) (Detached)
1657.world (21/10/15 02:20:20) (Detached)
2 Sockets in /var/run/screen/S-gingercook.
If you turn back to each screen it opens a remote console for each specific server and from there you can enter commands that is specific to the game such as banning people, killing etc..
These game commands are too long and i want to simplify it. For example when i select a player instead of the command
c_select(AllPlayers[4])
I want to simplify it as
p'4'
so linux would send c_select(AllPlayers[4]) to the game console.. Is it possible to do such a thing.. i have some idea about shell scripting, it is kind of a real beginner but i know basic statements and such.
And then accept arguments so that you could use 1, 2, 3, 4, A, or other stuff. But the syntax would not match what you show.
Further, you could create an alias. You can try that manually in the command line and when you get it right you can insert it into a profile file, like .bashrc in your home directory.
Also the same issue is that the syntax would not be exactly as you've envisioned:
Code:
$ alias p4=c_select\(AllPlayers[4]\)
Would work, but putting the single quotes or even other things like parentheses around the 4 in the first term gets rejected, even if I try to escape it using \. Type 'alias' to see what aliases you do have defined and once you successfully create one you can type the left side to validate that you got it working properly.
If so, you would want to add public ssh keys from your machine to the authorized_keys file on the server, so you don't need to enter the passwords when connecting to the server.
Further you could create aliases for the remote machines in the .ssh/config file on your machine, to have easy access to the servers.
Then you could use "ssh <alias_to_server> <command_to_execute>" to send the commands from your machine to the servers.
For these commands you can then generate aliases or use a shell script.
And then accept arguments so that you could use 1, 2, 3, 4, A, or other stuff. But the syntax would not match what you show.
Further, you could create an alias. You can try that manually in the command line and when you get it right you can insert it into a profile file, like .bashrc in your home directory.
Also the same issue is that the syntax would not be exactly as you've envisioned:
Code:
$ alias p4=c_select\(AllPlayers[4]\)
Would work, but putting the single quotes or even other things like parentheses around the 4 in the first term gets rejected, even if I try to escape it using \. Type 'alias' to see what aliases you do have defined and once you successfully create one you can type the left side to validate that you got it working properly.
Thank you very much.. But the problem is, since game console in screen is a different environment, so I should enter this p4 into the game console and then linux should take this command and replace it with c_select(AllPlayers[4])
Is the game console a regular terminal window or part of the game? By regular terminal window are you entering the command like:
[user@server:~]$ game c_select(AllPlayers[4])
If the console is actually the game then an alias or other terminal shortcut as far as I know is not going to work. That would require you to change the game source code.
Is the game console a regular terminal window or part of the game? By regular terminal window are you entering the command like:
[user@server:~]$ game c_select(AllPlayers[4])
If the console is actually the game then an alias or other terminal shortcut as far as I know is not going to work. That would require you to change the game source code.
It is don't starve together.. And you don't enter commands to terminal. So console is the game console where all logs can be seen and such...
The remote console is something like this.
Quote:
0032
[SHARD] CLOSE CONNECTION for 2752831393
CloseConnectionWithReason: ID_DST_SHARD_SILENT_DISCONNECT
[Steam] UserDisconnect successfully sent for steamid '76561198102297818'
[SHARD] Received disconnect notification for 'KU_ZnDkO0Ka' on server '[SHDMASTER](1)' ('[SHDMASTER](1)')
[SHARD] Migration of player 'KU_ZnDkO0Ka' to 'caves(485967294)' (14) succeeded
[SHARD] Writing save location file for 'KU_ZnDkO0Ka'
[SHARD] Save location file written! /home/gingercook/.klei/DoNotStarveTogether/save/session/FFFFFFFF896B1359/KU_ZnDkO0Ka_/savelocation c_listallplayers''
ConsoleInput: "c_listallplayers''"
[1] BluAngel <wilson>
[2] paul <woodie>
[3] Fabioty <wx78>
[4] Ghostmin <willow>
[5] klik2001 <wathgrithr>
where c_listallplayers''
is a console input that i entered. Basically it is a different environment.. Not terminal. It is a program that you download from steamcmd so it has its very own console like any other game server on steamcmd. Then the only way is to change source code?
Instead of attaching to the screen session and then typing the command, you might consider sending commands to the screen session remotely from your shell (detached from screen).
The command to do this would look something like this:
My suggestion obviously doesn't help of you don't know the player number etc, as you can't "see" the detached session :-(
If you still want to consider that approach, though, an external "listplayers" command might be achieved by sending the command, then using the "hardcopy" screen command to capture what is on the screen, and viewing that. For example:
Instead of attaching to the screen session and then typing the command, you might consider sending commands to the screen session remotely from your shell (detached from screen).
The command to do this would look something like this:
Where "-p 1" is the screen window number in which your game console is running, and "^M" is a carriage return (can be entered with Ctrl-V Ctrl-M).
This in turn can easily be wrapped in a script called "p" which takes "cave" (the screen session) and "4" (the player number) as arguments.
Actually the thing is, whatever is entered to the console is saved simultaneously to a file called log.txt (all server operations in console (not only commands, player leave, announcements, any operations that is made in server etc) is saved in this file) in server files... So I guess linux can get this console input from log.txt file and then can edit and resent to the game console..
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.