Beispiel #1
0
        protected virtual bool Initialize()
        {
            Console.WriteLine("Initializing...");
            NetworkedEntity.InitializeTypes();

            if (IsMultiplayer)
            {
                Networking            = new ServerNetworking(NetworkPort, IsDedicated ? MaxClients : (MaxClients - 1));
                Networking.Connected += (o, e) =>
                {
                    RemoteClient.Create(e.Connection);
                    Console.WriteLine("Remote hail: " + e.Connection.RemoteHailMessage);
                };

                Networking.Disconnected += (o, e) =>
                {
                    long id         = e.Connection.UniqueID;
                    bool deliberate = true; // true means disconnected, false means timed out
                    ClientDisconnected(Client.GetByID(id), deliberate);
                    Client.AllClients.Remove(id);
                };
            }

            return(true);
        }
Beispiel #2
0
        public void Startup(IServiceProvider serviceProvider)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            _logger = serviceProvider.GetRequiredService <ILogger>();

            _engine = serviceProvider.GetRequiredService <IServerEngine>();

            _engineModels = serviceProvider.GetRequiredService <IServerModels>();

            if (_engine.IsDedicatedServer)
            {
                GameBridge = Shared.Bridge.GameBridge.CreateBridge(null);
            }
            else
            {
                GameBridge = (GameBridge)serviceProvider.GetRequiredService <IBridge>();
            }

            _networking = serviceProvider.GetRequiredService <ServerNetworking>();

            _entities = serviceProvider.GetRequiredService <ServerEntities>();

            _entities.Startup();
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            AuxiliaryServerWorker.WriteInfo("Welcome to the AntVault 3 server.");
            AuxiliaryServerWorker.WriteInfo("Write /Start to get started!");
            string Command = Console.ReadLine();

            while (Command.ToLower() != "/exit")
            {
                if (Command.ToLower() == "/start")
                {
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    ServerNetworking.StartServer();
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
                    Command = Console.ReadLine();
                }
                else if (Command.ToLower() == "/stop")
                {
                    ServerNetworking.StopServer();
                    Command = Console.ReadLine();
                }
                else if (Command.ToLower().StartsWith("/updatestatus"))
                {
                    Command = Command + ";";
                    string NewStatus = AuxiliaryServerWorker.GetElement(Command, " ".ToUpperInvariant(), ";");
                    MainServerWorker.UpdateStatus(NewStatus);
                    Command = Console.ReadLine();
                }
                else if (Command.ToLower().StartsWith("/aboutuser"))
                {
                    Command = Command + ";";
                    string UserToCheck = AuxiliaryServerWorker.GetElement(Command, " ".ToUpperInvariant(), ";");
                    MainServerWorker.AboutUser(UserToCheck);
                    Command = Console.ReadLine();
                }
                else
                {
                    AuxiliaryServerWorker.WriteError("Command not recognised");
                    Command = Console.ReadLine();
                }
            }
            if (Command.ToLower() == "/exit")
            {
                AuxiliaryServerWorker.WriteInfo("Application will exit in");
                AuxiliaryServerWorker.WriteInfo("5");
                Thread.Sleep(1000);
                AuxiliaryServerWorker.WriteInfo("4");
                Thread.Sleep(1000);
                AuxiliaryServerWorker.WriteInfo("3");
                Thread.Sleep(1000);
                AuxiliaryServerWorker.WriteInfo("2");
                Thread.Sleep(1000);
                AuxiliaryServerWorker.WriteInfo("1");
                Thread.Sleep(1000);
                Environment.Exit(0);
            }
        }
Beispiel #4
0
 //On Object Awake
 private void Awake()
 {
     //Check Singleton
     if (instance != null && instance != this)
     {
         Destroy(this);
     }
     else
     {
         instance = this;
     }
 }
    // Use this for initialization
    void Start()
    {
        Application.runInBackground = true;

        // RPC
        RPCHandler handler   = new RPCHandler();
        IRPCParser rpcParser = new RPCParser(handler);

        // Server
        ServerNetworking server = new ServerNetworking(rpcParser, 7777);

        server.CreateServer();

        Calculator calc = new Calculator(handler);
    }
