Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete deployment on aws #31

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
542 changes: 375 additions & 167 deletions terrastick/Deployment/scripts/aws.sh

Large diffs are not rendered by default.

7 changes: 0 additions & 7 deletions terrastick/Deployment/scripts/configs/aws-config.txt

This file was deleted.

10 changes: 10 additions & 0 deletions terrastick/Deployment/scripts/configs/aws-config.txt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PROFILE_NAME=default
ACCESS_KEY_ID=
SECRET_ACCESS_KEY=
REGION=eu-central-1
NUM_BOT_INSTANCES=2
INSTANCE_TYPE=t2.micro
BASE_AMI_ID=ami-0ec7f9846da6b0f61
WORLD_NAME=2022DistSys
TERRASTICK_VERSION=terrastick-test-v0.7
TERRASTICK_WORKLOAD=TEL
14 changes: 7 additions & 7 deletions terrastick/Deployment/scripts/configs/das-config.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
VUNET_USERNAME=aba448
NUM_NODES=4
RESERVE_DURATION=00:30:00
VUNET_USERNAME=abi354
NUM_NODES=6
RESERVE_DURATION=00:10:00
DAS_VERSION_TO_USE=5
DAS5_USERNAME=aba448
DAS6_USERNAME=aba448
DAS5_USERNAME=abi354
DAS6_USERNAME=abi354
WORLD_NAME=2022DistSys
TERRASTICK_VERSION=terrastick-test-v0.5
TERRASTICK_VERSION=terrastick-test-v0.7
TERRASTICK_WORKLOAD=TEL
TERRASTICK_IP=10.141.0.0
TERRASTICK_IP=10.141.0.0
10 changes: 10 additions & 0 deletions terrastick/Deployment/scripts/configs/das-config.txt.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
VUNET_USERNAME=
NUM_NODES=4
RESERVE_DURATION=00:10:00
DAS_VERSION_TO_USE=5
DAS5_USERNAME=
DAS6_USERNAME=
WORLD_NAME=2022DistSys
TERRASTICK_VERSION=terrastick-test-v0.7
TERRASTICK_WORKLOAD=TEL
TERRASTICK_IP=10.141.0.0
4 changes: 2 additions & 2 deletions terrastick/Deployment/scripts/das.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ remote_commands=$(cat <<CMD
sed -i "s/export TERRASTICK_IP=.*/export TERRASTICK_IP=10.141.0.\$(echo \$server_node | sed 's/node0*\([1-9][0-9]*\)/\1/' | grep -oE '[0-9]+')/" ~/.bashrc
sed -i 's/export TERRASTICK_WORKLOAD=.*/export TERRASTICK_WORKLOAD=TEL/' ~/.bashrc
source ~/.bashrc
ssh \$server_node 'cd ~/$DIR_NAME/server && screen -L -S server -d -m bash -c "./TShock.Server -world ~/$DIR_NAME/server/worlds/$WORLD_NAME.wld"' && echo "Server started on \$server_node"
ssh \$server_node 'cd ~/$DIR_NAME/server && screen -L -S server -d -m bash -c "./TShock.Server -port 7777 -maxplayers 20 -world ~/$DIR_NAME/server/worlds/$WORLD_NAME.wld "' && echo "Server started on \$server_node"
echo "waiting for server to start" && sleep 10

# start process exporter on server node
Expand All @@ -158,7 +158,7 @@ remote_commands=$(cat <<CMD
# start prometheus on prometheus node
sed -i "s/TERRASTICK_IP/\$TERRASTICK_IP/g" ~/$DIR_NAME/prometheus/prometheus-2.37.8.linux-amd64/prometheus-terrastick.yml
ssh \$prometheus_node 'cd ~/$DIR_NAME/prometheus/prometheus-2.37.8.linux-amd64 && screen -L -S prometheus -d -m bash -c "./prometheus --config.file=prometheus-terrastick.yml"' && echo "Prometheus started on \$prometheus_node"
# echo "waiting for prometheus to start" && sleep 10
# echo "waiting for prometheus to start and waiting for server to load up" && sleep 30

for node in \$bot_nodes; do
echo "Bot node: \$node"
Expand Down
68 changes: 62 additions & 6 deletions terrastick/PlayerEmulations/TrClient/TClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using TrProtocol;
using TrProtocol.Models;
using TrProtocol.Packets;
Expand Down Expand Up @@ -241,13 +242,48 @@ void UpdateSpawn(UpdatePlayer pkt)
this.RunTeleportWorkLoad(int.Parse(time));

}
if (pkt.Text._text.Contains("start") && this.workload == "WLK")
{
this.ChatText("Starting walk work load");
string time = pkt.Text._text.Split(' ')[2];

this.RunWalkWorkLoadAsync(int.Parse(time));

}
});




}

