Skip to content

Instantly share code, notes, and snippets.

@rdeioris
Created March 16, 2018 18:22
Show Gist options
  • Save rdeioris/2b42ae59c05278ca252f349080b42858 to your computer and use it in GitHub Desktop.
Save rdeioris/2b42ae59c05278ca252f349080b42858 to your computer and use it in GitHub Desktop.
System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Steamworks;
using Aiv.Fast2D;
namespace SteamIntegration
{
class Program
{
static void Main(string[] args)
{
Window window = new Window(1024, 576, "Steam Test");
if (!SteamAPI.Init())
{
Console.WriteLine("steam failed");
}
Callback<GameOverlayActivated_t> overlayCallback = Callback<GameOverlayActivated_t>.Create(
(callback) =>
{
Console.WriteLine(callback.m_bActive);
}
);
Console.WriteLine(SteamFriends.GetPersonaName());
int numberOfFriends = SteamFriends.GetFriendCount(EFriendFlags.k_EFriendFlagAll);
for (int i = 0; i < numberOfFriends; i++)
{
CSteamID SteamId = SteamFriends.GetFriendByIndex(i, EFriendFlags.k_EFriendFlagAll);
Console.WriteLine(SteamFriends.GetFriendPersonaName(SteamId));
}
CSteamID clanId = CSteamID.Nil;
int numberOfClans = SteamFriends.GetClanCount();
for(int i=0;i<numberOfClans;i++)
{
clanId = SteamFriends.GetClanByIndex(i);
string clanName = SteamFriends.GetClanName(clanId);
if (clanName == "aiv01")
{
SteamFriends.JoinClanChatRoom(clanId);
break;
}
}
var clanChatCallback = Callback<GameConnectedClanChatMsg_t>.Create(
(callback) =>
{
string message;
EChatEntryType entryType;
CSteamID sender;
SteamFriends.GetClanChatMessage(callback.m_steamIDClanChat,
callback.m_iMessageID, out message, 100, out entryType, out sender);
Console.WriteLine(message);
}
);
var sessionCallback = Callback<P2PSessionRequest_t>.Create(
(callback) =>
{
// start accepting data from the specific user
Console.WriteLine("new user detected !!!");
SteamNetworking.AcceptP2PSessionWithUser(callback.m_steamIDRemote);
}
);
while (window.IsOpened)
{
if (window.GetKey(KeyCode.Space))
{
int membersCount = SteamFriends.GetClanChatMemberCount(clanId);
for(int i=0;i<membersCount;i++)
{
CSteamID clanMemberId = SteamFriends.GetChatMemberByIndex(clanId, i);
byte[] data = Encoding.ASCII.GetBytes("P2P packet from " + SteamFriends.GetFriendPersonaName(clanMemberId));
SteamNetworking.SendP2PPacket(clanMemberId, data, (uint)data.Length, EP2PSend.k_EP2PSendReliable);
}
//SteamFriends.SendClanChatMessage(clanId, "Hello from " + SteamFriends.GetPersonaName());
}
window.Update();
SteamAPI.RunCallbacks();
uint packetSize;
while(SteamNetworking.IsP2PPacketAvailable(out packetSize))
{
byte[] data = new byte[100];
uint truePacketLength;
CSteamID sender;
if (SteamNetworking.ReadP2PPacket(data, 100, out truePacketLength, out sender))
{
Console.WriteLine(Encoding.ASCII.GetString(data, 0, (int)truePacketLength));
}
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment