Example #1
0
    public void CmdSendMissile(string FromPlayer, string ToPlayer, int TileIndex)
    {
        int MyPosY      = (int)Mathf.Floor(TileIndex / 6);
        int MyPosX      = TileIndex - (MyPosY * 6);
        int PlayerIndex = MyGlobalController.PlayersNames.IndexOf(ToPlayer);

        if (MyGlobalController.PlayersShips[PlayerIndex][TileIndex] == GridElement.GridElementState.Occupied)
        {
            MyGlobalController.PlayersShips[PlayerIndex][TileIndex] = GridElement.GridElementState.Hit;
            MyNetworkController.CmdAppendToConsole(FromPlayer + " launched a missile on " + ToPlayer + " at (" + MyPosX + "," + MyPosY + ") and Hit...", NetworkController.Severities.Warning);

            if (CheckLossCondition(MyGlobalController.PlayersShips[PlayerIndex]))
            {
                RpcYouJustDied(ToPlayer);

                MyGlobalController.PlayersNames.RemoveAt(PlayerIndex);
                MyGlobalController.PlayersShips.RemoveAt(PlayerIndex);

                MyNetworkController.CmdAppendToConsole(ToPlayer + " Just lost all the ships... Goodbye...", NetworkController.Severities.Exception);
            }
        }
        else
        {
            MyNetworkController.CmdAppendToConsole(FromPlayer + " launched a missile on " + ToPlayer + " at (" + MyPosX + "," + MyPosY + ") and missed...", NetworkController.Severities.Info);
        }

        MemoryStream    MSS = new MemoryStream();
        MemoryStream    MSN = new MemoryStream();
        BinaryFormatter BF  = new BinaryFormatter();

        BF.Serialize(MSS, MyGlobalController.PlayersShips);
        BF.Serialize(MSN, MyGlobalController.PlayersNames);
        RpcSendShipsToClients(Convert.ToBase64String(MSS.GetBuffer()), Convert.ToBase64String(MSN.GetBuffer()));
    }
Example #2
0
    public override void OnStartLocalPlayer()
    {
        base.OnStartLocalPlayer();
        OnStartClient();
        string LanIP = GetComputer_LanIP();

        MyGlobalController.LogDebug("Client Started");

        MyGlobalController.LogDebug(MyGlobalController.MyPlayerName + " Launching CmdConnectPlayer");
        if (isServer)
        {
            MyGlobalController.PlayersNames = new List <string>();
            MyGlobalController.PlayersShips = new List <GridElement.GridElementState[]>();
            MyGlobalController.PlayersShips.Add(new GridElement.GridElementState[48]);
            MyGlobalController.PlayersNames.Add(MyGlobalController.WelcomeInputName.text);
            MyGlobalController.MyPlayerName = MyGlobalController.WelcomeInputName.text;
            MyNetworkController.CmdAppendToConsole(MyGlobalController.WelcomeInputName.text + " Connected as a Host.", NetworkController.Severities.Info);
            if (LanIP.Split('\n').Length > 2)
            {
                MyNetworkController.CmdAppendToConsole("Clients connecting to this Host should enter one of these HostIPs : " + LanIP, NetworkController.Severities.Warning);
            }
            else
            {
                MyNetworkController.CmdAppendToConsole("Clients connecting to this Host should enter this HostIP: " + LanIP, NetworkController.Severities.Warning);
            }

            MyGlobalController.SetState(GlobalController.GuiGlobalState.SetMyShips);
        }
        else
        {
            CmdConnectPlayer(MyGlobalController.WelcomeInputName.text, gameObject);
        }
    }