Beispiel #6
0
    private void Awake()
    {
        Application.targetFrameRate = 60;

        ConsoleWriteRedirecter.Redirect();

        if (applicationId == -1)
        {
            applicationId = Network.Utils.GetIPBasedApplicationId();
        }


        NetworkInterface         = new ServerNetworking(connectToProfileServer ? profileServerSettings : null, gatewayServerSettings, applicationId);
        NetworkInterface.OnTick += () => { MainThreadQueuer.Instance.AddMessage(FireOnTick); };
        NPCManager    = new NPCManager(NetworkInterface);
        PlayerManager = new PlayerManager(NetworkInterface);

        NetworkInterface.StartService();
    }
Beispiel #7
0
        protected virtual void ShutDown()
        {
            Console.WriteLine("Server is shutting down");

            if (Networking != null)
            {
                Networking.Disconnect("Server is shutting down");
                Networking = null;
            }

            if (Client.LocalClient != null)
            {
                Client.LocalClient = null;
            }

            Client.AllClients.Clear();
            Entity.AllEntities.Clear();
            Entity.NetworkedEntities.Clear();

            InboundMessage.ToLocalClient.Clear();
            InboundMessage.ToLocalServer.Clear();

            Instance = null;
        }
 /// <summary>
 /// Starts the process of accepting client connections in a separate thread.
 /// </summary>
 private void AcceptConnectionsAsync()
 {
     _tcpState = ServerNetworking.AwaitClientConnections(80, ClientConnectionEstablished,
                                                         ClientConnectionFailed);
 }
Beispiel #9
0
 //On Object Destroy (Safeguard)
 public void OnDestroy()
 {
     instance = null;
 }
Beispiel #10
0
 public ServerForm()
 {
     InitializeComponent();
     serverApi = new ServerNetworking();
 }
Beispiel #11
0
        /// <summary>
        /// Initalise a game including the global settings.
        /// </summary>
        /// <param name="type">The Type of game to setup.</param>
        /// <param name="playerNames">List of player names.</param>
        public Game(char type, List <string> playerNames)
        {
            if (playerNames == null)
            {
                throw new ArgumentNullException("playerNames");
            }
            GameType = type;
            // Settings
            Round = 0;

            if (type != 'J')
            {
                Rounds               = Properties.Settings.Default.Rounds;
                CardsPerUser         = Properties.Settings.Default.Cards;
                NeverHaveI           = Properties.Settings.Default.NeverHaveI;
                RebootingTheUniverse = Properties.Settings.Default.Rebooting;
                Cheats               = Properties.Settings.Default.Cheats;

                // Deal First Hand
                PrepareDeck();
                List <Tuple <int, Card> > hands = new List <Tuple <int, Card> >();
                try
                {
                    hands = Dealer.Deal(GameSet, playerNames.Count, CardsPerUser);
                }
                catch (ApplicationException ex)
                {
                    MessageBox.Show("Error, game not started. " + ex.Message, "Game Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    Playable = false;
                    return;
                }

                // Setup Players
                Players = new List <Player>();
                int player = 0;
                foreach (string playerName in playerNames)
                {
                    List <Card> hand = new List <Card>();
                    foreach (Tuple <int, Card> card in hands.GetRange(player * CardsPerUser, CardsPerUser))
                    {
                        hand.Add(card.Item2);
                    }
                    Players.Add(new Player(playerName, hand));
                    if (Players[player].Name.ToLower().StartsWith("[bot]"))
                    {
                        BotCount++;
                    }
                    else
                    {
                        PlayerCount++;
                    }
                    player++;
                }

                //get game ready
                CurrentBlackCard = 0;

                HostNetwork  = new ServerNetworking(this);
                LocalPlayers = new List <ClientNetworking>();
                Stage        = 'W';
                Playable     = true;
                NextRound();
            }
            else
            {
                Players = new List <Cards.Player>();
                Players.Add(new Player(playerNames[0], new List <Card>()));
            }
        }