You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 2.0 kB

3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using CommandLine;
  2. using Grpc.Core;
  3. using Protobuf;
  4. namespace Server
  5. {
  6. public class Program
  7. {
  8. static ServerBase CreateServer(ArgumentOptions options)
  9. {
  10. return options.Playback ? new PlaybackServer(options) : new GameServer(options);
  11. }
  12. static int Main(string[] args)
  13. {
  14. foreach (var arg in args)
  15. {
  16. Console.Write($"{arg} ");
  17. }
  18. Console.WriteLine();
  19. ArgumentOptions? options = null;
  20. _ = Parser.Default.ParseArguments<ArgumentOptions>(args).WithParsed(o => { options = o; });
  21. if (options == null)
  22. {
  23. Console.WriteLine("Argument parsing failed!");
  24. return 1;
  25. }
  26. Console.WriteLine("Server begins to run: " + options.ServerPort.ToString());
  27. try
  28. {
  29. var server = CreateServer(options);
  30. Grpc.Core.Server rpcServer = new Grpc.Core.Server(new[] { new ChannelOption(ChannelOptions.SoReuseport, 0) })
  31. {
  32. Services = { AvailableService.BindService(server) },
  33. Ports = { new ServerPort(options.ServerIP, options.ServerPort, ServerCredentials.Insecure) }
  34. };
  35. rpcServer.Start();
  36. Console.WriteLine("Server begins to listen!");
  37. server.WaitForEnd();
  38. Console.WriteLine("Server end!");
  39. rpcServer.ShutdownAsync().Wait();
  40. Thread.Sleep(50);
  41. Console.WriteLine("");
  42. Console.WriteLine("=================== Final Score ====================");
  43. Console.WriteLine($"Studnet: {server.GetScore()[0]}");
  44. Console.WriteLine($"Tricker: {server.GetScore()[1]}");
  45. }
  46. catch (Exception ex)
  47. {
  48. Console.WriteLine(ex.ToString());
  49. }
  50. return 0;
  51. }
  52. }
  53. }