private async Task RunWalkWorkLoadAsync(int v)
{
int secs = v;
Random rand = new Random();
var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(v * 1000));

while (await timer.WaitForNextTickAsync())
{
var xPos = this.SpawnX;
var yPos = this.SpawnY;
var rand1 = new Random();
// random delta between -10 and 10
var deltaX = rand1.Next(-100, 100);

var newXPos = (rand.Next() >= 0.5) ? xPos + deltaX : xPos - deltaX;
await this.WalkPlayer(xPos, yPos, newXPos, yPos);
this.ChatText("Teleported to " + newXPos + " " + yPos);
if (secs-- == 0)
{
this.ChatText("WORKLOAD COMPLETE");
break;
}
}
timer.Dispose();
}


public bool connected = false;

public void GameLoop(string host, int port, string password)
Expand Down Expand Up @@ -310,19 +346,39 @@ public void TeleportPlayer(int x, int y)
// Home Position Y Single Home Position for Potion of Return, only sent if UsedPotionofReturn flag is true

});
this.SpawnX = x;
this.SpawnY = y;
}

public async Task WalkPlayer(int x1,int y1,int x2,int y2)
{
var lerp = new Vector2 { X = x1, Y = y1 };
var lerp2 = new Vector2 { X = x2, Y = y2 };
var timer = new PeriodicTimer(TimeSpan.FromMilliseconds(1000));
while (await timer.WaitForNextTickAsync())
{
lerp = Vector2.Lerp(lerp, lerp2, 0.5f);
Send(new UpdatePlayer
{
PlayerSlot = this.PlayerSlot,
Bit1 = 0,
Bit2 = 0,
Bit3 = 0,
Bit4 = 0,
SelectedItem = 0,
Position = new Vector2 { X = lerp.X, Y = lerp.Y },
Velocity = new Vector2 { X = lerp2.X - lerp.X, Y = lerp2.Y - lerp.Y }
});
this.SpawnX = (int)lerp.X;
this.SpawnY = (int)lerp.Y;
}
}
private void GameLoopInternal(string password)
{

Console.WriteLine("Sending Client Hello...");
Hello(CurRelease);

/*TcpClient verify = new TcpClient();
byte[] raw = Encoding.ASCII.GetBytes("-1551487326");
verify.Connect(new IPEndPoint(endPoint.Address, 7980));
verify.GetStream().Write(raw, 0, raw.Length);
verify.Close();*/

On<RequestPassword>(_ => Send(new SendPassword { Password = password }));
//On<StatusText>(_=> )
connected = true;
Expand Down
3 changes: 2 additions & 1 deletion terrastick/PlayerEmulations/TrClientTest/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ static void Main(string[] args)
{
string ip = "127.0.0.1";
string workload = "TEL";
string name = "BOT";
// name is botname and last 5 characters of hostname
string name = "BOT_" + Environment.MachineName.Substring(Environment.MachineName.Length - 5);
string logpath = "terrastick_bot_logs";

if (Environment.GetEnvironmentVariable("TERRASTICK_IP") != null)
Expand Down
7 changes: 7 additions & 0 deletions terrastick/PlayerEmulations/TrProtocol/Models/Vector2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,11 @@ public override string ToString()
{
return $"[{X}, {Y}]";
}
public static Vector2 Lerp(Vector2 origin,Vector2 dest, float amount)
{
var X = origin.X + (dest.X - origin.X) * amount;
var Y = origin.Y + (dest.Y - origin.Y) * amount;
return new Vector2(X, Y);

}
}