Coder Social home page Coder Social logo

sharptox's Introduction

SharpTox Build Status

This project aims to provide a simple library that wraps all of the functions found in the Tox library. Tox is a free (as in freedom) Skype replacement.

Feel free to contribute!

Things you'll need

  • The libtox(core, av and dns) library, you should compile that yourself from the ProjectTox GitHub repo. Guidelines on how to do this can be found here. If you don't feel like compiling this yourself, you can find automatic builds for windows here: x86 or x64

Depending on how you compiled the core libraries, the names of those may differ from the defaults in SharpTox. Be sure to change the value of the const string dll in ToxFunctions.cs, ToxAvFunctions.cs, ToxDnsFunctions.cs and ToxEncryptionFunctions.cs accordingly if needed.

Compiling and Testing

Assuming you have the libraries mentioned above installed, it's time to compile (and test) SharpTox.

Windows
  • Clone this repository.
  • Open SharpTox.sln in Visual Studio.
  • Let Visual Studio restore the NuGet packages and build the solution.
  • Optionally, run the tests by clicking 'Run All' in the Test Explorer.

Or from the command line (Be sure to install NUnit and NuGet first):

git clone https://github.com/alexbakker/SharpTox
nuget restore
msbuild /p:Configuration:Debug
nunit-console-x86 SharpTox.Tests/bin/Debug/SharpTox.Tests.dll
Linux
  • Install 'mono-complete' (this should include nunit), grab the latest version of NuGet and execute the following commands:
git clone https://github.com/alexbakker/SharpTox
mono NuGet.exe restore
xbuild /p:Configuration="Debug POSIX"
nunit-console4 SharpTox.Tests/bin/Debug/SharpTox.Tests.dll

If you're having issues obtaining the NuGet packages, try executing: mozroots --import --sync

Looking for precompiled binaries? Check this.

Basic Usage

using System;
using SharpTox.Core;

class Program
{
    static Tox tox;

    static void Main(string[] args)
    {
        ToxOptions options = new ToxOptions(true, true);

        tox = new Tox(options);
        tox.OnFriendRequestReceived += tox_OnFriendRequestReceived;
        tox.OnFriendMessageReceived += tox_OnFriendMessageReceived;

        foreach (ToxNode node in Nodes)
            tox.Bootstrap(node);

        tox.Name = "SharpTox";
        tox.StatusMessage = "Testing SharpTox";

        tox.Start();

        string id = tox.Id.ToString();
        Console.WriteLine("ID: {0}", id);

        Console.ReadKey();
        tox.Dispose();
    }

    //check https://wiki.tox.im/Nodes for an up-to-date list of nodes
    static ToxNode[] Nodes = new ToxNode[]
    {
        new ToxNode("192.254.75.98", 33445, new ToxKey(ToxKeyType.Public, "951C88B7E75C867418ACDB5D273821372BB5BD652740BCDF623A4FA293E75D2F")),
        new ToxNode("144.76.60.215", 33445, new ToxKey(ToxKeyType.Public, "04119E835DF3E78BACF0F84235B300546AF8B936F035185E2A8E9E0A67C8924F"))
    };

    static void tox_OnFriendMessageReceived(object sender, ToxEventArgs.FriendMessageEventArgs e)
    {
        //get the name associated with the friendnumber
        string name = tox.GetFriendName(e.FriendNumber);

        //print the message to the console
        Console.WriteLine("<{0}> {1}", name, e.Message);
    }

    static void tox_OnFriendRequestReceived(object sender, ToxEventArgs.FriendRequestEventArgs e)
    {
        //automatically accept every friend request we receive
        tox.AddFriendNoRequest(e.PublicKey);
    }
}

Contact

  • Join the official IRC channel #tox-dev on freenode Official Tox Dev IRC Channel

sharptox's People

Contributors

alexbakker avatar impyy avatar schulz3000 avatar txdv avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sharptox's Issues

Incorrect pinvoke signatures

Hello,

I see the following comment in \Toxy-future\Toxy-future\Toxy\Managers\ProfileManager.cs:

//why does this always return true?!?
if (data.IsEncrypted)

The Dllimport signatures for all the libtox functions appear to be using the wrong MarshalAs parameter.

Example:

[return: MarshalAs(UnmanagedType.Bool)]
internal static extern bool IsDataEncrypted(byte[] data);

Change the MarshalAs parameter to UnmanagedType.I1 as thats how the CLR marshals C-Style (8-bit) BOOLEAN values.

Example:
[return: MarshalAs(UnmanagedType.I1)]
internal static extern bool IsDataEncrypted(byte[] data);

This results in the correct result in my local tests... I'm entirely not sure why the libtox build is compiling their (32bit) bool types as (8bit) BOOLEAN but until they sort that out you'll have to change all your pinvoke signature to use MarshalAs(UnmanagedType.I1).

Hope it helps
-dmex

System.BadImageFormatException

System.BadImageFormatException: 'Kan bestand of assembly SharpTox, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null of een van de afhankelijkheden hiervan niet laden. Poging om een programma te laden met een onjuiste indeling.'

I seem to have this weird exception pointing towards the start of my application "Application.Run(new FileLoader());"
The callstack points towards external code and the line I mentioned.

Task.Delay cause tox offline

In tox loop.

while (_running)
{
      if (_cancelTokenSource.IsCancellationRequested)
          break;

      int delay = DoIterate();
      await Task.Delay(delay);
}

Task.Delay was used to sleep for some time. But if the threads in thread pool are not enough, it will take 500ms to create a new thread. This may cause tox offline. I recommend to use Thread.sleep instead.

Building a client

After some trouble i finally have an error free copy of this repo.

But what now?
Where to start?
Which funtions are available?

Do you have any documentation (on how to build an own Tox messenger in C#)?

Application crashes

My application crashes when friend goes offline, simply closing the application.

Window journal log:

Application: powershell_ise.exe
Platform Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Details: System.AccessViolationException
Stack:
   in SharpTox.Core.ToxFunctions.Iterate (SharpTox.Core.ToxHandle)
   in SharpTox.Core.Tox.DoIterate ()
   in SharpTox.Core.Tox + << Loop> b__57_0> d.MoveNext ()
   in System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.InvokeMoveNext (System.Object)
   in System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   in System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   in System.Runtime.CompilerServices.AsyncMethodBuilderCore + MoveNextRunner.Run ()
   in System.Threading.Tasks.AwaitTaskContinuation.RunOrScheduleAction (System.Action, Boolean, System.Threading.Tasks.Task ByRef)
   in System.Threading.Tasks.Task.FinishContinuations ()
   in System.Threading.Tasks.Task.FinishStageThree ()
   in System.Threading.Tasks.Task`1 [[System.Threading.Tasks.VoidTaskResult, mscorlib, Version = 4.0.0.0, Culture = neutral, PublicKeyToken = b77a5c561934e089]]. TrySetResult (System.Threading.Tasks.VoidTaskResult)
   in System.Threading.Tasks.Task + DelayPromise.Complete ()
   in System.Threading.Tasks.Task + <> c__DisplayClass2. <Delay> b__5 (System.Object)
   in System.Threading.TimerQueueTimer.CallCallbackInContext (System.Object)
   in System.Threading.ExecutionContext.RunInternal (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   in System.Threading.ExecutionContext.Run (System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean)
   in System.Threading.TimerQueueTimer.CallCallback ()
   in System.Threading.TimerQueueTimer.Fire ()
   in System.Threading.TimerQueue.FireNextTimers ()
   in System.Threading.TimerQueue.AppDomainTimerCallback ()

Garbage collection

The callback delegates tend to be collected by the GC.
This causes exceptions when those get called.

Making those delegates class members should solve this issue.

System.AccessViolationException win7 x32 but x64 no problem

应用程序: FreeChat.exe
Framework 版本: v4.0.30319
说明: 由于未经处理的异常,进程终止。
异常信息: System.AccessViolationException
堆栈:
在 SharpTox.Encryption.ToxEncryptionFunctions.PassEncrypt(Byte[], UInt32, Byte[], UInt32, Byte[], SharpTox.Encryption.ToxErrorEncryption ByRef)
在 SharpTox.Encryption.ToxEncryption.EncryptData(Byte[], System.String, SharpTox.Encryption.ToxErrorEncryption ByRef)
在 SharpTox.Core.Tox.GetData(System.String)
在 FreeChat.App.SaveData()
在 FreeChat.App.Start(System.String, System.String)
在 FreeChat.Form_LoginTox.button_login_Click(System.Object, System.EventArgs)
在 System.Windows.Forms.Control.OnClick(System.EventArgs)
在 System.Windows.Forms.Button.OnClick(System.EventArgs)
在 System.Windows.Forms.Button.OnMouseUp(System.Windows.Forms.MouseEventArgs)
在 System.Windows.Forms.Control.WmMouseUp(System.Windows.Forms.Message ByRef, System.Windows.Forms.MouseButtons, Int32)
在 System.Windows.Forms.Control.WndProc(System.Windows.Forms.Message ByRef)
在 System.Windows.Forms.ButtonBase.WndProc(System.Windows.Forms.Message ByRef)
在 System.Windows.Forms.Button.WndProc(System.Windows.Forms.Message ByRef)
在 System.Windows.Forms.Control+ControlNativeWindow.OnMessage(System.Windows.Forms.Message ByRef)
在 System.Windows.Forms.Control+ControlNativeWindow.WndProc(System.Windows.Forms.Message ByRef)
在 System.Windows.Forms.NativeWindow.Callback(IntPtr, Int32, IntPtr, IntPtr)
在 System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG ByRef)
在 System.Windows.Forms.Application+ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr, Int32, Int32)
在 System.Windows.Forms.Application+ThreadContext.RunMessageLoopInner(Int32, System.Windows.Forms.ApplicationContext)
在 System.Windows.Forms.Application+ThreadContext.RunMessageLoop(Int32, System.Windows.Forms.ApplicationContext)
在 System.Windows.Forms.Application.RunDialog(System.Windows.Forms.Form)
在 System.Windows.Forms.Form.ShowDialog(System.Windows.Forms.IWin32Window)
在 System.Windows.Forms.Form.ShowDialog()
在 FreeChat.Form_StartChat..ctor()
在 FreeChat.Program.Main(System.String[])

xbuild issue

Good day,

Im getting 31 Errors after executing
xbuild /p:Configuration="Debug POSIX"

Whole process that I did:
Install TOXCORE
sudo apt-get install build-essential libtool autotools-dev automake checkinstall check git yasm libsodium13 libsodium-dev
sudo apt-get install libopus-dev libvpx-dev pkg-config
git clone https://github.com/irungentoo/toxcore.git toxcore
cd toxcore
autoreconf -i
./configure
make
sudo make install

Sharp TOX
sudo apt-get install mono-complete
sudo apt install nuget
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0328081BFF6A14DA29AA6A19B38D3D831EF
echo "deb http://download.mono-project.com/repo/debian wheezy main" | sudo tee /etc/apt/sources.list.d/mono-xamarin.list
sudo apt-get update
sudo apt-get install ca-certificates-mono
sudo nuget restore
xbuild /p:Configuration="Debug POSIX"
FAILED HERE

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.