Skip to main content

Overview

ACHCE Client uses Firebase Realtime Database to manage player connections and track active sessions. This guide walks you through setting up Firebase and integrating it with the application.

Prerequisites

Before you begin, ensure you have:
  • A Google account
  • Visual Studio with .NET Framework 4.7.2 or higher
  • NuGet Package Manager

Firebase Project Setup

1

Create a Firebase Project

  1. Go to the Firebase Console
  2. Click Add Project
  3. Enter a project name (e.g., “ACHCE-Client”)
  4. Follow the setup wizard to create your project
2

Enable Realtime Database

  1. In the Firebase Console, navigate to Build > Realtime Database
  2. Click Create Database
  3. Choose a database location (select the closest region to your users)
  4. Start in Test mode for development (configure security rules later)
3

Get Database Credentials

  1. In the Realtime Database section, note your Database URL (e.g., https://your-project.firebaseio.com/)
  2. Navigate to Project Settings (gear icon) > Service accounts
  3. Click Database secrets
  4. Copy your Legacy token (AuthSecret)
Keep your AuthSecret private. Never commit it to version control.

Install FireSharp Package

The ACHCE Client uses FireSharp 2.0.4 to communicate with Firebase Realtime Database.
1

Install via NuGet Package Manager

Open the Package Manager Console in Visual Studio and run:
Install-Package FireSharp -Version 2.0.4
2

Verify Installation

Check that packages.config includes the following packages:
<package id="FireSharp" version="2.0.4" targetFramework="net472" />
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net472" />
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net472" />

Configure Firebase Connection

The Firebase configuration is defined in the main form class (Form1.cs). Here’s how to set it up:

Firebase Configuration Object

The application uses the IFirebaseConfig interface to configure the connection:
Form1.cs:24-28
IFirebaseConfig fcon = new FirebaseConfig()
{
    AuthSecret = "", // token Firebase
    BasePath = "" // link firebase
};
1

Add Firebase Credentials

Replace the empty strings with your Firebase credentials:
IFirebaseConfig fcon = new FirebaseConfig()
{
    AuthSecret = "your-legacy-token-here",
    BasePath = "https://your-project.firebaseio.com/"
};
AuthSecret
string
required
Your Firebase legacy token (database secret). This authenticates your application with Firebase.
BasePath
string
required
Your Firebase Realtime Database URL. Must end with a trailing slash.
2

Initialize Firebase Client

The client is initialized when the form loads:
Form1.cs:32-42
IFirebaseClient client;

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.");
    }
    // ... rest of initialization
}
The try-catch block handles connection errors gracefully by displaying a message if Firebase is unreachable.

Database Structure

ACHCE Client stores player information in the following structure:
{
  "PlayerIpList": {
    "RandomPlayerName1": {
      "IP": "123.456.789.0"
    },
    "RandomPlayerName2": {
      "IP": "98.765.432.1"
    }
  }
}

Writing Data

When a player connects, their IP address is stored with a randomly generated name:
Form1.cs:58-69
private void PlayAcON()
{
    Player ply = new Player()
    {
        IP = IpPlayer,
    };
    // informacion del cliente que se agrega a la base de datos
    var setter = client.Set("PlayerIpList/" + randomName, ply);
}

Deleting Data

When the application closes, the player data is removed from the database:
Form1.cs:100-104
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    var result = client.Delete("PlayerIpList/" + randomName);
    MessageBox.Show("data deleted successfully");
}

Security Considerations

Production Security RulesBefore deploying to production, configure proper Firebase security rules to restrict database access. Test mode rules allow anyone to read/write your database.
Recommended security rules for production:
{
  "rules": {
    "PlayerIpList": {
      ".read": "auth != null",
      ".write": "auth != null"
    }
  }
}

Troubleshooting

Connection Failed Error

If you see “there was problem in the internet”:
  • Verify your internet connection
  • Check that the BasePath URL is correct and ends with /
  • Confirm your AuthSecret is valid
  • Ensure Firebase Realtime Database is enabled in your project

Authentication Errors

  • Make sure you’re using the Legacy token from Database secrets
  • Verify the token hasn’t been revoked in Firebase Console
  • Check that your Firebase project has billing enabled (if required)

Data Not Appearing

  • Open the Firebase Console and navigate to Realtime Database
  • Check the Data tab to see if entries are being created
  • Verify your database rules allow writes
  • Ensure the Player class properties match the expected structure

Next Steps

Client Configuration

Configure application settings and behavior

Getting Started

Set up the development environment

Build docs developers (and LLMs) love