Skip to main content

Overview

The ACHCE Client application uses two main forms to manage the user interface and player lifecycle. Form1 (ACHCE) handles player initialization, database connection, and loading screen, while Form2 manages the main application window with fullscreen display.

Form1 (ACHCE)

The primary form that manages player connection, Firebase database integration, and the initial loading screen.

Class Definition

namespace vbEngC
{
    public partial class ACHCE : System.Windows.Forms.Form
    {
        // IP del jugador
        public string IpPlayer;
        // Nombre aleatorio para ingresar a la DATA BASE
        public string randomName;
    }
}

Properties

IpPlayer
string
Stores the player’s public IP address retrieved from the PublicIPAddress class.
randomName
string
Stores the randomly generated name used as the player’s unique identifier in the Firebase database.
client
IFirebaseClient
The Firebase client instance used for database operations.

Firebase Configuration

The form initializes a Firebase connection using the following configuration:
IFirebaseConfig fcon = new FirebaseConfig()
{
    AuthSecret = "", // token Firebase
    BasePath = "" // link firebase
};

IFirebaseClient client;
The AuthSecret and BasePath must be configured with your actual Firebase credentials before the application can connect to the database.

Methods

Form1_Load

Initializes the player session by creating a Firebase client, generating a random name, retrieving the player’s IP address, and adding the player to the database.
public void Form1_Load(object sender, EventArgs e)
{
    try
    {
        // nuevo cliente en la base de datos
        client = new FireSharp.FirebaseClient(fcon);
    }
    catch
    {
        MessageBox.Show("there was problem in the internet.");
    }

    // Clase para Generar nombres para el usuario
    GenerateRandomNames names = new GenerateRandomNames();
    Random rand = new Random();

    // Genera un nombre aleatorio
    randomName = names.GenerateRandomName(rand);

    // Obtener la ip del cliente
    PublicIPAddress IpAddressPlayer = new PublicIPAddress();
    IpPlayer = IpAddressPlayer.GetPublicIPAddress();

    PlayAcON();// agregar la informacion del cliente a la base de datos
}
Initialization Flow
  1. Firebase Connection: Creates a new Firebase client
  2. Error Handling: Displays a message if internet connection fails
  3. Name Generation: Creates a random identifier for the player
  4. IP Retrieval: Fetches the player’s public IP address
  5. Database Registration: Calls PlayAcON() to add player to database

PlayAcON

Adds the player’s information to the Firebase database under the PlayerIpList collection.
private void PlayAcON()
{
    Player ply = new Player()
    {
        IP = IpPlayer,
    };
    // informacion del cliente que se agrega a la base de datos, en este caso la ip con un nombre random
    var setter = client.Set("PlayerIpList/" + randomName, ply);
}
Database Path
string
Stores player data at PlayerIpList/{randomName} with the player’s IP address.

timer1_Tick

Monitors the player initialization process and transitions to Form2 when the IP address is retrieved.
private void timer1_Tick(object sender, EventArgs e)
{
    if (IpPlayer != null)
    {
        Form2 form2 = new Form2();
        this.Hide();
        timer2.Stop();
        form2.Show();
    }
}
Transition Logic
  • Condition: Waits until IpPlayer is populated
  • Action: Creates and shows Form2, hides Form1, stops timer2
  • Purpose: Ensures smooth transition from loading to main application

Timer2_Tick

Updates the loading screen with a visual indicator.
private void Timer2_Tick(object sender, EventArgs e)
{
    string texto = "/"; // Texto inicial
    int indice = 0; // Índice de la letra que se agregará

    // Verificar si se han agregado todas las letras
    if (indice < texto.Length)
    {
        // Agregar la siguiente letra al TextBox
        TextoCarga.Text += texto[indice];
        indice++;
    }
}

Form1_FormClosed

Removes the player from the database when the application is closed.
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    var result = client.Delete("PlayerIpList/" + randomName);
    MessageBox.Show("data deleted successfully");
}
This cleanup method ensures that players are automatically removed from the active player list when they exit the application, preventing stale data in the database.

Timers

timer1
Timer
Monitors player initialization and triggers the transition to Form2.
timer2
Timer
Updates the loading screen visual indicator.

Form2

The main application form that displays fullscreen content after player initialization.

Class Definition

namespace vbEngC
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
    }
}

Methods

Form2_Load

Configures the form to display in fullscreen mode based on the primary monitor’s resolution.
private void Form2_Load(object sender, EventArgs e)
{
    // Obtener la resolución del monitor principal
    Rectangle resolution = Screen.PrimaryScreen.Bounds;

    // Ajustar el tamaño de la ventana de la aplicación
    this.Size = new Size(resolution.Width, resolution.Height);

    // Ajustar la posición de la ventana de la aplicación
    this.Location = new Point((resolution.Width - this.Width), (resolution.Height - this.Height));
}
Display Configuration
Size
Size
Sets the form size to match the primary screen resolution for fullscreen display.
Location
Point
Positions the form at the top-left corner of the screen (0, 0).

pictureBox2_Click

Handles the exit button click event to close the application.
private void pictureBox2_Click(object sender, EventArgs e)
{
    Application.Exit();
}

Application Flow

// 1. Form1 loads
ACHCE form1 = new ACHCE();
form1.Load += Form1_Load;

// 2. Firebase client created
client = new FireSharp.FirebaseClient(fcon);

// 3. Generate random name
randomName = names.GenerateRandomName(rand);

// 4. Get player IP
IpPlayer = IpAddressPlayer.GetPublicIPAddress();

// 5. Add to database
PlayAcON();

Integration Example

Here’s how all components work together:
// Complete player lifecycle
public void Form1_Load(object sender, EventArgs e)
{
    // Step 1: Connect to Firebase
    try
    {
        client = new FireSharp.FirebaseClient(fcon);
    }
    catch
    {
        MessageBox.Show("there was problem in the internet.");
        return;
    }

    // Step 2: Generate unique identifier
    GenerateRandomNames names = new GenerateRandomNames();
    Random rand = new Random();
    randomName = names.GenerateRandomName(rand);

    // Step 3: Get player IP address
    PublicIPAddress IpAddressPlayer = new PublicIPAddress();
    IpPlayer = IpAddressPlayer.GetPublicIPAddress();

    // Step 4: Create player record
    Player ply = new Player()
    {
        IP = IpPlayer,
    };

    // Step 5: Store in database
    var setter = client.Set("PlayerIpList/" + randomName, ply);
}

Error Handling

Firebase Connection Errors

If the Firebase connection fails, a message box alerts the user: “there was problem in the internet.”Consider implementing retry logic or more specific error messages for production use.

Best Practices

  1. Network validation: Check internet connectivity before attempting Firebase operations
  2. Graceful degradation: Provide offline functionality when possible
  3. User feedback: Display clear error messages and loading indicators
  4. Resource cleanup: Always remove player data on application exit

UI Components

Form1 (Loading Screen)

  • TextoCarga: TextBox displaying loading progress indicator
  • timer1: Monitors initialization completion
  • timer2: Updates loading animation

Form2 (Main Window)

  • pictureBox2: Exit button image control
  • Fullscreen display: Auto-configured to primary monitor resolution

Build docs developers (and LLMs) love