Basic task lookup
This commit is contained in:
		
							
								
								
									
										4
									
								
								.github/workflows/auth_test.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										4
									
								
								.github/workflows/auth_test.yml
									
									
									
									
										vendored
									
									
								
							@ -20,6 +20,10 @@ jobs:
 | 
				
			|||||||
        working-directory: authorizer
 | 
					        working-directory: authorizer
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
          dotnet add package StackExchange.Redis --version 2.1.39 --source https://www.myget.org/F/stackoverflow/api/v3/index.json
 | 
					          dotnet add package StackExchange.Redis --version 2.1.39 --source https://www.myget.org/F/stackoverflow/api/v3/index.json
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					          # AWS SDK
 | 
				
			||||||
 | 
					          dotnet add package AWSSDK.Core --version 3.5.0-beta
 | 
				
			||||||
 | 
					          dotnet add package AWSSDK.ECS --version 3.5.0-beta
 | 
				
			||||||
      - name: Build
 | 
					      - name: Build
 | 
				
			||||||
        working-directory: authorizer
 | 
					        working-directory: authorizer
 | 
				
			||||||
        run: |
 | 
					        run: |
 | 
				
			||||||
 | 
				
			|||||||
@ -30,6 +30,22 @@ class AuthServer
 | 
				
			|||||||
        server = new TcpListener(address, port);
 | 
					        server = new TcpListener(address, port);
 | 
				
			||||||
        ecs = new AmazonECSClient();
 | 
					        ecs = new AmazonECSClient();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Amazon.ECS.Model.Task GetTask(string task_arn)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        // Builds ECS Request
 | 
				
			||||||
 | 
					        DescribeTasksRequest r = new DescribeTasksRequest();
 | 
				
			||||||
 | 
					        List<string> tasks = new List<string>();
 | 
				
			||||||
 | 
					        tasks.Add(task_arn);
 | 
				
			||||||
 | 
					        r.Tasks = tasks;
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        //Send Describe Tasks Request
 | 
				
			||||||
 | 
					        var t = ecs.DescribeTasksAsync(r);
 | 
				
			||||||
 | 
					        t.RunSynchronously();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        //Return result
 | 
				
			||||||
 | 
					        return t.Result.Tasks[0];
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
    private void ServerLoop()
 | 
					    private void ServerLoop()
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
        while(running)
 | 
					        while(running)
 | 
				
			||||||
@ -49,29 +65,33 @@ class AuthServer
 | 
				
			|||||||
                Byte[] bytes = new byte[256];
 | 
					                Byte[] bytes = new byte[256];
 | 
				
			||||||
                String data = null;
 | 
					                String data = null;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                long num_of_tasks = redis.conn.ListLength("tasks");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                writer.Write("Hey there bud!");
 | 
					                if(num_of_tasks > 0)
 | 
				
			||||||
                writer.Flush();
 | 
					                {
 | 
				
			||||||
                Console.WriteLine("HERE");
 | 
					                    
 | 
				
			||||||
 | 
					                    var task = GetTask(redis.conn.ListGetByIndex("tasks",0));
 | 
				
			||||||
 | 
					                    int port = task.Containers[0].NetworkBindings[0].HostPort;
 | 
				
			||||||
 | 
					                    string hostname = task.Containers[0].NetworkBindings[0].BindIP;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                byte[] sendBytes = System.Text.Encoding.ASCII.GetBytes("GET / HTTP/1.1");
 | 
					                    writer.Write("server:" + hostname + ":" + port.ToString());
 | 
				
			||||||
                stream.Write(sendBytes, 0, sendBytes.Length);
 | 
					                    writer.Flush();
 | 
				
			||||||
                client.Client.Send(sendBytes);
 | 
					                    Console.WriteLine("Routed client to " + hostname + ":" + port.ToString());
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					                else
 | 
				
			||||||
                //BinaryWriter writer = new BinaryWriter(stream);
 | 
					                {
 | 
				
			||||||
                //writer.Write("TEST");
 | 
					                    string msg = "ERROR: No valid game server found!";
 | 
				
			||||||
 | 
					                    Console.WriteLine(msg);
 | 
				
			||||||
                
 | 
					                    writer.Write(msg);
 | 
				
			||||||
 | 
					                    writer.Flush();
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                //Read any client response
 | 
				
			||||||
                int i;
 | 
					                int i;
 | 
				
			||||||
 | 
					 | 
				
			||||||
                while((i = stream.Read(bytes, 0, bytes.Length)) != 0)
 | 
					                while((i = stream.Read(bytes, 0, bytes.Length)) != 0)
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
 | 
					                    data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
 | 
				
			||||||
                    Console.WriteLine("Recieved: {0}", data);
 | 
					                    Console.WriteLine("Recieved: {0}", data);
 | 
				
			||||||
 | 
					 | 
				
			||||||
    
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                
 | 
					                
 | 
				
			||||||
                client.Close();
 | 
					                client.Close();
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user